charginfo.js 9.4 KB

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