batteryControl.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. // pages/ucenter/control/batteryControl.js
  2. var selectPopup1;
  3. var selectPopup2;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. code: '202007221111110201',
  10. s1_index: -1,
  11. select1_text: '点击选择',
  12. select2_text: '点击选择',
  13. select1_arr:[],
  14. select2_arr:[],
  15. select1_index:-1,
  16. select2_index:-1,
  17. batteryByStation: {},
  18. chargPile:{
  19. // chargPileName:'测试电池包',
  20. // chargPileId:'202007221111110201',
  21. // address:'雁塔区小寨西路',
  22. // wxTest:'wxTest',
  23. chargPileName:'',
  24. chargPileId:'',
  25. address:'',
  26. wxTest:'wxTest',
  27. },
  28. cars:[],
  29. carIndex: -1,
  30. locations:[],
  31. locationIndex: -1,
  32. wxTest:{
  33. msg:'uuddudududud',
  34. index:0,
  35. t: new Date().valueOf(),
  36. tnum: 0,
  37. },
  38. tractorTaskTypeIndex: -1,
  39. tractorTaskTypeList:[
  40. {
  41. "txt": "装载电池包",
  42. "val": 2
  43. },
  44. {
  45. "txt": "卸载电池包",
  46. "val": 3
  47. },
  48. {
  49. "txt": "离开电池包",
  50. "val": 4
  51. }
  52. ]
  53. },
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */
  57. onLoad(options) {
  58. let that = this
  59. // let {code} = options
  60. // this.setData({
  61. // code
  62. // })
  63. wx.request({
  64. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/ivCar',
  65. data: {
  66. },
  67. method: 'POST',
  68. success(res) {
  69. let cars = res?.data?.result?res?.data?.result:[]
  70. that.setData({
  71. cars
  72. })
  73. }
  74. })
  75. wx.request({
  76. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/ivParkPoint',
  77. data: {
  78. },
  79. method: 'POST',
  80. success(res) {
  81. console.info(res);
  82. let locations = res?.data?.result?res?.data?.result:[]
  83. that.setData({
  84. locations
  85. })
  86. }
  87. })
  88. let userInfo = wx.getStorageSync('userInfo');
  89. // 加载下拉框
  90. wx.request({
  91. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/batteryByStation',
  92. // data: charePileId,
  93. data:{
  94. chargPileId: '1771052602050748417',
  95. userId: userInfo.userId
  96. },
  97. method: 'POST',
  98. success(res) {
  99. res = res.data
  100. let batteryByStation = res.result
  101. let select1_arr = Object.keys(batteryByStation).sort().map(it=>{
  102. let regex = /chargStationName=(.*?)(,|")/;
  103. let match = it.match(regex);
  104. return match && match[1]?match[1]:it
  105. })
  106. let ee = {
  107. "detail":{
  108. "value":0
  109. }
  110. }
  111. that.setData({
  112. batteryByStation,
  113. select1_arr,
  114. })
  115. },
  116. fail(e) {
  117. getApp().showNetworkError();
  118. }
  119. });
  120. // wx.showToast({
  121. // title: that.data.code,
  122. // icon: 'success',
  123. // duration: 2000
  124. // })
  125. },
  126. loadSelect2(){
  127. let that = this;
  128. let index1 = that.data.select1_index
  129. let batteryByStation = that.data.batteryByStation;
  130. let key = Object.keys(batteryByStation).sort()[index1]
  131. let select2_arr = batteryByStation[key].map(it=>it.chargPileName)
  132. that.setData({
  133. select2_arr,
  134. })
  135. },
  136. bindPickerChange1(e){
  137. let index = e.detail.value
  138. let text = this.data.select1_arr[index]
  139. this.setData({
  140. select1_index: index,
  141. select1_text: text,
  142. select2_index: -1,
  143. select2_text: '点击选择',
  144. chargPile:{}
  145. })
  146. this.loadSelect2()
  147. },
  148. bindPickerChange2(e){
  149. let that = this;
  150. let index = e.detail.value
  151. let text = this.data.select2_arr[index]
  152. let index1 = that.data.select1_index
  153. let batteryByStation = that.data.batteryByStation;
  154. let key = Object.keys(batteryByStation).sort()[index1]
  155. console.info(index1)
  156. console.info(index)
  157. console.info(key)
  158. console.info(batteryByStation[key])
  159. let code = batteryByStation[key].map(it=>it.chargPileId)[index]
  160. this.setData({
  161. select2_index: index,
  162. select2_text: text,
  163. code
  164. })
  165. that.loadCode()
  166. },
  167. loadCode(){
  168. let that = this
  169. let index1 = that.data.select1_index
  170. let batteryByStation = that.data.batteryByStation;
  171. let key = Object.keys(batteryByStation).sort()[index1]
  172. let chargPile = batteryByStation[key][that.data.select2_index]
  173. // let userInfo = wx.getStorageSync('userInfo');
  174. // wx.request({
  175. // url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  176. // data: {
  177. // chargPileId:that.data.code,
  178. // userId: userInfo.userId
  179. // },
  180. // method: 'POST',
  181. // success(res) {
  182. // // log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
  183. // console.info(res)
  184. // if (!res.data || res.data.code == 500) {
  185. // wx.showModal({
  186. // showCancel: false,
  187. // content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号',
  188. // confirmColor:'#00AADD',
  189. // });
  190. // }else{
  191. // let chargPile = res.data.result;
  192. that.setData({
  193. chargPile
  194. })
  195. // }
  196. // },
  197. // fail(e) {
  198. // getApp().showNetworkError();
  199. // }
  200. // });
  201. },
  202. /**
  203. * 生命周期函数--监听页面初次渲染完成
  204. */
  205. onReady() {
  206. selectPopup1 = this.selectComponent("#selectpopup1");
  207. selectPopup2 = this.selectComponent("#selectpopup2");
  208. },
  209. /**
  210. * 生命周期函数--监听页面显示
  211. */
  212. onShow() {
  213. },
  214. /**
  215. * 生命周期函数--监听页面隐藏
  216. */
  217. onHide() {
  218. },
  219. /**
  220. * 生命周期函数--监听页面卸载
  221. */
  222. onUnload() {
  223. },
  224. /**
  225. * 页面相关事件处理函数--监听用户下拉动作
  226. */
  227. onPullDownRefresh() {
  228. },
  229. /**
  230. * 页面上拉触底事件的处理函数
  231. */
  232. onReachBottom() {
  233. },
  234. /**
  235. * 用户点击右上角分享
  236. */
  237. onShareAppMessage() {
  238. },
  239. upBtn(){
  240. let that = this;
  241. // if(that.wxTestDebug(that,'u') > 4){
  242. // return ;
  243. // }
  244. that.bettyControl(1)
  245. },
  246. downBtn(){
  247. let that = this;
  248. // if(that.wxTestDebug(that,'d') > 4){
  249. // return ;
  250. // }
  251. that.bettyControl(2);
  252. },
  253. pauseBtn(){
  254. let that = this;
  255. // if(that.wxTestDebug(that,'d') > 4){
  256. // return ;
  257. // }
  258. that.bettyControl(3);
  259. },
  260. bettyControl(bettyControl){
  261. let that = this;
  262. wx.showLoading({
  263. title: '控制电池中。。。',
  264. mask: true
  265. })
  266. wx.request({
  267. url: getApp().globalData.postHeadAgreement +'/restapi/pileLog/bettyControl',
  268. data: {
  269. bettyControl,
  270. chargPileId: that.data.chargPile.chargPileId
  271. },
  272. method: 'POST',
  273. success(res) {
  274. console.info(res)
  275. wx.hideLoading()
  276. wx.showToast({
  277. icon: 'none',
  278. title: res.data.msg,
  279. duration: 1000
  280. })
  281. }
  282. })
  283. },
  284. wxTestDebugClick(){
  285. let that = this
  286. if(new Date().valueOf() - that.data.wxTest.t <= 1000){
  287. that.data.wxTest.tnum = that.data.wxTest.tnum + 1
  288. }else{
  289. that.data.wxTest.tnum = 0
  290. }
  291. that.data.wxTest.t = new Date().valueOf()
  292. if(that.data.wxTest.tnum > 10){
  293. wx.request({
  294. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/wxTest/switch',
  295. data: {
  296. },
  297. method: 'GET',
  298. success(res) {
  299. that.data.wxTest.tnum = 0
  300. wx.showToast({
  301. title: "调试模式: " + res.data.msg,
  302. duration: 1000
  303. })
  304. }
  305. })
  306. }
  307. },
  308. wxTestDebug(that,s){
  309. // let that = this;
  310. if(that.data.wxTest.msg.length == that.data.wxTest.index + 1){
  311. wx.request({
  312. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/wxTest/switch',
  313. data: {
  314. },
  315. method: 'GET',
  316. success(res) {
  317. wx.showToast({
  318. title: "调试模式: " + res.data.msg,
  319. duration: 1000
  320. })
  321. }
  322. })
  323. idx = 0;
  324. that.setData({
  325. wxTest:{
  326. msg:that.data.wxTest.msg,
  327. index: idx,
  328. }
  329. })
  330. return;
  331. }
  332. let idx = 0
  333. if(that.data.wxTest.msg.substr(that.data.wxTest.index,1) == s){
  334. idx = that.data.wxTest.index + 1
  335. that.setData({
  336. wxTest:{
  337. msg:that.data.wxTest.msg,
  338. index: idx,
  339. }
  340. })
  341. }else{
  342. idx = 0;
  343. that.setData({
  344. wxTest:{
  345. msg:that.data.wxTest.msg,
  346. index: idx,
  347. }
  348. })
  349. }
  350. return idx;
  351. },
  352. carTap(e){
  353. let carIndex = e.currentTarget.dataset.idx;
  354. this.setData({
  355. carIndex
  356. })
  357. },
  358. locationTap(e){
  359. let locationIndex = e.currentTarget.dataset.idx;
  360. this.setData({
  361. locationIndex
  362. })
  363. },
  364. tractorTaskTypeTap(e){
  365. let tractorTaskTypeIndex = e.currentTarget.dataset.idx;
  366. this.setData({
  367. tractorTaskTypeIndex
  368. })
  369. },
  370. submit(){
  371. let that = this;
  372. if(this.data.carIndex==-1){
  373. wx.showToast({
  374. icon: 'none',
  375. title: '请选择车辆',
  376. duration: 1000
  377. })
  378. return ;
  379. }
  380. if(this.data.locationIndex==-1){
  381. wx.showToast({
  382. icon: 'none',
  383. title: '请选择点位',
  384. duration: 1000
  385. })
  386. return ;
  387. }
  388. if(this.data.tractorTaskTypeIndex==-1){
  389. wx.showToast({
  390. icon: 'none',
  391. title: '请选择任务类型',
  392. duration: 1000
  393. })
  394. return ;
  395. }
  396. let car = this.data.cars[this.data.carIndex];
  397. let location = this.data.locations[this.data.locationIndex]
  398. wx.showModal({
  399. title: '提示',
  400. content: '是否调度当前车辆?' + car.carName + "|" + location.pointShowName,
  401. complete: (res) => {
  402. if (res.cancel) {
  403. }
  404. if (res.confirm) {
  405. wx.showLoading({
  406. title: '调度车辆中。。。',
  407. mask: true
  408. })
  409. let userInfo = wx.getStorageSync('userInfo');
  410. // userId:
  411. wx.request({
  412. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/createIvCarRequirement?'
  413. + 'finalTargetParkPointId=' + location.id
  414. + '&carId=' + car.id
  415. // + '&chargePileId=' + that.data.chargPile.id
  416. + '&chargePileId=12'
  417. + '&userId=' + userInfo.userId
  418. // + '&requirementType=' + that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  419. + '&requirementType=0',
  420. data:{
  421. // "finalTargetParkPointId":location.id,
  422. // "carId":car.id,
  423. // "chargePileId":that.data.chargPile.chargPileId,
  424. // "userId":userInfo.userId,
  425. // "requirementType":that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  426. },
  427. method: 'POST',
  428. success(ress) {
  429. if(ress && ress.statusCode==200){
  430. let iid = ress.data.result.id;
  431. console.info(iid);
  432. console.info("11111111111111111");
  433. wx.request({
  434. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/xingshen',
  435. data: {
  436. // capacityResourceId: car.id,
  437. // targetParkPointId: location.id,
  438. // tractorTaskType: that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  439. // ivCarId:car.id,
  440. // targetParkPointId: 1,
  441. // capacityResourceId: location.id,
  442. // tractorTaskType: that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  443. carId:car.id,
  444. parkPointId: location.id,
  445. carRequirementId: iid,
  446. tractorTaskType: that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  447. },
  448. method: 'POST',
  449. success(res) {
  450. wx.hideLoading();
  451. if(res.statusCode==200){
  452. if(res.data.code==200){
  453. wx.showToast({
  454. icon: 'success',
  455. title: res.data.msg,
  456. duration: 1000
  457. })
  458. }else{
  459. wx.showToast({
  460. icon: 'none',
  461. title: '调度失败:' + res.data.msg,
  462. duration: 1000
  463. })
  464. }
  465. }else{
  466. wx.showToast({
  467. icon: 'none',
  468. title: '调度失败',
  469. duration: 1000
  470. })
  471. }
  472. }
  473. })
  474. }
  475. },
  476. })
  477. }
  478. }
  479. })
  480. },
  481. goToScanResult(){
  482. let userInfo = wx.getStorageSync('userInfo');
  483. let that = this;
  484. wx.request({
  485. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  486. // data: charePileId,
  487. data:{
  488. chargPileId: that.data.chargPile.chargPileId,
  489. userId: userInfo.userId
  490. },
  491. method: 'POST',
  492. success(res) {
  493. //console.log(res.data);
  494. // log.info('[首页]', '[获取微信扫一扫充电桩]', '[响应]', res.data);
  495. if (!res.data || res.data.code == 500) {
  496. //没有该充电桩信息
  497. wx.showModal({
  498. showCancel: false,
  499. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号',
  500. confirmColor:'#00AADD',
  501. });
  502. } else {
  503. res.data = res.data.result
  504. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  505. 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) {
  506. //充电桩故障
  507. wx.showModal({
  508. showCancel: false,
  509. content: '终端故障,维修中',
  510. confirmColor:'#00AADD',
  511. });
  512. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  513. wx.showModal({
  514. showCancel: false,
  515. content: '正在充电中',
  516. confirmColor:'#00AADD',
  517. });
  518. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  519. wx.setStorage({
  520. key: "scan_chargpile",
  521. data: res.data
  522. });
  523. // log.info('[首页]', '[微信扫一扫充电桩空闲跳转去充电界面]');
  524. let url = `/pages/scan_result/scan_result`;
  525. wx.navigateTo({
  526. url
  527. });
  528. }
  529. }
  530. },
  531. fail(e) {
  532. getApp().showNetworkError();
  533. }
  534. });
  535. },
  536. })