parkingLists.vue 14 KB

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