parkingLists.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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&&isShowSearchParking==false" class="icon" name="list" size="44" color="#ffffff"
  10. placeholder-color="#B5B5B5" search-icon-color="#B3B3B3" @click="listIconClick"></u-icon>
  11. <u-icon v-if="searchContent||isShowSearchParking==true" 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 @click="clickSearchParking(item)">{{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|kmUnit}}</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="createMonth(item)">办理包月</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. },
  146. methods:{
  147. /*
  148. * 查询输入框发生变化
  149. *
  150. * */
  151. searchInputChange (value) {
  152. // 为空时关闭搜索列表
  153. if (value === '') {
  154. this.isShowSearchParking = false
  155. }
  156. this.isShowParkingDetail = false
  157. this.getNearRoadsl()
  158. },
  159. getLocation(){
  160. let that = this;
  161. console.log("请求定位")
  162. that.loading = true
  163. uni.getLocation({
  164. type:"gcj02",
  165. success : function (res) {
  166. console.log("定位返回信息:", res);
  167. that.latitude = res.latitude;
  168. that.longitude = res.longitude;
  169. that.currentPosition.latitude = res.latitude
  170. that.currentPosition.longitude = res.longitude
  171. that.loading = false
  172. that.getNearRoadsl()
  173. },
  174. fail: function(res){
  175. this.$refs.uToast.show({
  176. title: res,
  177. type: 'error',
  178. })
  179. }
  180. })
  181. },
  182. /**
  183. * 导航
  184. * */
  185. navigation (lat, lon) {
  186. // uni.openLocation({
  187. // latitude: parseFloat(lat),
  188. // longitude: parseFloat(lon),
  189. // scale: 18
  190. // })
  191. // 腾讯地图用webview
  192. uni.navigateTo({
  193. url: '/pages/parkingLists/map_web_view/map_web_view?url=https://3gimg.qq.com/lightmap/v1/marker/?marker=coord:'+lat+','+lon+'&referer=myApp&key=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL'
  194. })
  195. },
  196. clearSearchInput () {
  197. this.searchContent = '';
  198. this.isShowSearchParking = false;
  199. this.getNearRoadsl()
  200. },
  201. /**
  202. * lon,lat 为当前选中点的经纬度
  203. * 默认首个点放大 如果有传入经纬度则对应的点放大
  204. * */
  205. getNearRoadsl(lon, lat){
  206. // await this.getLocation();
  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. this.covers = []
  215. res.data.forEach((item, index, arr)=>{
  216. if(item.latitude && item.longitude){
  217. nearParkingList.push(item)
  218. let marker = {
  219. latitude: item.latitude,
  220. longitude: item.longitude,
  221. id: String(index),
  222. iconPath: require('./../../static/img/parking-icon.png'),
  223. width: 20,
  224. height: 25
  225. }
  226. // 选中经纬度图标变大
  227. if (lon && lat) {
  228. if (lon === item.longitude && lat === item.latitude) {
  229. marker.width = 40
  230. marker.height = 50
  231. }
  232. } else {
  233. if (this.covers.length > 0) {
  234. this.covers[0].width = 40
  235. this.covers[0].height = 50
  236. }
  237. }
  238. this.covers.push(marker)
  239. }
  240. })
  241. this.nearParkingList = nearParkingList;
  242. this.latitude = nearParkingList[0]?.latitude||this.currentPosition.latitude;
  243. this.longitude = nearParkingList[0]?.longitude||this.currentPosition.longitude;
  244. this.nearParkingFlag = true
  245. if (this.searchContent) {
  246. this.searchParkingList = nearParkingList
  247. this.isShowSearchParking = true
  248. this.nearParkingFlag = false
  249. }
  250. }).catch(err=>{
  251. this.$refs.uToast.show({
  252. title: err.msg,
  253. type: 'error',
  254. });
  255. });
  256. },
  257. /**
  258. * 点击地图上的标记点触发
  259. * */
  260. markertap(e){
  261. let lon,lat
  262. this.covers.forEach((item, index) => {
  263. if (e.detail.markerId === item.id) {
  264. lon = item.longitude
  265. lat = item.latitude
  266. this.swiperCurrent = index
  267. }
  268. })
  269. this.getNearRoadsl(lon, lat)
  270. },
  271. /*
  272. *地址发生变化
  273. *
  274. * */
  275. swiperChange (item) {
  276. let map = uni.createMapContext('pagemap');
  277. map.moveToLocation({
  278. longitude: this.nearParkingList[item.detail.current].longitude,
  279. latitude: this.nearParkingList[item.detail.current].latitude
  280. })
  281. this.getNearRoadsl(this.nearParkingList[item.detail.current].longitude, this.nearParkingList[item.detail.current].latitude)
  282. },
  283. /**
  284. * 点击单个停车场看详情
  285. * item 为选中项参数
  286. * */
  287. clickSearchParking (item) {
  288. console.log('clickSearchParking',item)
  289. // this.parkingDetailData = item
  290. // this.isShowParkingDetail = true
  291. // this.latitude = item.latitude
  292. // this.longitude = item.longitude
  293. // this.getNearRoadsl(item.longitude, item.latitude)
  294. // setTimeout(() => {
  295. // this.isShowSearchParking = false
  296. // }, 500)
  297. // this.scale = 18
  298. this.$u.route({
  299. url: 'pages/parkingInformation/parkingInformation',
  300. params:{
  301. roadInfo:JSON.stringify(item)
  302. }
  303. })
  304. },
  305. /**
  306. * 跳转停车标准页面
  307. * {roadNo} 路段编码
  308. * */
  309. lookParkingRule (item) {
  310. this.$u.route({
  311. url: 'pages/chargeStandard/chargeStandard',
  312. params: {
  313. roadNo: item.roadNo
  314. }
  315. })
  316. },
  317. /*搜索右侧按钮点击
  318. */
  319. listIconClick(){
  320. this.isShowSearchParking = true;
  321. this.nearParkingFlag = false;
  322. this.searchParkingList = this.nearParkingList;
  323. // this.getNearRoadsl();
  324. },
  325. createMonth(item){
  326. this.$u.route({
  327. url: 'pages/handleMonthly/handleMonthly',
  328. params: {
  329. roadNo:item.roadNo
  330. }
  331. });
  332. }
  333. }
  334. }
  335. </script>
  336. <style lang="scss" scoped>
  337. .wrap{margin-top: 20vh;}
  338. @import url("./parkingLists.scss");
  339. </style>