|
- // pages/passCar/passCar.js
- let config = require('../../config/config.js')
- let Http = require('../../utils/HttpBasics')
- const app = getApp();
- Page({
- data: {
- park: null,
- carList: [],
- payList:[],
- addCar: null,
- tcq: 2,
- flag:''
- },
- /*车牌动态样式 */
- changeStyle: function () {
- var height = this.data.dataHeight == '150rpx' ? '80rpx' : '150rpx';
- var lineHeight = this.data.dataHeight == '150rpx' ? '80rpx' : '150rpx';
- var fontWeight = this.data.fontWeight == '600' ? '500' : '600';
- this.setData({
- dataHeight: height,
- dataLineHeight: lineHeight,
- dataFontWeight: fontWeight
- });
- },
- onLoad: function (options) {
- var that = this
- that.init();
- this.getList();
- },
- onShow: function (options) {
- var that = this
- if (options)
- console.log(options)
- if (that.data.addCar) {
- console.log(JSON.stringify(that.data.addCar))
- // 绑车牌
- if (app.globalData.carLogin) {
- that.bindCar(that.data.addCar)
- } else {
- that.bindCar(that.data.addCar)
- }
- that.setData({
- addCar: null
- })
- }
- },
- //我的停车券的显示与消失
- showquan: function () {
- let that = this;
- if (that.data.tcq == 1) {
- that.setData({
- tcq: 2
- })
- }
- else if (that.data.tcq == 2) {
- that.setData({
- tcq: 1
- })
- }
- },
- jumpToAdd: function () {
- wx.navigateTo({
- url: '/pages/addPark/addPark',
- });
- },
- passc: function () {
- wx.showToast({
- title: '宝宝最可爱~',
- })
- },
- // orderPay: function () {
- // wx.redirectTo({
- // url: '/pages/pay/pay'
- // });
- // },
-
- //券绑定卡
- bindCoupon: function () {
- var that = this
- // ETCP
- for(let car of that.data.carList){
- if (car.stopFee.remainingFee){
- that.data.payList.push(car)
- console.log(car)
- }
- }
- // if (that.data.payList.length==0){
- // wx.showModal({
- // title: '提示',
- // showCancel: false,
- // content: "您还没有在场车辆!",
- // })
- // return
- // }
- var etcpData = {
- etcpToken: app.globalData.etcpToken,
- carNumber: that.data.payList[0].carNumber ? that.data.payList[0].carNumber:'',
- couponFreeId:5655,
- merchantId: '196123418314145793',
- }
- console.log('--->>>'+JSON.stringify(etcpData))
- // 停简单
- var tjdData = {
- carNumber: that.data.payList[0].carNumber,
- }
- var postCouponData = (app.globalData.parkVendor == 1) ? etcpData : tjdData
- // that.setData({
- // loading: true,
- // content: "正在进行车牌绑定券,请稍后...",
- // });
- // wx.showToast({
- // title: '00000',
- // })
- Http.post({
- url: config.api.getCarCoupon,
- data: postCouponData,
- })
- .then(res => {
- that.initUsrCarList()
- wx.showModal({
- title: '提示',
- showCancel: false,
- content: "车牌绑定优免券成功!",
- success: function (res) {
- console.log(res);
- that.setData({
- // flag:res.data.
- })
- }
- })
- })
- .catch(error => {
- console.log(error)
- wx.showModal({
- title: '提示',
- showCancel: false,
- content: error.message,
- success: function () { }
- })
- })
- },
-
-
- //获取名下停车券列表
- getList() {
- var that = this;
- console.log('1111111111111111111111.......');
- // console.log(key);
- // console.log(pageNum);
- if (1) {
- // wx.showLoading({
- // title: "加载中"
- // });
- Http.get({
- url: config.api.couponOrderList + "?type=5",
- data: {
- pageNum: 1,
- pageSize: 8,
- couponOrderStatus: 0
- }
- }).then(res => {
- console.log('>>>>>>>>>>>>>>Res'+JSON.stringify(res))
- that.setData({
- couponList: res.data.list
- })
- console.log("姐姐的订单列表");
- setTimeout(function () {
- wx.hideLoading();
- }, 1200);
- // if (pageNum >= res.data.pages) {
- // that.setData({
- // allow_load: false
- // });
- // }
- /**
- * 先赋值后渲染页面
- * concat 不会改变原数组值
- * push 会改变原数组值,但不会一条一条插入,而是整个数组插入
- */
- // that.data.list = that.data.list.concat(res.data.list);
- // that.setData({
- // list: that.data.list
- // });
- });
- } else {
- console.log("加载完成allow_load设置成false");
- }
- },
-
- bindCar: function (carNum) {
- var that = this
- // ETCP
- var etcpData = {
- etcpToken: app.globalData.etcpToken,
- carNumber: carNum,
- }
- // 停简单
- var tjdData = {
- carNumber: carNum,
- }
- var postData = (app.globalData.parkVendor == 1) ? etcpData : tjdData
- Http.post({
- url: config.api.bindCar,
- data: postData,
- })
- .then(res => {
- console.log(res)
- that.setData({
- addCar: null
- })
- that.initUsrCarList()
- wx.showModal({
- title: '提示',
- showCancel: false,
- content: "绑车牌成功!",
- success: function () { }
- })
- })
- .catch(error => {
- console.log(error)
- wx.showModal({
- title: '提示',
- showCancel: false,
- content: error.data.message,
- success: function () { }
- })
- })
- },
- unbindCar: function (carNum) {
- var that = this
- var postData =
- (app.globalData.parkVendor == 1) ? {
- etcpToken: app.globalData.etcpToken,
- carNumber: carNum,
- } : {
- carNumber: carNum,
- }
- Http.post({
- url: config.api.unbindCar,
- data: postData,
- })
- .then(res => {
- console.log(res)
- that.initUsrCarList()
- wx.showModal({
- title: '提示',
- showCancel: false,
- content: "解绑车牌成功!",
- success: function () { }
- })
- })
- .catch(error => {
- wx.showModal({
- title: '提示',
- showCancel: false,
- content: "解绑车牌失败!",
- success: function () { }
- })
- })
- },
- unbindCarBtn: function (e) {
- console.log(e)
- var that = this
- var carNum = e.currentTarget.dataset.car
- that.unbindCar(carNum)
- },
- getStopFeeItem: function (carItem, i) {
- var that = this
- var postData =
- (app.globalData.parkVendor == 1) ? {
- etcpToken: app.globalData.etcpToken,
- carNumber: carItem.carNumber,
- } : {
- carNumber: carItem.carNumber,
- outCarId: carItem.outCarId,
- }
- var stopFee = 'carList[' + i + '].stopFee'
- var extraData = 'carList[' + i + '].extraData'
- var extraDataStr = {params:{CarNumber:carItem.carNumber}}
- console.log(postData)
- Http.post({
- url: config.api.getCarStopFee,
- data: postData
- })
- .then(res => {
- console.log(res)
- console.log(stopFee)
- that.setData({
- [stopFee]: res.data,
- [extraData]: extraDataStr
- })
- })
- .catch(error => {
- console.log(error)
- })
- },
- getStopFee: function () {
- var that = this
- // carLogin
- for (var i = 0; i < that.data.carList.length; i++) {
- that.getStopFeeItem(that.data.carList[i], i)
- }
- // console.log(JSON.stringify(getStopFeeItem))
- },
- initPark: function () {
- var that = this
- // 车场信息获取
- Http.get({
- url: config.api.getParkInfo,
- data: {}
- })
- .then(res => {
- console.log(res)
- that.setData({
- park: res.data,
- })
- })
- },
- initUsrCarList: function () {
- var that = this
- // 绑定车获取
- Http.get({
- url: config.api.getUserCarList,
- data: {}
- }).then(res => {
- console.log(res);
- that.setData({
- carList: res.data
- })
- })
- },
- init: function () {
- var that = this
-
- app.parkInitCallback = token => {
- that.initPark()
- that.initUsrCarList()
- if (!app.globalData.carLogin) {
- // 共同登录
- Http.post({
- url: config.api.carInit,
- data: {
- phone: app.globalData.phone
- }
- }).then(res => {
- app.globalData.carLogin = true
- app.globalData.parkVendor = res.data.vendor
- if (res.data.token != "undefined") {
- app.globalData.etcpToken = res.data.token
- console.log("etcpToken", app.globalData.etcpToken)
- }
- // 获取 停车费
- that.getStopFee()
- })
- }
- }
- if (app.globalData.token && app.globalData.token != null) {
- app.parkInitCallback(app.globalData.token)
- }
- }
- })
|