index.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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.scanFlag){
  595. return;
  596. }
  597. this.scanFlag = true;
  598. wx.showLoading({
  599. title: '努力加载中...',
  600. })
  601. console.log("打开扫一扫");
  602. log.info('[首页]', '[打开扫一扫]');
  603. let that = this;
  604. if (!this.data.isLogin) {
  605. log.info('[首页]', '[未登陆跳转登录界面]');
  606. let url = `/pages/login/phone_login/phone_login`;
  607. that.scanFlag = false;
  608. wx.hideLoading();
  609. wx.navigateTo({
  610. url
  611. });
  612. return;
  613. } else {
  614. log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: this.data.userInfo.userId });
  615. wx.request({
  616. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  617. data: {
  618. userId: this.data.userInfo.userId
  619. },
  620. method: 'POST',
  621. success(res) {
  622. let {
  623. data
  624. } = res;
  625. let {
  626. result: order
  627. } = data;
  628. log.info('[首页]', '[获取用户是否有未支付订单]', '[响应]', data);
  629. if (data && order && data.code == 200) {
  630. that.scanFlag = false;
  631. wx.hideLoading();
  632. log.info('[首页]', '[用户有未支付订单跳转订单支付界面]');
  633. wx.showModal({
  634. showCancel: false,
  635. content: '你有未支付的订单,请先支付',
  636. success: function (res) {
  637. //console.log(res);
  638. if (!res.cancel) {
  639. //点击确定
  640. let url = `/pages/order/order?orderid=${order.orderid}&userId=${order.userId}&chargPileId=${order.chargPileId}`;
  641. wx.navigateTo({
  642. url
  643. });
  644. }
  645. }
  646. });
  647. //console.log(that.data.result);
  648. } else {
  649. //console.log('无订单');
  650. log.info('[首页]', '[用户无未支付订单]');
  651. //console.log("打开扫一扫");
  652. wx.scanCode({
  653. success: function (d) {
  654. //console.log("完成扫一扫");
  655. //console.log(d);
  656. //兼容标准格式hlht://202001022222220101.330414214二维码
  657. let scanResult = d.result;
  658. if((!scanResult) || scanResult == ""){
  659. scanResult="*"
  660. }
  661. console.log(scanResult);
  662. if (scanResult.startsWith("hlht://") || scanResult.startsWith("HLHT://")){
  663. scanResult = scanResult.substring(7, scanResult.indexOf("."));
  664. }
  665. console.log(scanResult);
  666. log.info('[首页]', '[用户完成扫一扫]', scanResult);
  667. log.info('[首页]', '[获取扫一扫充电桩]', '[请求]', scanResult);
  668. wx.request({
  669. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  670. // data: scanResult,
  671. data: {
  672. chargPileId:scanResult,
  673. userId: that.data.userInfo.userId
  674. },
  675. method: 'POST',
  676. success(res) {
  677. console.log(scanResult);
  678. log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
  679. if (!res.data || res.data.code == 500) {
  680. that.scanFlag = false;
  681. wx.hideLoading();
  682. //没有该充电桩信息
  683. wx.showModal({
  684. showCancel: false,
  685. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号'
  686. });
  687. } else {
  688. res.data = res.data.result
  689. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  690. 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) {
  691. //充电桩故障
  692. wx.showModal({
  693. showCancel: false,
  694. content: '终端故障,维修中'
  695. });
  696. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  697. wx.showModal({
  698. showCancel: false,
  699. content: '正在充电中'
  700. });
  701. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  702. wx.setStorage({
  703. key: "scan_chargpile",
  704. data: res.data
  705. });
  706. log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
  707. let url = `/pages/scan_result/scan_result`;
  708. that.scanFlag = false;
  709. wx.hideLoading();
  710. wx.navigateTo({
  711. url
  712. });
  713. }
  714. that.scanFlag = false;
  715. wx.hideLoading();
  716. }
  717. },
  718. fail(e) {
  719. getApp().showNetworkError();
  720. }
  721. });
  722. },
  723. fail(e){
  724. that.scanFlag = false;
  725. wx.hideLoading();
  726. }
  727. });
  728. }
  729. },
  730. fail(e) {
  731. that.scanFlag = false;
  732. wx.hideLoading();
  733. getApp().showNetworkError();
  734. }
  735. });
  736. }
  737. },
  738. //地图位移
  739. mapchange(e) {
  740. if (e.type == 'end') {
  741. if (!mapregionchange_makertap) {
  742. //console.log("移动地图");
  743. let that = this;
  744. let wMap = wx.createMapContext('map');
  745. wMap.getCenterLocation({
  746. type: 'gcj02',
  747. success: function (res) {
  748. let {
  749. latitude,
  750. longitude
  751. } = res;
  752. let userInfo = wx.getStorageSync('userInfo');
  753. let isLogin = wx.getStorageSync('isLogin');
  754. var chargStationType;
  755. if (!userInfo.flag) {
  756. //用户是普通用户
  757. chargStationType = '2';
  758. }
  759. wx.request({
  760. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargStations',
  761. data: {
  762. lon: longitude,
  763. lat: latitude,
  764. distance: that.data.distanceinfo[that.data.distanceinfoindex].value,
  765. chargStationType
  766. },
  767. method: 'POST',
  768. success(res) {
  769. let {
  770. data
  771. } = res;
  772. let markers = [];
  773. var flag = false;
  774. if(data){
  775. data.forEach((item, index) => {
  776. var iconPath;
  777. if (that.data.markerId && that.data.markerId == item.id) {
  778. iconPath = "/images/marker_checked.png";
  779. flag = true;
  780. } else {
  781. iconPath = "/images/marker.png";
  782. if (that.data.myChargeStationsIds.indexOf(item.id + ',') != -1) {
  783. iconPath = "/images/marker1.png";
  784. }
  785. //撤销普通用户显示异常站
  786. if (isLogin && userInfo.flag) {
  787. //撤销结束
  788. if (item.breaknum && item.breaknum != 0) {
  789. iconPath = "/images/marker_b.png";
  790. }
  791. //撤销普通用户显示异常站
  792. }
  793. //撤销结束
  794. }
  795. //console.log(Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon));
  796. var marker = {
  797. name: item.chargStationName,
  798. address: item.address,
  799. width: "46rpx",
  800. height: "67rpx",
  801. iconPath: iconPath,
  802. id: item.id,
  803. callout: {},
  804. latitude: item.lat,
  805. longitude: item.lon,
  806. //distance: item.distance / 1000,
  807. distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
  808. chargPileNum: item.fastCharg + item.slowCharg,
  809. fastCharg: item.fastCharg,
  810. slowCharg: item.slowCharg,
  811. freenum: item.freenum,
  812. fastfreenum: item.fastfreenum,
  813. slowfreenum: item.slowfreenum,
  814. breaknum: item.breaknum,
  815. /** 电费 */
  816. chargprice: item.chargprice,
  817. /** 服务费 */
  818. serviceprice: item.serviceprice,
  819. /** 停车费 */
  820. stopprice: item.stopprice,
  821. operationState: item.operationState
  822. };
  823. markers[index] = marker;
  824. });
  825. }
  826. if (!flag) {
  827. that.setData({
  828. textData: null,
  829. markerId: null,
  830. });
  831. }
  832. that.setData({
  833. markers: markers
  834. });
  835. },
  836. fail(e) {
  837. getApp().showNetworkError();
  838. }
  839. });
  840. }
  841. });
  842. } else {
  843. //点击marker的情况下
  844. //console.log("点击marker");
  845. mapregionchange_makertap = false;
  846. }
  847. }
  848. },
  849. /**
  850. * 生命周期函数--监听页面显示
  851. */
  852. onShow: function () {
  853. let userInfo = wx.getStorageSync('userInfo');
  854. let isLogin = wx.getStorageSync('isLogin');
  855. // 页面显示
  856. if (userInfo && isLogin) {
  857. //console.log(userInfo);
  858. //userInfo.flag = true;
  859. this.setData({
  860. userInfo: userInfo,
  861. isLogin: isLogin
  862. });
  863. if ((!userInfo.userId && userInfo.userId != 0)){
  864. log.info('[首页]', '[已登陆未有用户ID跳转登录界面]');
  865. let url = `/pages/login/phone_login/phone_login`;
  866. wx.navigateTo({
  867. url
  868. });
  869. return;
  870. }
  871. log.info('[首页]', '[获取用户是否有未完成订单]', '[请求]', { userId: userInfo.userId });
  872. wx.request({
  873. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  874. data: {
  875. userId: userInfo.userId
  876. },
  877. method: 'POST',
  878. success(res) {
  879. let {
  880. data
  881. } = res;
  882. log.info('[首页]', '[获取用户是否有未完成订单]', '[响应]', data);
  883. if (data && data.code == 200) {
  884. log.info('[首页]', '[有未完成订单跳充电界面]');
  885. //获取用户正在充电的订单,并跳转到该页面
  886. let url = `/pages/charging/charging?orderid=${data.result.orderid}&userId=${userInfo.userId}&chargPileId=${data.result.chargPileId}`;
  887. //let url = `/pages/charging/charging?userId=${userInfo.userId}`;
  888. wx.navigateTo({
  889. url
  890. });
  891. } else {
  892. //console.log(res);
  893. }
  894. },
  895. fail(e) {
  896. getApp().showNetworkError();
  897. }
  898. });
  899. } else {
  900. //未登录信息
  901. this.setData({
  902. userInfo: {}
  903. });
  904. }
  905. },
  906. bindDistanceinfoChange: function (e) {
  907. let distance = this.data.distanceinfo[e.detail.value].value;
  908. this.setData({
  909. distanceinfoindex: e.detail.value
  910. });
  911. },
  912. Sure: function () {
  913. this.setData({
  914. showModal: false
  915. });
  916. }
  917. })