index.js 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. //index.js
  2. //获取应用实例
  3. let app = getApp();
  4. let wechat = require("../../utils/wechat");
  5. let amap = require("../../utils/amap");
  6. let Util = require("../../utils/util");
  7. let log = require('../../utils/log.js');
  8. let wxpro = require('../../utils/wx-promise-pro.js');
  9. let mapregionchange_makertap = false;
  10. wxpro.promisifyAll()
  11. // wxpro.promisify(wx.getSystemInfo)().then(console.log)
  12. for (var variable in wx) {
  13. if (wx.hasOwnProperty(variable)) {
  14. wx.pro[variable] = wxpro.promisify(wx[variable])
  15. }
  16. }
  17. Page({
  18. data: {
  19. scanFlag:false,
  20. markers: [],
  21. latitude: 39.9088120620532,
  22. longitude: 116.39747668717192,
  23. user_lat: 39.9088120620532,
  24. user_lon: 116.39747668717192,
  25. textData: null,
  26. city: null,
  27. markerId: null,
  28. keywords: "搜索充电桩",
  29. userInfo: {},
  30. isLogin: false,
  31. myChargeStationsIds: '',
  32. distanceinfo: [
  33. // {
  34. // value: 1000,
  35. // text: '1km'
  36. // }, {
  37. // value: 2000,
  38. // text: '2km'
  39. // }, {
  40. // value: 5000,
  41. // text: '5km'
  42. // },
  43. {
  44. value: 10000,
  45. text: '10km'
  46. },
  47. // {
  48. // value: 20000,
  49. // text: '20km'
  50. // },
  51. {
  52. value: 50000,
  53. text: '50km'
  54. }, {
  55. value: 100000,
  56. text: '100km'
  57. }],
  58. distanceinfoindex: 0,
  59. polygon: [{
  60. points: [{
  61. latitude: 31,
  62. longitude: 131
  63. }, {
  64. latitude: 31,
  65. longitude: 131.1
  66. }, {
  67. latitude: 31.1,
  68. longitude: 131.1
  69. }, , {
  70. latitude: 31.1,
  71. longitude: 131
  72. }]
  73. }],
  74. showModal: false,
  75. notice: null
  76. },
  77. howtouse(){
  78. wx.navigateTo({
  79. url:'/pages/howtouse/howtouse'
  80. });
  81. },
  82. wxScan(q) {
  83. //console.log(decodeURIComponent(e.q));
  84. let charePileId = decodeURIComponent(q).replace("https://cdgl.pjnes.com/", "");
  85. //console.log(charePileId);
  86. log.info('[首页]', '[微信扫一扫]', { 'q': q });
  87. if(!charePileId){
  88. charePileId = "0"
  89. }
  90. if (charePileId) {
  91. let userInfo = wx.getStorageSync('userInfo');
  92. let isLogin = wx.getStorageSync('isLogin');
  93. if (isLogin && userInfo.flag) {
  94. return;
  95. }
  96. if (!isLogin) {
  97. log.info('[首页]', '[未登陆跳转登录界面]');
  98. let url = `/pages/login/phone_login/phone_login`;
  99. wx.navigateTo({
  100. url
  101. });
  102. return;
  103. } else {
  104. log.info('[首页]', '[获取用户是否有未完成订单]', '[请求]', { userId: userInfo.userId });
  105. wx.request({
  106. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  107. data: {
  108. userId: userInfo.userId
  109. },
  110. method: 'POST',
  111. success(res) {
  112. let {
  113. data
  114. } = res;
  115. log.info('[首页]', '[获取用户是否有未完成订单]', '[响应]', data);
  116. if (data && data.code == 200) {
  117. log.info('[首页]', '[有未完成订单跳充电界面]');
  118. //onShow会跳转
  119. } else {
  120. //console.log('无订单');
  121. log.info('[首页]', '[用户无未完成订单]');
  122. log.info('[首页]', '[获取微信扫一扫充电桩]', '[请求]', charePileId);
  123. wx.request({
  124. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  125. // data: charePileId,
  126. data:{
  127. chargPileId:charePileId,
  128. userId: userInfo.userId
  129. },
  130. method: 'POST',
  131. success(res) {
  132. //console.log(res.data);
  133. log.info('[首页]', '[获取微信扫一扫充电桩]', '[响应]', res.data);
  134. if (!res.data || res.data.code == 500) {
  135. //没有该充电桩信息
  136. wx.showModal({
  137. showCancel: false,
  138. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号',
  139. confirmColor:'#00AADD',
  140. });
  141. } else {
  142. res.data = res.data.result
  143. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  144. 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) {
  145. //充电桩故障
  146. wx.showModal({
  147. showCancel: false,
  148. content: '终端故障,维修中',
  149. confirmColor:'#00AADD',
  150. });
  151. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  152. wx.showModal({
  153. showCancel: false,
  154. content: '正在充电中',
  155. confirmColor:'#00AADD',
  156. });
  157. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  158. wx.setStorage({
  159. key: "scan_chargpile",
  160. data: res.data
  161. });
  162. log.info('[首页]', '[微信扫一扫充电桩空闲跳转去充电界面]');
  163. let url = `/pages/scan_result/scan_result`;
  164. wx.navigateTo({
  165. url
  166. });
  167. }
  168. }
  169. },
  170. fail(e) {
  171. getApp().showNetworkError();
  172. }
  173. });
  174. }
  175. },
  176. fail(e) {
  177. getApp().showNetworkError();
  178. }
  179. });
  180. }
  181. }
  182. },
  183. onLoad(e) {
  184. this.scanFlag = false;
  185. wx.hideLoading();
  186. if (e.q) {
  187. //console.log(decodeURIComponent(e.q));
  188. //let charePileId = decodeURIComponent(e.q).replace("https://cdgl.pjnes.com/", "");
  189. //console.log(charePileId);
  190. //if (charePileId){
  191. //}
  192. let userInfo = wx.getStorageSync('userInfo');
  193. let isLogin = wx.getStorageSync('isLogin');
  194. // userInfo.flag=true;
  195. this.setData({
  196. userInfo,
  197. isLogin
  198. });
  199. this.click_scan_control(e.q,false);
  200. // this.wxScan(e.q);
  201. }
  202. log.info('[首页]', '[加载完成]');
  203. amap.getRegeo(function () {
  204. var fail = function (obj) {
  205. wx.showModal({
  206. title: '请求失败',
  207. content: obj.errMsg,
  208. confirmColor:'#00AADD',
  209. });
  210. }
  211. })
  212. .then(d => {
  213. //console.log(d);
  214. let {
  215. latitude,
  216. longitude,
  217. latitude: user_lat,
  218. longitude: user_lon
  219. } = d[0];
  220. //console.log(d[0].regeocodeData.addressComponent);
  221. var {
  222. city
  223. } = d[0].regeocodeData.addressComponent;
  224. if (d[0].regeocodeData.addressComponent.city.length == 0) {
  225. var {
  226. province: city
  227. } = d[0].regeocodeData.addressComponent;
  228. }
  229. let that = this;
  230. let userInfo = wx.getStorageSync('userInfo');
  231. let isLogin = wx.getStorageSync('isLogin');
  232. // userInfo.flag=true;
  233. this.setData({
  234. city,
  235. latitude,
  236. longitude,
  237. user_lat,
  238. user_lon,
  239. userInfo,
  240. isLogin
  241. });
  242. //开始请求充电站信息
  243. var chargStationType;
  244. if (!userInfo.flag) {
  245. //用户是普通用户
  246. chargStationType = '2';
  247. }
  248. wx.request({
  249. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargStations',
  250. data: {
  251. lon: longitude,
  252. lat: latitude,
  253. distance: that.data.distanceinfo[that.data.distanceinfoindex].value,
  254. chargStationType
  255. },
  256. method: 'POST',
  257. success(res) {
  258. //userInfo.flag = true;
  259. if (isLogin && userInfo.flag) {
  260. wx.request({
  261. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/userChargStations',
  262. data: {
  263. userId: userInfo.userId,
  264. lat: latitude,
  265. lon: longitude
  266. },
  267. method: 'POST',
  268. success(res1) {
  269. var myChargeStationsIds = '';
  270. res1.data.forEach((item, index) => {
  271. myChargeStationsIds += item.id + ",";
  272. });
  273. //console.log(myChargeStationsIds);
  274. let {
  275. data
  276. } = res;
  277. let markers = [];
  278. data.forEach((item, index) => {
  279. //item.callout = {
  280. // content: item.name, //文本 String 1.2.0
  281. // display: 'BYCLICK', //'BYCLICK': 点击显示; 'ALWAYS': 常显 String 1.2.0
  282. // textAlign: 'center' //文本对齐方式。有效值: left, right, center String 1.6.0
  283. // };
  284. var iconPath = "/images/marker.png";
  285. if (myChargeStationsIds.indexOf(item.id + ',') != -1) {
  286. iconPath = "/images/marker1.png";
  287. }
  288. if (item.breaknum && item.breaknum != 0) {
  289. iconPath = "/images/marker_b.png";
  290. }
  291. /**
  292. * 运营状态 初始,待运营,运营中,暂停营业,关闭,未运营
  293. * */
  294. //private Long operationState;
  295. var marker = {
  296. name: item.chargStationName,
  297. address: item.address,
  298. width: "46rpx",
  299. height: "67rpx",
  300. chargfeatures: item.chargfeatures ,
  301. iconPath: iconPath,
  302. id: item.id,
  303. callout: {},
  304. latitude: item.lat,
  305. longitude: item.lon,
  306. //distance: item.distance / 1000,
  307. distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
  308. chargPileNum: item.fastCharg + item.slowCharg,
  309. fastCharg: item.fastCharg,
  310. slowCharg: item.slowCharg,
  311. freenum: item.freenum,
  312. fastfreenum: item.fastfreenum,
  313. slowfreenum: item.slowfreenum,
  314. breaknum: item.breaknum,
  315. /** 电费 */
  316. chargprice: item.chargprice,
  317. /** 服务费 */
  318. serviceprice: item.serviceprice,
  319. /** 停车费 */
  320. stopprice: item.stopprice,
  321. operationState: item.operationState
  322. };
  323. markers[index] = marker;
  324. });
  325. that.setData({
  326. markers,
  327. myChargeStationsIds
  328. });
  329. },
  330. fail(e) {
  331. getApp().showNetworkError();
  332. }
  333. });
  334. } else {
  335. let {
  336. data
  337. } = res;
  338. let markers = [];
  339. if(data){
  340. data.forEach((item, index) => {
  341. //item.callout = {
  342. // content: item.name, //文本 String 1.2.0
  343. // display: 'BYCLICK', //'BYCLICK': 点击显示; 'ALWAYS': 常显 String 1.2.0
  344. // textAlign: 'center' //文本对齐方式。有效值: left, right, center String 1.6.0
  345. // };
  346. var iconPath = "/images/marker.png";
  347. //撤销普通用户显示异常站
  348. //if (item.breaknum && item.breaknum != 0) {
  349. // iconPath = "/images/marker_b.png";
  350. //}
  351. //撤销结束
  352. var marker = {
  353. name: item.chargStationName,
  354. address: item.address,
  355. width: "46rpx",
  356. height: "67rpx",
  357. chargfeatures: item.chargfeatures ,
  358. iconPath: iconPath,
  359. id: item.id,
  360. callout: {},
  361. latitude: item.lat,
  362. longitude: item.lon,
  363. //distance: item.distance / 1000,
  364. distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
  365. chargPileNum: item.fastCharg + item.slowCharg,
  366. fastCharg: item.fastCharg,
  367. slowCharg: item.slowCharg,
  368. freenum: item.freenum,
  369. fastfreenum: item.fastfreenum,
  370. slowfreenum: item.slowfreenum,
  371. breaknum: item.breaknum,
  372. /** 电费 */
  373. chargprice: item.chargprice,
  374. /** 服务费 */
  375. serviceprice: item.serviceprice,
  376. /** 停车费 */
  377. stopprice: item.stopprice,
  378. operationState: item.operationState,
  379. sharpChargPrice : item.sharpChargPrice,
  380. sharpServicePrice : item.sharpServicePrice,
  381. peakChargPrice : item.peakChargPrice,
  382. peakServicePrice : item.peakServicePrice,
  383. flatChargPrice : item.flatChargPrice,
  384. flatServicePrice : item.flatServicePrice,
  385. valleyChargPrice : item.valleyChargPrice,
  386. valleyServicePrice : item.valleyServicePrice,
  387. resultList: item.resultList
  388. };
  389. markers[index] = marker;
  390. });
  391. }
  392. that.setData({
  393. markers
  394. });
  395. }
  396. },
  397. fail(e) {
  398. getApp().showNetworkError();
  399. }
  400. });
  401. })
  402. .catch(e => {
  403. console.log(e);
  404. });
  405. let that = this;
  406. let userInfo = wx.getStorageSync('userInfo');
  407. let isLogin = wx.getStorageSync('isLogin');
  408. //console.log(userInfo);
  409. if (isLogin) {
  410. wx.request({
  411. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/lastNotice',
  412. data: { loginName: userInfo.loginName },
  413. method: 'POST',
  414. success(res) {
  415. //console.log(res);
  416. //res.data = { noticeTitle: '派捷充电例行维护通知', noticeContent:'nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好'};
  417. if (res.data) {
  418. that.setData({
  419. showModal: true,
  420. notice: res.data
  421. });
  422. } else {
  423. that.setData({
  424. showModal: false,
  425. notice: null
  426. });
  427. }
  428. },
  429. fail(e) {
  430. //console.log(e);
  431. that.setData({
  432. showModal: false,
  433. notice: null
  434. });
  435. getApp().showNetworkError();
  436. }
  437. });
  438. }
  439. },
  440. //跳转个人中心
  441. bindUserAvatarUrl() {
  442. let url = `/pages/ucenter/index/index`;
  443. wx.navigateTo({
  444. url
  445. });
  446. },
  447. //搜索
  448. bindInput() {
  449. var {
  450. user_lat: latitude,
  451. user_lon: longitude,
  452. city
  453. } = this.data;
  454. //console.log(this.data.city);
  455. let url = `/pages/inputtip/inputtip?city=${city}&lonlat=${longitude},${latitude}`;
  456. wx.navigateTo({
  457. url
  458. });
  459. },
  460. //单击地图mark
  461. makertap(e) {
  462. mapregionchange_makertap = true;
  463. //console.log(e);
  464. let {
  465. markerId
  466. } = e.detail;
  467. // console.log({
  468. // e
  469. // });
  470. let {
  471. markers
  472. } = this.data;
  473. //撤销普通用户显示异常站
  474. let userInfo = wx.getStorageSync('userInfo');
  475. let isLogin = wx.getStorageSync('isLogin');
  476. let showBadMark = false;
  477. if (isLogin && userInfo.flag) {
  478. showBadMark = true;
  479. }
  480. //撤销结束
  481. markers.forEach((item, index) => {
  482. item.iconPath = "/images/marker.png";
  483. if (this.data.myChargeStationsIds.indexOf(item.id + ',') != -1) {
  484. item.iconPath = "/images/marker1.png";
  485. }
  486. //撤销普通用户显示异常站
  487. if (showBadMark) {
  488. //撤销结束
  489. if (item.breaknum && item.breaknum != 0) {
  490. item.iconPath = "/images/marker_b.png";
  491. }
  492. //撤销普通用户显示异常站
  493. }
  494. //撤销结束
  495. if (item.id == markerId) {
  496. item.iconPath = "/images/marker_checked.png";
  497. this.showMarkerInfo(item);
  498. }
  499. });
  500. this.setData({
  501. markers,
  502. markerId
  503. });
  504. },
  505. //将mark呈现在地图中心点,并弹出详细信息框
  506. showMarkerInfo(data) {
  507. let {
  508. latitude,
  509. longitude
  510. } = data;
  511. this.setData({
  512. textData: data,
  513. latitude: latitude,
  514. longitude: longitude
  515. })
  516. },
  517. //改变选中mark的颜色
  518. changeMarkerColor(markerId) {
  519. let {
  520. markers
  521. } = this.data;
  522. //撤销普通用户显示异常站
  523. let userInfo = wx.getStorageSync('userInfo');
  524. let isLogin = wx.getStorageSync('isLogin');
  525. let showBadMark = false;
  526. if (isLogin && userInfo.flag) {
  527. showBadMark = true;
  528. }
  529. //撤销结束
  530. markers.forEach((item, index) => {
  531. item.iconPath = "/images/marker.png";
  532. if (this.data.myChargeStationsIds.indexOf(item.id + ',') != -1) {
  533. item.iconPath = "/images/marker1.png";
  534. }
  535. //撤销普通用户显示异常站
  536. if (showBadMark) {
  537. //撤销结束
  538. if (item.breaknum && item.breaknum != 0) {
  539. item.iconPath = "/images/marker_b.png";
  540. }
  541. //撤销普通用户显示异常站
  542. }
  543. //撤销结束
  544. if (item.id == markerId) {
  545. item.iconPath = "/images/marker_checked.png";
  546. }
  547. })
  548. this.setData({
  549. markers,
  550. markerId
  551. });
  552. },
  553. seeInfo(e){
  554. console.log("11111");
  555. // 起点
  556. let {
  557. user_lat: latitude,
  558. user_lon: longitude,
  559. markers,
  560. markerId,
  561. city,
  562. textData
  563. } = this.data;
  564. let {
  565. name,
  566. address,
  567. chargprice,
  568. serviceprice,
  569. } = textData;
  570. console.log("222222");
  571. console.log(markers);
  572. if (!markers.length) return;
  573. console.log("3333333");
  574. // 终点
  575. markers.forEach((item, index) => {
  576. if (markerId && markerId == item.id) {
  577. let {
  578. name: latitude2,
  579. longitude: longitude2
  580. } = item;
  581. wx.setStorage({
  582. key: "index_seeInfo_chargpile",
  583. data: item
  584. });
  585. let url = `/pages/charginfo/charginfo?name=${name}&address=${address}&chargprice=${chargprice}&serviceprice=${serviceprice}&chargid=${markerId}`;
  586. //console.log(url);
  587. wx.navigateTo({
  588. url
  589. });
  590. }
  591. });
  592. },
  593. //导航
  594. getRoute(e) {
  595. //console.log(e);
  596. // 起点
  597. let {
  598. user_lat: latitude,
  599. user_lon: longitude,
  600. markers,
  601. markerId,
  602. city,
  603. textData
  604. } = this.data;
  605. let {
  606. name,
  607. address
  608. } = textData;
  609. if (!markers.length) return;
  610. // 终点
  611. markers.forEach((item, index) => {
  612. if (markerId && markerId == item.id) {
  613. let {
  614. latitude: latitude2,
  615. longitude: longitude2
  616. } = item;
  617. let url = `/pages/routes/routes?longitude=${longitude}&latitude=${latitude}&longitude2=${longitude2}&latitude2=${latitude2}&city=${city}&name=${name}&desc=${address}`;
  618. //console.log(url);
  619. wx.navigateTo({
  620. url
  621. });
  622. }
  623. });
  624. return;
  625. },
  626. //回到当前位置
  627. click_location_control(e) {
  628. //console.log("回到用户当前定位点");
  629. // let {
  630. // controlId
  631. // } = e;
  632. let mpCtx = wx.createMapContext("map");
  633. mpCtx.moveToLocation();
  634. },
  635. //打开扫一扫
  636. click_scan_control_outer(){
  637. this.click_scan_control("",true)
  638. },
  639. click_scan_control(scanResult,inner) {
  640. if(this.scanFlag){
  641. return;
  642. }
  643. this.scanFlag = true;
  644. wx.showLoading({
  645. title: '努力加载中...',
  646. })
  647. console.log("打开扫一扫");
  648. log.info('[首页]', '[打开扫一扫]');
  649. let that = this;
  650. if (!this.data.isLogin) {
  651. log.info('[首页]', '[未登陆跳转登录界面]');
  652. let url = `/pages/login/phone_login/phone_login`;
  653. that.scanFlag = false;
  654. wx.hideLoading();
  655. wx.navigateTo({
  656. url
  657. });
  658. return;
  659. } else {
  660. if(!this.phoneCheck()){
  661. return;
  662. }
  663. log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: this.data.userInfo.userId });
  664. wx.request({
  665. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  666. data: {
  667. userId: this.data.userInfo.userId
  668. },
  669. method: 'POST',
  670. success(res) {
  671. let {
  672. data
  673. } = res;
  674. let {
  675. result: order
  676. } = data;
  677. log.info('[首页]', '[获取用户是否有未支付订单]', '[响应]', data);
  678. if (data && order && data.code == 200) {
  679. that.scanFlag = false;
  680. wx.hideLoading();
  681. log.info('[首页]', '[用户有未支付订单跳转订单支付界面]');
  682. wx.showModal({
  683. showCancel: false,
  684. content: '你有未支付的订单,请先支付',
  685. confirmColor:'#00AADD',
  686. success: function (res) {
  687. //console.log(res);
  688. if (!res.cancel) {
  689. //点击确定
  690. let url = `/pages/order/order?orderid=${order.orderid}&userId=${order.userId}&chargPileId=${order.chargPileId}`;
  691. wx.navigateTo({
  692. url
  693. });
  694. }
  695. }
  696. });
  697. //console.log(that.data.result);
  698. } else {
  699. //console.log('无订单');
  700. log.info('[首页]', '[用户无未支付订单]');
  701. //console.log("打开扫一扫");
  702. if(inner){
  703. wx.pro.scanCode().then(d=>{
  704. that.afterScanCode(d,that,inner)
  705. }).catch(e=>{
  706. that.scanFlag = false;
  707. wx.hideLoading();
  708. });
  709. }else{
  710. that.afterScanCode(scanResult,that,inner)
  711. }
  712. }
  713. },
  714. fail(e) {
  715. that.scanFlag = false;
  716. wx.hideLoading();
  717. getApp().showNetworkError();
  718. }
  719. });
  720. }
  721. },
  722. afterScanCode(d,that,inner){
  723. let scanResult = ""
  724. if(inner){
  725. //console.log("完成扫一扫");
  726. //console.log(d);
  727. //兼容标准格式hlht://202001022222220101.330414214二维码
  728. scanResult = d.result;
  729. if((!scanResult) || scanResult == ""){
  730. scanResult="*"
  731. }
  732. }else{
  733. scanResult = decodeURIComponent(d)
  734. //console.log(charePileId);
  735. log.info('[首页]', '[微信扫一扫]', { 'd': d });
  736. if(!scanResult){
  737. scanResult = "0"
  738. }
  739. }
  740. if (scanResult.startsWith("hlht://") || scanResult.startsWith("HLHT://")){
  741. scanResult = scanResult. substring(7, scanResult.indexOf("."));
  742. }
  743. scanResult = scanResult.replace("https://cdgl.pjnes.com/", "");
  744. scanResult = scanResult.replace("https://cdglyy.pjnes.com/", "");
  745. console.log('扫描到的内容: [' + scanResult + '] , 是否内部按钮:' + inner)
  746. log.info('[首页]', '[用户完成扫一扫]', scanResult);
  747. log.info('[首页]', '[获取扫一扫充电桩]', '[请求]', scanResult);
  748. wx.request({
  749. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  750. // data: scanResult,
  751. data: {
  752. chargPileId:scanResult,
  753. userId: that.data.userInfo.userId
  754. },
  755. method: 'POST',
  756. success(res) {
  757. log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
  758. if (!res.data || res.data.code == 500) {
  759. that.scanFlag = false;
  760. wx.hideLoading();
  761. //没有该充电桩信息
  762. wx.showModal({
  763. showCancel: false,
  764. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号',
  765. confirmColor:'#00AADD',
  766. });
  767. } else {
  768. res.data = res.data.result
  769. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  770. 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) {
  771. //充电桩故障
  772. wx.showModal({
  773. showCancel: false,
  774. content: '终端故障,维修中',
  775. confirmColor:'#00AADD',
  776. });
  777. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  778. wx.showModal({
  779. showCancel: false,
  780. content: '正在充电中',
  781. confirmColor:'#00AADD',
  782. });
  783. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  784. wx.setStorage({
  785. key: "scan_chargpile",
  786. data: res.data
  787. });
  788. log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
  789. let url = `/pages/scan_result/scan_result`;
  790. that.scanFlag = false;
  791. wx.hideLoading();
  792. wx.navigateTo({
  793. url
  794. });
  795. }
  796. that.scanFlag = false;
  797. wx.hideLoading();
  798. }
  799. },
  800. fail(e) {
  801. getApp().showNetworkError();
  802. }
  803. });
  804. },
  805. //地图位移
  806. mapchange(e) {
  807. if (e.type == 'end') {
  808. if (!mapregionchange_makertap) {
  809. //console.log("移动地图");
  810. let that = this;
  811. let wMap = wx.createMapContext('map');
  812. wMap.getCenterLocation({
  813. type: 'gcj02',
  814. success: function (res) {
  815. let {
  816. latitude,
  817. longitude
  818. } = res;
  819. let userInfo = wx.getStorageSync('userInfo');
  820. let isLogin = wx.getStorageSync('isLogin');
  821. var chargStationType;
  822. if (!userInfo.flag) {
  823. //用户是普通用户
  824. chargStationType = '2';
  825. }
  826. wx.request({
  827. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargStations',
  828. data: {
  829. lon: longitude,
  830. lat: latitude,
  831. distance: that.data.distanceinfo[that.data.distanceinfoindex].value,
  832. chargStationType
  833. },
  834. method: 'POST',
  835. success(res) {
  836. let {
  837. data
  838. } = res;
  839. let markers = [];
  840. var flag = false;
  841. if(data){
  842. data.forEach((item, index) => {
  843. var iconPath;
  844. if (that.data.markerId && that.data.markerId == item.id) {
  845. iconPath = "/images/marker_checked.png";
  846. flag = true;
  847. } else {
  848. iconPath = "/images/marker.png";
  849. if (that.data.myChargeStationsIds.indexOf(item.id + ',') != -1) {
  850. iconPath = "/images/marker1.png";
  851. }
  852. //撤销普通用户显示异常站
  853. if (isLogin && userInfo.flag) {
  854. //撤销结束
  855. if (item.breaknum && item.breaknum != 0) {
  856. iconPath = "/images/marker_b.png";
  857. }
  858. //撤销普通用户显示异常站
  859. }
  860. //撤销结束
  861. }
  862. //console.log(Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon));
  863. var marker = {
  864. name: item.chargStationName,
  865. address: item.address,
  866. width: "46rpx",
  867. height: "67rpx",
  868. chargfeatures: item.chargfeatures ,
  869. iconPath: iconPath,
  870. id: item.id,
  871. callout: {},
  872. latitude: item.lat,
  873. longitude: item.lon,
  874. //distance: item.distance / 1000,
  875. distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
  876. chargPileNum: item.fastCharg + item.slowCharg,
  877. fastCharg: item.fastCharg,
  878. slowCharg: item.slowCharg,
  879. freenum: item.freenum,
  880. fastfreenum: item.fastfreenum,
  881. slowfreenum: item.slowfreenum,
  882. breaknum: item.breaknum,
  883. /** 电费 */
  884. chargprice: item.chargprice,
  885. /** 服务费 */
  886. serviceprice: item.serviceprice,
  887. /** 停车费 */
  888. stopprice: item.stopprice,
  889. operationState: item.operationState,
  890. sharpChargPrice : item.sharpChargPrice,
  891. sharpServicePrice : item.sharpServicePrice,
  892. peakChargPrice : item.peakChargPrice,
  893. peakServicePrice : item.peakServicePrice,
  894. flatChargPrice : item.flatChargPrice,
  895. flatServicePrice : item.flatServicePrice,
  896. valleyChargPrice : item.valleyChargPrice,
  897. valleyServicePrice : item.valleyServicePrice,
  898. resultList: item.resultList
  899. };
  900. markers[index] = marker;
  901. });
  902. }
  903. if (!flag) {
  904. that.setData({
  905. textData: null,
  906. markerId: null,
  907. });
  908. }
  909. that.setData({
  910. markers: markers
  911. });
  912. },
  913. fail(e) {
  914. getApp().showNetworkError();
  915. }
  916. });
  917. }
  918. });
  919. } else {
  920. //点击marker的情况下
  921. //console.log("点击marker");
  922. mapregionchange_makertap = false;
  923. }
  924. }
  925. },
  926. phoneCheck(){
  927. if (this.data.userInfo.bindingPhone==0) {
  928. wx.showModal({
  929. title: '提示',
  930. content: '当前账户未绑定手机号,请您进行手机号绑定操作',
  931. showCancel:false,
  932. confirmText: '去绑定',
  933. confirmColor:'#00AADD',
  934. success: function (res1) {
  935. let url = `/pages/bindPhone/bindPhone`;
  936. wx.navigateTo({
  937. url
  938. });
  939. }
  940. })
  941. return false;
  942. }else{
  943. return true;
  944. }
  945. },
  946. /**
  947. * 生命周期函数--监听页面显示
  948. */
  949. onShow: function () {
  950. let userInfo = wx.getStorageSync('userInfo');
  951. let isLogin = wx.getStorageSync('isLogin');
  952. // 页面显示
  953. if (userInfo && isLogin) {
  954. //console.log(userInfo);
  955. //userInfo.flag = true;
  956. this.setData({
  957. userInfo: userInfo,
  958. isLogin: isLogin
  959. });
  960. if ((!userInfo.userId && userInfo.userId != 0)){
  961. log.info('[首页]', '[已登陆未有用户ID跳转登录界面]');
  962. let url = `/pages/login/phone_login/phone_login`;
  963. wx.navigateTo({
  964. url
  965. });
  966. return;
  967. }
  968. log.info('[首页]', '[获取用户是否有未完成订单]', '[请求]', { userId: userInfo.userId });
  969. wx.request({
  970. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  971. data: {
  972. userId: userInfo.userId
  973. },
  974. method: 'POST',
  975. success(res) {
  976. let {
  977. data
  978. } = res;
  979. log.info('[首页]', '[获取用户是否有未完成订单]', '[响应]', data);
  980. if (data && data.code == 200) {
  981. log.info('[首页]', '[有未完成订单跳充电界面]');
  982. //获取用户正在充电的订单,并跳转到该页面
  983. let url = `/pages/charging/charging?orderid=${data.result.orderid}&userId=${userInfo.userId}&chargPileId=${data.result.chargPileId}`;
  984. //let url = `/pages/charging/charging?userId=${userInfo.userId}`;
  985. wx.navigateTo({
  986. url
  987. });
  988. } else {
  989. //console.log(res);
  990. }
  991. },
  992. fail(e) {
  993. getApp().showNetworkError();
  994. }
  995. });
  996. } else {
  997. //未登录信息
  998. this.setData({
  999. userInfo: {}
  1000. });
  1001. }
  1002. },
  1003. bindDistanceinfoChange: function (e) {
  1004. let distance = this.data.distanceinfo[e.detail.value].value;
  1005. this.setData({
  1006. distanceinfoindex: e.detail.value
  1007. });
  1008. },
  1009. Sure: function () {
  1010. this.setData({
  1011. showModal: false
  1012. });
  1013. }
  1014. })