parkingLists.vue 11 KB

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