parkingLists.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. },
  153. onShow() {
  154. this.getLocation();
  155. },
  156. methods:{
  157. /*
  158. * 查询输入框发生变化
  159. *
  160. * */
  161. searchInputChange (value) {
  162. console.log(value)
  163. if (value === '') {
  164. this.isShowParkingDetail = false
  165. this.isShowSearchParking = false
  166. }
  167. this.getNearRoadsl()
  168. },
  169. getLocation(){
  170. let that = this;
  171. // console.log("请求定位")
  172. uni.getLocation({
  173. type:"gcj02",
  174. success : function (res) {
  175. console.log("定位返回信息:", res);
  176. that.latitude = res.latitude;
  177. that.longitude = res.longitude;
  178. that.currentPosition.latitude = res.latitude
  179. that.currentPosition.longitude = res.longitude
  180. console.log(that.currentPosition)
  181. // that.getNearRoadsl()
  182. },
  183. fail: function(res){
  184. console.log("请求错误:", res)
  185. }
  186. })
  187. },
  188. navigation (lat, lon) {
  189. uni.openLocation({
  190. latitude: parseFloat(lat),
  191. longitude:parseFloat(lon),
  192. scale: 18
  193. })
  194. },
  195. async getNearRoadsl(){
  196. // await this.getLocation();
  197. console.log(this.currentPosition)
  198. this.$u.api.nearRoadsl({
  199. latitude: this.currentPosition.latitude,
  200. longitude:this.currentPosition.longitude,
  201. roadName: this.searchContent
  202. })
  203. .then(res=>{
  204. const nearParkingList = []
  205. res.data.forEach((item, index)=>{
  206. if(item.latitude&&item.longitude){
  207. nearParkingList.push(item)
  208. let marker = {
  209. latitude: item.latitude,
  210. longitude:item.longitude,
  211. id: '1',
  212. iconPath: require('./../../static/img/parking-icon.png')
  213. }
  214. this.covers.push(marker);
  215. }
  216. })
  217. this.nearParkingList = nearParkingList
  218. this.latitude = nearParkingList[0].latitude
  219. this.longitude = nearParkingList[0].longitude
  220. this.loading = false
  221. if (this.searchContent) {
  222. this.searchParkingList = nearParkingList
  223. this.isShowSearchParking = true
  224. }
  225. }).catch(err=>{
  226. this.$refs.uToast.show({
  227. title: err.msg,
  228. type: 'error',
  229. });
  230. console.log('getNearRoadsl ',err)
  231. });
  232. },
  233. /**
  234. * 点击地图上的标记点触发
  235. * */
  236. markertap(e){
  237. console.log(e)
  238. for (let i = 0; i < this.nearParkingList.length; i++) {
  239. let item = this.nearParkingList[i]
  240. if (item.latitude === e.latitude && item.longitude === e.longitude) {
  241. this.swiperCurrent = i
  242. }
  243. }
  244. },
  245. /*
  246. *地址发生变化
  247. *
  248. * */
  249. swiperChange (item) {
  250. console.log(item.detail)
  251. this.latitude = this.nearParkingList[item.detail.current].latitude
  252. this.longitude = this.nearParkingList[item.detail.current].longitude
  253. },
  254. /**
  255. * 点击单个停车场看详情
  256. * item 为选中项参数
  257. * */
  258. clickSearchParking (item) {
  259. this.parkingDetailData = item
  260. this.isShowParkingDetail = true
  261. this.isShowSearchParking = false
  262. this.latitude = item.latitude
  263. this.longitude = item.longitude
  264. }
  265. }
  266. }
  267. </script>
  268. <style lang="scss" scoped>
  269. .wrap{margin-top: 20vh;}
  270. @import url("./parkingLists.scss");
  271. </style>