index.js 39 KB

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