index.js 36 KB

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