parkingLists.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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-select v-model="mapSelect" :list="mapSelectList" @confirm="mapSelectConfirm"></u-select>
  106. <u-toast ref="uToast" />
  107. </view>
  108. </template>
  109. <script>
  110. export default{
  111. data(){
  112. return{
  113. searchContent: '',
  114. page_map:'',
  115. loading: false,
  116. latitude: 26.64969,
  117. longitude: 106.636453,
  118. scale: 16,
  119. currentPosition: {
  120. latitude: 26.64969,
  121. longitude: 106.636453,
  122. },
  123. covers: [],
  124. // 附近列表是否显示
  125. nearParkingFlag: false,
  126. // 轮播选中
  127. swiperCurrent: 0,
  128. // 附近停车列表
  129. nearParkingList: [],
  130. // 是否显示停车场列表
  131. isShowSearchParking: false,
  132. // 搜索停车场列表
  133. searchParkingList: [],
  134. // 显示单个停车场数据
  135. isShowParkingDetail: false,
  136. // 单个停车场数据
  137. parkingDetailData: {},
  138. mapSelect: false,
  139. mapSelectList: [
  140. {
  141. value: '1',
  142. label: '腾讯地图'
  143. },
  144. // {
  145. // value: '2',
  146. // label: '百度地图'
  147. // },
  148. {
  149. value: '3',
  150. label: '高德地图'
  151. }
  152. ],
  153. // 选中位置经纬度
  154. currentPositionHover: {}
  155. }
  156. },
  157. onLoad(page){
  158. console.log(page)
  159. this.getLocation()
  160. if (page.keyword) {
  161. this.searchContent = page.keyword
  162. this.searchInputChange(page.keyword)
  163. }
  164. },
  165. // onShow() {
  166. // this.isShowSearchParking = false
  167. // this.isShowParkingDetail = false
  168. // },
  169. methods:{
  170. /*
  171. * 查询输入框发生变化
  172. *
  173. * */
  174. searchInputChange (value) {
  175. // 为空时关闭搜索列表
  176. if (value === '') {
  177. this.isShowSearchParking = false
  178. }
  179. this.isShowParkingDetail = false
  180. this.getNearRoadsl()
  181. },
  182. getLocation(){
  183. let that = this;
  184. console.log("请求定位")
  185. that.loading = true
  186. uni.getLocation({
  187. type:"gcj02",
  188. success : function (res) {
  189. console.log("定位返回信息:", res);
  190. that.latitude = res.latitude;
  191. that.longitude = res.longitude;
  192. that.currentPosition.latitude = res.latitude
  193. that.currentPosition.longitude = res.longitude
  194. that.loading = false
  195. that.getNearRoadsl()
  196. },
  197. fail: function(res){
  198. this.$refs.uToast.show({
  199. title: res,
  200. type: 'error',
  201. })
  202. }
  203. })
  204. },
  205. /**
  206. * 导航
  207. * */
  208. navigation (latitude, longitude) {
  209. this.currentPositionHover = {
  210. latitude: latitude,
  211. longitude: longitude
  212. }
  213. this.mapSelect = true
  214. // 腾讯地图用webview
  215. // uni.navigateTo({
  216. // url: '/pages/parkingLists/map_web_view/map_web_view?url=https://3gimg.qq.com/lightmap/v1/marker/?marker=coord:'+latitude+','+longitude+'&referer=myApp&key=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL'
  217. // })
  218. },
  219. // 多地图选择
  220. mapSelectConfirm(item) {
  221. const name = item[0].label
  222. console.log(this.currentPosition)
  223. console.log(this.currentPositionHover)
  224. switch(name) {
  225. case '腾讯地图':
  226. uni.navigateTo({
  227. url: '/pages/parkingLists/map_web_view/map_web_view?url=https://3gimg.qq.com/lightmap/v1/marker/?marker=coord:'+this.currentPositionHover.latitude+','+this.currentPositionHover.longitude+'&referer=myApp&key=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL'
  228. })
  229. break;
  230. case '百度地图':
  231. uni.navigateTo({
  232. url: `/pages/parkingLists/map_web_view/map_web_view?url=${encodeURIComponent(`http://api.map.baidu.com/direction?origin=latlng:${this.latitude},${this.longitude}|name:起点&destination=latlng:${this.currentPositionHover.latitude},${this.currentPositionHover.longitude}|name:终点&mode=driving&output=html&src=webapp.baidu.openAPIdemo`)}`
  233. })
  234. break;
  235. case '高德地图':
  236. uni.navigateTo({
  237. url: `/pages/parkingLists/map_web_view/map_web_view?url=${encodeURIComponent(`//uri.amap.com/navigation?from=${this.currentPosition.longitude},${this.currentPosition.latitude},起点&to=${this.currentPositionHover.longitude},${this.currentPositionHover.latitude},终点&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0`)}`
  238. })
  239. break;
  240. }
  241. },
  242. clearSearchInput () {
  243. this.searchContent = '';
  244. this.isShowSearchParking = false;
  245. this.getNearRoadsl()
  246. },
  247. /**
  248. * lon,lat 为当前选中点的经纬度
  249. * 默认首个点放大 如果有传入经纬度则对应的点放大
  250. * */
  251. getNearRoadsl(lon, lat){
  252. // await this.getLocation();
  253. this.$u.api.nearRoadsl({
  254. latitude: this.currentPosition.latitude,
  255. longitude:this.currentPosition.longitude,
  256. roadName: this.searchContent
  257. })
  258. .then(res=>{
  259. const nearParkingList = [] // 附近停车场列表
  260. this.covers = []
  261. res.data.forEach((item, index, arr)=>{
  262. if(item.latitude && item.longitude){
  263. nearParkingList.push(item)
  264. let marker = {
  265. latitude: item.latitude,
  266. longitude: item.longitude,
  267. id: String(index),
  268. iconPath: require('./../../static/img/parking-icon.png'),
  269. width: 20,
  270. height: 25
  271. }
  272. // 选中经纬度图标变大
  273. if (lon && lat) {
  274. if (lon === item.longitude && lat === item.latitude) {
  275. marker.width = 40
  276. marker.height = 50
  277. }
  278. } else {
  279. if (this.covers.length > 0) {
  280. this.covers[0].width = 40
  281. this.covers[0].height = 50
  282. }
  283. }
  284. this.covers.push(marker)
  285. }
  286. })
  287. this.nearParkingList = nearParkingList;
  288. this.latitude = nearParkingList[0]?.latitude||this.currentPosition.latitude;
  289. this.longitude = nearParkingList[0]?.longitude||this.currentPosition.longitude;
  290. this.nearParkingFlag = true
  291. if (this.searchContent) {
  292. this.searchParkingList = nearParkingList
  293. this.isShowSearchParking = true
  294. this.nearParkingFlag = false
  295. }
  296. }).catch(err=>{
  297. this.$refs.uToast.show({
  298. title: err.msg,
  299. type: 'error',
  300. });
  301. });
  302. },
  303. /**
  304. * 点击地图上的标记点触发
  305. * */
  306. markertap(e){
  307. let lon,lat
  308. this.covers.forEach((item, index) => {
  309. if (e.detail.markerId === item.id) {
  310. lon = item.longitude
  311. lat = item.latitude
  312. this.swiperCurrent = index
  313. }
  314. })
  315. this.getNearRoadsl(lon, lat)
  316. },
  317. /*
  318. *地址发生变化
  319. *
  320. * */
  321. swiperChange (item) {
  322. let map = uni.createMapContext('pagemap');
  323. map.moveToLocation({
  324. longitude: this.nearParkingList[item.detail.current].longitude,
  325. latitude: this.nearParkingList[item.detail.current].latitude
  326. })
  327. this.getNearRoadsl(this.nearParkingList[item.detail.current].longitude, this.nearParkingList[item.detail.current].latitude)
  328. },
  329. /**
  330. * 点击单个停车场看详情
  331. * item 为选中项参数
  332. * */
  333. clickSearchParking (item) {
  334. console.log('clickSearchParking',item)
  335. // this.parkingDetailData = item
  336. // this.isShowParkingDetail = true
  337. // this.latitude = item.latitude
  338. // this.longitude = item.longitude
  339. // this.getNearRoadsl(item.longitude, item.latitude)
  340. // setTimeout(() => {
  341. // this.isShowSearchParking = false
  342. // }, 500)
  343. // this.scale = 18
  344. this.$u.route({
  345. url: 'pages/parkingInformation/parkingInformation',
  346. params:{
  347. roadInfo:JSON.stringify(item)
  348. }
  349. })
  350. },
  351. /**
  352. * 跳转停车标准页面
  353. * {roadNo} 路段编码
  354. * */
  355. lookParkingRule (item) {
  356. this.$u.route({
  357. url: 'pages/chargeStandard/chargeStandard',
  358. params: {
  359. roadNo: item.roadNo
  360. }
  361. })
  362. },
  363. /*搜索右侧按钮点击
  364. */
  365. listIconClick(){
  366. this.isShowSearchParking = true;
  367. this.nearParkingFlag = false;
  368. this.searchParkingList = this.nearParkingList;
  369. // this.getNearRoadsl();
  370. },
  371. createMonth(item){
  372. this.$u.route({
  373. url: 'pages/handleMonthly/handleMonthly',
  374. params: {
  375. roadNo:item.roadNo
  376. }
  377. });
  378. }
  379. }
  380. }
  381. </script>
  382. <style lang="scss" scoped>
  383. .wrap{margin-top: 20vh;}
  384. @import url("./parkingLists.scss");
  385. </style>