123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594 |
- let log = require('../../utils/log.js');
- Page({
-
- data: {
- chargPile: null,
- orderid: null,
- userId: null,
- repaidbalance: 0,
- resultTable: [],
-
- carParkingRate: false,
-
- parkTime: 0,
- url:'/images/scan_result.png',
- authStatus: 1,
- defPlateNumber:'',
- occupyFee:{},
- showOccupyFee:false
- },
- resetResultList(resultList){
- let that = this
- resultList.forEach(item=>{
- item["sumPrice"] = that.resetResultListSumPrice(item)
- })
- },
- resetResultListSumPrice(item){
-
- if(!item.elecPrice && item.elecPrice!=0){
- return '暂无费用'
- }
- if(!item.servicePrice && item.servicePrice!=0){
- return '暂无费用'
- }
- return parseFloat((item.elecPrice + item.servicePrice).toFixed(6))
- },
-
- onLoad: function (options) {
- let that = this;
- wx.getStorage({
- key: 'scan_chargpile',
- success: function (res) {
- console.log(res);
-
- var chargPile = res.data;
- let authStatus = chargPile.authStatus
- let resultTable = chargPile.resultList
- that.resetResultList(resultTable)
- that.setData({
- resultTable,
- authStatus
- })
- chargPile.sharpTotalPrice = parseFloat((chargPile.sharpChargPrice + chargPile.sharpServicePrice).toFixed(6));
- chargPile.peakTotalPrice = parseFloat((chargPile.peakChargPrice + chargPile.peakServicePrice).toFixed(6));
- chargPile.flatTotalPrice = parseFloat((chargPile.flatChargPrice + chargPile.flatServicePrice).toFixed(6));
- chargPile.valleyTotalPrice = parseFloat((chargPile.valleyChargPrice + chargPile.valleyServicePrice).toFixed(6));
- chargPile.totalprice = parseFloat((chargPile.chargprice + chargPile.serviceprice).toFixed(6));
- that.setData({
- chargPile
- });
-
-
- that.execParking(that,chargPile)
- wx.removeStorage({
- key: 'scan_chargpile',
- success(res) {
- console.log(res);
- }
- });
- log.info('[扫码]', '[加载完成]', '[参数]', res.data);
- let userInfo = wx.getStorageSync('userInfo');
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/syncUser',
- data: {
- loginName: userInfo.loginName
- },
- method: 'POST',
- success: function (res) {
- let {
- data
- } = res;
- log.info('[扫码]', '[同步用户数据]', '[响应]', data);
- console.info('[扫码]', '[同步用户数据]', '[响应]', data);
- if (data.code && data.code != 200) {
- log.info('[扫码]', '[同步用户数据]', '[失败data null||data.code<>200跳转登陆界面]', data);
- } else {
- that.setData({
- repaidbalance:data.repaidbalance
- });
- }
- },
- fail(e) {
- console.log("用户数据同步失败");
- log.info('[扫码]', '[同步用户数据]', '[fail]', e);
- }
- });
-
- }
- });
- this.getOccupyFee(options.chargPileId);
- },
- getOccupyFee(chargPileId){
-
- this.selectOccupyFee(chargPileId)
- .then(result => {
- console.log("查询结果:", result);
- this.setData({
- occupyFee:result,
- showOccupyFee:true
- })
- })
- .catch(error => {
- console.error("查询失败:", error);
- });
- },
- async selectOccupyFee(chargPileId) {
- try {
- const res = await new Promise((resolve, reject) => {
- wx.request({
- url: `${getApp().globalData.postHeadAgreement}/restapi/wechat/queryOccupyFee`,
- data: {
- chargPileId: chargPileId
- },
- method: 'POST',
- success: (response) => {
- resolve(response.data);
- },
- fail: (error) => {
- reject(error);
- }
- });
- });
- if (res.code == 200) {
- return res.result;
- } else {
- throw new Error(`Error: ${res.code}`);
- }
- } catch (e) {
- console.log("查询占位费模版信息异常", e);
- log.info('[扫码]', '[查询占位费模版信息]', '[fail]', e);
- throw e;
- }
- },
- execParking(that,chargPile){
- let stationId = chargPile.chargStationId;
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carParkingRate?stationId=' + stationId,
-
-
-
- method: 'POST',
- success: function (res) {
-
-
-
- console.info(res)
- let reduceTime = res.data?.reduceTime;
- if(!reduceTime){
- that.setData({
- carParkingRate:false
- })
- return;
- }
- that.setData({
- carParkingRate:true
- })
- try{
- that.setData({
- parkTime: parseFloat((reduceTime/ 3600).toFixed(2))
- })
- }catch(e){
- that.setData({
- carParkingRate:false
- })
- }
- },
- fail(e) {
- console.log("用户数据同步失败");
- log.info('[扫码]', '[同步用户数据]', '[fail]', e);
- }
- });
- },
- beginChargeInner(that,plateNumber){
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
-
- wx.showLoading({
- title: '开启充电中...',
- mask: true
- });
- log.info('[扫码]', '[开始充电流程]');
-
- log.info('[扫码]', '[同步用户数据]', '[请求]', {
- loginName: userInfo.loginName
- });
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/syncUser',
- data: {
- loginName: userInfo.loginName,
- },
- method: 'POST',
- success: function (res) {
- wx.hideLoading();
- let {
- data
- } = res;
- log.info('[扫码]', '[同步用户数据]', '[响应]', data);
- console.info('[扫码]', '[同步用户数据]', '[响应]', data);
- if (data.code && data.code != 200) {
- wx.removeStorageSync('userInfo');
- wx.removeStorageSync('isLogin');
- let url = '/pages/login/phone_login/phone_login';
- wx.redirectTo({
- url,
- });
- log.info('[扫码]', '[同步用户数据]', '[失败data null||data.code<>200跳转登陆界面]', data);
- } else {
- wx.setStorageSync('userInfo', data);
- wx.setStorageSync('isLogin', true);
- let repaidbalance = data.repaidbalance;
- that.setData({
- repaidbalance
- });
-
- if(data.bindingPhone==0){
- wx.showModal({
- title: '提示',
- content: '您未绑定手机号,请重新登录后自动刷新绑定信息',
- confirmText: '去登录',
- showCancel:false,
- confirmColor:'#00AADD',
- success: function (res1) {
- if (res1.confirm) {
- wx.removeStorageSync('userInfo');
- wx.removeStorageSync('isLogin');
- let url = '/pages/login/phone_login/phone_login';
- wx.redirectTo({
- url
- })
- }
- }
- });
- log.info('[扫码]', '[同步用户数据]', '[未绑定手机号]', data);
- }else if (!data.repaidbalance || data.repaidbalance <= 0) {
- wx.showModal({
- showCancel: false,
- content: '余额不足,请充值!',
- confirmColor:'#00AADD',
- success: function (res) {
- if (res.confirm) {
- let url = "/pages/chargemoney/chargemoney";
- wx.navigateTo({
- url
- });
- }
- }
- });
- log.info('[扫码]', '[同步用户数据]', '[data.repaidbalance null||data.repaidbalance<=0余额不足跳转充值界面]', data);
- } else if (data.repaidbalance > 0 && data.repaidbalance <= 15) {
- wx.showModal({
- title: '余额:' + data.repaidbalance + '元',
- showCancel: false,
- confirmText: "去充值",
- confirmColor:'#00AADD',
- content: '余额过低,请尽快充值!',
- success: function (res) {
- if (res.confirm) {
- let url = "/pages/chargemoney/chargemoney";
- wx.navigateTo({
- url
- });
- }
- }
- });
- log.info('[扫码]', '[同步用户数据]', '[0<data.repaidbalance<=15余额过低]', data);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- } else if (data.repaidbalance > 15) {
- log.info('[扫码]', '[同步用户数据]', '[余额充足开始充电]', data);
- that.beginCharge_satrt(plateNumber,1);
- }
- }
- }
- });
-
- },
- beginChargeMsg(e){
- let that = this
- wx.requestSubscribeMessage({
- tmplIds: ['3FR5XRyycT81ZWMdVi_ZQYKJcVatZr2Tm7DgcLwCD1I','KWHBIONCrdumgTkE1dpIpAZRgrN5TuhpHuZ0uU-Eud4','XWj70eHMLAjLlufPuhE_NQmdSQzhrOwEXIblWveH0bk'],
- success (res33333) {
- that.beginCharge(e)
- },fail(reee){
- console.info("ffffffffffffff")
- console.info(reee)
- }
- })
- },
- beginCharge(e) {
- let that = this
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- if(!that.data.carParkingRate){
- that.beginChargeInner(that,'');
- return;
- }
-
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carList?loginName=' + userInfo.loginName,
-
-
-
- method: 'POST',
- success: function (res) {
- let userCarList = res.data;
- userCarList = userCarList.filter(it=>it.defaultType==1);
- console.info(userCarList)
- if(userCarList.length==0 ){
- wx.showModal({
- title: '提示',
- content: '当前充电站可减免停车费,是否绑定车牌信息?',
- confirmText: '绑定车牌',
- cancelText: '直接启动',
- showCancel:true,
- confirmColor:'#00AADD',
- cancelColor:'#00AADD',
- success: function (ress1) {
- if(ress1.confirm){
- let url = '/pages/ucenter/car/chooseCar'
- wx.navigateTo({
- url
- });
- }else{
- that.beginChargeInner(that,'')
- }
- }
- });
- }else{
- let userCar = userCarList[0]
- wx.showModal({
- title: '提示',
- content: '确定使用' + userCar.plateNumber + '车牌信息减免停车费?',
- confirmText: '确定',
- cancelText: '其他车牌',
- showCancel:true,
- confirmColor:'#00AADD',
- cancelColor:'#00AADD',
- success: function (ress1) {
- if(ress1.confirm){
- that.beginChargeInner(that,userCar.plateNumber)
- }else{
- let url = '/pages/ucenter/car/chooseCar'
- wx.navigateTo({
- url
- });
- }
- return;
- },
- fail: function(res1){
- console.info(res1)
- }
- });
- }
- },
- fail(e) {
- console.log("查询车辆失败");
- log.info('[查询车辆]','[fail]', e);
- }
- });
-
-
- },
- beginCharge_satrt(plateNumber,runTimes) {
- wx.showLoading({
- title: '开启充电中...',
- mask: true
- });
- let that = this;
- let terminalNum = this.data.chargPile.chargPileId;
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- console.log(terminalNum);
- let userId = userInfo.userId;
- let chargstarttime = new Date().getTime();
- console.log(chargstarttime);
- log.info('[扫码]', '[开始充电]', '[请求]', {
-
- chargPileId: terminalNum,
- userId: userId,
- chargstarttime: chargstarttime
- });
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/miniprogramadd',
- data: {
-
- chargPileId: terminalNum,
- userId: userId,
- chargstarttime: chargstarttime,
- userPlateNumber: plateNumber,
- runTimes:runTimes
- },
- method: 'POST',
- fail(e) {
- wx.hideLoading();
-
- wx.showModal({
- showCancel: false,
- content: '开启充电失败',
- confirmColor:'#00AADD',
- });
- log.info('[扫码]', '[开始充电]', '[fail]', e);
- },
- success(res) {
- wx.hideLoading();
- let {
- data
- } = res;
- log.info('[扫码]', '[开始充电]', '[响应]', data);
- if (data && data.code == 200) {
-
-
- let {
- orderid
- } = data;
- log.info('[扫码]', '[开始充电]', '[成功,跳转充电中页面]', data);
-
- let url = `/pages/charging/charging?orderid=${orderid}&userId=${userId}&chargPileId=${terminalNum}`;
- wx.redirectTo({
- url
- });
- } else if (data && data.code == 501) {
-
- wx.showModal({
- showCancel: false,
- content: '余额不足,请充值!',
- confirmColor:'#00AADD',
- });
- log.info('[扫码]', '[开始充电]', '[失败data.code=501余额不足]', data);
- } else if (data && data.code == 502) {
-
- wx.showModal({
- showCancel: false,
- content: data.message,
- confirmColor:'#00AADD',
- });
- log.info('[扫码]', '[开始充电]', '[失败data.code=502' + data.message + ']', data);
- } else if (data && data.code == 503) {
-
- let msg = res?.data?.message
- wx.showModal({
- title: '提示',
- showCancel: true,
- content: msg,
- cancelText:'其他车辆',
- confirmText:'继续启动',
- confirmColor:'#00AADD',
- cancelColor:'#00AADD',
- success: function (res) {
- if (res.cancel) {
-
- } else {
-
- that.beginCharge_satrt(plateNumber,runTimes + 1)
- }
- },
- fail: function (res) { },
- complete: function (res) { },
- });
- log.info('[扫码]', '[开始充电]', '[失败data.code=502' + data.message + ']', data);
- } else {
-
- let msg = res?.data?.message
- msg = msg?msg:'开启充电失败'
- wx.showModal({
- showCancel: false,
- content: msg,
- confirmColor:'#00AADD',
- });
- log.info('[扫码]', '[开始充电]', '[失败]', data);
- }
- }
- });
- },
- previewImage(e){
- let cur = e.target.dataset.src;
- console.info(cur)
- wx.previewImage({
- current: cur,
- urls: [cur]
- })
- },
-
- onReady: function () {
- },
-
- onShow: function () {
- let car = wx.getStorageSync('chooseCar_plateNumber')
- let plateNumber = ''
- if(car){
- plateNumber = car.plateNumber;
- wx.removeStorageSync('chooseCar_plateNumber')
- }
- this.setData({
- plateNumber
- })
- console.info('将会自动跳过弹窗,默认车牌号:' + plateNumber)
- if(car){
- this.beginChargeInner(this,plateNumber)
- }
- },
-
- onHide: function () {
- },
-
- onUnload: function () {
- },
-
- onPullDownRefresh: function () {
- },
-
- onReachBottom: function () {
- },
-
- onShareAppMessage: function () {
- }
- })
|