index.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  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. } = textData;
  731. console.log("222222");
  732. console.log(markers);
  733. if (!markers.length) return;
  734. console.log("3333333");
  735. // 终点
  736. markers.forEach((item, index) => {
  737. if (markerId && markerId == item.id) {
  738. let {
  739. name: latitude2,
  740. longitude: longitude2
  741. } = item;
  742. wx.setStorage({
  743. key: "index_seeInfo_chargpile",
  744. data: item
  745. });
  746. let url = `/pages/charginfo/charginfo?name=${name}&address=${address}&chargprice=${chargprice}&serviceprice=${serviceprice}&chargid=${markerId}`;
  747. //console.log(url);
  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. name: item.chargStationName,
  1077. address: item.address,
  1078. width: "46rpx",
  1079. height: "67rpx",
  1080. chargfeatures: item.chargfeatures ,
  1081. iconPath: iconPath,
  1082. id: item.id,
  1083. callout: {},
  1084. latitude: item.lat,
  1085. longitude: item.lon,
  1086. //distance: item.distance / 1000,
  1087. distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
  1088. chargPileNum: item.fastCharg + item.slowCharg,
  1089. fastCharg: item.fastCharg,
  1090. slowCharg: item.slowCharg,
  1091. freenum: item.freenum,
  1092. fastfreenum: item.fastfreenum,
  1093. slowfreenum: item.slowfreenum,
  1094. breaknum: item.breaknum,
  1095. /** 电费 */
  1096. chargprice: item.chargprice,
  1097. /** 服务费 */
  1098. serviceprice: item.serviceprice,
  1099. /** 停车费 */
  1100. stopprice: item.stopprice,
  1101. operationState: item.operationState,
  1102. sharpChargPrice : item.sharpChargPrice,
  1103. sharpServicePrice : item.sharpServicePrice,
  1104. peakChargPrice : item.peakChargPrice,
  1105. peakServicePrice : item.peakServicePrice,
  1106. flatChargPrice : item.flatChargPrice,
  1107. flatServicePrice : item.flatServicePrice,
  1108. valleyChargPrice : item.valleyChargPrice,
  1109. valleyServicePrice : item.valleyServicePrice,
  1110. resultList: item.resultList,
  1111. chargStationId: item.id,
  1112. stationTag: item.stationTag,
  1113. stationTagList: item.stationTagList,
  1114. offlineServicecall: item.offlineServicecall,
  1115. };
  1116. markers[index] = marker;
  1117. });
  1118. }
  1119. if (!flag) {
  1120. that.setData({
  1121. textData: null,
  1122. markerId: null,
  1123. });
  1124. }
  1125. that.setData({
  1126. markers: markers
  1127. });
  1128. },
  1129. fail(e) {
  1130. getApp().showNetworkError();
  1131. }
  1132. });
  1133. }
  1134. });
  1135. } else {
  1136. //点击marker的情况下
  1137. //console.log("点击marker");
  1138. mapregionchange_makertap = false;
  1139. }
  1140. }
  1141. },
  1142. phoneCheck(){
  1143. if (this.data.userInfo.bindingPhone==0) {
  1144. wx.hideLoading();
  1145. wx.showModal({
  1146. title: '提示',
  1147. content: '当前账户未绑定手机号,请您进行手机号绑定操作',
  1148. showCancel:false,
  1149. confirmText: '去绑定',
  1150. confirmColor:'#00AADD',
  1151. success: function (res1) {
  1152. let url = `/pages/bindPhone/bindPhone`;
  1153. wx.navigateTo({
  1154. url
  1155. });
  1156. }
  1157. })
  1158. return false;
  1159. }else{
  1160. return true;
  1161. }
  1162. },
  1163. /**
  1164. * 生命周期函数--监听页面显示
  1165. */
  1166. onShow: function () {
  1167. this.data.scanFlag = false;
  1168. let userInfo = wx.getStorageSync('userInfo');
  1169. let isLogin = wx.getStorageSync('isLogin');
  1170. // 页面显示
  1171. if (userInfo && isLogin) {
  1172. //console.log(userInfo);
  1173. //userInfo.flag = true;
  1174. this.setData({
  1175. userInfo: userInfo,
  1176. isLogin: isLogin
  1177. });
  1178. if ((!userInfo.userId && userInfo.userId != 0)){
  1179. log.info('[首页]', '[已登陆未有用户ID跳转登录界面]');
  1180. let url = `/pages/login/phone_login/phone_login`;
  1181. wx.navigateTo({
  1182. url
  1183. });
  1184. return;
  1185. }
  1186. // 查询订单
  1187. log.info('[首页]', '[获取用户是否有未完成订单]', '[请求]', { userId: userInfo.userId });
  1188. wx.request({
  1189. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  1190. data: {
  1191. userId: userInfo.userId
  1192. },
  1193. method: 'POST',
  1194. success(res) {
  1195. let {
  1196. data
  1197. } = res;
  1198. log.info('[首页]', '[获取用户是否有未完成订单]', '[响应]', data);
  1199. if (data && data.code == 200) {
  1200. log.info('[首页]', '[有未完成订单跳充电界面]');
  1201. //获取用户正在充电的订单,并跳转到该页面
  1202. let url = `/pages/charging/charging?orderid=${data.result.orderid}&userId=${userInfo.userId}&chargPileId=${data.result.chargPileId}`;
  1203. //let url = `/pages/charging/charging?userId=${userInfo.userId}`;
  1204. wx.navigateTo({
  1205. url
  1206. });
  1207. } else {
  1208. //console.log(res);
  1209. }
  1210. },
  1211. fail(e) {
  1212. getApp().showNetworkError();
  1213. }
  1214. });
  1215. // 查询呼叫电车
  1216. console.log("查询呼叫电车")
  1217. wx.request({
  1218. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/ivCarRequirement' +
  1219. '?userId='+userInfo.userId,
  1220. data: {
  1221. },
  1222. method: 'POST',
  1223. success(res) {
  1224. console.log(res?.data?.result?.requirementStep)
  1225. // 0-7 进等待 8进终端详情
  1226. if(res?.data?.result?.requirementStep>=0 && res?.data?.result?.requirementStep<=7){
  1227. // 等待
  1228. let url = `/pages/batteryPack/batteryPackWait`;
  1229. wx.reLaunch({
  1230. url
  1231. });
  1232. }else if(res?.data?.result?.requirementStep==8){
  1233. // 8进终端详情
  1234. let url = `/pages/batteryPack/batteryPackWait`;
  1235. wx.reLaunch({
  1236. url
  1237. });
  1238. }
  1239. },
  1240. fail(e) {
  1241. getApp().showNetworkError();
  1242. }
  1243. });
  1244. } else {
  1245. //未登录信息
  1246. this.setData({
  1247. userInfo: {}
  1248. });
  1249. }
  1250. },
  1251. bindDistanceinfoChange: function (e) {
  1252. let distance = this.data.distanceinfo[e.detail.value].value;
  1253. this.setData({
  1254. distanceinfoindex: e.detail.value
  1255. });
  1256. },
  1257. Sure: function () {
  1258. this.setData({
  1259. showModal: false
  1260. });
  1261. },
  1262. handleAgreePrivacyAuthorization() {
  1263. console.info('3333333333333');
  1264. this.setData({
  1265. showPrivacy: false
  1266. })
  1267. // 用户同意隐私协议事件回调
  1268. // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
  1269. // wx.getUserProfile()
  1270. // wx.chooseMedia()
  1271. // wx.getClipboardData()
  1272. // wx.startRecord()
  1273. },
  1274. handleOpenPrivacyContract() {
  1275. // 打开隐私协议页面
  1276. wx.openPrivacyContract({
  1277. success: () => {}, // 打开成功
  1278. fail: () => {}, // 打开失败
  1279. complete: () => {}
  1280. })
  1281. }
  1282. })