charginfo.js 12 KB

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