parkingLists.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. break;
  236. case '百度地图':
  237. uni.navigateTo({
  238. 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`)}`
  239. })
  240. break;
  241. case '高德地图':
  242. uni.navigateTo({
  243. 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`)}`
  244. })
  245. break;
  246. }
  247. },
  248. clearSearchInput () {
  249. this.searchContent = '';
  250. this.isShowSearchParking = false;
  251. this.getNearRoadsl()
  252. },
  253. /**
  254. * lon,lat 为当前选中点的经纬度
  255. * 默认首个点放大 如果有传入经纬度则对应的点放大
  256. * */
  257. getNearRoadsl(lon, lat){
  258. // await this.getLocation();
  259. this.$u.api.nearRoadsl({
  260. latitude: this.currentPosition.latitude,
  261. longitude:this.currentPosition.longitude,
  262. roadName: this.searchContent
  263. })
  264. .then(res=>{
  265. const nearParkingList = [] // 附近停车场列表
  266. this.covers = []
  267. res.data.forEach((item, index, arr)=>{
  268. if(item.latitude && item.longitude){
  269. nearParkingList.push(item)
  270. let marker = {
  271. latitude: item.latitude,
  272. longitude: item.longitude,
  273. id: String(index),
  274. iconPath: require('./../../static/img/parking-icon.png'),
  275. width: 20,
  276. height: 25
  277. }
  278. // 选中经纬度图标变大
  279. if (lon && lat) {
  280. if (lon === item.longitude && lat === item.latitude) {
  281. marker.width = 40
  282. marker.height = 50
  283. }
  284. } else {
  285. if (this.covers.length > 0) {
  286. this.covers[0].width = 40
  287. this.covers[0].height = 50
  288. }
  289. }
  290. this.covers.push(marker)
  291. }
  292. })
  293. this.nearParkingList = nearParkingList;
  294. this.latitude = nearParkingList[0]?.latitude||this.currentPosition.latitude;
  295. this.longitude = nearParkingList[0]?.longitude||this.currentPosition.longitude;
  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. *
  326. * */
  327. swiperChange (item) {
  328. let map = uni.createMapContext('pagemap');
  329. map.moveToLocation({
  330. longitude: this.nearParkingList[item.detail.current].longitude,
  331. latitude: this.nearParkingList[item.detail.current].latitude
  332. })
  333. this.getNearRoadsl(this.nearParkingList[item.detail.current].longitude, this.nearParkingList[item.detail.current].latitude)
  334. },
  335. /**
  336. * 点击单个停车场看详情
  337. * item 为选中项参数
  338. * */
  339. clickSearchParking (item) {
  340. console.log('clickSearchParking',item)
  341. // this.parkingDetailData = item
  342. // this.isShowParkingDetail = true
  343. // this.latitude = item.latitude
  344. // this.longitude = item.longitude
  345. // this.getNearRoadsl(item.longitude, item.latitude)
  346. // setTimeout(() => {
  347. // this.isShowSearchParking = false
  348. // }, 500)
  349. // this.scale = 18
  350. this.$u.route({
  351. url: 'pages/parkingInformation/parkingInformation',
  352. params:{
  353. roadInfo:JSON.stringify(item)
  354. }
  355. })
  356. },
  357. /**
  358. * 跳转停车标准页面
  359. * {roadNo} 路段编码
  360. * */
  361. lookParkingRule (item) {
  362. this.$u.route({
  363. url: 'pages/chargeStandard/chargeStandard',
  364. params: {
  365. roadNo: item.roadNo
  366. }
  367. })
  368. },
  369. /*搜索右侧按钮点击
  370. */
  371. listIconClick(){
  372. this.isShowSearchParking = true;
  373. this.nearParkingFlag = false;
  374. this.searchParkingList = this.nearParkingList;
  375. // this.getNearRoadsl();
  376. },
  377. createMonth(item){
  378. this.$u.route({
  379. url: 'pages/handleMonthly/handleMonthly',
  380. params: {
  381. roadNo:item.roadNo
  382. }
  383. });
  384. }
  385. }
  386. }
  387. </script>
  388. <style lang="scss" scoped>
  389. .wrap{margin-top: 20vh;}
  390. @import url("./parkingLists.scss");
  391. </style>