index.js 34 KB

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