eleCarMap.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. // pages/charginfo/eleCarMap.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. longitude:116.4965075,
  8. latitude: 40.006103,
  9. speed:0,
  10. scale:20,
  11. accuracy:0,
  12. chargid:0,
  13. ele_chargList:[],
  14. ele_park:[1,2,3],
  15. markers:[],
  16. markTemp:{
  17. id: 1,
  18. latitude: 23.098994,
  19. longitude: 113.322520,
  20. iconPath: '/images/triangle.png',
  21. height: 5,
  22. width: 5,
  23. customCallout: {
  24. anchorX: 0,
  25. anchorY: 0,
  26. display: "ALWAYS"
  27. }
  28. // anchor:{x: 0.5, y:1 },
  29. // callout: {
  30. // content: '文本内容',
  31. // color: '#000000',
  32. // fontSize: 14,
  33. // borderWidth: 2,
  34. // borderRadius: 5,
  35. // borderColor: '#FFFFFF',
  36. // bgColor: '#ffffff',
  37. // padding: 5,
  38. // display: 'ALWAYS',
  39. // textAlign: 'center'
  40. // }
  41. },
  42. eleActiveIndex: -1,
  43. parkActiveIndex: -1,
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad(options) {
  49. let that = this;
  50. let json = wx.getStorageSync("eleCarMapPage")
  51. let {chargid} = json;
  52. that.setData({chargid})
  53. let userInfo = wx.getStorageSync('userInfo');
  54. that.setData({
  55. userInfo
  56. })
  57. this.getEleData()
  58. },
  59. /**
  60. * 生命周期函数--监听页面初次渲染完成
  61. */
  62. onReady() {
  63. },
  64. /**
  65. * 生命周期函数--监听页面显示
  66. */
  67. onShow() {
  68. },
  69. /**
  70. * 生命周期函数--监听页面隐藏
  71. */
  72. onHide() {
  73. },
  74. /**
  75. * 生命周期函数--监听页面卸载
  76. */
  77. onUnload() {
  78. },
  79. /**
  80. * 页面相关事件处理函数--监听用户下拉动作
  81. */
  82. onPullDownRefresh() {
  83. },
  84. /**
  85. * 页面上拉触底事件的处理函数
  86. */
  87. onReachBottom() {
  88. },
  89. /**
  90. * 用户点击右上角分享
  91. */
  92. onShareAppMessage() {
  93. },
  94. addHandler(json){
  95. let {
  96. chargid
  97. } = json
  98. this.setData({
  99. chargid
  100. })
  101. this.getEleData()
  102. },
  103. callouttap(e){
  104. // eleActiveIndex: -1,
  105. // parkActiveIndex: -1,
  106. let that = this;
  107. let index = e.markerId;
  108. console.info(e.markerId)
  109. let ele_chargList = this.data.ele_chargList;
  110. let mm = ele_chargList[index]
  111. if(mm.lock){
  112. return
  113. }
  114. if(mm.active){
  115. mm.active = false;
  116. if(mm.objType == 'ele'){
  117. that.setData({
  118. eleActiveIndex:-1
  119. })
  120. }else{
  121. that.setData({
  122. parkActiveIndex:-1
  123. })
  124. }
  125. this.setData({
  126. ele_chargList
  127. })
  128. return;
  129. }
  130. mm.active = true;
  131. if(mm.objType == 'ele'){
  132. if( that.data.eleActiveIndex >=0){
  133. ele_chargList[ that.data.eleActiveIndex].active = false
  134. }
  135. that.setData({
  136. eleActiveIndex:index
  137. })
  138. }else{
  139. if( that.data.parkActiveIndex >=0){
  140. ele_chargList[ that.data.parkActiveIndex].active = false
  141. }
  142. that.setData({
  143. parkActiveIndex:index
  144. })
  145. }
  146. // ele_chargList.forEach(key=>{
  147. // })
  148. console.info(this.data.ele_chargList)
  149. let car_active = false
  150. if(this.data.parkActiveIndex >=0 && this.data.eleActiveIndex >=0 ){
  151. car_active = true
  152. }
  153. this.setData({
  154. ele_chargList,
  155. car_active
  156. })
  157. },
  158. getEleData(){
  159. console.info("查询数据")
  160. // 新源恒远210调试站
  161. let that = this;
  162. // 充电桩
  163. wx.request({
  164. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/chargInfo',
  165. data: {
  166. id: that.data.chargid,
  167. pagenum: 1,
  168. ivType: 1,
  169. pagesize: 10000,
  170. },
  171. method: 'POST',
  172. success(res) {
  173. console.log(res);
  174. let chargList = res.data.chargList.rows;
  175. let ele_chargList = []
  176. chargList.forEach(key => {
  177. let chargstatusname = '';
  178. let chargstatusclass = '';
  179. if(key.chargstatus == 2){
  180. chargstatusname='空闲中'
  181. chargstatusclass = 'chargstatus_kxz'
  182. }else if(key.chargstatus == 11){
  183. chargstatusname='已插枪'
  184. chargstatusclass = 'chargstatus_ycq'
  185. }else if(key.chargstatus == 3 || key.chargstatus == 10){
  186. chargstatusname='充电中'
  187. chargstatusclass = 'chargstatus_cdz'
  188. }else if(key.chargstatus == 0){
  189. chargstatusname='离线'
  190. chargstatusclass = 'chargstatus_lx'
  191. }else{
  192. chargstatusname='故障'
  193. chargstatusclass = 'chargstatus_gz'
  194. }
  195. key.chargstatusname = chargstatusname;
  196. key.chargstatusclass = chargstatusclass;
  197. let mark = JSON.parse(JSON.stringify(that.data.markTemp));
  198. if(key?.currentParkPoint?.latitude && key?.currentParkPoint?.longitude ){
  199. mark.id = that.data.ele_chargList.length + ele_chargList.length;
  200. mark.latitude = key?.currentParkPoint?.latitude
  201. mark.longitude = key?.currentParkPoint?.longitude
  202. mark['ele_lock'] = key?.lockStatus == 1
  203. mark['ele_unlock'] = key?.lockStatus == 0
  204. mark['park_lock'] = false
  205. mark['park_unlock'] = false
  206. mark['lock'] = mark['ele_lock'] || mark['park_lock']
  207. mark['active'] = false
  208. mark['title'] = key?.currentSoc? key?.currentSoc + '%' : '-'
  209. mark['type'] = mark['ele_lock'] ? '锁定' : '未锁定'
  210. mark['objType'] = 'ele'
  211. // mark['chargPileId'] = that.data.chargid
  212. // mark['chargPileId'] = key?.chargPileId
  213. mark['chargPileId'] = key?.id
  214. // mark.callout.content = key?.currentParkPoint?.pointShowName
  215. ele_chargList.push(mark)
  216. that.setData({
  217. longitude:mark.longitude,
  218. latitude:mark.latitude,
  219. })
  220. }
  221. })
  222. console.log(ele_chargList);
  223. // that.rechargeTimeOrder(chargemoneylogs);
  224. wx.hideLoading()
  225. that.setData({
  226. ele_chargList: that.data.ele_chargList.concat(ele_chargList),
  227. markers: that.data.markers.concat(ele_chargList),
  228. // ele_total: res.data.chargList.total,
  229. // ele_dataLoading: false,
  230. // ele_fastFree : res.data.fastFree,
  231. // ele_slowFree : res.data.slowFree,
  232. // ele_fastSum : res.data.fastSum,
  233. // ele_slowSum : res.data.slowSum
  234. });
  235. console.log(ele_chargList);
  236. }
  237. });
  238. // 停靠点
  239. wx.request({
  240. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/ivparkByStation',
  241. data: {
  242. id: that.data.chargid,
  243. pagenum: 1,
  244. ivType: 1,
  245. pagesize: 10000,
  246. },
  247. method: 'POST',
  248. success(res) {
  249. console.log(res);
  250. let chargList = res.data;
  251. let ele_chargList = []
  252. chargList.forEach(key => {
  253. let chargstatusname = '';
  254. let chargstatusclass = '';
  255. if(key.chargstatus == 2){
  256. chargstatusname='空闲中'
  257. chargstatusclass = 'chargstatus_kxz'
  258. }else if(key.chargstatus == 11){
  259. chargstatusname='已插枪'
  260. chargstatusclass = 'chargstatus_ycq'
  261. }else if(key.chargstatus == 3 || key.chargstatus == 10){
  262. chargstatusname='充电中'
  263. chargstatusclass = 'chargstatus_cdz'
  264. }else if(key.chargstatus == 0){
  265. chargstatusname='离线'
  266. chargstatusclass = 'chargstatus_lx'
  267. }else{
  268. chargstatusname='故障'
  269. chargstatusclass = 'chargstatus_gz'
  270. }
  271. key.chargstatusname = chargstatusname;
  272. key.chargstatusclass = chargstatusclass;
  273. let mark = JSON.parse(JSON.stringify(that.data.markTemp));
  274. mark.id = that.data.ele_chargList.length + ele_chargList.length;
  275. mark.latitude = key?.latitude
  276. mark.longitude = key?.longitude
  277. mark['ele_lock'] = false
  278. mark['ele_unlock'] = false
  279. mark['park_lock'] = key?.parkStatus == 1
  280. mark['park_unlock'] = key?.parkStatus == 0
  281. mark['lock'] = mark['ele_lock'] || mark['park_lock']
  282. mark['active'] = false
  283. mark['title'] = key?.pointShowName? key?.pointShowName : '-'
  284. mark['type'] = mark['ele_lock'] ? '占用' : '空闲'
  285. mark['objType'] = 'park'
  286. mark['ivParkPointId'] = key?.ivParkPointId;
  287. // mark.callout.content = key?.currentParkPoint?.pointShowName
  288. ele_chargList.push(mark)
  289. that.setData({
  290. longitude:mark.longitude,
  291. latitude:mark.latitude,
  292. })
  293. })
  294. console.log(ele_chargList);
  295. // that.rechargeTimeOrder(chargemoneylogs);
  296. wx.hideLoading()
  297. that.setData({
  298. ele_chargList: that.data.ele_chargList.concat(ele_chargList),
  299. markers: that.data.markers.concat(ele_chargList),
  300. // ele_park: that.data.ele_park.concat(chargList),
  301. // ele_total: res.data.chargList.total,
  302. // ele_dataLoading: false,
  303. // ele_fastFree : res.data.fastFree,
  304. // ele_slowFree : res.data.slowFree,
  305. // ele_fastSum : res.data.fastSum,
  306. // ele_slowSum : res.data.slowSum
  307. });
  308. }
  309. });
  310. },
  311. callCar(){
  312. let that = this
  313. let car_active = that.data.car_active;
  314. if(!car_active){
  315. return;
  316. }
  317. let ivParkPointId = that.data.ele_chargList[that.data.parkActiveIndex].ivParkPointId
  318. let chargePileId = that.data.ele_chargList[that.data.eleActiveIndex].chargPileId
  319. let userId = that.data.userInfo.userId
  320. wx.request({
  321. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/callCarRequirement?'
  322. + 'ivParkPointId=' + ivParkPointId
  323. + '&chargePileId=' + chargePileId
  324. + '&userId=' + userId
  325. + '&requirementType=0',
  326. data: {
  327. },
  328. method: 'POST',
  329. success: function (res) {
  330. if( res.data.code ==200){
  331. // 走你
  332. let url = `/pages/batteryPack/batteryPackWait`;
  333. wx.redirectTo({
  334. url
  335. });
  336. }else{
  337. // 给出提示
  338. wx.showModal({
  339. showCancel: false,
  340. content: "调度失败" + res.data?.msg,
  341. confirmColor:'#00AADD',
  342. });
  343. }
  344. },
  345. fail(e) {
  346. console.log("呼叫充电车失败");
  347. }
  348. })
  349. }
  350. })