batteryControl.js 13 KB

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