parkingLists.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <view class="parking">
  3. <view class="loading" v-show="loading"><u-loadmore status="loading" icon-type="flower" :load-text="{ loading: '正在定位中...' }" /></view>
  4. <view class="parking-header">
  5. <u-search placeholder="搜索停车场" v-model="searchContent" :show-action="false" @change="searchInputChange"></u-search>
  6. <u-icon
  7. v-if="!searchContent && isShowSearchParking == false"
  8. class="icon"
  9. name="list"
  10. size="44"
  11. color="#ffffff"
  12. placeholder-color="#B5B5B5"
  13. search-icon-color="#B3B3B3"
  14. @click="listIconClick"
  15. ></u-icon>
  16. <u-icon
  17. v-if="searchContent || isShowSearchParking == true"
  18. class="icon"
  19. name="close"
  20. size="36"
  21. color="#ffffff"
  22. placeholder-color="#B5B5B5"
  23. search-icon-color="#B3B3B3"
  24. @click="clearSearchInput"
  25. ></u-icon>
  26. </view>
  27. <view class="parking-map">
  28. <map
  29. id="pagemap"
  30. style="width: 100%; height: calc(100vh - 240rpx)"
  31. :show-location="true"
  32. :latitude="latitude"
  33. :longitude="longitude"
  34. @markertap="markertap"
  35. :enable-traffic="true"
  36. :enable-zoom="true"
  37. :scale="scale"
  38. :markers="covers"
  39. ></map>
  40. </view>
  41. <view class="address-box" :class="nearParkingObj.type == 'down' ? 'address-down' : 'address-up'" v-if="nearParkingFlag">
  42. <view class="address-box-down-icon" :class="{ 'up-icon': nearParkingObj.type === 'up' }" @click="pullDown"></view>
  43. <scroll-view scroll-y class="address-box-scroll" :style="{ height: `calc(${nearParkingObj.height} - 76rpx)` }">
  44. <view class="address-box-list">
  45. <view class="address-box-list-item" v-for="(item, index) in nearParkingList" :key="index" @click="positionAddress(item)">
  46. <view class="abli-header">
  47. <view class="abli-header-title">{{ item.roadName }}</view>
  48. <view class="abli-header-subtitle">{{ item.areaName }}</view>
  49. <view class="abli-header-surplus">
  50. <view class="abli-header-surplus-left"
  51. >余位<text>{{ item.spaceIdle }}</text></view
  52. >
  53. <view class="abli-header-surplus-right" :class="{ disabled: !item.monthAmount }" @click="createMonth(item)">办理包月</view>
  54. </view>
  55. </view>
  56. <view class="abli-bottom">
  57. <view class="abli-bottom-left">
  58. <view class="abli-bottom-left-navigation" @click="navigation(item.latitude, item.longitude, item.areaName)">导航</view>
  59. <view class="abli-bottom-left-distance">{{ item.distance | kmUnit }}</view>
  60. </view>
  61. <view class="abli-bottom-right" @click="lookParkingRule(item)">包月规则</view>
  62. </view>
  63. </view>
  64. </view>
  65. </scroll-view>
  66. </view>
  67. <view class="parking-address-list" v-if="isShowSearchParking">
  68. <view class="parking-address-list-item" v-for="(item, index) in searchParkingList" :key="index + 's'" @click="clickSearchParking(item)">
  69. <view class="pali-left">
  70. <view>{{ item.roadName }}</view>
  71. <view>{{ item.areaName }}</view>
  72. </view>
  73. <view class="pali-right">
  74. <image src="../../static/img/distance-icon.png" mode="" @click.stop="navigation(item.latitude, item.longitude, item.areaName)"></image>
  75. <view>路线</view>
  76. </view>
  77. </view>
  78. </view>
  79. <u-select v-model="mapSelect" :list="mapSelectList" @confirm="mapSelectConfirm"></u-select>
  80. <map id="map" hidden="true"></map>
  81. <u-toast ref="uToast" />
  82. </view>
  83. </template>
  84. <script>
  85. import { qqMapTransBMap } from '../../utils/mapTrans.js';
  86. export default {
  87. data() {
  88. return {
  89. searchContent: '',
  90. page_map: '',
  91. loading: false,
  92. latitude: 26.64969,
  93. longitude: 106.636453,
  94. scale: 16,
  95. currentPosition: {
  96. latitude: 26.64969,
  97. longitude: 106.636453
  98. },
  99. covers: [],
  100. // 附近列表是否显示
  101. nearParkingFlag: false,
  102. // 轮播选中
  103. swiperCurrent: 0,
  104. // 附近停车列表
  105. nearParkingList: [],
  106. // 是否显示停车场列表
  107. isShowSearchParking: false,
  108. // 搜索停车场列表
  109. searchParkingList: [],
  110. // 显示单个停车场数据
  111. isShowParkingDetail: false,
  112. // 单个停车场数据
  113. parkingDetailData: {},
  114. mapSelect: false,
  115. mapSelectList: [
  116. {
  117. value: '1',
  118. label: '腾讯地图'
  119. },
  120. {
  121. value: '2',
  122. label: '百度地图'
  123. },
  124. {
  125. value: '3',
  126. label: '高德地图'
  127. }
  128. ],
  129. // 选中位置经纬度
  130. currentPositionHover: {},
  131. nearParkingObj: {
  132. height: '70vh',
  133. type: 'down'
  134. }
  135. };
  136. },
  137. onLoad(page) {
  138. this.getLocation();
  139. if (page.keyword) {
  140. this.searchContent = page.keyword;
  141. this.searchInputChange(page.keyword);
  142. }
  143. },
  144. methods: {
  145. /**
  146. * 查询输入框发生变化
  147. * @date 2021-08-10
  148. * @param {String} value
  149. */
  150. searchInputChange(value) {
  151. // 为空时关闭搜索列表
  152. if (value === '') {
  153. this.isShowSearchParking = false;
  154. }
  155. this.isShowParkingDetail = false;
  156. this.getNearRoadsl();
  157. },
  158. /**
  159. * 获取定位
  160. * @date 2021-08-10
  161. * @returns {any}
  162. */
  163. getLocation() {
  164. const that = this;
  165. console.log('请求定位');
  166. // that.getNearRoadsl();
  167. that.loading = true;
  168. if (navigator.geolocation) {
  169. // 判断是否有这个对象
  170. navigator.geolocation.getCurrentPosition(function (pos) {
  171. console.log('经度:' + pos.coords.longitude + '纬度:' + pos.coords.latitude);
  172. that.latitude = pos.coords.latitude;
  173. that.longitude = pos.coords.longitude;
  174. that.currentPosition.latitude = pos.coords.latitude;
  175. that.currentPosition.longitude = pos.coords.longitude;
  176. that.loading = false;
  177. that.getNearRoadsl();
  178. });
  179. } else {
  180. this.$refs.uToast.show({
  181. title: '当前系统不支持GPS API',
  182. type: 'error'
  183. });
  184. }
  185. },
  186. /**
  187. * 导航
  188. * @date 2021-08-10
  189. * @param {Number} latitude
  190. * @param {Number} longitude
  191. * @returns {any}
  192. */
  193. navigation(latitude, longitude, areaName) {
  194. this.currentPositionHover = {
  195. latitude,
  196. longitude,
  197. areaName
  198. };
  199. this.mapSelect = true;
  200. },
  201. // 多地图选择
  202. mapSelectConfirm(item) {
  203. const name = item[0].label;
  204. switch (name) {
  205. case '腾讯地图':
  206. // uni.navigateTo({
  207. // url:
  208. // '/pages/parkingLists/map_web_view/map_web_view?url=https://3gimg.qq.com/lightmap/v1/marker/?marker=coord:' +
  209. // this.currentPositionHover.latitude +
  210. // ',' +
  211. // this.currentPositionHover.longitude +
  212. // '&referer=myApp&key=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL'
  213. // });
  214. location.href = `https://apis.map.qq.com/uri/v1/routeplan?type=drive&from=我的位置&fromcoord=${this.latitude},${this.longitude}&to=${this.currentPositionHover.areaName}&tocoord=${this.currentPositionHover.latitude},${this.currentPositionHover.longitude}&policy=1&referer=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL`;
  215. break;
  216. case '百度地图':
  217. location.href = `http://api.map.baidu.com/marker?location=
  218. ${this.currentPositionHover.latitude},${this.currentPositionHover.longitude}&title=目的地&content=${this.currentPositionHover.areaName}
  219. &output=html&src=webapp.baidu.openAPIdemo`;
  220. break;
  221. case '高德地图':
  222. // const gdurl = `https://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`;
  223. // window.location.href = gdurl;
  224. location.href = `https://uri.amap.com/navigation?from=${this.longitude},${this.latitude},我的位置&to=${this.currentPositionHover.longitude},${this.currentPositionHover.latitude},${this.currentPositionHover.areaName}&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0`;
  225. break;
  226. }
  227. },
  228. /**
  229. * 清空搜索框内容
  230. * @date 2021-08-10
  231. * @returns {any}
  232. */
  233. clearSearchInput() {
  234. this.searchContent = '';
  235. this.isShowSearchParking = false;
  236. this.getNearRoadsl();
  237. },
  238. /**
  239. * 默认首个点放大 如果有传入经纬度则对应的点放大
  240. * @date 2021-08-10
  241. * @param {Number} lon
  242. * @param {Number} lat
  243. * @returns {any}
  244. */
  245. getNearRoadsl(lon, lat) {
  246. this.$u.api
  247. .nearRoadsl({
  248. latitude: this.currentPosition.latitude,
  249. longitude: this.currentPosition.longitude,
  250. roadName: this.searchContent
  251. })
  252. .then((res) => {
  253. const nearParkingList = []; // 附近停车场列表
  254. this.covers = [];
  255. res.data.forEach((item, index, arr) => {
  256. if (item.latitude && item.longitude) {
  257. nearParkingList.push(item);
  258. const marker = {
  259. latitude: item.latitude,
  260. longitude: item.longitude,
  261. id: String(index),
  262. iconPath: require('./../../static/img/parking-icon.png'),
  263. width: 20,
  264. height: 25
  265. };
  266. // 选中经纬度图标变大
  267. if (lon && lat) {
  268. if (lon === item.longitude && lat === item.latitude) {
  269. marker.width = 40;
  270. marker.height = 50;
  271. }
  272. } else {
  273. if (this.covers.length > 0) {
  274. this.covers[0].width = 40;
  275. this.covers[0].height = 50;
  276. }
  277. }
  278. this.covers.push(marker);
  279. }
  280. });
  281. this.nearParkingList = nearParkingList;
  282. if (nearParkingList.length > 0) {
  283. this.latitude = nearParkingList[0]?.latitude || this.currentPosition.latitude;
  284. this.longitude = nearParkingList[0]?.longitude || this.currentPosition.longitude;
  285. } else {
  286. this.$refs.uToast.show({
  287. title: '没有相关停车场信息',
  288. type: 'warning'
  289. });
  290. }
  291. this.nearParkingFlag = true;
  292. if (this.searchContent) {
  293. this.searchParkingList = nearParkingList;
  294. this.isShowSearchParking = true;
  295. this.nearParkingFlag = false;
  296. }
  297. })
  298. .catch((err) => {
  299. this.$refs.uToast.show({
  300. title: err.msg,
  301. type: 'error'
  302. });
  303. });
  304. },
  305. /**
  306. * 点击地图上的标记点触发
  307. **/
  308. markertap(e) {
  309. let lon, lat;
  310. this.covers.forEach((item, index) => {
  311. if (e.detail.markerId === item.id) {
  312. lon = item.longitude;
  313. lat = item.latitude;
  314. this.swiperCurrent = index;
  315. }
  316. });
  317. this.getNearRoadsl(lon, lat);
  318. },
  319. /**
  320. * 地址发生变化
  321. * @date 2021-08-10
  322. * @param {Object} item
  323. * @returns {any}
  324. */
  325. swiperChange(item) {
  326. const map = uni.createMapContext('pagemap');
  327. map.moveToLocation({
  328. longitude: this.nearParkingList[item.detail.current].longitude,
  329. latitude: this.nearParkingList[item.detail.current].latitude
  330. });
  331. this.getNearRoadsl(this.nearParkingList[item.detail.current].longitude, this.nearParkingList[item.detail.current].latitude);
  332. },
  333. /**
  334. * 点击单个地址
  335. * @date 2022-08-31
  336. * @param {any} item
  337. * @returns {any}
  338. */
  339. positionAddress(item) {
  340. const map = uni.createMapContext('pagemap');
  341. map.moveToLocation({
  342. longitude: item.longitude,
  343. latitude: item.latitude
  344. });
  345. this.getNearRoadsl(item.longitude, item.latitude);
  346. },
  347. /**
  348. * 点击单个停车场看详情
  349. * @date 2021-08-10
  350. * @param {Object} item 为选中项参数
  351. * @returns {any}
  352. */
  353. clickSearchParking(item) {
  354. if (item.monthAmount) {
  355. this.$u.route({
  356. url: 'pages/parkingInformation/parkingInformation',
  357. params: {
  358. roadInfo: JSON.stringify(item),
  359. longitude: this.longitude,
  360. latitude: this.latitude
  361. }
  362. });
  363. }
  364. },
  365. /**
  366. * 跳转停车标准页面
  367. * @date 2021-08-10
  368. * @param {Object} item
  369. * @returns {any}
  370. */
  371. lookParkingRule(item) {
  372. this.$u.route({
  373. url: 'pages/chargeStandard/chargeStandard',
  374. params: {
  375. roadNo: item.roadNo
  376. }
  377. });
  378. },
  379. /**
  380. * 搜索右侧按钮点击
  381. **/
  382. listIconClick() {
  383. this.isShowSearchParking = true;
  384. this.nearParkingFlag = false;
  385. this.searchParkingList = this.nearParkingList;
  386. },
  387. /**
  388. * 跳转包月
  389. * @date 2021-08-10
  390. * @param {Object} item
  391. * @returns {any}
  392. */
  393. createMonth(item) {
  394. if (item.monthAmount) {
  395. this.$u.route({
  396. url: 'pages/handleMonthly/handleMonthly',
  397. params: {
  398. roadNo: item.roadNo
  399. }
  400. });
  401. }
  402. },
  403. pullDown() {
  404. if (this.nearParkingObj.height === '25vh') {
  405. this.nearParkingObj.height = '70vh';
  406. this.nearParkingObj.type = 'down';
  407. } else {
  408. this.nearParkingObj.height = '25vh';
  409. this.nearParkingObj.type = 'up';
  410. }
  411. }
  412. }
  413. };
  414. </script>
  415. <style lang="scss" scoped>
  416. .wrap {
  417. margin-top: 20vh;
  418. }
  419. @import './parkingLists.scss';
  420. </style>