parkingLists.vue 12 KB

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