index.js 44 KB

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