index.js 34 KB

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