batteryPackWait.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // pages/batteryPack/batteryPackWait.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. chargePileId: -9,
  8. timer:{},
  9. userInfo:{},
  10. // count: 0 , // 用于测试
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. let that = this
  17. let userInfo = wx.getStorageSync('userInfo');
  18. let timer = setInterval(()=>{
  19. that.wait(that)
  20. }, 2000);
  21. that.setData({
  22. timer,
  23. userInfo
  24. })
  25. },
  26. wait(that){
  27. let userInfo = that.data.userInfo;
  28. if(!userInfo){
  29. return;
  30. }
  31. wx.request({
  32. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/ivCarRequirement' +
  33. '?userId='+userInfo.userId,
  34. data: {
  35. },
  36. method: 'POST',
  37. success(res) {
  38. // 0-7 进等待 8进终端详情
  39. if(res?.data?.result?.requirementStep>=0 && res?.data?.result?.requirementStep<=7
  40. // || that.data.count < 3
  41. ){
  42. that.setData({
  43. chargePileId: res?.data?.result?.terminalId,
  44. // chargePileId: res?.data?.result?.terminalId,
  45. // count: that.data.count + 1
  46. })
  47. // 等待
  48. console.log(new Date() + " - requirementStep:" + res?.data?.result?.requirementStep)
  49. }else if(res?.data?.result?.requirementStep==8
  50. // || that.data.count>3
  51. ){
  52. that.setData({
  53. chargePileId: res?.data?.result?.terminalId,
  54. // chargePileId: res?.data?.result?.terminalId,
  55. // count: that.data.count + 1
  56. })
  57. // 8进终端详情
  58. clearInterval(that.data.timer)
  59. that.gotoScan_result(that)
  60. }else{
  61. that.gotoIndex()
  62. }
  63. },
  64. fail(e) {
  65. getApp().showNetworkError();
  66. }
  67. });
  68. },
  69. gotoIndex(){
  70. let url = `/pages/index/index`;
  71. wx.reLaunch({
  72. url
  73. });
  74. },
  75. gotoScan_result(that){
  76. let chargPileId = that.data.chargePileId
  77. let userInfo = that.data.userInfo
  78. wx.request({
  79. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  80. // data: charePileId,
  81. data:{
  82. chargPileId,
  83. userId: userInfo.userId
  84. },
  85. method: 'POST',
  86. success(res) {
  87. //console.log(res.data);
  88. // log.info('[首页]', '[获取微信扫一扫充电桩]', '[响应]', res.data);
  89. if (!res.data || res.data.code == 500) {
  90. //没有该充电桩信息
  91. wx.showModal({
  92. showCancel: false,
  93. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号',
  94. confirmColor:'#00AADD',
  95. });
  96. } else {
  97. res.data = res.data.result
  98. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  99. 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) {
  100. //充电桩故障
  101. wx.showModal({
  102. showCancel: false,
  103. content: '终端故障,维修中',
  104. confirmColor:'#00AADD',
  105. });
  106. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  107. wx.showModal({
  108. showCancel: false,
  109. content: '正在充电中',
  110. confirmColor:'#00AADD',
  111. });
  112. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  113. wx.setStorage({
  114. key: "scan_chargpile",
  115. data: res.data
  116. });
  117. // log.info('[首页]', '[微信扫一扫充电桩空闲跳转去充电界面]');
  118. let url = `/pages/scan_result/scan_result`;
  119. wx.reLaunch({
  120. url
  121. });
  122. }
  123. }
  124. },
  125. fail(e) {
  126. getApp().showNetworkError();
  127. }
  128. });
  129. },
  130. /**
  131. * 生命周期函数--监听页面初次渲染完成
  132. */
  133. onReady() {
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow() {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide() {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload() {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh() {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom() {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage() {
  164. }
  165. })