carControl.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. },
  108. /**
  109. * 生命周期函数--监听页面初次渲染完成
  110. */
  111. onReady() {
  112. },
  113. /**
  114. * 生命周期函数--监听页面显示
  115. */
  116. onShow() {
  117. },
  118. /**
  119. * 生命周期函数--监听页面隐藏
  120. */
  121. onHide() {
  122. },
  123. /**
  124. * 生命周期函数--监听页面卸载
  125. */
  126. onUnload() {
  127. },
  128. /**
  129. * 页面相关事件处理函数--监听用户下拉动作
  130. */
  131. onPullDownRefresh() {
  132. },
  133. /**
  134. * 页面上拉触底事件的处理函数
  135. */
  136. onReachBottom() {
  137. },
  138. /**
  139. * 用户点击右上角分享
  140. */
  141. onShareAppMessage() {
  142. },
  143. upBtn(){
  144. let that = this;
  145. // if(that.wxTestDebug(that,'u') > 4){
  146. // return ;
  147. // }
  148. that.bettyControl(1)
  149. },
  150. downBtn(){
  151. let that = this;
  152. // if(that.wxTestDebug(that,'d') > 4){
  153. // return ;
  154. // }
  155. that.bettyControl(2);
  156. },
  157. bettyControl(bettyControl){
  158. let that = this;
  159. wx.showLoading({
  160. title: '控制电池中。。。',
  161. mask: true
  162. })
  163. wx.request({
  164. url: getApp().globalData.postHeadAgreement +'/restapi/pileLog/bettyControl',
  165. data: {
  166. bettyControl,
  167. chargPileId: that.data.chargPile.chargPileId
  168. },
  169. method: 'POST',
  170. success(res) {
  171. console.info(res)
  172. wx.hideLoading()
  173. wx.showToast({
  174. icon: 'none',
  175. title: res.data.msg,
  176. duration: 1000
  177. })
  178. }
  179. })
  180. },
  181. wxTestDebugClick(){
  182. let that = this
  183. if(new Date().valueOf() - that.data.wxTest.t <= 1000){
  184. that.data.wxTest.tnum = that.data.wxTest.tnum + 1
  185. }else{
  186. that.data.wxTest.tnum = 0
  187. }
  188. that.data.wxTest.t = new Date().valueOf()
  189. if(that.data.wxTest.tnum > 10){
  190. wx.request({
  191. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/wxTest/switch',
  192. data: {
  193. },
  194. method: 'GET',
  195. success(res) {
  196. that.data.wxTest.tnum = 0
  197. wx.showToast({
  198. title: "调试模式: " + res.data.msg,
  199. duration: 1000
  200. })
  201. }
  202. })
  203. }
  204. },
  205. wxTestDebug(that,s){
  206. // let that = this;
  207. if(that.data.wxTest.msg.length == that.data.wxTest.index + 1){
  208. wx.request({
  209. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/wxTest/switch',
  210. data: {
  211. },
  212. method: 'GET',
  213. success(res) {
  214. wx.showToast({
  215. title: "调试模式: " + res.data.msg,
  216. duration: 1000
  217. })
  218. }
  219. })
  220. idx = 0;
  221. that.setData({
  222. wxTest:{
  223. msg:that.data.wxTest.msg,
  224. index: idx,
  225. }
  226. })
  227. return;
  228. }
  229. let idx = 0
  230. if(that.data.wxTest.msg.substr(that.data.wxTest.index,1) == s){
  231. idx = that.data.wxTest.index + 1
  232. that.setData({
  233. wxTest:{
  234. msg:that.data.wxTest.msg,
  235. index: idx,
  236. }
  237. })
  238. }else{
  239. idx = 0;
  240. that.setData({
  241. wxTest:{
  242. msg:that.data.wxTest.msg,
  243. index: idx,
  244. }
  245. })
  246. }
  247. return idx;
  248. },
  249. carTap(e){
  250. let carIndex = e.currentTarget.dataset.idx;
  251. this.setData({
  252. carIndex
  253. })
  254. },
  255. locationTap(e){
  256. let locationIndex = e.currentTarget.dataset.idx;
  257. this.setData({
  258. locationIndex
  259. })
  260. },
  261. tractorTaskTypeTap(e){
  262. let tractorTaskTypeIndex = e.currentTarget.dataset.idx;
  263. this.setData({
  264. tractorTaskTypeIndex
  265. })
  266. },
  267. submit(){
  268. let that = this;
  269. if(this.data.carIndex==-1){
  270. wx.showToast({
  271. icon: 'none',
  272. title: '请选择车辆',
  273. duration: 1000
  274. })
  275. return ;
  276. }
  277. if(this.data.locationIndex==-1){
  278. wx.showToast({
  279. icon: 'none',
  280. title: '请选择点位',
  281. duration: 1000
  282. })
  283. return ;
  284. }
  285. if(this.data.tractorTaskTypeIndex==-1){
  286. wx.showToast({
  287. icon: 'none',
  288. title: '请选择任务类型',
  289. duration: 1000
  290. })
  291. return ;
  292. }
  293. let car = this.data.cars[this.data.carIndex];
  294. let location = this.data.locations[this.data.locationIndex]
  295. wx.showModal({
  296. title: '提示',
  297. content: '是否调度当前车辆?' + car.carName + "|" + location.pointShowName,
  298. complete: (res) => {
  299. if (res.cancel) {
  300. }
  301. if (res.confirm) {
  302. wx.showLoading({
  303. title: '调度车辆中。。。',
  304. mask: true
  305. })
  306. let userInfo = wx.getStorageSync('userInfo');
  307. // userId:
  308. wx.request({
  309. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/createIvCarRequirement?'
  310. + 'finalTargetParkPointId=' + location.id
  311. + '&carId=' + car.id
  312. // + '&chargePileId=' + that.data.chargPile.id
  313. + '&chargePileId=12'
  314. + '&userId=' + userInfo.userId
  315. // + '&requirementType=' + that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  316. + '&requirementType=0',
  317. data:{
  318. // "finalTargetParkPointId":location.id,
  319. // "carId":car.id,
  320. // "chargePileId":that.data.chargPile.chargPileId,
  321. // "userId":userInfo.userId,
  322. // "requirementType":that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  323. },
  324. method: 'POST',
  325. success(ress) {
  326. if(ress && ress.statusCode==200){
  327. let iid = ress.data.result.id;
  328. console.info(iid);
  329. console.info("11111111111111111");
  330. wx.request({
  331. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/xingshen',
  332. data: {
  333. // capacityResourceId: car.id,
  334. // targetParkPointId: location.id,
  335. // tractorTaskType: that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  336. // ivCarId:car.id,
  337. // targetParkPointId: 1,
  338. // capacityResourceId: location.id,
  339. // tractorTaskType: that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  340. carId:car.id,
  341. parkPointId: location.id,
  342. carRequirementId: iid,
  343. tractorTaskType: that.data.tractorTaskTypeList[that.data.tractorTaskTypeIndex]['val'],
  344. },
  345. method: 'POST',
  346. success(res) {
  347. wx.hideLoading();
  348. if(res.statusCode==200){
  349. if(res.data.code==200){
  350. wx.showToast({
  351. icon: 'success',
  352. title: res.data.msg,
  353. duration: 1000
  354. })
  355. }else{
  356. wx.showToast({
  357. icon: 'none',
  358. title: '调度失败:' + res.data.msg,
  359. duration: 1000
  360. })
  361. }
  362. }else{
  363. wx.showToast({
  364. icon: 'none',
  365. title: '调度失败',
  366. duration: 1000
  367. })
  368. }
  369. }
  370. })
  371. }
  372. },
  373. })
  374. }
  375. }
  376. })
  377. },
  378. })