|
- let config = require("../../config/config.js");
- let Http = require("../../utils/HttpBasics");
- let Util = require("../../utils/util");
- let app = getApp();
- Page({
- data: {
- park: null,
- carList: [],
- payList: [],
- addCar: null,
- tcq: 2,
- flag: "",
- extraData: {},
- desc: '',
- title: '',
- indicatorDots: true,
- autoplay: false,
- interval: 5000,
- duration: 1000,
- current: 0,
- stopFees: {},
- },
- /**
- * 车牌轮播滑动
- */
- onSlideChangeEnd: function (e) {
- var that = this;
- /**
- * 获得当前的车牌号码
- */
- var listCardNum = (that.data.carList)[e.detail.current].carNumber;
- console.log(listCardNum);
- that.setData({
- listCardNum: listCardNum
- });
- /**
- * 获得停车费用
- */
- that.getStopFee(listCardNum);
- },
- gotomange: function () {
- wx.navigateTo({
- url: '/pages/managelicenseplate/managelicenseplate',
- })
- },
- onLoad: function (options) {
- var that = this;
- /**
- * 获得分享小程序的
- * title
- * desc
- */
-
- Http.get({
- url: config.api.getWeapNote,
- data: {
- appId: config.weapp.AppId,
- }
- })
- .then(res => {
- let weapNote = JSON.parse(res.data.weapNote);
- that.setData({
- desc: weapNote.carpage.desc,
- title: weapNote.carpage.title
- })
- });
-
- },
-
-
- jumpToAdd: function () {
- wx.navigateTo({
- url: "/pages/addPark/addPark"
- });
- },
- passc: function () {
- wx.navigateTo({
- url: '/pages/ques/ques',
- })
- },
-
-
- //券绑定车牌
- bindCoupon: function (e) {
- console.log(e);
- var that = this;
- wx.showLoading({
- title: '加载中...',
- });
- if (that.data.couponList.length > 0) {
- /**
- * etcp
- */
- var etcpData = {
- etcpToken: app.globalData.etcpToken,
- carNumber: that.data.listCardNum,
- /**
- * 待解决
- */
- couponOrderId: that.data.couponList[0].id
- };
- console.log(etcpData);
- /**
- * 停简单
- */
- var tjdData = {
- carNumber: that.data.listCardNum
- };
- var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
- Http.post({
- url: config.api.getCarCoupon,
- data: postCouponData
- })
- .then(res => {
- that.initUsrCarList();
- wx.hideLoading();
- })
- .catch(error => {
- console.log(error);
- })
- } else {
- console.log("没有停车券可以绑定")
- wx.hideLoading();
- }
- },
-
- //获取名下停车券列表
- getList() {
- var that = this;
- Http.get({
- url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
- data: {
- pageNum: 1,
- pageSize: 8,
- couponOrderStatus: 0
- }
- }).then(res => {
- console.log(res);
- that.setData({
- couponList: res.data.list
- });
- });
- },
-
- onShow: function (options) {
- var that = this;
- that.getList();
- that.init();
- },
-
- /**
- * 绑定车牌
- */
-
- 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.initUsrCarList();
- wx.showModal({
- title: "提示",
- showCancel: false,
- content: "绑车牌成功!",
- success: function () {}
- });
- })
- .catch(error => {
- console.log(error);
- wx.showModal({
- title: "提示",
- showCancel: false,
- content: error.message,
- success: function () {}
- });
- });
- },
-
-
- /**
- * 车场信息获取
- */
- initPark: function () {
- var that = this;
- Http.get({
- url: config.api.getParkInfo,
- data: {}
- }).then(res => {
- that.setData({
- park: res.data
- });
- });
- },
-
-
- /**
- * 绑定车获取
- */
- initUsrCarList: function (flag) {
- console.log(flag);
- var that = this;
- Http.get({
- url: config.api.getUserCarList,
- data: {}
- }).then(res => {
- console.log(res)
- that.setData({
- carList: res.data
- });
- /**
- * flag ==flags
- * 表示从首页onShow进来的
- */
- if (flag == "flags") {
- var listCardNum = res.data[0].carNumber;
- console.log(listCardNum);
- that.setData({
- listCardNum: listCardNum
- })
- /**
- * 获得停车费用
- */
- that.getStopFee(listCardNum);
- }
- })
- },
-
- /**
- * 获得停车费用修改
- */
- getStopFee: function (carNumber) {
- var that = this;
- var postData =
- app.globalData.parkVendor == 1 ? {
- etcpToken: app.globalData.etcpToken,
- carNumber: carNumber
- } : {
- carNumber: carNumber,
- outCarId: outCarId
- };
- var extraDataStr = {
- params: {
- CarNumber: carNumber
- }
- };
- that.setData({
- extraData: extraDataStr
- });
- Http.post({
- url: config.api.getCarStopFee,
- data: postData
- })
- .then(res => {
- that.setData({
- stopFees: res.data
- })
- that.setData({
- timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
- })
- })
- .catch(error => {
- console.log(error);
- wx.showModal({
- title: '提示',
- content: error.message,
- showCancel: false
- })
- that.setData({
- stopFees: {}
- })
- });
- },
-
- /**
- * 共同登录
- */
- init: function (carNumber) {
- var that = this;
- app.parkInitCallback = token => {
- that.initPark();
- if (!app.globalData.carLogin) {
- /**
- * 判断是否授权手机号
- */
- Http.post({
- url: config.api.checkPhoneStatus,
- data: {}
- })
- .then(res => {
- console.log(res);
- Http.post({
- url: config.api.carInit,
- data: {
- phone: app.globalData.phone
- }
- }).then(res => {
- console.log(res);
- app.globalData.carLogin = true;
- app.globalData.parkVendor = res.data.vendor;
- if (res.data.token) {
- app.globalData.etcpToken = res.data.token;
- }
- /**
- * 获得停车费用
- */
- that.initUsrCarList("flags");
- console.log(app.globalData.etcpToken);
- });
- })
- .catch(err => {
- console.log(err);
- if (err.code == 11005) {
- // 用户手机未授权
- /**
- * 将值传到用户手机号授权的页面
- *
- */
- wx.redirectTo({
- url: "/pages/getphoneInfo/index"
- });
- } else if (err.code == 11006) {
- // 用户手机已加密
- wx.redirectTo({
- url: "/pages/phoneinput/phoneinput"
- });
- }
- })
- }
- };
- if (app.globalData.token && app.globalData.token != null) {
- app.parkInitCallback(app.globalData.token);
- }
- },
- /**
- * 下拉刷新
- */
- onPullDownRefresh: function(e) {
- let that = this;
- that.initUsrCarList("flags");
- wx.stopPullDownRefresh();
- },
- // 用户点击右上角分享
- onShareAppMessage: function () {
- return {
- title: this.data.title,
- desc: this.data.desc,
- success: function (res) {
- wx.showToast({
- title: "分享成功",
- duration: 1000,
- icon: "success"
- });
- }
- }
- }
- });
|