parkingLists.vue 8.2 KB

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