123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- 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: [],
- userInfo:{},
- isLogin: false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- 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.fastFree,
- slowFree : res.data.slowFree,
- fastSum : res.data.fastSum,
- slowSum : res.data.slowSum
- });
- }
- });
- },
- goScanResult(e){
- // scan_result
- let {
- keywords
- } = e.currentTarget.dataset;
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- let chargid = keywords.chargPileId;
- let that = this;
- if(isLogin && userInfo.bindingPhone==0){
- wx.showModal({
- title: '提示',
- content: '当前账户未绑定手机号,请您进行手机号绑定操作',
- showCancel:false,
- confirmText: '去绑定',
- confirmColor:'#00AADD',
- success: function (res1) {
- let url = `/pages/bindPhone/bindPhone`;
- wx.navigateTo({
- url
- });
- }
- });
- return;
- }
- wx.showLoading({
- title: '努力加载中...',
- })
- 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: '你有未支付的订单,请先支付',
- confirmColor:'#00AADD',
- 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,
- confirmColor:'#00AADD',
- 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: '终端故障,维修中',
- confirmColor:'#00AADD',
- });
- } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
- wx.showModal({
- showCancel: false,
- content: '正在充电中',
- confirmColor:'#00AADD',
- });
- } 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) {
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- //console.log(userInfo);
- // 页面显示
- if (userInfo && isLogin) {
- //userInfo.flag = true;
- this.setData({
- userInfo: userInfo,
- isLogin: isLogin
- });
- } else {
- //未登录信息
- this.setData({
- userInfo: {}
- });
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- bindScrollTolowerEvent: function(){
- this.getPage();
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|