import * as echarts from '../../ec-canvas/echarts'; import * as lf from '../../ec-canvas/echarts-liquidfill'; let log = require('../../utils/log.js'); Page({ /** * 页面的初始数据 */ data: { name:'', address:'', chargprice: '', serviceprice: '', chargid: '', sumprice: '', fastFree:0, slowFree:0, fastSum:0, slowSum:0, pagesize:30, pagenum:1, total:-1, loadTotal: 0, dataLoading: false, finishedLoadTap: 0, chargList: [], }, /** * 生命周期函数--监听页面加载 */ onLoad: function(e) { let { name, address, chargprice, serviceprice, chargid } = e; name = name=='null'?null:name; address = address=='null'?null:address; chargprice = chargprice=='null'?null:chargprice; serviceprice = serviceprice=='null'?null:serviceprice; chargid = chargid=='null'?null:chargid; let sumprice = (chargprice==null || serviceprice==null)? null:chargprice+serviceprice; this.setData({ name, address, chargprice, serviceprice, chargid, sumprice }); let that = this; this.getPage(); }, getPage(){ if(this.data.chargList.length == this.data.total){ this.setData({ finishedLoadTap:this.data.finishedLoadTap+1 }) if(this.data.finishedLoadTap>0){ wx.showToast({ title: '全部加载完毕', icon: 'success', duration: 2000 }) } return } if(this.data.dataLoading){ return } this.setData({ dataLoading: true }) wx.showLoading({ title: '数据加载中....', }) let that = this; wx.request({ url: getApp().globalData.postHeadAgreement +'/restapi/wechat/chargInfo', data: { id: that.data.chargid, pagenum: this.data.pagenum++, pagesize: 30, }, method: 'POST', success(res) { console.log(res); let chargList = res.data.chargList.rows; chargList.forEach(key => { let chargstatusname = ''; let chargstatusclass = ''; if(key.chargstatus == '2'){ chargstatusname='空闲中' chargstatusclass = 'chargstatus_kxz' }else if(key.chargstatus == '11'){ chargstatusname='已插枪' chargstatusclass = 'chargstatus_ycq' }else if(key.chargstatus == '3' || key.chargstatus == '10'){ chargstatusname='充电中' chargstatusclass = 'chargstatus_cdz' }else{ chargstatusname='故障' chargstatusclass = 'chargstatus_gz' } key.chargstatusname = chargstatusname; key.chargstatusclass = chargstatusclass; }) console.log(chargList); // that.rechargeTimeOrder(chargemoneylogs); wx.hideLoading() that.setData({ chargList: that.data.chargList.concat(chargList), total: res.data.chargList.total, dataLoading: false, fastFree : res.data.fastSum, slowFree : res.data.fastFree, fastSum : res.data.fastSum, slowSum : res.data.slowSum }); } }); }, goScanResult(){ // scan_result wx.showLoading({ title: '努力加载中...', }) let userInfo = wx.getStorageSync('userInfo'); let isLogin = wx.getStorageSync('isLogin'); let that = this; if (!isLogin) { log.info('[首页]', '[未登陆跳转登录界面]'); let url = `/pages/login/login`; wx.hideLoading(); wx.navigateTo({ url }); return; } else { log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: userInfo.userId }); wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement', data: { userId: userInfo.userId }, method: 'POST', success(res) { let { data } = res; let { result: order } = data; log.info('[首页]', '[获取用户是否有未支付订单]', '[响应]', data); if (data && order && data.code == 200) { wx.hideLoading(); log.info('[首页]', '[用户有未支付订单跳转订单支付界面]'); wx.showModal({ showCancel: false, content: '你有未支付的订单,请先支付', success: function (res) { //console.log(res); if (!res.cancel) { //点击确定 let url = `/pages/order/order?orderid=${order.orderid}&userId=${order.userId}&chargPileId=${order.chargPileId}`; wx.navigateTo({ url }); } } }); //console.log(that.data.result); } else { //console.log('无订单'); log.info('[首页]', '[用户无未支付订单]'); wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile', // data: scanResult, data: { chargPileId: chargid, userId: userInfo.userId }, method: 'POST', success(res) { console.log(chargid); log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data); if (!res.data || res.data.code == 500) { that.scanFlag = false; wx.hideLoading(); //没有该充电桩信息 wx.showModal({ showCancel: false, content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号' }); } else { res.data = res.data.result //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等 if (!res.data.chargstatus || res.data.chargstatus == 0 || res.data.chargstatus == 1 || res.data.chargstatus == 4 || res.data.chargstatus == 5 || res.data.chargstatus == 6 || res.data.chargstatus == 9) { //充电桩故障 wx.showModal({ showCancel: false, content: '终端故障,维修中' }); } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) { wx.showModal({ showCancel: false, content: '正在充电中' }); } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) { wx.setStorage({ key: "scan_chargpile", data: res.data }); log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]'); let url = `/pages/scan_result/scan_result`; wx.hideLoading(); wx.navigateTo({ url }); } wx.hideLoading(); } }, fail(e) { getApp().showNetworkError(); } }); } }, fail(e) { that.scanFlag = false; wx.hideLoading(); getApp().showNetworkError(); } }); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function(e) { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, bindScrollTolowerEvent: function(){ this.getPage(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })