//logs.js let util = require('../../../utils/util.js'); let wechat = require("../../../utils/wechat"); let amap = require("../../../utils/amap"); Page({ timer: null, data: { userInfo: {}, isLogin: false, searchString: null, chargpiles: [], pageNum: 1, total: 0, showAll: false, showTop: true, scrollTop: 0 }, onLoad(e) {}, //20201207去掉默认加载监控充电桩数据 onLoad_bak(e) { wx.showLoading({ title: '加载中', mask: true }); let userInfo = wx.getStorageSync('userInfo'); let isLogin = wx.getStorageSync('isLogin'); let that = this; // 页面显示 if (userInfo && isLogin) { this.setData({ userInfo: userInfo, isLogin: isLogin }); wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargpileList', data: { pams: userInfo.userId, params: { pageSize: 10, pageNum: 1 //orderByColumn: //isAsc: asc } }, method: 'POST', success(res) { //console.log(res); if (res.data && res.data.code == 0) { let { rows: chargpiles } = res.data; var show_chargpiles = []; chargpiles.forEach((item, index) => { show_chargpiles.push({ chargStationId: item.chargStationId, chargPileName: item.chargPileName, chargPileId: item.chargPileId, chargStationName: item.chargStationName, chargmode: item.chargmode,//name = "充电模式", readConverterExp = "1=自动,2=手动" chargway: item.chargway,//name = "充电方式", readConverterExp = "1=直流,2=交流" chargstatus: item.chargstatus//充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等 }); }); //充电状态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.navigateTo({ // url // }); // } if (res.data.total <= 10) { that.setData({ chargpiles: show_chargpiles, total: res.data.total, showAll: true, pageNum: 1, scrollTop: 24 }); } else { that.setData({ chargpiles: show_chargpiles, total: res.data.total, showAll: false, pageNum: 1, scrollTop: 24 }); } wx.hideLoading(); } } }); } }, bindInput(e) { this.setData({ searchString: e.detail.value }); }, bindSearch(e) { let { searchString: keywords } = this.data; if (keywords) { let url = `/pages/ucenter/chargpilemonitor/chargpilemonitorsearch?keywords=${keywords}`; wx.navigateTo({ url }); } }, scrollFn(e) { // 防抖,优化性能 // 当滚动时,滚动条位置距离页面顶部小于设定值时,触发下拉刷新 // 通过将设定值尽可能小,并且初始化scroll-view组件竖向滚动条位置为设定值。来实现下拉刷新功能,但没有官方的体验好 // clearTimeout(this.timer) // if (e.detail.scrollTop < this.data.scrollTop) { // this.timer = setTimeout(() => { // this.loadInitData() // }, 350) // } if (e.detail.scrollTop > 24) { //clearTimeout(this.timer); this.setData({ showTop: false }); } // if (e.detail.scrollTop == 0) { // this.timer = setTimeout(() => { // if (!this.data.showTop) { // this.setData({ // showTop: true // }); // } // }, 350) // } }, loadInitData(e) { if (!this.data.showTop) { //clearTimeout(this.timer); //this.timer = setTimeout(() => { this.setData({ showTop: true, scrollTop: 24 }); //}, 50) } else { wx.showLoading({ title: '刷新中', mask: true }); let that = this; // 页面显示 if (that.data.userInfo && that.data.isLogin) { wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargpileList', data: { pams: that.data.userInfo.userId, params: { pageSize: 10, pageNum: 1 //orderByColumn: //isAsc: asc } }, method: 'POST', success(res) { //console.log(res); if (res.data && res.data.code == 0) { let { rows: chargpiles } = res.data; var show_chargpiles = []; chargpiles.forEach((item, index) => { show_chargpiles.push({ chargStationId: item.chargStationId, chargPileName: item.chargPileName, chargPileId: item.chargPileId, chargStationName: item.chargStationName, chargmode: item.chargmode,//name = "充电模式", readConverterExp = "1=自动,2=手动" chargway: item.chargway,//name = "充电方式", readConverterExp = "1=直流,2=交流" chargstatus: item.chargstatus//充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等 }); }); if (res.data.total <= 10) { that.setData({ chargpiles: show_chargpiles, total: res.data.total, showAll: true, pageNum: 1, scrollTop: 24 }); } else { that.setData({ chargpiles: show_chargpiles, total: res.data.total, showAll: false, pageNum: 1, scrollTop: 24 }); } wx.hideLoading(); } } }); } } }, loadMoreData(e) { var totalPage = parseInt((this.data.total + 10 - 1) / 10); if ((this.data.pageNum + 1) > totalPage) { this.setData({ showAll: true }); return; } wx.showLoading({ title: '加载中', mask: true }); let that = this; let pageNum = this.data.pageNum + 1; this.setData({ pageNum }); // 页面显示 if (that.data.userInfo && that.data.isLogin) { wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargpileList', data: { pams: that.data.userInfo.userId, params: { pageSize: 10, pageNum: pageNum //orderByColumn: //isAsc: asc } }, method: 'POST', success(res) { //console.log(res); if (res.data && res.data.code == 0) { let { rows: chargpiles } = res.data; var show_chargpiles = that.data.chargpiles; chargpiles.forEach((item, index) => { show_chargpiles.push({ chargStationId: item.chargStationId, chargPileName: item.chargPileName, chargPileId: item.chargPileId, chargStationName: item.chargStationName, chargmode: item.chargmode,//name = "充电模式", readConverterExp = "1=自动,2=手动" chargway: item.chargway,//name = "充电方式", readConverterExp = "1=直流,2=交流" chargstatus: item.chargstatus//充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等 }); }); that.setData({ chargpiles: show_chargpiles }); if (pageNum * 10 >= that.data.total) { that.setData({ showAll: true }); } wx.hideLoading(); } } }); } } });