parkingLists.vue 9.4 KB

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