parkingLists.vue 14 KB

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