parkingLists.vue 16 KB

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