|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617 |
- const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
- let app = getApp();
- let config = require("../../config/config.js");
- let Http = require("../../utils/HttpBasics");
- let Util = require("../../utils/util");
- const imgurl = require("../../utils/imgurl");
- Page({
- data: {
- parkUrl: imgurl.park.url,
- jianUrl: imgurl.jian.url,
- qidaiUrl: imgurl.qidai.url,
- addUrl: imgurl.add.url,
- quanUrl: imgurl.quan.url,
- cheUrl: imgurl.che.url,
- ruleUrl: imgurl.rule.url,
- wentiUrl: imgurl.wenti.url,
- park: null,
- carList: [],
- payList: [],
- addCar: null,
- tcq: 2,
- flag: "",
- extraData: {},
- desc: '',
- title: '',
- indicatorDots: true,
- autoplay: false,
- interval: 5000,
- duration: 1000,
- current: 0,
- stopFees: {},
- scroll: true,
- ifHaveCarModular:"",
- canIUse: wx.canIUse("navigator")
- },
- /**
- * 车牌轮播滑动
- */
- onSlideChangeEnd: function (e) {
- var that = this;
- /**
- * 获得当前的车牌号码
- */
- var listCardNum = (that.data.carList)[e.detail.current].carNumber;
- that.setData({
- listCardNum: listCardNum
- });
- /**
- * 获得停车费用
- */
- if (that.data.scroll) {
- that.getStopFee(listCardNum);
- }
- },
-
- //停车费用为0
- paySuccess:function(){
- wx.showModal({
- title: '支付成功',
- content: '请尽快离场',
- showCancel:false
- })
- },
-
- gotomange: function () {
- wx.navigateTo({
- url: '/pages/managelicenseplate/managelicenseplate',
- })
- },
- bindfail: function (res) {
- console.log(res)
- },
- gotoetcp: function () {
- wx.navigateToMiniProgram({
- appId: that.data.etcpAppId,
- extraData: this.data.extraData,
- envVersion: 'release',
- path: "pages/main/main",
- })
- },
- showquan: function () {
- wx.navigateTo({
- url: '/pages/passCar/couponList/couponList',
- })
- },
- gotodetail: function (e) {
- wx.showModal({
- title: '缴费规则',
- content: e.target.dataset.rule,
- showCancel: false,
- })
- },
- onShow: function (options) {
- var that = this;
- that.setData({
- etcpAppId: extConfig.attr.etcpAppId,
- etcpVersion: extConfig.attr.etcpVersion,
- etcpCallbackUrl: extConfig.attr.etcpCallbackUrl,
- ifHaveCarModular: extConfig.attr.ifHaveCarModular
- })
- if (app.globalData.token) {
- that.getList();
- that.init();
- } else {
- that.init();
- }
- /**
- * 只有用户选择了优惠券
- * 才会进行券和车牌的绑定
- */
- if (wx.getStorageSync("chosed") && that.data.quanid) {
- that.getStopFee(that.data.listCardNum);
- that.bindCoupon(that.data.quanid);
- wx.setStorage({
- key: 'chosed',
- data: '',
- })
- };
- if (app.globalData.token) {
- that.initUsrCarList();
- }
-
- if (that.data.addCar) {
- // 绑车牌
- if (app.globalData.carLogin) {
- that.bindCar(that.data.addCar);
- } else {
- that.bindCar(that.data.addCar);
- }
- that.setData({
- addCar: null
- });
- }
- },
- 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
- })
- })
- .catch(err => {
- console.log(err);
- })
- // 登录
- var scene = decodeURIComponent(options.scene);
- that.setData({
- scene: scene
- });
- if (app.globalData.token) { } else {
- app.getLocation();
- that.userLogin()
- }
- },
- /**
- * 用户登录
- */
- userLogin: function () {
- var that = this;
- // 登录
- wx.login({
- success: ({
- code
- }) => {
- wx.getSystemInfo({
- success: function (res) {
- that.setData({
- systemInfo: JSON.stringify(res)
- })
- }
- })
- var usrdata = {
- appId: config.weapp.AppId,
- code: code,
- sceneAddress: app.globalData.sceneAddress,
- scene: that.data.scene,
- systemInfo: that.data.systemInfo
- };
- if (app.globalData.locationInfo) {
- usrdata = {
- appId: config.weapp.AppId,
- code: code,
- sceneAddress: app.globalData.sceneAddress,
- latitude: "" + app.globalData.locationInfo.latitude,
- longitude: "" + app.globalData.locationInfo.longitude,
- scene: that.data.scene,
- systemInfo: that.data.systemInfo
- };
- }
- Http.post({
- url: config.api.login,
- data: usrdata
- })
- .then(res => {
- app.globalData.token = res.data.token;
- Http.setToken(res.data.token);
- that.checkUserCarStatus();
- // that.getUserInfo();
- that.getList();
- that.init();
- that.initUsrCarList();
- return Http.get({
- url: config.api.checkUserStatus,
- data: {}
- });
- })
- .then(res => {
- })
- .catch(err => {
- if (err.code == 11004) {
- // 用户昵称未授权
- wx.redirectTo({
- url: "/pages/getuserinfo/index"
- });
- } else {
- wx.showModal({
- title: '提示',
- content: err.errMsg,
- showCancel: false
- })
- }
- });
- }
- });
- },
- /**
- * 检查用户是否有车
- */
- checkUserCarStatus: function () {
- var that = this;
- Http.get({
- url: config.api.userCarCount,
- data: {}
- }).then(res => {
- if (res.data > 0) {
- // 用户名下有车
- app.globalData.phone = res.data.phone;
- app.globalData.supportCar = true;
- // 共同登录
- that.userCarLogin();
- }
- })
- .catch(err => {
- })
- },
- /**
- * 获取用户信息
- */
- // getUserInfo: function () {
- // // 获取用户信息
- // wx.getSetting({
- // success: res => {
- // if (res.authSetting["scope.userInfo"]) {
- // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
- // wx.getUserInfo({
- // success: res => {
- // // 可以将 res 发送给后台解码出 unionId
- // }
- // });
- // }
- // }
- // })
- // },
- jumpToAdd: function () {
- wx.navigateTo({
- url: `/pages/addPark/addPark?flags=managepalte`
- });
- },
- passc: function () {
- wx.navigateTo({
- url: '/pages/ques/ques',
- })
- },
-
-
- /**
- * 券绑定车牌
- */
- bindCoupon: function (quanid) {
- var that = this;
- /**
- * etcp
- */
- var etcpData = {
- etcpToken: app.globalData.etcpToken,
- carNumber: that.data.listCardNum,
- couponOrderId: quanid
- };
- /**
- * 停简单
- */
- 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();
- })
- .catch(err => {
- console.log(err)
- wx.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- },
- /**
- * 选择优惠券
- */
- gotoquan: function () {
- let that = this;
- if (that.data.quanid) {
- wx.navigateTo({
- url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
- })
- } else {
- wx.navigateTo({
- url: '/pages/passCar/choicecoupon/choicecoupon',
- })
- }
-
- },
-
- //获取名下停车券列表
- getList() {
- var that = this;
- Http.get({
- url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
- data: {
- pageNum: 1,
- pageSize: 8,
- couponOrderStatus: 0
- }
- }).then(res => {
- that.setData({
- couponList: res.data.list
- });
- })
- .catch(err => {
- console.log(err)
- })
- },
-
-
- /**
- * 共同登录
- */
- init: function (carNumber) {
- var that = this;
- app.parkInitCallback = token => {
- that.initPark();
- that.getParkStatus();
- if (!app.globalData.carLogin) {
- /**
- * 判断是否授权手机号
- */
- Http.get({
- url: config.api.checkPhoneStatus,
- data: {}
- })
- .then(res => {
- 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) {
- app.globalData.etcpToken = res.data.token;
- }
- /**
- * 获得停车费用
- */
- that.initUsrCarList("flags");
- });
- })
- .catch(err => {
- if (err.code == 11005) {
- // 用户手机未授权
- /**
- * 将值传到用户手机号授权的页面
- *
- */
- wx.redirectTo({
- url: "/pages/getphoneInfo/index"
- });
- } else if (err.code == 11006) {
- // 用户手机已加密
- wx.redirectTo({
- url: "/pages/phoneinput/phoneinput"
- });
- } else {
- wx.showToast({
- title: err.errMsg,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- }
- })
- }
- };
- if (app.globalData.token && app.globalData.token != null) {
- app.parkInitCallback(app.globalData.token);
- }
- },
-
- 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 => {
- that.setData({
- addCar: null
- });
- that.initUsrCarList();
- wx.showModal({
- title: "提示",
- showCancel: false,
- content: "绑车牌成功!",
- success: function () { }
- });
- })
- .catch(error => {
- wx.showModal({
- title: "提示",
- showCancel: false,
- content: error.data.message,
- success: function () { }
- });
- });
- },
- /**
- * 车场信息获取
- */
- initPark: function () {
- var that = this;
- Http.get({
- url: config.api.getParkInfo,
- data: {}
- })
- .then(res => {
- that.setData({
- park: res.data
- })
- })
- .catch(err => {
- console.log(err);
- // wx.showToast({
- // title: err.message,
- // icon: 'none',
- // duration: 2000,
- // mask: false
- // });
- })
- },
-
- /**
- * 车场状态获取
- */
- getParkStatus: function () {
- var that = this;
- Http.get({
- url: config.api.getParkStatus,
- })
- .then(res => {
- console.log(res)
- })
- .catch(err => {
- console.log(err)
- // wx.showToast({
- // title: err.message,
- // icon:"none"
- // })
- })
- },
-
-
- /**
- * 绑定车获取
- */
- initUsrCarList: function (flag) {
- var that = this;
- Http.get({
- url: config.api.getUserCarList,
- data: {}
- }).then(res => {
- that.setData({
- carList: res.data
- });
- /**
- * flag ==flags
- * 表示从首页onShow进来的
- */
- if (flag == "flags" && res.data.length > 0) {
- var listCardNum = res.data[0].carNumber;
- that.setData({
- listCardNum: listCardNum
- })
- /**
- * 获得停车费用
- */
- that.getStopFee(listCardNum);
- }
- })
- .catch(err => {
- wx.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- },
-
- /**
- * 获得停车费用修改
- */
- getStopFee: function (carNumber) {
- let that = this;
- let postData =
- app.globalData.parkVendor == 1 ? {
- etcpToken: app.globalData.etcpToken,
- carNumber: carNumber
- } : {
- carNumber: carNumber,
- outCarId: outCarId
- };
- Http.post({
- url: config.api.getCarStopFee,
- data: postData
- })
- .then(res => {
- console.log(res)
- var extraDataStr = {
- params: {
- token: app.globalData.etcpToken,
- syncId: res.data.orderId,
- payType: 6, // 小程序支付
- CarNumber: carNumber,
- returnUrl: that.data.etcpCallbackUrl,
- source: "FUMAO-001",
- actionId: "1" //操作ID,1:小程序支付
- }
- };
- that.setData({
- extraData: extraDataStr,
- stopFees: res.data,
- timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
- });
- that.setData({
- scroll: true
- })
- })
- .catch(error => {
- that.setData({
- stopFees: {},
- scroll: true
- })
- });
- },
-
- /**
- * 下拉刷新
- */
- 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"
- });
- }
- }
- }
- });
|