parkingLists.vue 14 KB

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