parkingLists.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. uni.getLocation({
  184. type:"gcj02",
  185. success : function (res) {
  186. console.log("定位返回信息:", res);
  187. that.latitude = res.latitude;
  188. that.longitude = res.longitude;
  189. that.currentPosition.latitude = res.latitude
  190. that.currentPosition.longitude = res.longitude
  191. that.loading = false
  192. that.getNearRoadsl()
  193. },
  194. fail: function(res){
  195. this.$refs.uToast.show({
  196. title: res,
  197. type: 'error',
  198. })
  199. }
  200. })
  201. },
  202. /**
  203. * 导航
  204. * */
  205. navigation (latitude, longitude) {
  206. // this.currentPositionHover = {
  207. // latitude: latitude,
  208. // longitude: longitude
  209. // }
  210. // this.mapSelect = true
  211. // 腾讯地图用webview
  212. uni.navigateTo({
  213. 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'
  214. })
  215. /* 组件多地图调用 */
  216. // this.nearParkingFlag = false
  217. // var options = {
  218. // destination:{ // 导航终点点坐标和名称
  219. // latitude: latitude,
  220. // longitude: longitude,
  221. // name: "终点"
  222. // },
  223. // mapId: "map" // map 组件的 id (微信小程序端必传)
  224. // }
  225. // Map.navigation(options)
  226. },
  227. // 多地图选择
  228. mapSelectConfirm(item) {
  229. const name = item[0].label
  230. switch(name) {
  231. case '腾讯地图':
  232. // uni.navigateTo({
  233. // 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'
  234. // })
  235. // uni.navigateTo({
  236. // 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'
  237. // })
  238. break;
  239. case '百度地图':
  240. uni.navigateTo({
  241. 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`)}`
  242. })
  243. break;
  244. case '高德地图':
  245. uni.navigateTo({
  246. 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`)}`
  247. })
  248. break;
  249. }
  250. },
  251. clearSearchInput () {
  252. this.searchContent = '';
  253. this.isShowSearchParking = false;
  254. this.getNearRoadsl()
  255. },
  256. /**
  257. * lon,lat 为当前选中点的经纬度
  258. * 默认首个点放大 如果有传入经纬度则对应的点放大
  259. * */
  260. getNearRoadsl(lon, lat){
  261. // await this.getLocation();
  262. this.$u.api.nearRoadsl({
  263. latitude: this.currentPosition.latitude,
  264. longitude:this.currentPosition.longitude,
  265. roadName: this.searchContent
  266. })
  267. .then(res=>{
  268. const nearParkingList = [] // 附近停车场列表
  269. this.covers = []
  270. res.data.forEach((item, index, arr)=>{
  271. if(item.latitude && item.longitude){
  272. nearParkingList.push(item)
  273. let marker = {
  274. latitude: item.latitude,
  275. longitude: item.longitude,
  276. id: String(index),
  277. iconPath: require('./../../static/img/parking-icon.png'),
  278. width: 20,
  279. height: 25
  280. }
  281. // 选中经纬度图标变大
  282. if (lon && lat) {
  283. if (lon === item.longitude && lat === item.latitude) {
  284. marker.width = 40
  285. marker.height = 50
  286. }
  287. } else {
  288. if (this.covers.length > 0) {
  289. this.covers[0].width = 40
  290. this.covers[0].height = 50
  291. }
  292. }
  293. this.covers.push(marker)
  294. }
  295. })
  296. this.nearParkingList = nearParkingList;
  297. if (nearParkingList.length > 0) {
  298. this.latitude = nearParkingList[0]?.latitude||this.currentPosition.latitude;
  299. this.longitude = nearParkingList[0]?.longitude||this.currentPosition.longitude;
  300. } else {
  301. this.$refs.uToast.show({
  302. title: '没有相关停车场信息',
  303. type: 'warning'
  304. })
  305. }
  306. this.nearParkingFlag = true
  307. if (this.searchContent) {
  308. this.searchParkingList = nearParkingList
  309. this.isShowSearchParking = true
  310. this.nearParkingFlag = false
  311. }
  312. }).catch(err=>{
  313. this.$refs.uToast.show({
  314. title: err.msg,
  315. type: 'error',
  316. });
  317. });
  318. },
  319. /**
  320. * 点击地图上的标记点触发
  321. * */
  322. markertap(e){
  323. let lon,lat
  324. this.covers.forEach((item, index) => {
  325. if (e.detail.markerId === item.id) {
  326. lon = item.longitude
  327. lat = item.latitude
  328. this.swiperCurrent = index
  329. }
  330. })
  331. this.getNearRoadsl(lon, lat)
  332. },
  333. /*
  334. *地址发生变化
  335. *
  336. * */
  337. swiperChange (item) {
  338. let map = uni.createMapContext('pagemap');
  339. map.moveToLocation({
  340. longitude: this.nearParkingList[item.detail.current].longitude,
  341. latitude: this.nearParkingList[item.detail.current].latitude
  342. })
  343. this.getNearRoadsl(this.nearParkingList[item.detail.current].longitude, this.nearParkingList[item.detail.current].latitude)
  344. },
  345. /**
  346. * 点击单个停车场看详情
  347. * item 为选中项参数
  348. * */
  349. clickSearchParking (item) {
  350. console.log('clickSearchParking',item)
  351. // this.parkingDetailData = item
  352. // this.isShowParkingDetail = true
  353. // this.latitude = item.latitude
  354. // this.longitude = item.longitude
  355. // this.getNearRoadsl(item.longitude, item.latitude)
  356. // setTimeout(() => {
  357. // this.isShowSearchParking = false
  358. // }, 500)
  359. // this.scale = 18
  360. this.$u.route({
  361. url: 'pages/parkingInformation/parkingInformation',
  362. params:{
  363. roadInfo:JSON.stringify(item)
  364. }
  365. })
  366. },
  367. /**
  368. * 跳转停车标准页面
  369. * {roadNo} 路段编码
  370. * */
  371. lookParkingRule (item) {
  372. this.$u.route({
  373. url: 'pages/chargeStandard/chargeStandard',
  374. params: {
  375. roadNo: item.roadNo
  376. }
  377. })
  378. },
  379. /*搜索右侧按钮点击
  380. */
  381. listIconClick(){
  382. this.isShowSearchParking = true;
  383. this.nearParkingFlag = false;
  384. this.searchParkingList = this.nearParkingList;
  385. // this.getNearRoadsl();
  386. },
  387. createMonth(item){
  388. this.$u.route({
  389. url: 'pages/handleMonthly/handleMonthly',
  390. params: {
  391. roadNo:item.roadNo
  392. }
  393. });
  394. }
  395. }
  396. }
  397. </script>
  398. <style lang="scss" scoped>
  399. .wrap{margin-top: 20vh;}
  400. @import url("./parkingLists.scss");
  401. </style>