// 引入JS
$ ( "#dateSure" ). on ( "click" ,function (){ // 点击事件
if (sendCardTypeId != null && $ ( "#dateSelectorOne" ). val () != "" ){
var startData = getDate ( $ ( "#dateSelectorOne" ). val ()) ;
var endData = DateAdd ( "m " , cardTimeLength , startData) ;
var endDataStr = moment(endData. getTime ()). format ( "YYYY-MM-DD HH:mm" ) ; // 将时间戳转为指定的时间格式 $ ( "#dateSelectorTwo" ). val (endDataStr) ;
}
})
$ (document). ready ( function (){ // 当页面加载时,就执行的方法
// 获取停车场列表
getParkingList () ;
// 根据用户Id获取车牌号
getLicensePlateByUserId () ;
getAccessToken () ;
}) ;
// 获取停车场Id
function test (parkingId){
sendParkingId = parkingId ;
getMonthlyCardTypeByParkingId (parkingId) ; // 调用方法,将值当做参数传给方法
}
$ . ajax ({ // 发送ajax请求
type : "POST" ,
url : cBaseurl + "/adminserver/normal/wxPublic/showAllParkingNameByMonthType" ,
dataType : "JSON" ,
data : {} ,
async : false ,
success : function (result) {
console. log (result) ;
if (result. status == 200 ) {
var backData = result. data ;
if (backData != null ){
var parkingInfoList = Array. of () ;
for ( var i= 0 ; ilength ; i++){
parkingInfoList. push ({ "parkingId" :backData[i]. parkingId , "value" :backData[i].parkingName}) ;
}
parkingSelect. updateWheel ( 0 , parkingInfoList) ;
}
} else {
alert ( " 参数异常!" ) ;
}
} ,
error : function (errorMsg) {
alert ( " 错误" + JSON. stringify (errorMsg)) ;
}
}) ;
// 发送ajax请求
$ . ajax ({
type : "POST" ,
url : cBaseurl + "/adminserver/normal/wxPublic/showAllParkingNameByMonthType" ,
dataType : "JSON" ,
data : {} ,
async : false ,
success : function(result){
if (result. status == 200 ) {
var backData = result. data ;
if (backData != null ){
var parkingInfoList = Array. of () ;
for ( var i= 0 ; ilength ; i++){
parkingId : backData[i]. parkingId ;
parkingName: backData[i].parkingName ;
}
}
} else {
alert ( " 参数异常!" ) ;
}
},
error : function (errorMsg) {
alert ( " 错误" + JSON. stringify (errorMsg)) ;
}
});
cardTypeStr += " class= 'item' > // 拼接字符串
" + monthData[i].cardTimeLength+" 个月"+ "
type= 'hidden' class= 'cardPrice' value= '"+ monthData[i].cardPrice+"' >
type= 'hidden' class= 'cardTimeLength' value= '"+ monthData[i].cardTimeLength+"' >
type= 'hidden' class= 'cardId' value= '"+ monthData[i].id+"' >
";
$ ( ". model " ). append (cardTypeStr) ;
$ ( ". model div " ). on ( "click" ,function (){
$ ( "#money" ). html ( "¥" + $ ( this ). find ( ". cardPrice " ). attr ( "value" ). toFixed ( 2 )) ; // 将值传给页面,并保留两位小数
totalMoney = $ ( this ). find ( ". cardPrice " ). attr ( "value" ) ;
cardTimeLength = $ ( this ). find ( ". cardTimeLength " ). attr ( "value" ) ;
sendCardTypeId = $ ( this ). find ( ". cardId " ). attr ( "value" ) ;
// 获取失效时间
getFaildate () ;
})
JSON. stringify // 将对象转为JSON格式
// 停车场列表,单选择器的使用
var parkingSelect = new MobileSelect ({
trigger : "#parkingId" ,
title : " 请选择停车场" ,
wheels : [
{ data :[
{ parkingId : '111' , value : ' 附近' } ,
]} ,
] ,
position : [ 0 ] ,
callback : function (indexArr , data){ // 回调函数,通过下标确定其值
test (data[ 0 ]. parkingId ) ;
}
}) ;
// 将时间戳转换日期格式
function formatDate (date , fmt) {
var finalTime = fmt ;
if ( /(y+)/ . test (finalTime)) {
finalTime = finalTime. replace (RegExp. $1 , (date. getFullYear () + '' ). substr ( 4 - RegExp. $1 . length )) ;
}
let o = {
'M+' : date. getMonth () + 1 ,
'd+' : date. getDate () ,
'h+' : date. getHours () ,
'm+' : date. getMinutes () ,
's+' : date. getSeconds ()
} ;
for ( let k in o) {
if ( new RegExp( `( ${k} )` ). test (finalTime)) {
let str = o[k] + '' ;
finalTime = finalTime. replace (RegExp. $1 , (RegExp. $1 . length === 1 ) ? str : this . padLeftZero (str)) ;
}
}
return finalTime ;
} ;
function padLeftZero (str) {
return ( '00' + str). substr (str. length ) ;
} ;
// 调用上面的方法,将时间戳转成时间格式 “yyyy-MM-dd hh:mm:ss”
monthDataTemp. startTime = self. formatDate ( new Date(monthDataTemp. startTime * 1000 ) , timeFormat) ;
monthDataTemp. endTime = self. formatDate ( new Date(monthDataTemp. endTime * 1000 ) , timeFormat) ;
// 使用vue 给div加个index下标,通过(obj.index)in licensePlate确定值
class= "wrapper" id= "index" >
class= "list" v-for= "(obj,index) in licensePlateData" >
class= "carLicensePlat" @click= "showOrHide(index)" > // 添加点击事件
class= "default" v-html= "obj.licensePlate" > v-if= "obj.isDefault" > 默认 ﹀ // 通过v-if进行vue条件约束
// 两种方式取值
在标签中: v-html = "obj.licensePlate" 也可以直接赋值: {{obj.licensePlate}} 保留两位小数: {{obj.licensePlate.toFixed(2)}}
//采用的是token传递用户的Id