parkingLists.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <template>
  2. <view class="parking">
  3. <view class="loading" v-show="loading">
  4. <u-loadmore status="loading" icon-type="flower" :load-text="{ loading: '正在定位中...' }" />
  5. </view>
  6. <view class="parking-header">
  7. <u-search placeholder="搜索停车点" v-model="searchContent" :show-action="false" @change="searchInputChange"> </u-search>
  8. <u-icon
  9. v-if="!searchContent && isShowSearchParking == false"
  10. class="icon"
  11. name="list"
  12. size="44"
  13. color="#ffffff"
  14. placeholder-color="#B5B5B5"
  15. search-icon-color="#B3B3B3"
  16. @click="listIconClick"
  17. />
  18. <u-icon
  19. v-if="searchContent || isShowSearchParking == true"
  20. class="icon"
  21. name="close"
  22. size="36"
  23. color="#ffffff"
  24. placeholder-color="#B5B5B5"
  25. search-icon-color="#B3B3B3"
  26. @click="clearSearchInput"
  27. />
  28. </view>
  29. <view class="parking-map">
  30. <map
  31. id="pagemap"
  32. style="width: 100%; height: calc(100vh - 240rpx)"
  33. :show-location="true"
  34. :latitude="latitude"
  35. :longitude="longitude"
  36. @markertap="markertap"
  37. :enable-traffic="true"
  38. :enable-zoom="true"
  39. :scale="scale"
  40. :markers="covers"
  41. />
  42. </view>
  43. <view class="address-box" :class="nearParkingObj.type == 'down' ? 'address-down' : 'address-up'" v-if="nearParkingFlag">
  44. <view class="address-box-down-icon" :class="{ 'up-icon': nearParkingObj.type === 'up' }" @click="pullDown"> </view>
  45. <!-- tab -->
  46. <u-tabs :list="tabObj.tabList" :is-scroll="false" :current="tabObj.current" bg-color="transparent" @change="tabChange"></u-tabs>
  47. <scroll-view scroll-y class="address-box-scroll" :style="{ height: `calc(${nearParkingObj.height} - 164rpx)` }">
  48. <view class="address-box-list" v-if="nearParkingList.length > 0">
  49. <view class="address-box-list-item" v-for="(item, index) in nearParkingList" :key="index" @click="positionAddress(item)">
  50. <view class="abli-header">
  51. <view class="abli-header-title"
  52. >{{ item.roadName || item.parkName }} <text class="abli-header-subtitle">{{ item.areaName }}</text></view
  53. >
  54. <view class="abli-header-surplus">
  55. <view class="abli-header-surplus-left">
  56. 余位<text>{{ item.spaceIdle || item.surplusPlace }}</text></view
  57. >
  58. <template v-if="tabObj.current === 1">
  59. <view class="abli-header-surplus-right" @click.stop="createMonth(item)">办理包月</view>
  60. </template>
  61. <template v-else-if="item.monthAmount">
  62. <view class="abli-header-surplus-right" @click.stop="createMonth(item)">办理包月</view>
  63. </template>
  64. <template v-else>
  65. <view class="abli-header-surplus-right" :class="{ disabled: !item.monthAmount }"> 办理包月</view>
  66. </template>
  67. </view>
  68. </view>
  69. <view class="abli-bottom">
  70. <view class="abli-bottom-left">
  71. <view class="abli-bottom-left-navigation" @click.stop="navigation(item.latitude, item.longitude, item.areaName)">导航</view>
  72. <view class="abli-bottom-left-distance">{{ item.distance | kmUnit }}</view>
  73. </view>
  74. <view class="abli-bottom-right" @click.stop="lookParkingRule(item)">收费规则</view>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="address-box-list" v-else>
  79. <u-empty text="暂无数据" mode="list"></u-empty>
  80. </view>
  81. </scroll-view>
  82. </view>
  83. <view class="parking-address-list" v-if="isShowSearchParking">
  84. <view class="parking-address-list-item" v-for="(item, index) in searchParkingList" :key="index + 's'" @click="clickSearchParking(item)">
  85. <view class="pali-left">
  86. <view>{{ item.roadName || item.parkName }}</view>
  87. <view>{{ item.areaName }}</view>
  88. </view>
  89. <view class="pali-right">
  90. <image src="../../static/img/distance-icon.png" mode="" @click.stop="navigation(item.latitude, item.longitude, item.areaName)"></image>
  91. <view>路线</view>
  92. </view>
  93. </view>
  94. </view>
  95. <u-select v-model="mapSelect" :list="mapSelectList" @confirm="mapSelectConfirm" />
  96. <map id="map" hidden="true" />
  97. <u-toast ref="uToast" />
  98. </view>
  99. </template>
  100. <script>
  101. import { qqMapTransBMap } from '@/utils/mapTrans.js';
  102. export default {
  103. data() {
  104. return {
  105. tabObj: {
  106. current: 0,
  107. tabList: [
  108. {
  109. name: '路段'
  110. },
  111. {
  112. name: '停车场'
  113. }
  114. ]
  115. },
  116. searchContent: '',
  117. page_map: '',
  118. loading: false,
  119. latitude: 26.64969,
  120. longitude: 106.636453,
  121. scale: 16,
  122. currentPosition: {
  123. latitude: 26.64969,
  124. longitude: 106.636453
  125. },
  126. covers: [],
  127. // 附近列表是否显示
  128. nearParkingFlag: false,
  129. // 轮播选中
  130. swiperCurrent: 0,
  131. // 附近停车列表
  132. nearParkingList: [],
  133. // 是否显示停车场列表
  134. isShowSearchParking: false,
  135. // 搜索停车场列表
  136. searchParkingList: [],
  137. // 显示单个停车场数据
  138. isShowParkingDetail: false,
  139. // 单个停车场数据
  140. parkingDetailData: {},
  141. mapSelect: false,
  142. mapSelectList: [
  143. {
  144. value: '1',
  145. label: '腾讯地图'
  146. },
  147. {
  148. value: '2',
  149. label: '百度地图'
  150. },
  151. {
  152. value: '3',
  153. label: '高德地图'
  154. }
  155. ],
  156. // 选中位置经纬度
  157. currentPositionHover: {},
  158. nearParkingObj: {
  159. height: '60vh',
  160. type: 'down'
  161. }
  162. };
  163. },
  164. onLoad(page) {
  165. this.getLocation();
  166. if (page.keyword) {
  167. this.searchContent = page.keyword;
  168. this.searchInputChange(page.keyword);
  169. }
  170. },
  171. methods: {
  172. /**
  173. * 查询输入框发生变化
  174. * @date 2021-08-10
  175. * @param {String} value
  176. */
  177. searchInputChange(value) {
  178. // 为空时关闭搜索列表
  179. if (value === '') {
  180. this.isShowSearchParking = false;
  181. }
  182. this.isShowParkingDetail = false;
  183. const obj = {
  184. 0: 'getNearRoadsl',
  185. 1: 'getParkingLotList'
  186. };
  187. this[obj[this.tabObj.current]]();
  188. },
  189. /**
  190. * 获取定位
  191. * @date 2021-08-10
  192. * @returns {any}
  193. */
  194. getLocation() {
  195. const that = this;
  196. console.log('请求定位');
  197. that.loading = true;
  198. if (navigator.geolocation) {
  199. // 判断是否有这个对象
  200. navigator.geolocation.getCurrentPosition(
  201. function (pos) {
  202. console.log('浏览器获取位置成功:', JSON.stringify(pos));
  203. console.log('经度:' + pos.coords.longitude + '纬度:' + pos.coords.latitude);
  204. that.latitude = pos.coords.latitude;
  205. that.longitude = pos.coords.longitude;
  206. that.currentPosition.latitude = pos.coords.latitude;
  207. that.currentPosition.longitude = pos.coords.longitude;
  208. that.loading = false;
  209. const obj = {
  210. 0: 'getNearRoadsl',
  211. 1: 'getParkingLotList'
  212. };
  213. that[obj[that.tabObj.current]]();
  214. },
  215. function (err) {
  216. console.log('浏览器获取位置失败:', JSON.stringify(err));
  217. uni.getLocation({
  218. type: 'gcj02',
  219. success: function (res) {
  220. console.log('当前位置的经度:' + res.longitude);
  221. console.log('当前位置的纬度:' + res.latitude);
  222. that.currentPosition.latitude = res.latitude;
  223. that.currentPosition.longitude = res.longitude;
  224. that.loading = false;
  225. const obj = {
  226. 0: 'getNearRoadsl',
  227. 1: 'getParkingLotList'
  228. };
  229. that[obj[that.tabObj.current]]();
  230. }
  231. });
  232. }
  233. );
  234. } else {
  235. this.$refs.uToast.show({
  236. title: '当前系统不支持GPS API',
  237. type: 'error'
  238. });
  239. }
  240. },
  241. /**
  242. * 导航
  243. * @date 2021-08-10
  244. * @param {Number} latitude
  245. * @param {Number} longitude
  246. * @returns {any}
  247. */
  248. navigation(latitude, longitude, areaName) {
  249. this.currentPositionHover = {
  250. latitude,
  251. longitude,
  252. areaName
  253. };
  254. this.mapSelect = true;
  255. },
  256. // 多地图选择
  257. mapSelectConfirm(item) {
  258. const name = item[0].label;
  259. switch (name) {
  260. case '腾讯地图':
  261. location.href = `https://apis.map.qq.com/uri/v1/routeplan?type=drive&from=我的位置&fromcoord=${this.currentPosition.latitude},${
  262. this.currentPosition.longitude
  263. }&to=${this.currentPositionHover.areaName || item.parkName}&tocoord=${this.currentPositionHover.latitude},${
  264. this.currentPositionHover.longitude
  265. }&policy=1&referer=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL`;
  266. break;
  267. case '百度地图':
  268. const lnglatObj = qqMapTransBMap(this.currentPositionHover.longitude, this.currentPositionHover.latitude);
  269. location.href = `http://api.map.baidu.com/marker?location=
  270. ${lnglatObj.lat},${lnglatObj.lng}&title=目的地&content=${this.currentPositionHover.areaName || item.parkName}
  271. &output=html&src=webapp.baidu.openAPIdemo`;
  272. break;
  273. case '高德地图':
  274. location.href = `https://uri.amap.com/navigation?from=${this.currentPosition.longitude},${this.currentPosition.latitude},我的位置&to=${
  275. this.currentPositionHover.longitude
  276. },${this.currentPositionHover.latitude},${
  277. this.currentPositionHover.areaName || item.parkName
  278. }&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0`;
  279. break;
  280. }
  281. },
  282. /**
  283. * 清空搜索框内容
  284. * @date 2021-08-10
  285. * @returns {any}
  286. */
  287. clearSearchInput() {
  288. this.searchContent = '';
  289. this.isShowSearchParking = false;
  290. const obj = {
  291. 0: 'getNearRoadsl',
  292. 1: 'getParkingLotList'
  293. };
  294. this[obj[this.tabObj.current]]();
  295. },
  296. /**
  297. * 默认首个点放大 如果有传入经纬度则对应的点放大
  298. * @date 2021-08-10
  299. * @param {Number} lon
  300. * @param {Number} lat
  301. * @returns {any}
  302. */
  303. getNearRoadsl(lon, lat) {
  304. this.$u.api
  305. .nearRoadsl({
  306. latitude: this.currentPosition.latitude,
  307. longitude: this.currentPosition.longitude,
  308. roadName: this.searchContent
  309. })
  310. .then((res) => {
  311. const nearParkingList = []; // 附近停车场列表
  312. this.covers = [];
  313. res.data.forEach((item, index, arr) => {
  314. if (item.latitude && item.longitude) {
  315. nearParkingList.push(item);
  316. const marker = {
  317. latitude: item.latitude,
  318. longitude: item.longitude,
  319. id: String(index),
  320. iconPath: require('./../../static/img/parking-icon.png'),
  321. width: 20,
  322. height: 25
  323. };
  324. // 选中经纬度图标变大
  325. if (lon && lat) {
  326. if (lon === item.longitude && lat === item.latitude) {
  327. marker.width = 40;
  328. marker.height = 50;
  329. }
  330. } else {
  331. if (this.covers.length > 0) {
  332. this.covers[0].width = 40;
  333. this.covers[0].height = 50;
  334. }
  335. }
  336. this.covers.push(marker);
  337. }
  338. });
  339. this.nearParkingList = nearParkingList;
  340. if (nearParkingList.length > 0) {
  341. this.latitude = nearParkingList[0]?.latitude || this.currentPosition.latitude;
  342. this.longitude = nearParkingList[0]?.longitude || this.currentPosition.longitude;
  343. }
  344. this.nearParkingFlag = true;
  345. if (this.searchContent) {
  346. this.searchParkingList = nearParkingList;
  347. this.isShowSearchParking = true;
  348. this.nearParkingFlag = false;
  349. }
  350. })
  351. .catch((err) => {
  352. this.$refs.uToast.show({
  353. title: err.msg,
  354. type: 'error'
  355. });
  356. });
  357. },
  358. getParkingLotList(lon, lat) {
  359. this.$u.api
  360. .nearParkingLot({
  361. status: 1,
  362. latitude: this.currentPosition.latitude,
  363. longitude: this.currentPosition.longitude,
  364. parkName: this.searchContent
  365. })
  366. .then((res) => {
  367. const nearParkingList = []; // 附近停车场列表
  368. this.covers = [];
  369. res?.data?.rows.forEach((item, index, arr) => {
  370. if (item.latitude && item.longitude) {
  371. nearParkingList.push(item);
  372. const marker = {
  373. latitude: item.latitude,
  374. longitude: item.longitude,
  375. id: String(index),
  376. iconPath: require('./../../static/img/parking-icon.png'),
  377. width: 20,
  378. height: 25
  379. };
  380. // 选中经纬度图标变大
  381. if (lon && lat) {
  382. if (lon === item.longitude && lat === item.latitude) {
  383. marker.width = 40;
  384. marker.height = 50;
  385. }
  386. } else {
  387. if (this.covers.length > 0) {
  388. this.covers[0].width = 40;
  389. this.covers[0].height = 50;
  390. }
  391. }
  392. this.covers.push(marker);
  393. }
  394. });
  395. this.nearParkingList = nearParkingList;
  396. if (nearParkingList.length > 0) {
  397. this.latitude = nearParkingList[0]?.latitude || this.currentPosition.latitude;
  398. this.longitude = nearParkingList[0]?.longitude || this.currentPosition.longitude;
  399. }
  400. this.nearParkingFlag = true;
  401. if (this.searchContent) {
  402. this.searchParkingList = nearParkingList;
  403. this.isShowSearchParking = true;
  404. this.nearParkingFlag = false;
  405. }
  406. })
  407. .catch((err) => {
  408. this.$refs.uToast.show({
  409. title: err.msg,
  410. type: 'error'
  411. });
  412. });
  413. },
  414. /**
  415. * 点击地图上的标记点触发
  416. **/
  417. markertap(e) {
  418. let lon, lat;
  419. this.covers.forEach((item, index) => {
  420. if (e.detail.markerId === item.id) {
  421. lon = item.longitude;
  422. lat = item.latitude;
  423. this.swiperCurrent = index;
  424. }
  425. });
  426. const obj = {
  427. 0: 'getNearRoadsl',
  428. 1: 'getParkingLotList'
  429. };
  430. this[obj[this.tabObj.current]](lon, lat);
  431. },
  432. /**
  433. * 地址发生变化
  434. * @date 2021-08-10
  435. * @param {Object} item
  436. * @returns {any}
  437. */
  438. swiperChange(item) {
  439. const map = uni.createMapContext('pagemap');
  440. map.moveToLocation({
  441. longitude: this.nearParkingList[item.detail.current].longitude,
  442. latitude: this.nearParkingList[item.detail.current].latitude
  443. });
  444. const obj = {
  445. 0: 'getNearRoadsl',
  446. 1: 'getParkingLotList'
  447. };
  448. this[obj[this.tabObj.current]](this.nearParkingList[item.detail.current].longitude, this.nearParkingList[item.detail.current].latitude);
  449. },
  450. /**
  451. * 点击单个地址
  452. * @date 2022-08-31
  453. * @param {any} item
  454. * @returns {any}
  455. */
  456. positionAddress(item) {
  457. const map = uni.createMapContext('pagemap');
  458. map.moveToLocation({
  459. longitude: item.longitude,
  460. latitude: item.latitude
  461. });
  462. const obj = {
  463. 0: 'getNearRoadsl',
  464. 1: 'getParkingLotList'
  465. };
  466. this[obj[this.tabObj.current]](item.longitude, item.latitude);
  467. },
  468. /**
  469. * 点击单个停车场看详情
  470. * @date 2021-08-10
  471. * @param {Object} item 为选中项参数
  472. * @returns {any}
  473. */
  474. clickSearchParking(item) {
  475. if (item.monthAmount) {
  476. this.$u.route({
  477. url: 'pages/parkingInformation/parkingInformation',
  478. params: {
  479. roadInfo: JSON.stringify(item),
  480. longitude: this.currentPosition.longitude,
  481. latitude: this.currentPosition.latitude
  482. }
  483. });
  484. }
  485. },
  486. /**
  487. * 跳转停车标准页面
  488. * @date 2021-08-10
  489. * @param {Object} item
  490. * @returns {any}
  491. */
  492. lookParkingRule(item) {
  493. const obj = {
  494. 0: 'roadNo',
  495. 1: 'parkNo'
  496. };
  497. const params = {};
  498. params[obj[this.tabObj.current]] = item[obj[this.tabObj.current]];
  499. this.$u.route({
  500. url: 'pages/chargeStandard/chargeStandard',
  501. params
  502. });
  503. },
  504. /**
  505. * 搜索右侧按钮点击
  506. **/
  507. listIconClick() {
  508. this.isShowSearchParking = true;
  509. this.nearParkingFlag = false;
  510. this.searchParkingList = this.nearParkingList;
  511. },
  512. /**
  513. * 跳转包月
  514. * @date 2021-08-10
  515. * @param {Object} item
  516. * @returns {any}
  517. */
  518. createMonth(item) {
  519. const obj = {
  520. 0: 'roadNo',
  521. 1: 'parkNo'
  522. };
  523. const params = {};
  524. params[obj[this.tabObj.current]] = item[obj[this.tabObj.current]];
  525. this.$u.route({
  526. url: 'pages/handleMonthly/handleMonthly',
  527. params
  528. });
  529. },
  530. pullDown() {
  531. if (this.nearParkingObj.height === '20vh') {
  532. this.nearParkingObj.height = '60vh';
  533. this.nearParkingObj.type = 'down';
  534. } else {
  535. this.nearParkingObj.height = '20vh';
  536. this.nearParkingObj.type = 'up';
  537. }
  538. },
  539. /**
  540. * tab切换触发
  541. * @param {Object} val
  542. */
  543. tabChange(val) {
  544. this.tabObj.current = val;
  545. const obj = {
  546. 0: 'getNearRoadsl',
  547. 1: 'getParkingLotList'
  548. };
  549. this[obj[val]]();
  550. }
  551. }
  552. };
  553. </script>
  554. <style lang="scss" scoped>
  555. .wrap {
  556. margin-top: 20vh;
  557. }
  558. @import './parkingLists.scss';
  559. </style>