index.js 45 KB

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