parkingLists.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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. // this.getNearRoadsl()
  169. if (page.keyword) {
  170. this.searchContent = page.keyword
  171. this.searchInputChange(page.keyword)
  172. }
  173. },
  174. methods: {
  175. /**
  176. * 查询输入框发生变化
  177. * @date 2021-08-10
  178. * @param {String} value
  179. */
  180. searchInputChange (value) {
  181. // 为空时关闭搜索列表
  182. if (value === '') {
  183. this.isShowSearchParking = false
  184. }
  185. this.isShowParkingDetail = false
  186. this.getNearRoadsl()
  187. },
  188. /**
  189. * 获取定位
  190. * @date 2021-08-10
  191. * @returns {any}
  192. */
  193. getLocation () {
  194. const that = this
  195. console.log('请求定位')
  196. that.loading = true
  197. if (navigator.geolocation) {
  198. // 判断是否有这个对象
  199. navigator.geolocation.getCurrentPosition(function (pos) {
  200. console.log('经度:' + pos.coords.longitude + '纬度:' + pos.coords.latitude)
  201. that.latitude = pos.coords.latitude
  202. that.longitude = pos.coords.longitude
  203. that.currentPosition.latitude = pos.coords.latitude
  204. that.currentPosition.longitude = pos.coords.longitude
  205. that.loading = false
  206. that.getNearRoadsl()
  207. })
  208. } else {
  209. this.$refs.uToast.show({
  210. title: '当前系统不支持GPS API',
  211. type: 'error'
  212. })
  213. };
  214. },
  215. /**
  216. * 导航
  217. * @date 2021-08-10
  218. * @param {Number} latitude
  219. * @param {Number} longitude
  220. * @returns {any}
  221. */
  222. navigation (latitude, longitude) {
  223. this.currentPositionHover = {
  224. latitude: latitude,
  225. longitude: longitude
  226. }
  227. this.mapSelect = true
  228. // 腾讯地图用webview
  229. // uni.navigateTo({
  230. // 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'
  231. // })
  232. /* 组件多地图调用 */
  233. // this.nearParkingFlag = false
  234. // var options = {
  235. // destination:{ // 导航终点点坐标和名称
  236. // latitude: latitude,
  237. // longitude: longitude,
  238. // name: "终点"
  239. // },
  240. // mapId: "map" // map 组件的 id (微信小程序端必传)
  241. // }
  242. // Map.navigation(options)
  243. },
  244. // 多地图选择
  245. mapSelectConfirm (item) {
  246. const name = item[0].label
  247. switch (name) {
  248. case '腾讯地图':
  249. uni.navigateTo({
  250. 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'
  251. })
  252. // uni.navigateTo({
  253. // 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'
  254. // })
  255. break
  256. case '百度地图':
  257. const bdOriginPoint = qqMapTransBMap(this.currentPosition.longitude, this.currentPosition.latitude) // 起点坐标
  258. const bdCurrPoint = qqMapTransBMap(this.currentPositionHover.longitude, this.currentPositionHover.latitude) // 终点坐标
  259. const baiduMap = 'https://map.baidu.com/mobile/webapp/index/index/foo=bar/vt=map'
  260. 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`
  261. console.log('百度地图theurl', bdurl)
  262. window.location.href = baiduMap
  263. break
  264. case '高德地图':
  265. 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`
  266. console.log('高德地图theurl', gdurl)
  267. window.location.href = gdurl
  268. // window.open(url, "_blank", "scrollbars=yes,resizable=1,modal=false,alwaysRaised=yes");
  269. // uni.navigateTo({
  270. // 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`)}`
  271. // })
  272. break
  273. }
  274. },
  275. /**
  276. * 清空搜索框内容
  277. * @date 2021-08-10
  278. * @returns {any}
  279. */
  280. clearSearchInput () {
  281. this.searchContent = ''
  282. this.isShowSearchParking = false
  283. this.getNearRoadsl()
  284. },
  285. /**
  286. * 默认首个点放大 如果有传入经纬度则对应的点放大
  287. * @date 2021-08-10
  288. * @param {Number} lon
  289. * @param {Number} lat
  290. * @returns {any}
  291. */
  292. getNearRoadsl (lon, lat) {
  293. this.$u.api.nearRoadsl({
  294. latitude: this.currentPosition.latitude,
  295. longitude: this.currentPosition.longitude,
  296. roadName: this.searchContent
  297. })
  298. .then(res => {
  299. const nearParkingList = [] // 附近停车场列表
  300. this.covers = []
  301. res.data.forEach((item, index, arr) => {
  302. if (item.latitude && item.longitude) {
  303. nearParkingList.push(item)
  304. const marker = {
  305. latitude: item.latitude,
  306. longitude: item.longitude,
  307. id: String(index),
  308. iconPath: require('./../../static/img/parking-icon.png'),
  309. width: 20,
  310. height: 25
  311. }
  312. // 选中经纬度图标变大
  313. if (lon && lat) {
  314. if (lon === item.longitude && lat === item.latitude) {
  315. marker.width = 40
  316. marker.height = 50
  317. }
  318. } else {
  319. if (this.covers.length > 0) {
  320. this.covers[0].width = 40
  321. this.covers[0].height = 50
  322. }
  323. }
  324. this.covers.push(marker)
  325. }
  326. })
  327. this.nearParkingList = nearParkingList
  328. if (nearParkingList.length > 0) {
  329. this.latitude = nearParkingList[0]?.latitude || this.currentPosition.latitude
  330. this.longitude = nearParkingList[0]?.longitude || this.currentPosition.longitude
  331. } else {
  332. this.$refs.uToast.show({
  333. title: '没有相关停车场信息',
  334. type: 'warning'
  335. })
  336. }
  337. this.nearParkingFlag = true
  338. if (this.searchContent) {
  339. this.searchParkingList = nearParkingList
  340. this.isShowSearchParking = true
  341. this.nearParkingFlag = false
  342. }
  343. }).catch(err => {
  344. this.$refs.uToast.show({
  345. title: err.msg,
  346. type: 'error'
  347. })
  348. })
  349. },
  350. /**
  351. * 点击地图上的标记点触发
  352. **/
  353. markertap (e) {
  354. let lon, lat
  355. this.covers.forEach((item, index) => {
  356. if (e.detail.markerId === item.id) {
  357. lon = item.longitude
  358. lat = item.latitude
  359. this.swiperCurrent = index
  360. }
  361. })
  362. this.getNearRoadsl(lon, lat)
  363. },
  364. /**
  365. * 地址发生变化
  366. * @date 2021-08-10
  367. * @param {Object} item
  368. * @returns {any}
  369. */
  370. swiperChange (item) {
  371. const map = uni.createMapContext('pagemap')
  372. map.moveToLocation({
  373. longitude: this.nearParkingList[item.detail.current].longitude,
  374. latitude: this.nearParkingList[item.detail.current].latitude
  375. })
  376. this.getNearRoadsl(this.nearParkingList[item.detail.current].longitude, this.nearParkingList[item.detail.current].latitude)
  377. },
  378. /**
  379. * 点击单个停车场看详情
  380. * @date 2021-08-10
  381. * @param {Object} item 为选中项参数
  382. * @returns {any}
  383. */
  384. clickSearchParking (item) {
  385. if (item.monthAmount) {
  386. this.$u.route({
  387. url: 'pages/parkingInformation/parkingInformation',
  388. params: {
  389. roadInfo: JSON.stringify(item)
  390. }
  391. })
  392. }
  393. },
  394. /**
  395. * 跳转停车标准页面
  396. * @date 2021-08-10
  397. * @param {Object} item
  398. * @returns {any}
  399. */
  400. lookParkingRule (item) {
  401. this.$u.route({
  402. url: 'pages/chargeStandard/chargeStandard',
  403. params: {
  404. roadNo: item.roadNo
  405. }
  406. })
  407. },
  408. /**
  409. * 搜索右侧按钮点击
  410. **/
  411. listIconClick () {
  412. this.isShowSearchParking = true
  413. this.nearParkingFlag = false
  414. this.searchParkingList = this.nearParkingList
  415. },
  416. /**
  417. * 跳转包月
  418. * @date 2021-08-10
  419. * @param {Object} item
  420. * @returns {any}
  421. */
  422. createMonth (item) {
  423. this.$u.route({
  424. url: 'pages/handleMonthly/handleMonthly',
  425. params: {
  426. roadNo: item.roadNo
  427. }
  428. })
  429. }
  430. }
  431. }
  432. </script>
  433. <style lang="scss" scoped>
  434. .wrap{margin-top: 20vh;}
  435. @import url("./parkingLists.scss");
  436. </style>