parkingLists.vue 13 KB

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