parkingLists.vue 12 KB

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