index.js 38 KB

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