index.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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. carParkingRate: false,
  77. showPrivacy:false
  78. },
  79. howtouse(){
  80. wx.navigateTo({
  81. url:'/pages/howtouse/howtouse'
  82. });
  83. },
  84. wxScan(q) {
  85. //console.log(decodeURIComponent(e.q));
  86. let charePileId = decodeURIComponent(q).replace("https://cdgl.pjnes.com/", "");
  87. //console.log(charePileId);
  88. log.info('[首页]', '[微信扫一扫]', { 'q': q });
  89. if(!charePileId){
  90. charePileId = "0"
  91. }
  92. if (charePileId) {
  93. let userInfo = wx.getStorageSync('userInfo');
  94. let isLogin = wx.getStorageSync('isLogin');
  95. if (isLogin && userInfo.flag) {
  96. return;
  97. }
  98. if (!isLogin) {
  99. log.info('[首页]', '[未登陆跳转登录界面]');
  100. let url = `/pages/login/phone_login/phone_login`;
  101. wx.navigateTo({
  102. url
  103. });
  104. return;
  105. } else {
  106. log.info('[首页]', '[获取用户是否有未完成订单]', '[请求]', { userId: userInfo.userId });
  107. wx.request({
  108. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  109. data: {
  110. userId: userInfo.userId
  111. },
  112. method: 'POST',
  113. success(res) {
  114. let {
  115. data
  116. } = res;
  117. log.info('[首页]', '[获取用户是否有未完成订单]', '[响应]', data);
  118. if (data && data.code == 200) {
  119. log.info('[首页]', '[有未完成订单跳充电界面]');
  120. //onShow会跳转
  121. } else {
  122. //console.log('无订单');
  123. log.info('[首页]', '[用户无未完成订单]');
  124. log.info('[首页]', '[获取微信扫一扫充电桩]', '[请求]', charePileId);
  125. wx.request({
  126. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  127. // data: charePileId,
  128. data:{
  129. chargPileId:charePileId,
  130. userId: userInfo.userId
  131. },
  132. method: 'POST',
  133. success(res) {
  134. //console.log(res.data);
  135. log.info('[首页]', '[获取微信扫一扫充电桩]', '[响应]', res.data);
  136. if (!res.data || res.data.code == 500) {
  137. //没有该充电桩信息
  138. wx.showModal({
  139. showCancel: false,
  140. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号',
  141. confirmColor:'#00AADD',
  142. });
  143. } else {
  144. res.data = res.data.result
  145. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  146. 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) {
  147. //充电桩故障
  148. wx.showModal({
  149. showCancel: false,
  150. content: '终端故障,维修中',
  151. confirmColor:'#00AADD',
  152. });
  153. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  154. wx.showModal({
  155. showCancel: false,
  156. content: '正在充电中',
  157. confirmColor:'#00AADD',
  158. });
  159. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  160. wx.setStorage({
  161. key: "scan_chargpile",
  162. data: res.data
  163. });
  164. log.info('[首页]', '[微信扫一扫充电桩空闲跳转去充电界面]');
  165. let url = `/pages/scan_result/scan_result`;
  166. wx.navigateTo({
  167. url
  168. });
  169. }
  170. }
  171. },
  172. fail(e) {
  173. getApp().showNetworkError();
  174. }
  175. });
  176. }
  177. },
  178. fail(e) {
  179. getApp().showNetworkError();
  180. }
  181. });
  182. }
  183. }
  184. },
  185. resetchargStations(data){
  186. let that = this
  187. // 刷新 stationTag)
  188. for(let i=0;i<data.length;i++){
  189. let seeInfoChargPile = data[i];
  190. that.resetStationTag(seeInfoChargPile);
  191. let resultTable = seeInfoChargPile.resultList
  192. that.resetResultList(resultTable);
  193. that.resetResultData(resultTable,seeInfoChargPile)
  194. }
  195. },
  196. resetResultData(resultList,data){
  197. if(!resultList){
  198. return;
  199. }
  200. for(let i=0;i<resultList.length;i++){
  201. if(resultList[i].currentTime){
  202. data.chargprice = resultList[i].elecPrice
  203. data.serviceprice = resultList[i].servicePrice
  204. }
  205. }
  206. },
  207. resetStationTag(seeInfoChargPile){
  208. let that = this
  209. if(!seeInfoChargPile){
  210. return;
  211. }
  212. if(!seeInfoChargPile?.stationTag){
  213. return;
  214. }
  215. seeInfoChargPile.stationTagList = seeInfoChargPile.stationTag.split("|");
  216. },
  217. resetResultList(resultList){
  218. let that = this
  219. if(!resultList){
  220. return;
  221. }
  222. resultList.forEach(item=>{
  223. item["sumPrice"] = that.resetResultListSumPrice(item);
  224. if(!item.elecPrice && item.elecPrice!=0){
  225. item["elecPrice"] = '暂无费用'
  226. }
  227. if(!item.servicePrice && item.servicePrice!=0){
  228. item["servicePrice"] = '暂无费用'
  229. }
  230. })
  231. },
  232. resetResultListSumPrice(item){
  233. if(!item.elecPrice && item.elecPrice!=0){
  234. return '暂无费用'
  235. }
  236. if(!item.servicePrice && item.servicePrice!=0){
  237. return '暂无费用'
  238. }
  239. return parseFloat((item.elecPrice + item.servicePrice).toFixed(6))
  240. },
  241. onLoad(e) {
  242. // 隐私开始
  243. wx.getPrivacySetting({
  244. success: res => {
  245. console.log(res) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  246. if (res.needAuthorization) {
  247. // 需要弹出隐私协议
  248. this.setData({
  249. showPrivacy: true
  250. })
  251. } else {
  252. // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
  253. // wx.getUserProfile()
  254. // wx.chooseMedia()
  255. // wx.getClipboardData()
  256. // wx.startRecord()
  257. }
  258. },
  259. fail: () => {},
  260. complete: () => {}
  261. })
  262. // 隐私结束
  263. this.data.scanFlag = false;
  264. wx.hideLoading();
  265. if (e.q) {
  266. //console.log(decodeURIComponent(e.q));
  267. //let charePileId = decodeURIComponent(e.q).replace("https://cdgl.pjnes.com/", "");
  268. //console.log(charePileId);
  269. //if (charePileId){
  270. //}
  271. let userInfo = wx.getStorageSync('userInfo');
  272. let isLogin = wx.getStorageSync('isLogin');
  273. // userInfo.flag=true;
  274. this.setData({
  275. userInfo,
  276. isLogin
  277. });
  278. this.click_scan_control(e.q,false);
  279. // this.wxScan(e.q);
  280. }
  281. log.info('[首页]', '[加载完成]');
  282. amap.getRegeo(function () {
  283. var fail = function (obj) {
  284. wx.showModal({
  285. title: '请求失败',
  286. content: obj.errMsg,
  287. confirmColor:'#00AADD',
  288. });
  289. }
  290. })
  291. .then(d => {
  292. //console.log(d);
  293. let {
  294. latitude,
  295. longitude,
  296. latitude: user_lat,
  297. longitude: user_lon
  298. } = d[0];
  299. //console.log(d[0].regeocodeData.addressComponent);
  300. var {
  301. city
  302. } = d[0].regeocodeData.addressComponent;
  303. if (d[0].regeocodeData.addressComponent.city.length == 0) {
  304. var {
  305. province: city
  306. } = d[0].regeocodeData.addressComponent;
  307. }
  308. let that = this;
  309. let userInfo = wx.getStorageSync('userInfo');
  310. let isLogin = wx.getStorageSync('isLogin');
  311. // userInfo.flag=true;
  312. this.setData({
  313. city,
  314. latitude,
  315. longitude,
  316. user_lat,
  317. user_lon,
  318. userInfo,
  319. isLogin
  320. });
  321. //开始请求充电站信息
  322. var chargStationType;
  323. if (!userInfo.flag) {
  324. //用户是普通用户
  325. chargStationType = '2';
  326. }
  327. wx.request({
  328. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargStations',
  329. data: {
  330. lon: longitude,
  331. lat: latitude,
  332. distance: that.data.distanceinfo[that.data.distanceinfoindex].value,
  333. chargStationType
  334. },
  335. method: 'POST',
  336. success(res) {
  337. //userInfo.flag = true;
  338. that.resetchargStations(res.data)
  339. if (isLogin && userInfo.flag) {
  340. wx.request({
  341. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/userChargStations',
  342. data: {
  343. userId: userInfo.userId,
  344. lat: latitude,
  345. lon: longitude
  346. },
  347. method: 'POST',
  348. success(res1) {
  349. var myChargeStationsIds = '';
  350. res1.data.forEach((item, index) => {
  351. myChargeStationsIds += item.id + ",";
  352. });
  353. //console.log(myChargeStationsIds);
  354. let {
  355. data
  356. } = res;
  357. let markers = [];
  358. data.forEach((item, index) => {
  359. //item.callout = {
  360. // content: item.name, //文本 String 1.2.0
  361. // display: 'BYCLICK', //'BYCLICK': 点击显示; 'ALWAYS': 常显 String 1.2.0
  362. // textAlign: 'center' //文本对齐方式。有效值: left, right, center String 1.6.0
  363. // };
  364. var iconPath = "/images/marker.png";
  365. if (myChargeStationsIds.indexOf(item.id + ',') != -1) {
  366. iconPath = "/images/marker1.png";
  367. }
  368. if (item.breaknum && item.breaknum != 0) {
  369. iconPath = "/images/marker_b.png";
  370. }
  371. /**
  372. * 运营状态 初始,待运营,运营中,暂停营业,关闭,未运营
  373. * */
  374. //private Long operationState;
  375. var marker = {
  376. name: item.chargStationName,
  377. address: item.address,
  378. width: "46rpx",
  379. height: "67rpx",
  380. chargfeatures: item.chargfeatures ,
  381. iconPath: iconPath,
  382. id: item.id,
  383. callout: {},
  384. latitude: item.lat,
  385. longitude: item.lon,
  386. //distance: item.distance / 1000,
  387. distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
  388. chargPileNum: item.fastCharg + item.slowCharg,
  389. fastCharg: item.fastCharg,
  390. slowCharg: item.slowCharg,
  391. freenum: item.freenum,
  392. fastfreenum: item.fastfreenum,
  393. slowfreenum: item.slowfreenum,
  394. breaknum: item.breaknum,
  395. /** 电费 */
  396. chargprice: item.chargprice,
  397. /** 服务费 */
  398. serviceprice: item.serviceprice,
  399. /** 停车费 */
  400. stopprice: item.stopprice,
  401. operationState: item.operationState,
  402. chargStationId: item.id,
  403. stationTag: item.stationTag,
  404. stationTagList: item.stationTagList,
  405. offlineServicecall: item.offlineServicecall,
  406. };
  407. markers[index] = marker;
  408. });
  409. that.setData({
  410. markers,
  411. myChargeStationsIds
  412. });
  413. },
  414. fail(e) {
  415. getApp().showNetworkError();
  416. }
  417. });
  418. } else {
  419. let {
  420. data
  421. } = res;
  422. let markers = [];
  423. if(data){
  424. data.forEach((item, index) => {
  425. //item.callout = {
  426. // content: item.name, //文本 String 1.2.0
  427. // display: 'BYCLICK', //'BYCLICK': 点击显示; 'ALWAYS': 常显 String 1.2.0
  428. // textAlign: 'center' //文本对齐方式。有效值: left, right, center String 1.6.0
  429. // };
  430. var iconPath = "/images/marker.png";
  431. //撤销普通用户显示异常站
  432. //if (item.breaknum && item.breaknum != 0) {
  433. // iconPath = "/images/marker_b.png";
  434. //}
  435. //撤销结束
  436. var marker = {
  437. name: item.chargStationName,
  438. address: item.address,
  439. width: "46rpx",
  440. height: "67rpx",
  441. chargfeatures: item.chargfeatures ,
  442. iconPath: iconPath,
  443. id: item.id,
  444. callout: {},
  445. latitude: item.lat,
  446. longitude: item.lon,
  447. //distance: item.distance / 1000,
  448. distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
  449. chargPileNum: item.fastCharg + item.slowCharg,
  450. fastCharg: item.fastCharg,
  451. slowCharg: item.slowCharg,
  452. freenum: item.freenum,
  453. fastfreenum: item.fastfreenum,
  454. slowfreenum: item.slowfreenum,
  455. breaknum: item.breaknum,
  456. /** 电费 */
  457. chargprice: item.chargprice,
  458. /** 服务费 */
  459. serviceprice: item.serviceprice,
  460. /** 停车费 */
  461. stopprice: item.stopprice,
  462. operationState: item.operationState,
  463. sharpChargPrice : item.sharpChargPrice,
  464. sharpServicePrice : item.sharpServicePrice,
  465. peakChargPrice : item.peakChargPrice,
  466. peakServicePrice : item.peakServicePrice,
  467. flatChargPrice : item.flatChargPrice,
  468. flatServicePrice : item.flatServicePrice,
  469. valleyChargPrice : item.valleyChargPrice,
  470. valleyServicePrice : item.valleyServicePrice,
  471. resultList: item.resultList,
  472. chargStationId: item.id,
  473. stationTag: item.stationTag,
  474. stationTagList: item.stationTagList,
  475. offlineServicecall: item.offlineServicecall,
  476. };
  477. markers[index] = marker;
  478. });
  479. }
  480. that.setData({
  481. markers
  482. });
  483. }
  484. },
  485. fail(e) {
  486. getApp().showNetworkError();
  487. }
  488. });
  489. })
  490. .catch(e => {
  491. console.log(e);
  492. });
  493. let that = this;
  494. let userInfo = wx.getStorageSync('userInfo');
  495. let isLogin = wx.getStorageSync('isLogin');
  496. //console.log(userInfo);
  497. if (isLogin) {
  498. wx.request({
  499. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/lastNotice',
  500. data: { loginName: userInfo.loginName },
  501. method: 'POST',
  502. success(res) {
  503. //console.log(res);
  504. //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你好'};
  505. if (res.data) {
  506. that.setData({
  507. showModal: true,
  508. notice: res.data
  509. });
  510. } else {
  511. that.setData({
  512. showModal: false,
  513. notice: null
  514. });
  515. }
  516. },
  517. fail(e) {
  518. //console.log(e);
  519. that.setData({
  520. showModal: false,
  521. notice: null
  522. });
  523. getApp().showNetworkError();
  524. }
  525. });
  526. }
  527. },
  528. //跳转个人中心
  529. bindUserAvatarUrl() {
  530. let url = `/pages/ucenter/index/index`;
  531. wx.navigateTo({
  532. url
  533. });
  534. },
  535. //搜索
  536. bindInput() {
  537. var {
  538. user_lat: latitude,
  539. user_lon: longitude,
  540. city
  541. } = this.data;
  542. //console.log(this.data.city);
  543. let url = `/pages/inputtip/inputtip?city=${city}&lonlat=${longitude},${latitude}`;
  544. wx.navigateTo({
  545. url
  546. });
  547. },
  548. //单击地图mark
  549. makertap(e) {
  550. mapregionchange_makertap = true;
  551. //console.log(e);
  552. let {
  553. markerId
  554. } = e.detail;
  555. // console.log({
  556. // e
  557. // });
  558. let {
  559. markers
  560. } = this.data;
  561. //撤销普通用户显示异常站
  562. let userInfo = wx.getStorageSync('userInfo');
  563. let isLogin = wx.getStorageSync('isLogin');
  564. let showBadMark = false;
  565. if (isLogin && userInfo.flag) {
  566. showBadMark = true;
  567. }
  568. //撤销结束
  569. markers.forEach((item, index) => {
  570. item.iconPath = "/images/marker.png";
  571. if (this.data.myChargeStationsIds.indexOf(item.id + ',') != -1) {
  572. item.iconPath = "/images/marker1.png";
  573. }
  574. //撤销普通用户显示异常站
  575. if (showBadMark) {
  576. //撤销结束
  577. if (item.breaknum && item.breaknum != 0) {
  578. item.iconPath = "/images/marker_b.png";
  579. }
  580. //撤销普通用户显示异常站
  581. }
  582. //撤销结束
  583. if (item.id == markerId) {
  584. item.iconPath = "/images/marker_checked.png";
  585. this.showMarkerInfo(item);
  586. }
  587. });
  588. this.setData({
  589. markers,
  590. markerId
  591. });
  592. },
  593. //将mark呈现在地图中心点,并弹出详细信息框
  594. showMarkerInfo(data) {
  595. let that = this
  596. let {
  597. latitude,
  598. longitude
  599. } = data;
  600. this.setData({
  601. textData: data,
  602. latitude: latitude,
  603. longitude: longitude
  604. })
  605. console.info(data)
  606. // 查询是否需要显示
  607. that.execParking(that,data.id)
  608. },
  609. execParking(that,stationId){
  610. wx.request({
  611. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carParkingRate?stationId=' + stationId,
  612. // data: {
  613. // loginName: userInfo.loginName
  614. // },
  615. method: 'POST',
  616. success: function (res) {
  617. // 是否减免停车费
  618. // carParkingRate: false,
  619. // parkTime: 0,
  620. console.info(res)
  621. let reduceTime = res.data?.reduceTime;
  622. if(!reduceTime){
  623. that.setData({
  624. carParkingRate:false
  625. })
  626. return;
  627. }
  628. that.setData({
  629. carParkingRate:true
  630. })
  631. try{
  632. that.setData({
  633. parkTime: parseFloat((reduceTime/ 3600).toFixed(2))
  634. })
  635. }catch(e){
  636. that.setData({
  637. carParkingRate:false
  638. })
  639. }
  640. },
  641. fail(e) {
  642. console.log("用户数据同步失败");
  643. log.info('[扫码]', '[同步用户数据]', '[fail]', e);
  644. }
  645. });
  646. },
  647. //改变选中mark的颜色
  648. changeMarkerColor(markerId) {
  649. let {
  650. markers
  651. } = this.data;
  652. //撤销普通用户显示异常站
  653. let userInfo = wx.getStorageSync('userInfo');
  654. let isLogin = wx.getStorageSync('isLogin');
  655. let showBadMark = false;
  656. if (isLogin && userInfo.flag) {
  657. showBadMark = true;
  658. }
  659. //撤销结束
  660. markers.forEach((item, index) => {
  661. item.iconPath = "/images/marker.png";
  662. if (this.data.myChargeStationsIds.indexOf(item.id + ',') != -1) {
  663. item.iconPath = "/images/marker1.png";
  664. }
  665. //撤销普通用户显示异常站
  666. if (showBadMark) {
  667. //撤销结束
  668. if (item.breaknum && item.breaknum != 0) {
  669. item.iconPath = "/images/marker_b.png";
  670. }
  671. //撤销普通用户显示异常站
  672. }
  673. //撤销结束
  674. if (item.id == markerId) {
  675. item.iconPath = "/images/marker_checked.png";
  676. }
  677. })
  678. this.setData({
  679. markers,
  680. markerId
  681. });
  682. },
  683. seeInfo(e){
  684. console.log("11111");
  685. // 起点
  686. let {
  687. user_lat: latitude,
  688. user_lon: longitude,
  689. markers,
  690. markerId,
  691. city,
  692. textData
  693. } = this.data;
  694. let {
  695. name,
  696. address,
  697. chargprice,
  698. serviceprice,
  699. } = textData;
  700. console.log("222222");
  701. console.log(markers);
  702. if (!markers.length) return;
  703. console.log("3333333");
  704. // 终点
  705. markers.forEach((item, index) => {
  706. if (markerId && markerId == item.id) {
  707. let {
  708. name: latitude2,
  709. longitude: longitude2
  710. } = item;
  711. wx.setStorage({
  712. key: "index_seeInfo_chargpile",
  713. data: item
  714. });
  715. let url = `/pages/charginfo/charginfo?name=${name}&address=${address}&chargprice=${chargprice}&serviceprice=${serviceprice}&chargid=${markerId}`;
  716. //console.log(url);
  717. wx.navigateTo({
  718. url
  719. });
  720. }
  721. });
  722. },
  723. //导航
  724. getRoute(e) {
  725. //console.log(e);
  726. // 起点
  727. let {
  728. user_lat: latitude,
  729. user_lon: longitude,
  730. markers,
  731. markerId,
  732. city,
  733. textData
  734. } = this.data;
  735. let {
  736. name,
  737. address
  738. } = textData;
  739. if (!markers.length) return;
  740. // 终点
  741. markers.forEach((item, index) => {
  742. if (markerId && markerId == item.id) {
  743. let {
  744. latitude: latitude2,
  745. longitude: longitude2
  746. } = item;
  747. let url = `/pages/routes/routes?longitude=${longitude}&latitude=${latitude}&longitude2=${longitude2}&latitude2=${latitude2}&city=${city}&name=${name}&desc=${address}`;
  748. //console.log(url);
  749. wx.navigateTo({
  750. url
  751. });
  752. }
  753. });
  754. return;
  755. },
  756. //回到当前位置
  757. click_location_control(e) {
  758. //console.log("回到用户当前定位点");
  759. // let {
  760. // controlId
  761. // } = e;
  762. let mpCtx = wx.createMapContext("map");
  763. mpCtx.moveToLocation();
  764. },
  765. //打开扫一扫
  766. click_scan_control_outer(){
  767. this.click_scan_control("",true)
  768. },
  769. click_scan_control(scanResult,inner) {
  770. if(this.data.scanFlag){
  771. return;
  772. }
  773. this.data.scanFlag = true;
  774. wx.showLoading({
  775. title: '努力加载中...',
  776. })
  777. console.log("打开扫一扫");
  778. log.info('[首页]', '[打开扫一扫]');
  779. let that = this;
  780. if (!this.data.isLogin) {
  781. log.info('[首页]', '[未登陆跳转登录界面]');
  782. let url = `/pages/login/phone_login/phone_login`;
  783. that.data.scanFlag = false;
  784. wx.hideLoading();
  785. wx.navigateTo({
  786. url
  787. });
  788. return;
  789. } else {
  790. if(!this.phoneCheck()){
  791. return;
  792. }
  793. log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: this.data.userInfo.userId });
  794. wx.request({
  795. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  796. data: {
  797. userId: this.data.userInfo.userId
  798. },
  799. method: 'POST',
  800. success(res) {
  801. let {
  802. data
  803. } = res;
  804. let {
  805. result: order
  806. } = data;
  807. log.info('[首页]', '[获取用户是否有未支付订单]', '[响应]', data);
  808. if (data && order && data.code == 200) {
  809. that.data.scanFlag = false;
  810. wx.hideLoading();
  811. log.info('[首页]', '[用户有未支付订单跳转订单支付界面]');
  812. wx.showModal({
  813. showCancel: false,
  814. content: '你有未支付的订单,请先支付',
  815. confirmColor:'#00AADD',
  816. success: function (res) {
  817. //console.log(res);
  818. if (!res.cancel) {
  819. //点击确定
  820. let url = `/pages/order/order?orderid=${order.orderid}&userId=${order.userId}&chargPileId=${order.chargPileId}`;
  821. wx.navigateTo({
  822. url
  823. });
  824. }
  825. }
  826. });
  827. //console.log(that.data.result);
  828. } else {
  829. //console.log('无订单');
  830. log.info('[首页]', '[用户无未支付订单]');
  831. //console.log("打开扫一扫");
  832. if(inner){
  833. wx.pro.scanCode().then(d=>{
  834. that.afterScanCode(d,that,inner)
  835. }).catch(e=>{
  836. that.data.scanFlag = false;
  837. wx.hideLoading();
  838. });
  839. }else{
  840. that.afterScanCode(scanResult,that,inner)
  841. }
  842. }
  843. },
  844. fail(e) {
  845. that.data.scanFlag = false;
  846. wx.hideLoading();
  847. getApp().showNetworkError();
  848. }
  849. });
  850. }
  851. },
  852. afterScanCode(d,that,inner){
  853. let scanResult = ""
  854. if(inner){
  855. //console.log("完成扫一扫");
  856. //console.log(d);
  857. //兼容标准格式hlht://202001022222220101.330414214二维码
  858. scanResult = d.result;
  859. if((!scanResult) || scanResult == ""){
  860. scanResult="*"
  861. }
  862. }else{
  863. scanResult = decodeURIComponent(d)
  864. //console.log(charePileId);
  865. log.info('[首页]', '[微信扫一扫]', { 'd': d });
  866. if(!scanResult){
  867. scanResult = "0"
  868. }
  869. }
  870. if (scanResult.startsWith("hlht://") || scanResult.startsWith("HLHT://")){
  871. scanResult = scanResult. substring(7, scanResult.indexOf("."));
  872. }
  873. scanResult = scanResult.replace("https://cdgl.pjnes.com/", "");
  874. scanResult = scanResult.replace("https://cdglyy.pjnes.com/", "");
  875. console.log('扫描到的内容: [' + scanResult + '] , 是否内部按钮:' + inner)
  876. log.info('[首页]', '[用户完成扫一扫]', scanResult);
  877. log.info('[首页]', '[获取扫一扫充电桩]', '[请求]', scanResult);
  878. wx.request({
  879. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
  880. // data: scanResult,
  881. data: {
  882. chargPileId:scanResult,
  883. userId: that.data.userInfo.userId
  884. },
  885. method: 'POST',
  886. success(res) {
  887. log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
  888. if (!res.data || res.data.code == 500) {
  889. that.data.scanFlag = false;
  890. wx.hideLoading();
  891. //没有该充电桩信息
  892. wx.showModal({
  893. showCancel: false,
  894. content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号',
  895. confirmColor:'#00AADD',
  896. });
  897. } else {
  898. res.data = res.data.result
  899. //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
  900. 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) {
  901. //充电桩故障
  902. wx.showModal({
  903. showCancel: false,
  904. content: '终端故障,维修中',
  905. confirmColor:'#00AADD',
  906. });
  907. } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
  908. wx.showModal({
  909. showCancel: false,
  910. content: '正在充电中',
  911. confirmColor:'#00AADD',
  912. });
  913. } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
  914. wx.setStorage({
  915. key: "scan_chargpile",
  916. data: res.data
  917. });
  918. log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
  919. let url = `/pages/scan_result/scan_result`;
  920. that.data.scanFlag = false;
  921. wx.hideLoading();
  922. wx.navigateTo({
  923. url
  924. });
  925. }
  926. that.data.scanFlag = false;
  927. wx.hideLoading();
  928. }
  929. },
  930. fail(e) {
  931. getApp().showNetworkError();
  932. }
  933. });
  934. },
  935. //地图位移
  936. mapchange(e) {
  937. if (e.type == 'end') {
  938. if (!mapregionchange_makertap) {
  939. //console.log("移动地图");
  940. let that = this;
  941. let wMap = wx.createMapContext('map');
  942. wMap.getCenterLocation({
  943. type: 'gcj02',
  944. success: function (res) {
  945. let {
  946. latitude,
  947. longitude
  948. } = res;
  949. let userInfo = wx.getStorageSync('userInfo');
  950. let isLogin = wx.getStorageSync('isLogin');
  951. var chargStationType;
  952. if (!userInfo.flag) {
  953. //用户是普通用户
  954. chargStationType = '2';
  955. }
  956. wx.request({
  957. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargStations',
  958. data: {
  959. lon: longitude,
  960. lat: latitude,
  961. distance: that.data.distanceinfo[that.data.distanceinfoindex].value,
  962. chargStationType
  963. },
  964. method: 'POST',
  965. success(res) {
  966. that.resetchargStations(res.data)
  967. let {
  968. data
  969. } = res;
  970. let markers = [];
  971. var flag = false;
  972. if(data){
  973. data.forEach((item, index) => {
  974. var iconPath;
  975. if (that.data.markerId && that.data.markerId == item.id) {
  976. iconPath = "/images/marker_checked.png";
  977. flag = true;
  978. } else {
  979. iconPath = "/images/marker.png";
  980. if (that.data.myChargeStationsIds.indexOf(item.id + ',') != -1) {
  981. iconPath = "/images/marker1.png";
  982. }
  983. //撤销普通用户显示异常站
  984. if (isLogin && userInfo.flag) {
  985. //撤销结束
  986. if (item.breaknum && item.breaknum != 0) {
  987. iconPath = "/images/marker_b.png";
  988. }
  989. //撤销普通用户显示异常站
  990. }
  991. //撤销结束
  992. }
  993. //console.log(Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon));
  994. var marker = {
  995. name: item.chargStationName,
  996. address: item.address,
  997. width: "46rpx",
  998. height: "67rpx",
  999. chargfeatures: item.chargfeatures ,
  1000. iconPath: iconPath,
  1001. id: item.id,
  1002. callout: {},
  1003. latitude: item.lat,
  1004. longitude: item.lon,
  1005. //distance: item.distance / 1000,
  1006. distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
  1007. chargPileNum: item.fastCharg + item.slowCharg,
  1008. fastCharg: item.fastCharg,
  1009. slowCharg: item.slowCharg,
  1010. freenum: item.freenum,
  1011. fastfreenum: item.fastfreenum,
  1012. slowfreenum: item.slowfreenum,
  1013. breaknum: item.breaknum,
  1014. /** 电费 */
  1015. chargprice: item.chargprice,
  1016. /** 服务费 */
  1017. serviceprice: item.serviceprice,
  1018. /** 停车费 */
  1019. stopprice: item.stopprice,
  1020. operationState: item.operationState,
  1021. sharpChargPrice : item.sharpChargPrice,
  1022. sharpServicePrice : item.sharpServicePrice,
  1023. peakChargPrice : item.peakChargPrice,
  1024. peakServicePrice : item.peakServicePrice,
  1025. flatChargPrice : item.flatChargPrice,
  1026. flatServicePrice : item.flatServicePrice,
  1027. valleyChargPrice : item.valleyChargPrice,
  1028. valleyServicePrice : item.valleyServicePrice,
  1029. resultList: item.resultList,
  1030. chargStationId: item.id,
  1031. stationTag: item.stationTag,
  1032. stationTagList: item.stationTagList,
  1033. offlineServicecall: item.offlineServicecall,
  1034. };
  1035. markers[index] = marker;
  1036. });
  1037. }
  1038. if (!flag) {
  1039. that.setData({
  1040. textData: null,
  1041. markerId: null,
  1042. });
  1043. }
  1044. that.setData({
  1045. markers: markers
  1046. });
  1047. },
  1048. fail(e) {
  1049. getApp().showNetworkError();
  1050. }
  1051. });
  1052. }
  1053. });
  1054. } else {
  1055. //点击marker的情况下
  1056. //console.log("点击marker");
  1057. mapregionchange_makertap = false;
  1058. }
  1059. }
  1060. },
  1061. phoneCheck(){
  1062. if (this.data.userInfo.bindingPhone==0) {
  1063. wx.hideLoading();
  1064. wx.showModal({
  1065. title: '提示',
  1066. content: '当前账户未绑定手机号,请您进行手机号绑定操作',
  1067. showCancel:false,
  1068. confirmText: '去绑定',
  1069. confirmColor:'#00AADD',
  1070. success: function (res1) {
  1071. let url = `/pages/bindPhone/bindPhone`;
  1072. wx.navigateTo({
  1073. url
  1074. });
  1075. }
  1076. })
  1077. return false;
  1078. }else{
  1079. return true;
  1080. }
  1081. },
  1082. /**
  1083. * 生命周期函数--监听页面显示
  1084. */
  1085. onShow: function () {
  1086. this.data.scanFlag = false;
  1087. let userInfo = wx.getStorageSync('userInfo');
  1088. let isLogin = wx.getStorageSync('isLogin');
  1089. // 页面显示
  1090. if (userInfo && isLogin) {
  1091. //console.log(userInfo);
  1092. //userInfo.flag = true;
  1093. this.setData({
  1094. userInfo: userInfo,
  1095. isLogin: isLogin
  1096. });
  1097. if ((!userInfo.userId && userInfo.userId != 0)){
  1098. log.info('[首页]', '[已登陆未有用户ID跳转登录界面]');
  1099. let url = `/pages/login/phone_login/phone_login`;
  1100. wx.navigateTo({
  1101. url
  1102. });
  1103. return;
  1104. }
  1105. log.info('[首页]', '[获取用户是否有未完成订单]', '[请求]', { userId: userInfo.userId });
  1106. wx.request({
  1107. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  1108. data: {
  1109. userId: userInfo.userId
  1110. },
  1111. method: 'POST',
  1112. success(res) {
  1113. let {
  1114. data
  1115. } = res;
  1116. log.info('[首页]', '[获取用户是否有未完成订单]', '[响应]', data);
  1117. if (data && data.code == 200) {
  1118. log.info('[首页]', '[有未完成订单跳充电界面]');
  1119. //获取用户正在充电的订单,并跳转到该页面
  1120. let url = `/pages/charging/charging?orderid=${data.result.orderid}&userId=${userInfo.userId}&chargPileId=${data.result.chargPileId}`;
  1121. //let url = `/pages/charging/charging?userId=${userInfo.userId}`;
  1122. wx.navigateTo({
  1123. url
  1124. });
  1125. } else {
  1126. //console.log(res);
  1127. }
  1128. },
  1129. fail(e) {
  1130. getApp().showNetworkError();
  1131. }
  1132. });
  1133. } else {
  1134. //未登录信息
  1135. this.setData({
  1136. userInfo: {}
  1137. });
  1138. }
  1139. },
  1140. bindDistanceinfoChange: function (e) {
  1141. let distance = this.data.distanceinfo[e.detail.value].value;
  1142. this.setData({
  1143. distanceinfoindex: e.detail.value
  1144. });
  1145. },
  1146. Sure: function () {
  1147. this.setData({
  1148. showModal: false
  1149. });
  1150. },
  1151. handleAgreePrivacyAuthorization() {
  1152. console.info('3333333333333');
  1153. this.setData({
  1154. showPrivacy: false
  1155. })
  1156. // 用户同意隐私协议事件回调
  1157. // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
  1158. // wx.getUserProfile()
  1159. // wx.chooseMedia()
  1160. // wx.getClipboardData()
  1161. // wx.startRecord()
  1162. },
  1163. handleOpenPrivacyContract() {
  1164. // 打开隐私协议页面
  1165. wx.openPrivacyContract({
  1166. success: () => {}, // 打开成功
  1167. fail: () => {}, // 打开失败
  1168. complete: () => {}
  1169. })
  1170. }
  1171. })