search_result.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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. Page({
  8. data: {
  9. markers: [],
  10. latitude: null,
  11. longitude: null,
  12. city: null,
  13. userInfo: {},
  14. isLogin: false,
  15. myChargeStationsIds: '',
  16. moneyActive: false,
  17. distanceActive: true,
  18. myChargeStationsActive: false,
  19. distancePng: 'asc',
  20. keywords: null,
  21. moneyPng: ''
  22. },
  23. resetchargStations(data){
  24. let that = this
  25. for(let i=0;i<data.length;i++){
  26. let seeInfoChargPile = data[i];
  27. that.resetStationTag(seeInfoChargPile);
  28. let resultTable = seeInfoChargPile.resultList
  29. that.resetResultList(resultTable);
  30. that.resetResultData(resultTable,seeInfoChargPile)
  31. }
  32. },
  33. resetResultData(resultList,data){
  34. if(!resultList){
  35. return;
  36. }
  37. for(let i=0;i<resultList.length;i++){
  38. if(resultList[i].currentTime){
  39. data.chargprice = resultList[i].elecPrice
  40. data.serviceprice = resultList[i].servicePrice
  41. }
  42. }
  43. },
  44. resetStationTag(seeInfoChargPile){
  45. let that = this
  46. if(!seeInfoChargPile){
  47. return;
  48. }
  49. if(!seeInfoChargPile?.stationTag){
  50. return;
  51. }
  52. seeInfoChargPile.stationTagList = seeInfoChargPile.stationTag.split("|");
  53. },
  54. resetResultList(resultList){
  55. let that = this
  56. if(!resultList){
  57. return;
  58. }
  59. resultList.forEach(item=>{
  60. item["sumPrice"] = that.resetResultListSumPrice(item);
  61. if(!item.elecPrice && item.elecPrice!=0){
  62. item["elecPrice"] = '暂无费用'
  63. }
  64. if(!item.servicePrice && item.servicePrice!=0){
  65. item["servicePrice"] = '暂无费用'
  66. }
  67. })
  68. },
  69. resetResultListSumPrice(item){
  70. if(!item.elecPrice && item.elecPrice!=0){
  71. return '暂无费用'
  72. }
  73. if(!item.servicePrice && item.servicePrice!=0){
  74. return '暂无费用'
  75. }
  76. return parseFloat((item.elecPrice + item.servicePrice).toFixed(6))
  77. },
  78. onLoad(e) {
  79. let {
  80. city,
  81. latitude,
  82. longitude,
  83. searchString
  84. } = e;
  85. console.log(city, latitude, longitude, searchString);
  86. this.setData({
  87. city,
  88. latitude,
  89. longitude,
  90. keywords: searchString
  91. });
  92. let userInfo = wx.getStorageSync('userInfo');
  93. let isLogin = wx.getStorageSync('isLogin');
  94. // 页面显示
  95. if (userInfo && isLogin) {
  96. //console.log(userInfo);
  97. //userInfo.flag = true;
  98. this.setData({
  99. userInfo: userInfo,
  100. isLogin: isLogin
  101. });
  102. } else {
  103. //未登录信息
  104. this.setData({
  105. userInfo: {}
  106. });
  107. }
  108. //开始请求充电站信息
  109. let that = this;
  110. var chargStationType;
  111. if (!userInfo.flag) {
  112. //用户是普通用户
  113. chargStationType = '2';
  114. }
  115. wx.request({
  116. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/chargStationsSearch',
  117. data: {
  118. searchString,
  119. chargStationType
  120. },
  121. method: 'POST',
  122. success(res) {
  123. that.resetchargStations(res.data)
  124. //userInfo.flag = true;
  125. if (isLogin && userInfo.flag) {
  126. wx.request({
  127. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/userChargStations',
  128. data: {
  129. userId: userInfo.userId,
  130. lat: latitude,
  131. lon: longitude
  132. },
  133. method: 'POST',
  134. success(res1) {
  135. var myChargeStationsIds = '';
  136. res1.data.forEach((item, index) => {
  137. myChargeStationsIds += item.id + ",";
  138. });
  139. console.log(myChargeStationsIds);
  140. let {
  141. data
  142. } = res;
  143. let markers = [];
  144. data.forEach((item, index) => {
  145. var marker = {
  146. brandName:item.brandName,
  147. name: item.chargStationName,
  148. address: item.address,
  149. width: "46rpx",
  150. height: "67rpx",
  151. iconPath: "/images/marker.png",
  152. chargfeatures:item.chargfeatures,
  153. id: item.id,
  154. callout: {},
  155. latitude: item.lat,
  156. longitude: item.lon,
  157. //distance: item.distance / 1000,
  158. distance: Util.distance(latitude, longitude, item.lat, item.lon),
  159. chargPileNum: item.fastCharg + item.slowCharg,
  160. fastCharg: item.fastCharg,
  161. slowCharg: item.slowCharg,
  162. freenum: item.freenum,
  163. fastfreenum: item.fastfreenum,
  164. slowfreenum: item.slowfreenum,
  165. breaknum: item.breaknum,
  166. /** 电费 */
  167. chargprice: item.chargprice,
  168. /** 服务费 */
  169. serviceprice: item.serviceprice,
  170. /** 停车费 */
  171. stopprice: item.stopprice,
  172. operationState: item.operationState,
  173. sharpChargPrice : item.sharpChargPrice,
  174. sharpServicePrice : item.sharpServicePrice,
  175. peakChargPrice : item.peakChargPrice,
  176. peakServicePrice : item.peakServicePrice,
  177. flatChargPrice : item.flatChargPrice,
  178. flatServicePrice : item.flatServicePrice,
  179. valleyChargPrice : item.valleyChargPrice,
  180. valleyServicePrice : item.valleyServicePrice,
  181. resultList: item.resultList,
  182. chargStationId: item.id,
  183. stationTag: item.stationTag,
  184. stationTagList: item.stationTagList,
  185. offlineServicecall: item.offlineServicecall,
  186. };
  187. if (myChargeStationsIds.indexOf(item.id + ',') != -1) {
  188. marker.userFlag = true;
  189. } else {
  190. marker.userFlag = false;
  191. }
  192. markers[index] = marker;
  193. });
  194. markers.sort(function (ma, mb) {
  195. return ma.distance - mb.distance;
  196. });
  197. that.setData({
  198. markers,
  199. myChargeStationsIds
  200. });
  201. console.log(markers);
  202. }
  203. });
  204. } else {
  205. let {
  206. data
  207. } = res;
  208. let markers = [];
  209. data.forEach((item, index) => {
  210. var marker = {
  211. brandName:item.brandName,
  212. name: item.chargStationName,
  213. address: item.address,
  214. width: "46rpx",
  215. height: "67rpx",
  216. iconPath: "/images/marker.png",
  217. chargfeatures:item.chargfeatures,
  218. id: item.id,
  219. callout: {},
  220. latitude: item.lat,
  221. longitude: item.lon,
  222. //distance: item.distance / 1000,
  223. distance: Util.distance(latitude, longitude, item.lat, item.lon),
  224. chargPileNum: item.fastCharg + item.slowCharg,
  225. fastCharg: item.fastCharg,
  226. slowCharg: item.slowCharg,
  227. freenum: item.freenum,
  228. fastfreenum: item.fastfreenum,
  229. slowfreenum: item.slowfreenum,
  230. breaknum: item.breaknum,
  231. /** 电费 */
  232. chargprice: item.chargprice,
  233. /** 服务费 */
  234. serviceprice: item.serviceprice,
  235. /** 停车费 */
  236. stopprice: item.stopprice,
  237. operationState: item.operationState,
  238. sharpChargPrice : item.sharpChargPrice,
  239. sharpServicePrice : item.sharpServicePrice,
  240. peakChargPrice : item.peakChargPrice,
  241. peakServicePrice : item.peakServicePrice,
  242. flatChargPrice : item.flatChargPrice,
  243. flatServicePrice : item.flatServicePrice,
  244. valleyChargPrice : item.valleyChargPrice,
  245. valleyServicePrice : item.valleyServicePrice,
  246. resultList: item.resultList,
  247. chargStationId: item.id,
  248. stationTag: item.stationTag,
  249. stationTagList: item.stationTagList,
  250. offlineServicecall: item.offlineServicecall,
  251. };
  252. markers[index] = marker;
  253. });
  254. markers.sort(function (ma, mb) {
  255. return ma.distance - mb.distance;
  256. });
  257. that.setData({
  258. markers
  259. });
  260. console.log(markers);
  261. }
  262. }
  263. });
  264. },
  265. onLoad2(e) {
  266. let {
  267. city,
  268. name,
  269. latitude,
  270. longitude,
  271. location
  272. } = e;
  273. console.log(name, latitude, longitude, location);
  274. this.setData({
  275. city,
  276. latitude,
  277. longitude
  278. });
  279. let userInfo = wx.getStorageSync('userInfo');
  280. let isLogin = wx.getStorageSync('isLogin');
  281. // 页面显示
  282. if (userInfo && isLogin) {
  283. //console.log(userInfo);
  284. //userInfo.flag = true;
  285. this.setData({
  286. userInfo: userInfo,
  287. isLogin: isLogin
  288. });
  289. } else {
  290. //未登录信息
  291. this.setData({
  292. userInfo: {}
  293. });
  294. }
  295. //开始请求充电站信息
  296. let that = this;
  297. var chargStationType;
  298. if (!userInfo.flag) {
  299. //用户是普通用户
  300. chargStationType = '2';
  301. }
  302. wx.request({
  303. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/chargStations',
  304. data: {
  305. lon: location.split(",")[0],
  306. lat: location.split(",")[1],
  307. distance: 10000,
  308. chargStationType
  309. },
  310. method: 'POST',
  311. success(res) {
  312. that.resetchargStations(res.data)
  313. //userInfo.flag = true;
  314. if (isLogin && userInfo.flag) {
  315. wx.request({
  316. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/userChargStations',
  317. data: {
  318. userId: userInfo.userId,
  319. lat: latitude,
  320. lon: longitude
  321. },
  322. method: 'POST',
  323. success(res1) {
  324. var myChargeStationsIds = '';
  325. res1.data.forEach((item, index) => {
  326. myChargeStationsIds += item.id + ",";
  327. });
  328. console.log(myChargeStationsIds);
  329. let {
  330. data
  331. } = res;
  332. let markers = [];
  333. data.forEach((item, index) => {
  334. console.log("itemitemitemitemitem");
  335. console.log(item);
  336. //item.callout = {
  337. // content: item.name, //文本 String 1.2.0
  338. // display: 'BYCLICK', //'BYCLICK': 点击显示; 'ALWAYS': 常显 String 1.2.0
  339. // textAlign: 'center' //文本对齐方式。有效值: left, right, center String 1.6.0
  340. // };
  341. //console.log(Util.distance(latitude, longitude, item.lat, item.lon));
  342. var marker = {
  343. name: item.chargStationName,
  344. address: item.address,
  345. width: "46rpx",
  346. height: "67rpx",
  347. iconPath: "/images/marker.png",
  348. chargfeatures:item.chargfeatures,
  349. id: item.id,
  350. callout: {},
  351. latitude: item.lat,
  352. longitude: item.lon,
  353. //distance: item.distance / 1000,
  354. distance: Util.distance(latitude, longitude, item.lat, item.lon),
  355. chargPileNum: item.fastCharg + item.slowCharg,
  356. fastCharg: item.fastCharg,
  357. slowCharg: item.slowCharg,
  358. freenum: item.freenum,
  359. fastfreenum: item.fastfreenum,
  360. slowfreenum: item.slowfreenum,
  361. breaknum: item.breaknum,
  362. /** 电费 */
  363. chargprice: item.chargprice,
  364. /** 服务费 */
  365. serviceprice: item.serviceprice,
  366. /** 停车费 */
  367. stopprice: item.stopprice,
  368. operationState: item.operationState,
  369. sharpChargPrice : item.sharpChargPrice,
  370. sharpServicePrice : item.sharpServicePrice,
  371. peakChargPrice : item.peakChargPrice,
  372. peakServicePrice : item.peakServicePrice,
  373. flatChargPrice : item.flatChargPrice,
  374. flatServicePrice : item.flatServicePrice,
  375. valleyChargPrice : item.valleyChargPrice,
  376. valleyServicePrice : item.valleyServicePrice,
  377. resultList: item.resultList,
  378. chargStationId: item.id,
  379. stationTag: item.stationTag,
  380. stationTagList: item.stationTagList,
  381. offlineServicecall: item.offlineServicecall,
  382. };
  383. if (myChargeStationsIds.indexOf(item.id + ',') != -1) {
  384. marker.userFlag = true;
  385. } else {
  386. marker.userFlag = false;
  387. }
  388. markers[index] = marker;
  389. });
  390. markers.sort(function(ma, mb) {
  391. return ma.distance - mb.distance;
  392. });
  393. that.setData({
  394. markers,
  395. myChargeStationsIds
  396. });
  397. console.log(markers);
  398. }
  399. });
  400. } else {
  401. let {
  402. data
  403. } = res;
  404. let markers = [];
  405. data.forEach((item, index) => {
  406. console.log("itemitemitemitemitem");
  407. //item.callout = {
  408. // content: item.name, //文本 String 1.2.0
  409. // display: 'BYCLICK', //'BYCLICK': 点击显示; 'ALWAYS': 常显 String 1.2.0
  410. // textAlign: 'center' //文本对齐方式。有效值: left, right, center String 1.6.0
  411. // };
  412. //console.log(Util.distance(latitude, longitude, item.lat, item.lon));
  413. var marker = {
  414. name: item.chargStationName,
  415. address: item.address,
  416. width: "46rpx",
  417. height: "67rpx",
  418. iconPath: "/images/marker.png",
  419. chargfeatures:item.chargfeatures,
  420. id: item.id,
  421. callout: {},
  422. latitude: item.lat,
  423. longitude: item.lon,
  424. //distance: item.distance / 1000,
  425. distance: Util.distance(latitude, longitude, item.lat, item.lon),
  426. chargPileNum: item.fastCharg + item.slowCharg,
  427. fastCharg: item.fastCharg,
  428. slowCharg: item.slowCharg,
  429. freenum: item.freenum,
  430. fastfreenum: item.fastfreenum,
  431. slowfreenum: item.slowfreenum,
  432. breaknum: item.breaknum,
  433. /** 电费 */
  434. chargprice: item.chargprice,
  435. /** 服务费 */
  436. serviceprice: item.serviceprice,
  437. /** 停车费 */
  438. stopprice: item.stopprice,
  439. operationState: item.operationState,
  440. sharpChargPrice : item.sharpChargPrice,
  441. sharpServicePrice : item.sharpServicePrice,
  442. peakChargPrice : item.peakChargPrice,
  443. peakServicePrice : item.peakServicePrice,
  444. flatChargPrice : item.flatChargPrice,
  445. flatServicePrice : item.flatServicePrice,
  446. valleyChargPrice : item.valleyChargPrice,
  447. valleyServicePrice : item.valleyServicePrice,
  448. resultList: item.resultList,
  449. chargStationId: item.id,
  450. stationTag: item.stationTag,
  451. stationTagList: item.stationTagList,
  452. offlineServicecall: item.offlineServicecall,
  453. };
  454. markers[index] = marker;
  455. });
  456. markers.sort(function(ma, mb) {
  457. return ma.distance - mb.distance;
  458. });
  459. that.setData({
  460. markers
  461. });
  462. console.log(markers);
  463. }
  464. }
  465. });
  466. },
  467. getRoute(e) {
  468. console.log(e);
  469. // 起点
  470. let {
  471. latitude,
  472. longitude,
  473. markers,
  474. city
  475. } = this.data;
  476. if (!markers.length) return;
  477. let markerId = e.currentTarget.id;
  478. // 终点
  479. markers.forEach((item, index) => {
  480. if (markerId && markerId == item.id) {
  481. let {
  482. name,
  483. address,
  484. latitude: latitude2,
  485. longitude: longitude2
  486. } = item;
  487. let url = `/pages/routes/routes?longitude=${longitude}&latitude=${latitude}&longitude2=${longitude2}&latitude2=${latitude2}&city=${city}&name=${name}&desc=${address}`;
  488. //console.log(url);
  489. wx.navigateTo({
  490. url
  491. });
  492. }
  493. });
  494. },
  495. goIndex(e) {
  496. //console.log(e);
  497. let that = this;
  498. let markerId = e.currentTarget.id;
  499. let pages = getCurrentPages();
  500. let prevPage = pages[0]; //首页
  501. let markers = this.data.markers; //首页
  502. this.data.markers.forEach((item, index) => {
  503. if (markerId && markerId == item.id) {
  504. wx.navigateBack({
  505. delta: pages.length
  506. });
  507. wx.request({
  508. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carParkingRate?stationId=' + item.id,
  509. method: 'POST',
  510. success: function (res) {
  511. // 是否减免停车费
  512. let carParkingRate = false
  513. let parkTime = 0;
  514. console.info(res)
  515. let reduceTime = res.data?.reduceTime;
  516. if(!reduceTime){
  517. carParkingRate = false
  518. }else{
  519. carParkingRate = true
  520. }
  521. try{
  522. parkTime = parseFloat((reduceTime/ 3600).toFixed(2))
  523. }catch(e){
  524. carParkingRate = false
  525. }
  526. let {
  527. latitude,
  528. longitude
  529. } = item;
  530. prevPage.setData({
  531. markers,
  532. markerId,
  533. latitude,
  534. longitude,
  535. carParkingRate,
  536. parkTime,
  537. keywords: that.data.keywords,
  538. textData: item
  539. });
  540. console.info({
  541. markers,
  542. markerId,
  543. latitude,
  544. longitude,
  545. keywords: that.data.keywords,
  546. textData: item
  547. })
  548. },
  549. fail(e) {
  550. console.log("用户数据同步失败");
  551. log.info('[扫码]', '[同步用户数据]', '[fail]', e);
  552. }
  553. });
  554. }
  555. });
  556. },
  557. myChargeStationsOrder(e) {
  558. let {
  559. markers
  560. } = this.data;
  561. if (markers && 0 != markers.length) {
  562. markers.sort(function(ma, mb) {
  563. return mb.userFlag - ma.userFlag == 0 ? ma.distance - mb.distance : mb.userFlag - ma.userFlag;
  564. });
  565. }
  566. this.setData({
  567. markers,
  568. myChargeStationsActive: true,
  569. distanceActive: false,
  570. moneyActive: false,
  571. moneyPng: '',
  572. distancePng: ''
  573. });
  574. },
  575. distanceOrder(e) {
  576. let {
  577. markers
  578. } = this.data;
  579. let {
  580. distancePng
  581. } = this.data;
  582. if (distancePng == '' || distancePng == 'desc') {
  583. if (markers && 0 != markers.length) {
  584. markers.sort(function(ma, mb) {
  585. return ma.distance - mb.distance;
  586. });
  587. }
  588. this.setData({
  589. distancePng: 'asc'
  590. });
  591. } else {
  592. if (markers && 0 != markers.length) {
  593. markers.sort(function(ma, mb) {
  594. return mb.distance - ma.distance;
  595. });
  596. }
  597. this.setData({
  598. distancePng: 'desc'
  599. });
  600. }
  601. this.setData({
  602. markers,
  603. myChargeStationsActive: false,
  604. distanceActive: true,
  605. moneyActive: false,
  606. moneyPng: ''
  607. });
  608. },
  609. moneyOrder(e) {
  610. let {
  611. markers
  612. } = this.data;
  613. let {
  614. moneyPng
  615. } = this.data;
  616. if (moneyPng == '' || moneyPng == 'desc') {
  617. if (markers && 0 != markers.length) {
  618. markers.sort(function(ma, mb) {
  619. return (ma.chargprice + ma.serviceprice + ma.stopprice) - (mb.chargprice + mb.serviceprice + mb.stopprice);
  620. });
  621. }
  622. this.setData({
  623. moneyPng: 'asc'
  624. });
  625. } else {
  626. if (markers && 0 != markers.length) {
  627. markers.sort(function(ma, mb) {
  628. return (mb.chargprice + mb.serviceprice + mb.stopprice) - (ma.chargprice + ma.serviceprice + ma.stopprice);
  629. });
  630. }
  631. this.setData({
  632. moneyPng: 'desc'
  633. });
  634. }
  635. this.setData({
  636. markers,
  637. myChargeStationsActive: false,
  638. distanceActive: false,
  639. moneyActive: true,
  640. distancePng: ''
  641. });
  642. }
  643. })