parkingLists.vue 9.1 KB

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