parkingLists.vue 15 KB

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