parkingLists.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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="parking-current-address" v-if="nearParkingFlag">
  42. <swiper class="swiper" :current="swiperCurrent" :indicator-dots="false" :vertical="true" :autoplay="false" previous-margin="30rpx" next-margin="30rpx" @change="swiperChange">
  43. <swiper-item v-for="(item, index) in nearParkingList" :key="index + 'n'">
  44. <view class="swiper-item">
  45. <view @click="clickSearchParking(item)">{{ item.roadName }}</view>
  46. <view>{{ item.areaName }}</view>
  47. <view class="swiper-item-font">
  48. <view>
  49. <text>空闲车位</text>
  50. <text class="yellow-font">{{ item.spaceIdle }}</text>
  51. </view>
  52. <view v-if="item.monthAmount">
  53. <text>包月费用</text>
  54. <text class="yellow-font">{{ item.monthAmount }}元</text>
  55. </view>
  56. <view>
  57. <text>距离</text>
  58. <text>{{ item.distance | kmUnit }}</text>
  59. </view>
  60. </view>
  61. <view class="swiper-item-button">
  62. <button type="default" @click="navigation(item.latitude, item.longitude)">导航</button>
  63. <button type="default" :disabled="!item.monthAmount" :class="{ disabled: !item.monthAmount }" @click="createMonth(item)">办理包月</button>
  64. </view>
  65. <view @click="lookParkingRule(item)">
  66. <text>点击查看停车规则</text>
  67. <u-icon name="arrow-right"></u-icon>
  68. </view>
  69. </view>
  70. </swiper-item>
  71. </swiper>
  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)"></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. import { qqMapTransBMap } from '../../utils/mapTrans.js';
  92. export default {
  93. data() {
  94. return {
  95. searchContent: '',
  96. page_map: '',
  97. loading: false,
  98. latitude: 26.64969,
  99. longitude: 106.636453,
  100. scale: 16,
  101. currentPosition: {
  102. latitude: 26.64969,
  103. longitude: 106.636453
  104. },
  105. covers: [],
  106. // 附近列表是否显示
  107. nearParkingFlag: false,
  108. // 轮播选中
  109. swiperCurrent: 0,
  110. // 附近停车列表
  111. nearParkingList: [],
  112. // 是否显示停车场列表
  113. isShowSearchParking: false,
  114. // 搜索停车场列表
  115. searchParkingList: [],
  116. // 显示单个停车场数据
  117. isShowParkingDetail: false,
  118. // 单个停车场数据
  119. parkingDetailData: {},
  120. mapSelect: false,
  121. mapSelectList: [
  122. {
  123. value: '1',
  124. label: '腾讯地图'
  125. },
  126. // {
  127. // value: '2',
  128. // label: '百度地图'
  129. // },
  130. {
  131. value: '3',
  132. label: '高德地图'
  133. }
  134. ],
  135. // 选中位置经纬度
  136. currentPositionHover: {}
  137. };
  138. },
  139. onLoad(page) {
  140. this.getLocation();
  141. // this.getNearRoadsl()
  142. if (page.keyword) {
  143. this.searchContent = page.keyword;
  144. this.searchInputChange(page.keyword);
  145. }
  146. },
  147. methods: {
  148. /**
  149. * 查询输入框发生变化
  150. * @date 2021-08-10
  151. * @param {String} value
  152. */
  153. searchInputChange(value) {
  154. // 为空时关闭搜索列表
  155. if (value === '') {
  156. this.isShowSearchParking = false;
  157. }
  158. this.isShowParkingDetail = false;
  159. this.getNearRoadsl();
  160. },
  161. /**
  162. * 获取定位
  163. * @date 2021-08-10
  164. * @returns {any}
  165. */
  166. getLocation() {
  167. const that = this;
  168. console.log('请求定位');
  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) {
  196. this.currentPositionHover = {
  197. latitude: latitude,
  198. longitude: longitude
  199. };
  200. this.mapSelect = true;
  201. // 腾讯地图用webview
  202. // uni.navigateTo({
  203. // url: '/pages/parkingLists/map_web_view/map_web_view?url=https://3gimg.qq.com/lightmap/v1/marker/?marker=coord:'+latitude+','+longitude+'&referer=myApp&key=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL'
  204. // })
  205. /* 组件多地图调用 */
  206. // this.nearParkingFlag = false
  207. // var options = {
  208. // destination:{ // 导航终点点坐标和名称
  209. // latitude: latitude,
  210. // longitude: longitude,
  211. // name: "终点"
  212. // },
  213. // mapId: "map" // map 组件的 id (微信小程序端必传)
  214. // }
  215. // Map.navigation(options)
  216. },
  217. // 多地图选择
  218. mapSelectConfirm(item) {
  219. const name = item[0].label;
  220. switch (name) {
  221. case '腾讯地图':
  222. uni.navigateTo({
  223. url:
  224. '/pages/parkingLists/map_web_view/map_web_view?url=https://3gimg.qq.com/lightmap/v1/marker/?marker=coord:' +
  225. this.currentPositionHover.latitude +
  226. ',' +
  227. this.currentPositionHover.longitude +
  228. '&referer=myApp&key=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL'
  229. });
  230. break;
  231. case '百度地图':
  232. const bdOriginPoint = qqMapTransBMap(this.currentPosition.longitude, this.currentPosition.latitude); // 起点坐标
  233. const bdCurrPoint = qqMapTransBMap(this.currentPositionHover.longitude, this.currentPositionHover.latitude); // 终点坐标
  234. const baiduMap = 'https://map.baidu.com/mobile/webapp/index/index/foo=bar/vt=map';
  235. const bdurl = `https://api.map.baidu.com/direction?origin=latlng:${bdOriginPoint.lat},${bdOriginPoint.lng}|name:起点&destination=latlng:${bdCurrPoint.lat},${
  236. bdCurrPoint.lng
  237. }|name:终点&mode=driving&output=html&src=webapp.baidu.openAPIdemo`;
  238. console.log('百度地图theurl', bdurl);
  239. window.location.href = baiduMap;
  240. break;
  241. case '高德地图':
  242. const gdurl = `https://uri.amap.com/navigation?from=${this.currentPosition.longitude},${this.currentPosition.latitude},起点&to=${this.currentPositionHover.longitude},${
  243. this.currentPositionHover.latitude
  244. },终点&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0`;
  245. console.log('高德地图theurl', gdurl);
  246. window.location.href = gdurl;
  247. // window.open(url, "_blank", "scrollbars=yes,resizable=1,modal=false,alwaysRaised=yes");
  248. // uni.navigateTo({
  249. // url: `/pages/parkingLists/map_web_view/map_web_view?url=${encodeURIComponent(`//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`)}`
  250. // })
  251. break;
  252. }
  253. },
  254. /**
  255. * 清空搜索框内容
  256. * @date 2021-08-10
  257. * @returns {any}
  258. */
  259. clearSearchInput() {
  260. this.searchContent = '';
  261. this.isShowSearchParking = false;
  262. this.getNearRoadsl();
  263. },
  264. /**
  265. * 默认首个点放大 如果有传入经纬度则对应的点放大
  266. * @date 2021-08-10
  267. * @param {Number} lon
  268. * @param {Number} lat
  269. * @returns {any}
  270. */
  271. getNearRoadsl(lon, lat) {
  272. this.$u.api
  273. .nearRoadsl({
  274. latitude: this.currentPosition.latitude,
  275. longitude: this.currentPosition.longitude,
  276. roadName: this.searchContent
  277. })
  278. .then(res => {
  279. const nearParkingList = []; // 附近停车场列表
  280. this.covers = [];
  281. res.data.forEach((item, index, arr) => {
  282. if (item.latitude && item.longitude) {
  283. nearParkingList.push(item);
  284. const marker = {
  285. latitude: item.latitude,
  286. longitude: item.longitude,
  287. id: String(index),
  288. iconPath: require('./../../static/img/parking-icon.png'),
  289. width: 20,
  290. height: 25
  291. };
  292. // 选中经纬度图标变大
  293. if (lon && lat) {
  294. if (lon === item.longitude && lat === item.latitude) {
  295. marker.width = 40;
  296. marker.height = 50;
  297. }
  298. } else {
  299. if (this.covers.length > 0) {
  300. this.covers[0].width = 40;
  301. this.covers[0].height = 50;
  302. }
  303. }
  304. this.covers.push(marker);
  305. }
  306. });
  307. this.nearParkingList = nearParkingList;
  308. if (nearParkingList.length > 0) {
  309. this.latitude = nearParkingList[0]?.latitude || this.currentPosition.latitude;
  310. this.longitude = nearParkingList[0]?.longitude || this.currentPosition.longitude;
  311. } else {
  312. this.$refs.uToast.show({
  313. title: '没有相关停车场信息',
  314. type: 'warning'
  315. });
  316. }
  317. this.nearParkingFlag = true;
  318. if (this.searchContent) {
  319. this.searchParkingList = nearParkingList;
  320. this.isShowSearchParking = true;
  321. this.nearParkingFlag = false;
  322. }
  323. })
  324. .catch(err => {
  325. this.$refs.uToast.show({
  326. title: err.msg,
  327. type: 'error'
  328. });
  329. });
  330. },
  331. /**
  332. * 点击地图上的标记点触发
  333. **/
  334. markertap(e) {
  335. let lon, lat;
  336. this.covers.forEach((item, index) => {
  337. if (e.detail.markerId === item.id) {
  338. lon = item.longitude;
  339. lat = item.latitude;
  340. this.swiperCurrent = index;
  341. }
  342. });
  343. this.getNearRoadsl(lon, lat);
  344. },
  345. /**
  346. * 地址发生变化
  347. * @date 2021-08-10
  348. * @param {Object} item
  349. * @returns {any}
  350. */
  351. swiperChange(item) {
  352. const map = uni.createMapContext('pagemap');
  353. map.moveToLocation({
  354. longitude: this.nearParkingList[item.detail.current].longitude,
  355. latitude: this.nearParkingList[item.detail.current].latitude
  356. });
  357. this.getNearRoadsl(this.nearParkingList[item.detail.current].longitude, this.nearParkingList[item.detail.current].latitude);
  358. },
  359. /**
  360. * 点击单个停车场看详情
  361. * @date 2021-08-10
  362. * @param {Object} item 为选中项参数
  363. * @returns {any}
  364. */
  365. clickSearchParking(item) {
  366. if (item.monthAmount) {
  367. this.$u.route({
  368. url: 'pages/parkingInformation/parkingInformation',
  369. params: {
  370. roadInfo: JSON.stringify(item)
  371. }
  372. });
  373. }
  374. },
  375. /**
  376. * 跳转停车标准页面
  377. * @date 2021-08-10
  378. * @param {Object} item
  379. * @returns {any}
  380. */
  381. lookParkingRule(item) {
  382. this.$u.route({
  383. url: 'pages/chargeStandard/chargeStandard',
  384. params: {
  385. roadNo: item.roadNo
  386. }
  387. });
  388. },
  389. /**
  390. * 搜索右侧按钮点击
  391. **/
  392. listIconClick() {
  393. this.isShowSearchParking = true;
  394. this.nearParkingFlag = false;
  395. this.searchParkingList = this.nearParkingList;
  396. },
  397. /**
  398. * 跳转包月
  399. * @date 2021-08-10
  400. * @param {Object} item
  401. * @returns {any}
  402. */
  403. createMonth(item) {
  404. this.$u.route({
  405. url: 'pages/handleMonthly/handleMonthly',
  406. params: {
  407. roadNo: item.roadNo
  408. }
  409. });
  410. }
  411. }
  412. };
  413. </script>
  414. <style lang="scss" scoped>
  415. .wrap {
  416. margin-top: 20vh;
  417. }
  418. @import url('./parkingLists.scss');
  419. </style>