index.js 39 KB

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