charginfo.js 12 KB

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