index.js 31 KB

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