search_result.js 21 KB

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