index.js 40 KB

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