charginfo.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. import * as echarts from '../../ec-canvas/echarts';
  2. import * as lf from '../../ec-canvas/echarts-liquidfill';
  3. let log = require('../../utils/log.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. name:'',
  10. address:'',
  11. chargprice: '',
  12. serviceprice: '',
  13. chargid: '',
  14. sumprice: '',
  15. fastFree:0,
  16. slowFree:0,
  17. fastSum:0,
  18. slowSum:0,
  19. pagesize:30,
  20. pagenum:1,
  21. total:-1,
  22. loadTotal: 0,
  23. dataLoading: false,
  24. finishedLoadTap: 0,
  25. chargList: [],
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function(e) {
  31. let { name, address, chargprice, serviceprice, chargid } = e;
  32. name = name=='null'?null:name;
  33. address = address=='null'?null:address;
  34. chargprice = chargprice=='null'?null:chargprice;
  35. serviceprice = serviceprice=='null'?null:serviceprice;
  36. chargid = chargid=='null'?null:chargid;
  37. let sumprice = (chargprice==null || serviceprice==null)? null:chargprice+serviceprice;
  38. this.setData({
  39. name,
  40. address,
  41. chargprice,
  42. serviceprice,
  43. chargid,
  44. sumprice
  45. });
  46. let that = this;
  47. this.getPage();
  48. },
  49. getPage(){
  50. if(this.data.chargList.length == this.data.total){
  51. this.setData({
  52. finishedLoadTap:this.data.finishedLoadTap+1
  53. })
  54. if(this.data.finishedLoadTap>0){
  55. wx.showToast({
  56. title: '全部加载完毕',
  57. icon: 'success',
  58. duration: 2000
  59. })
  60. }
  61. return
  62. }
  63. if(this.data.dataLoading){
  64. return
  65. }
  66. this.setData({
  67. dataLoading: true
  68. })
  69. wx.showLoading({
  70. title: '数据加载中....',
  71. })
  72. let that = this;
  73. wx.request({
  74. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/chargInfo',
  75. data: {
  76. id: that.data.chargid,
  77. pagenum: this.data.pagenum++,
  78. pagesize: 30,
  79. },
  80. method: 'POST',
  81. success(res) {
  82. console.log(res);
  83. let chargList = res.data.chargList.rows;
  84. chargList.forEach(key => {
  85. let chargstatusname = '';
  86. let chargstatusclass = '';
  87. if(key.chargstatus == '2'){
  88. chargstatusname='空闲中'
  89. chargstatusclass = 'chargstatus_kxz'
  90. }else if(key.chargstatus == '11'){
  91. chargstatusname='已插枪'
  92. chargstatusclass = 'chargstatus_ycq'
  93. }else if(key.chargstatus == '3' || key.chargstatus == '10'){
  94. chargstatusname='充电中'
  95. chargstatusclass = 'chargstatus_cdz'
  96. }else{
  97. chargstatusname='故障'
  98. chargstatusclass = 'chargstatus_gz'
  99. }
  100. key.chargstatusname = chargstatusname;
  101. key.chargstatusclass = chargstatusclass;
  102. })
  103. console.log(chargList);
  104. // that.rechargeTimeOrder(chargemoneylogs);
  105. wx.hideLoading()
  106. that.setData({
  107. chargList: that.data.chargList.concat(chargList),
  108. total: res.data.chargList.total,
  109. dataLoading: false,
  110. fastFree : res.data.fastSum,
  111. slowFree : res.data.fastFree,
  112. fastSum : res.data.fastSum,
  113. slowSum : res.data.slowSum
  114. });
  115. }
  116. });
  117. },
  118. goScanResult(){
  119. // scan_result
  120. wx.showLoading({
  121. title: '努力加载中...',
  122. })
  123. let userInfo = wx.getStorageSync('userInfo');
  124. let isLogin = wx.getStorageSync('isLogin');
  125. let that = this;
  126. if (!isLogin) {
  127. log.info('[首页]', '[未登陆跳转登录界面]');
  128. let url = `/pages/login/login`;
  129. wx.hideLoading();
  130. wx.navigateTo({
  131. url
  132. });
  133. return;
  134. } else {
  135. log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: userInfo.userId });
  136. wx.request({
  137. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  138. data: {
  139. userId: userInfo.userId
  140. },
  141. method: 'POST',
  142. success(res) {
  143. let {
  144. data
  145. } = res;
  146. let {
  147. result: order
  148. } = data;
  149. log.info('[首页]', '[获取用户是否有未支付订单]', '[响应]', data);
  150. if (data && order && data.code == 200) {
  151. wx.hideLoading();
  152. log.info('[首页]', '[用户有未支付订单跳转订单支付界面]');
  153. wx.showModal({
  154. showCancel: false,
  155. content: '你有未支付的订单,请先支付',
  156. success: function (res) {
  157. //console.log(res);
  158. if (!res.cancel) {
  159. //点击确定
  160. let url = `/pages/order/order?orderid=${order.orderid}&userId=${order.userId}&chargPileId=${order.chargPileId}`;
  161. wx.navigateTo({
  162. url
  163. });
  164. }
  165. }
  166. });
  167. //console.log(that.data.result);
  168. } else {
  169. //console.log('无订单');
  170. log.info('[首页]', '[用户无未支付订单]');
  171. wx.request({
  172. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  173. // data: scanResult,
  174. data: {
  175. chargPileId: chargid,
  176. userId: userInfo.userId
  177. },
  178. method: 'POST',
  179. success(res) {
  180. console.log(chargid);
  181. log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
  182. if (!res.data || res.data.code == 500) {
  183. that.scanFlag = false;
  184. wx.hideLoading();
  185. //没有该充电桩信息
  186. wx.showModal({
  187. showCancel: false,
  188. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号'
  189. });
  190. } else {
  191. res.data = res.data.result
  192. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  193. 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) {
  194. //充电桩故障
  195. wx.showModal({
  196. showCancel: false,
  197. content: '终端故障,维修中'
  198. });
  199. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  200. wx.showModal({
  201. showCancel: false,
  202. content: '正在充电中'
  203. });
  204. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  205. wx.setStorage({
  206. key: "scan_chargpile",
  207. data: res.data
  208. });
  209. log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
  210. let url = `/pages/scan_result/scan_result`;
  211. wx.hideLoading();
  212. wx.navigateTo({
  213. url
  214. });
  215. }
  216. wx.hideLoading();
  217. }
  218. },
  219. fail(e) {
  220. getApp().showNetworkError();
  221. }
  222. });
  223. }
  224. },
  225. fail(e) {
  226. that.scanFlag = false;
  227. wx.hideLoading();
  228. getApp().showNetworkError();
  229. }
  230. });
  231. }
  232. },
  233. /**
  234. * 生命周期函数--监听页面初次渲染完成
  235. */
  236. onReady: function() {
  237. },
  238. /**
  239. * 生命周期函数--监听页面显示
  240. */
  241. onShow: function(e) {
  242. },
  243. /**
  244. * 生命周期函数--监听页面隐藏
  245. */
  246. onHide: function() {
  247. },
  248. /**
  249. * 生命周期函数--监听页面卸载
  250. */
  251. onUnload: function() {
  252. },
  253. bindScrollTolowerEvent: function(){
  254. this.getPage();
  255. },
  256. /**
  257. * 页面相关事件处理函数--监听用户下拉动作
  258. */
  259. onPullDownRefresh: function() {
  260. },
  261. /**
  262. * 页面上拉触底事件的处理函数
  263. */
  264. onReachBottom: function() {
  265. },
  266. /**
  267. * 用户点击右上角分享
  268. */
  269. onShareAppMessage: function() {
  270. }
  271. })