parkingLists.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="parking">
  3. <view class="loading" v-show="loading">
  4. <u-loading size="36" mode="flower"></u-loading>
  5. </view>
  6. <view class="parking-header">
  7. <u-search placeholder="搜索停车场" v-model="searchContent" :show-action="false" @change="searchInputChange"></u-search>
  8. <u-icon v-if="!searchContent" class="icon" name="list" size="44" color="#ffffff"
  9. placeholder-color="#B5B5B5" search-icon-color="#B3B3B3"></u-icon>
  10. <u-icon v-if="searchContent" class="icon" name="close" size="36" color="#ffffff"
  11. placeholder-color="#B5B5B5" search-icon-color="#B3B3B3" @click="clearSearchInput"></u-icon>
  12. </view>
  13. <view class="parking-map">
  14. <map
  15. id="pagemap"
  16. style="width: 100%; height: calc(100vh - 240rpx);"
  17. :show-location="true"
  18. :latitude="latitude"
  19. :longitude="longitude"
  20. @markertap="markertap"
  21. :enable-traffic="true"
  22. :enable-zoom="true"
  23. :scale="scale"
  24. :markers="covers"></map>
  25. </view>
  26. <!-- <u-empty src="/static/img/empty.png" icon-size="335" text="正在建设中" color="#878787" mode="search"></u-empty> -->
  27. <view class="parking-current-address" v-if="nearParkingFlag">
  28. <swiper class="swiper" :current="swiperCurrent" :indicator-dots="false" :autoplay="false" previous-margin="30rpx" next-margin="30rpx" @change="swiperChange">
  29. <swiper-item v-for="(item, index) in nearParkingList" :key="index + 'n'">
  30. <view class="swiper-item">
  31. <view>{{item.roadName}}</view>
  32. <view>{{item.areaName}}</view>
  33. <view class="swiper-item-font">
  34. <view>
  35. <text>余位</text>
  36. <text class="yellow-font">{{item.spaceIdle}}</text>
  37. </view>
  38. <view v-if="item.monthAmount">
  39. <text>包月费用</text>
  40. <text class="yellow-font">{{item.monthAmount}}元</text>
  41. </view>
  42. <view>
  43. <text>距离</text>
  44. <text>{{item.distance}}m</text>
  45. </view>
  46. </view>
  47. <view class="swiper-item-button">
  48. <button type="default" @click="navigation(item.latitude, item.longitude)">导航</button>
  49. <button type="default" :disabled="!item.monthAmount" :class="{'disabled': !item.monthAmount}" @click="$u.route({url: 'pages/handleMonthly/handleMonthly'})">办理包月</button>
  50. </view>
  51. <view @click="$u.route({url: 'pages/chargeStandard/chargeStandard'})">
  52. <text>点击查看停车规则</text>
  53. <u-icon name="arrow-right"></u-icon>
  54. </view>
  55. </view>
  56. </swiper-item>
  57. </swiper>
  58. </view>
  59. <view class="parking-address-list" v-if="searchParkingList.length > 0 && isShowSearchParking">
  60. <view class="parking-address-list-item" v-for="(item, index) in searchParkingList" :key="index + 's'" @click="clickSearchParking(item)">
  61. <view class="pali-left">
  62. <view>{{item.roadName}}</view>
  63. <view>{{item.areaName}}</view>
  64. </view>
  65. <view class="pali-right">
  66. <image src="../../static/img/distance-icon.png" mode="" @click="navigation(item.latitude, item.longitude)"></image>
  67. <view>路线</view>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="parking-address-details" v-if="isShowParkingDetail">
  72. <view class="parking-address-details-title">
  73. <view class="padt-header">
  74. <view class="padt-header-title">
  75. <view>{{parkingDetailData.roleName}}</view>
  76. <view>贵阳市云岩区北京东路与贵阳绕城高速交叉…</view>
  77. </view>
  78. <view class="padt-header-icon">
  79. <image src="../../static/img/distance-icon.png" mode=""></image>
  80. <view>{{parkingDetailData.distance}}m</view>
  81. </view>
  82. </view>
  83. <view class="padt-timeline">服务时间<text>7:00-21:00</text></view>
  84. </view>
  85. <view class="parking-address-details-numer">
  86. <view>
  87. <view>120</view>
  88. <view>共有车位</view>
  89. </view>
  90. <view>
  91. <view>30</view>
  92. <view>空闲车位</view>
  93. </view>
  94. </view>
  95. <view class="parking-address-details-price">
  96. <view>
  97. <text>10</text>
  98. <text>元/小时 包月费用:300元</text>
  99. </view>
  100. <view @click="$u.route({url: 'pages/chargeStandard/chargeStandard'})">点击查看停车规则</view>
  101. </view>
  102. <view class="parking-address-details-button">办理包月</view>
  103. </view>
  104. <u-toast ref="uToast" />
  105. </view>
  106. </template>
  107. <script>
  108. export default{
  109. data(){
  110. return{
  111. searchContent: '',
  112. page_map:'',
  113. loading: false,
  114. // id: 0, //使用 marker点击事件 需要填写id
  115. latitude: 26.64969,
  116. longitude: 106.636453,
  117. scale: 16,
  118. currentPosition: {
  119. latitude: 26.64969,
  120. longitude: 106.636453,
  121. },
  122. covers: [
  123. // {
  124. // latitude: 26.597864,
  125. // longitude: 106.72947,
  126. // id: '0',
  127. // iconPath: require('./../../static/img/parking-icon.png')
  128. // },
  129. // {
  130. // latitude: 26.497864,
  131. // longitude: 106.72947,
  132. // id: '1',
  133. // iconPath: require('./../../static/img/parking-icon.png')
  134. // }
  135. ],
  136. // 附近列表是否显示
  137. nearParkingFlag: false,
  138. // 轮播选中
  139. swiperCurrent: 0,
  140. // 附近停车列表
  141. nearParkingList: [],
  142. // 是否显示停车场列表
  143. isShowSearchParking: false,
  144. // 搜索停车场列表
  145. searchParkingList: [],
  146. // 显示单个停车场数据
  147. isShowParkingDetail: false,
  148. // 单个停车场数据
  149. parkingDetailData: {}
  150. }
  151. },
  152. onLoad(){
  153. this.getLocation()
  154. },
  155. onShow() {
  156. this.isShowSearchParking = false
  157. this.isShowParkingDetail = false
  158. // this.getNearRoadsl()
  159. },
  160. methods:{
  161. /*
  162. * 查询输入框发生变化
  163. *
  164. * */
  165. searchInputChange (value) {
  166. // 为空时关闭搜索列表
  167. if (value === '') {
  168. this.isShowSearchParking = false
  169. }
  170. this.isShowParkingDetail = false
  171. this.getNearRoadsl()
  172. },
  173. getLocation(){
  174. let that = this;
  175. console.log("请求定位")
  176. that.loading = true
  177. uni.getLocation({
  178. type:"gcj02",
  179. success : function (res) {
  180. console.log("定位返回信息:", res);
  181. that.latitude = res.latitude;
  182. that.longitude = res.longitude;
  183. that.currentPosition.latitude = res.latitude
  184. that.currentPosition.longitude = res.longitude
  185. that.loading = false
  186. that.getNearRoadsl()
  187. },
  188. fail: function(res){
  189. this.$refs.uToast.show({
  190. title: res,
  191. type: 'error',
  192. })
  193. }
  194. })
  195. },
  196. /**
  197. * 导航
  198. * */
  199. navigation (lat, lon) {
  200. uni.openLocation({
  201. latitude: parseFloat(lat),
  202. longitude: parseFloat(lon),
  203. scale: 18
  204. })
  205. },
  206. clearSearchInput () {
  207. this.searchContent = ''
  208. this.getNearRoadsl()
  209. },
  210. /**
  211. * lon,lat 为当前选中点的经纬度
  212. * */
  213. getNearRoadsl(lon, lat){
  214. // await this.getLocation();
  215. this.$u.api.nearRoadsl({
  216. latitude: this.currentPosition.latitude,
  217. longitude:this.currentPosition.longitude,
  218. roadName: this.searchContent
  219. })
  220. .then(res=>{
  221. const nearParkingList = [] // 附近停车场列表
  222. this.covers = []
  223. res.data.forEach((item, index, arr)=>{
  224. if(item.latitude&&item.longitude){
  225. nearParkingList.push(item)
  226. let marker = {
  227. latitude: item.latitude,
  228. longitude: item.longitude,
  229. id: String(index),
  230. iconPath: require('./../../static/img/parking-icon.png'),
  231. width: 20,
  232. height: 25
  233. }
  234. if (lon && lat) {
  235. if (lon === item.longitude && lat === item.latitude) {
  236. marker.width = 40
  237. marker.height = 50
  238. }
  239. } else {
  240. if (index === 1) {
  241. marker.width = 40
  242. marker.height = 50
  243. }
  244. }
  245. this.covers.push(marker)
  246. }
  247. })
  248. this.nearParkingList = nearParkingList
  249. this.latitude = nearParkingList[0].latitude
  250. this.longitude = nearParkingList[0].longitude
  251. this.nearParkingFlag = true
  252. if (this.searchContent) {
  253. this.searchParkingList = nearParkingList
  254. this.isShowSearchParking = true
  255. this.nearParkingFlag = false
  256. }
  257. }).catch(err=>{
  258. this.$refs.uToast.show({
  259. title: err.msg,
  260. type: 'error',
  261. });
  262. });
  263. },
  264. /**
  265. * 点击地图上的标记点触发
  266. * */
  267. markertap(e){
  268. let lon,lat
  269. this.covers.forEach((item, index) => {
  270. if (e.detail.markerId === item.id) {
  271. lon = item.longitude
  272. lat = item.latitude
  273. this.swiperCurrent = index
  274. }
  275. })
  276. this.getNearRoadsl(lon, lat)
  277. },
  278. /*
  279. *地址发生变化
  280. *
  281. * */
  282. swiperChange (item) {
  283. let map = uni.createMapContext('pagemap');
  284. map.moveToLocation({
  285. longitude: this.nearParkingList[item.detail.current].longitude,
  286. latitude: this.nearParkingList[item.detail.current].latitude
  287. })
  288. this.getNearRoadsl(this.nearParkingList[item.detail.current].longitude, this.nearParkingList[item.detail.current].latitude)
  289. },
  290. /**
  291. * 点击单个停车场看详情
  292. * item 为选中项参数
  293. * */
  294. clickSearchParking (item) {
  295. this.parkingDetailData = item
  296. this.isShowParkingDetail = true
  297. this.isShowSearchParking = false
  298. this.latitude = item.latitude
  299. this.longitude = item.longitude
  300. this.getNearRoadsl(item.longitude, item.latitude)
  301. this.scale = 18
  302. }
  303. }
  304. }
  305. </script>
  306. <style lang="scss" scoped>
  307. .wrap{margin-top: 20vh;}
  308. @import url("./parkingLists.scss");
  309. </style>