batteryControl.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. bettyControl(bettyControl){
  163. let that = this;
  164. wx.showLoading({
  165. title: '控制电池中。。。',
  166. mask: true
  167. })
  168. wx.request({
  169. url: getApp().globalData.postHeadAgreement +'/restapi/pileLog/bettyControl',
  170. data: {
  171. bettyControl,
  172. chargPileId: that.data.chargPile.chargPileId
  173. },
  174. method: 'POST',
  175. success(res) {
  176. console.info(res)
  177. wx.hideLoading()
  178. wx.showToast({
  179. icon: 'none',
  180. title: res.data.msg,
  181. duration: 1000
  182. })
  183. }
  184. })
  185. },
  186. wxTestDebugClick(){
  187. let that = this
  188. if(new Date().valueOf() - that.data.wxTest.t <= 1000){
  189. that.data.wxTest.tnum = that.data.wxTest.tnum + 1
  190. }else{
  191. that.data.wxTest.tnum = 0
  192. }
  193. that.data.wxTest.t = new Date().valueOf()
  194. if(that.data.wxTest.tnum > 10){
  195. wx.request({
  196. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/wxTest/switch',
  197. data: {
  198. },
  199. method: 'GET',
  200. success(res) {
  201. that.data.wxTest.tnum = 0
  202. wx.showToast({
  203. title: "调试模式: " + res.data.msg,
  204. duration: 1000
  205. })
  206. }
  207. })
  208. }
  209. },
  210. wxTestDebug(that,s){
  211. // let that = this;
  212. if(that.data.wxTest.msg.length == that.data.wxTest.index + 1){
  213. wx.request({
  214. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/wxTest/switch',
  215. data: {
  216. },
  217. method: 'GET',
  218. success(res) {
  219. wx.showToast({
  220. title: "调试模式: " + res.data.msg,
  221. duration: 1000
  222. })
  223. }
  224. })
  225. idx = 0;
  226. that.setData({
  227. wxTest:{
  228. msg:that.data.wxTest.msg,
  229. index: idx,
  230. }
  231. })
  232. return;
  233. }
  234. let idx = 0
  235. if(that.data.wxTest.msg.substr(that.data.wxTest.index,1) == s){
  236. idx = that.data.wxTest.index + 1
  237. that.setData({
  238. wxTest:{
  239. msg:that.data.wxTest.msg,
  240. index: idx,
  241. }
  242. })
  243. }else{
  244. idx = 0;
  245. that.setData({
  246. wxTest:{
  247. msg:that.data.wxTest.msg,
  248. index: idx,
  249. }
  250. })
  251. }
  252. return idx;
  253. },
  254. carTap(e){
  255. let carIndex = e.currentTarget.dataset.idx;
  256. this.setData({
  257. carIndex
  258. })
  259. },
  260. locationTap(e){
  261. let locationIndex = e.currentTarget.dataset.idx;
  262. this.setData({
  263. locationIndex
  264. })
  265. },
  266. tractorTaskTypeTap(e){
  267. let tractorTaskTypeIndex = e.currentTarget.dataset.idx;
  268. this.setData({
  269. tractorTaskTypeIndex
  270. })
  271. },
  272. submit(){
  273. let that = this;
  274. if(this.data.carIndex==-1){
  275. wx.showToast({
  276. icon: 'none',
  277. title: '请选择车辆',
  278. duration: 1000
  279. })
  280. return ;
  281. }
  282. if(this.data.locationIndex==-1){
  283. wx.showToast({
  284. icon: 'none',
  285. title: '请选择点位',
  286. duration: 1000
  287. })
  288. return ;
  289. }
  290. if(this.data.tractorTaskTypeIndex==-1){
  291. wx.showToast({
  292. icon: 'none',
  293. title: '请选择任务类型',
  294. duration: 1000
  295. })
  296. return ;
  297. }
  298. let car = this.data.cars[this.data.carIndex];
  299. let location = this.data.locations[this.data.locationIndex]
  300. wx.showModal({
  301. title: '提示',
  302. content: '是否调度当前车辆?' + car.carName + "|" + location.pointShowName,
  303. complete: (res) => {
  304. if (res.cancel) {
  305. }
  306. if (res.confirm) {
  307. wx.showLoading({
  308. title: '调度车辆中。。。',
  309. mask: true
  310. })
  311. let userInfo = wx.getStorageSync('userInfo');
  312. // userId:
  313. wx.request({
  314. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/createIvCarRequirement?'
  315. + 'finalTargetParkPointId=' + location.id
  316. + '&carId=' + car.id
  317. // + '&chargePileId=' + that.data.chargPile.id
  318. + '&chargePileId=12'
  319. + '&userId=' + userInfo.userId
  320. // + '&requirementType=' + that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  321. + '&requirementType=0',
  322. data:{
  323. // "finalTargetParkPointId":location.id,
  324. // "carId":car.id,
  325. // "chargePileId":that.data.chargPile.chargPileId,
  326. // "userId":userInfo.userId,
  327. // "requirementType":that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  328. },
  329. method: 'POST',
  330. success(ress) {
  331. if(ress && ress.statusCode==200){
  332. let iid = ress.data.result.id;
  333. console.info(iid);
  334. console.info("11111111111111111");
  335. wx.request({
  336. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/xingshen',
  337. data: {
  338. // capacityResourceId: car.id,
  339. // targetParkPointId: location.id,
  340. // tractorTaskType: that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  341. // ivCarId:car.id,
  342. // targetParkPointId: 1,
  343. // capacityResourceId: location.id,
  344. // tractorTaskType: that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  345. carId:car.id,
  346. parkPointId: location.id,
  347. carRequirementId: iid,
  348. tractorTaskType: that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  349. },
  350. method: 'POST',
  351. success(res) {
  352. wx.hideLoading();
  353. if(res.statusCode==200){
  354. if(res.data.code==200){
  355. wx.showToast({
  356. icon: 'success',
  357. title: res.data.msg,
  358. duration: 1000
  359. })
  360. }else{
  361. wx.showToast({
  362. icon: 'none',
  363. title: '调度失败:' + res.data.msg,
  364. duration: 1000
  365. })
  366. }
  367. }else{
  368. wx.showToast({
  369. icon: 'none',
  370. title: '调度失败',
  371. duration: 1000
  372. })
  373. }
  374. }
  375. })
  376. }
  377. },
  378. })
  379. }
  380. }
  381. })
  382. },
  383. goToScanResult(){
  384. let userInfo = wx.getStorageSync('userInfo');
  385. let that = this;
  386. wx.request({
  387. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  388. // data: charePileId,
  389. data:{
  390. chargPileId: that.data.chargPile.chargPileId,
  391. userId: userInfo.userId
  392. },
  393. method: 'POST',
  394. success(res) {
  395. //console.log(res.data);
  396. // log.info('[首页]', '[获取微信扫一扫充电桩]', '[响应]', res.data);
  397. if (!res.data || res.data.code == 500) {
  398. //没有该充电桩信息
  399. wx.showModal({
  400. showCancel: false,
  401. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号',
  402. confirmColor:'#00AADD',
  403. });
  404. } else {
  405. res.data = res.data.result
  406. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  407. 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) {
  408. //充电桩故障
  409. wx.showModal({
  410. showCancel: false,
  411. content: '终端故障,维修中',
  412. confirmColor:'#00AADD',
  413. });
  414. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  415. wx.showModal({
  416. showCancel: false,
  417. content: '正在充电中',
  418. confirmColor:'#00AADD',
  419. });
  420. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  421. wx.setStorage({
  422. key: "scan_chargpile",
  423. data: res.data
  424. });
  425. // log.info('[首页]', '[微信扫一扫充电桩空闲跳转去充电界面]');
  426. let url = `/pages/scan_result/scan_result`;
  427. wx.navigateTo({
  428. url
  429. });
  430. }
  431. }
  432. },
  433. fail(e) {
  434. getApp().showNetworkError();
  435. }
  436. });
  437. }
  438. })