searchparking.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view>
  3. <u-navbar
  4. title="我的停车"
  5. title-color="#fff"
  6. :custom-back="customBack"
  7. :border-bottom="false"
  8. back-icon-color="#CCE8FF"
  9. :background="{ background: 'linear-gradient(145deg, #41AFF9 0%, #2D8CFB 100%)' }"
  10. >
  11. </u-navbar>
  12. <view class="tab-fixed">
  13. <u-tabs-swiper
  14. activeColor="#008CFF"
  15. ref="tabs"
  16. :list="tabList"
  17. :current="tabCurrent"
  18. @change="tabChange"
  19. :is-scroll="false"
  20. swiperWidth="100%"
  21. ></u-tabs-swiper>
  22. </view>
  23. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" height="calc(100vh - 84px)" top="50rpx">
  24. <view class="parkinglist">
  25. <view class="parkinglist-item" v-for="(item, index) in parkinglist" :key="index" @click="navigation(item.latitude, item.longitude)">
  26. <view class="up u-flex u-row-between">
  27. <view class="vehicle-no">{{ item.vehicleNo || '-' }}</view>
  28. <view class="space-name">{{ item.spaceName || '-' }}</view>
  29. </view>
  30. <view class="down u-flex u-row-left">
  31. <u-icon name="map-fill" color="#008CFF" size="28"></u-icon>
  32. <view class="road-name" v-if="tabCurrentItem.value === 'park'">{{ item.parkingName || '-' }}</view>
  33. <view class="road-name" v-else>{{ item.roadName || '-' }}</view>
  34. </view>
  35. </view>
  36. </view>
  37. </mescroll-body>
  38. <u-toast ref="uToast" />
  39. </view>
  40. </template>
  41. <script>
  42. import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
  43. export default {
  44. mixins: [MescrollMixin], // 使用mixin
  45. data() {
  46. return {
  47. parkinglist: [],
  48. tabCurrent: 0,
  49. tabCurrentItem: {},
  50. tabList: [
  51. { name: '路段', value: 'road' },
  52. { name: '停车场', value: 'park' }
  53. ],
  54. // 当前位置信息
  55. currentPosition: {
  56. latitude: '',
  57. longitude: ''
  58. }
  59. };
  60. },
  61. onLoad() {
  62. this.tabCurrentItem = this.tabList[this.tabCurrent];
  63. // this.getLocation();
  64. },
  65. onShow() {},
  66. methods: {
  67. /**
  68. * 获取当前位置信息
  69. * @date 2022-10-09
  70. * @returns {any}
  71. */
  72. getLocation() {
  73. const that = this;
  74. if (navigator.geolocation) {
  75. // 判断是否有这个对象
  76. navigator.geolocation.getCurrentPosition(function (pos) {
  77. console.log('经度:' + pos.coords.longitude + '纬度:' + pos.coords.latitude);
  78. that.currentPosition.latitude = pos.coords.latitude;
  79. that.currentPosition.longitude = pos.coords.longitude;
  80. });
  81. } else {
  82. uni.getLocation({
  83. type: 'gcj02',
  84. success: function (res) {
  85. console.log('当前位置的经度:' + res.longitude);
  86. console.log('当前位置的纬度:' + res.latitude);
  87. that.currentPosition.latitude = res.latitude;
  88. that.currentPosition.longitude = res.longitude;
  89. }
  90. });
  91. }
  92. },
  93. customBack() {
  94. this.$u.route({
  95. type: 'switchTab',
  96. url: 'pages/index/index'
  97. });
  98. },
  99. tabChange(cur) {
  100. this.tabCurrent = cur;
  101. this.tabCurrentItem = this.tabList[cur];
  102. this.mescroll.resetUpScroll();
  103. },
  104. /**
  105. * 导航
  106. * */
  107. navigation(lat, lon) {
  108. uni.openLocation({
  109. latitude: parseFloat(lat),
  110. longitude: parseFloat(lon),
  111. scale: 18
  112. });
  113. },
  114. // 多地图选择
  115. /**
  116. * 描述
  117. * @date 2022-10-09
  118. * @param {any} item
  119. * @returns {any}
  120. */
  121. mapSelectConfirm(item) {
  122. const name = item[0].label;
  123. switch (name) {
  124. case '腾讯地图':
  125. location.href = `https://apis.map.qq.com/uri/v1/routeplan?type=drive&from=我的位置&fromcoord=${this.currentPosition.latitude},${this.currentPosition.longitude}&to=${this.currentPositionHover.areaName}&tocoord=${this.currentPositionHover.latitude},${this.currentPositionHover.longitude}&policy=1&referer=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL`;
  126. break;
  127. case '百度地图':
  128. location.href = `http://api.map.baidu.com/marker?location=
  129. ${this.currentPositionHover.latitude},${this.currentPositionHover.longitude}&title=目的地&content=${this.currentPositionHover.areaName}
  130. &output=html&src=webapp.baidu.openAPIdemo`;
  131. break;
  132. case '高德地图':
  133. location.href = `https://uri.amap.com/navigation?from=${this.currentPosition.longitude},${this.currentPosition.latitude},我的位置&to=${this.currentPositionHover.longitude},${this.currentPositionHover.latitude},${this.currentPositionHover.areaName}&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0`;
  134. break;
  135. }
  136. },
  137. downCallback() {
  138. this.mescroll.resetUpScroll();
  139. },
  140. upCallback(page) {
  141. if (this.tabCurrentItem.value === 'park') {
  142. this.getParkingLotParkingList(page);
  143. } else {
  144. this.getRoadParkingList(page);
  145. }
  146. },
  147. /**
  148. * 获取路段我的停车
  149. */
  150. getRoadParkingList({ num, size }) {
  151. this.$u.api
  152. .getOrderList({
  153. orderStatus: 1,
  154. pageNum: num,
  155. pageSize: size
  156. })
  157. .then((res) => {
  158. //设置列表数据
  159. let curPageData = res.data.pageInfo.rows;
  160. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  161. let curPageLen = curPageData.length;
  162. let totalPage = res.data.pageInfo.pages;
  163. if (num == 1) this.parkinglist = []; //如果是第一页需手动置空列表
  164. this.parkinglist = this.parkinglist.concat(curPageData); //追加新数据
  165. // 请求成功,隐藏加载状态
  166. //后台接口有返回列表的总页数 totalPage
  167. this.mescroll.endByPage(curPageLen, totalPage);
  168. if (this.parkinglist.length <= 0) {
  169. this.listEmpty = true;
  170. }
  171. })
  172. .catch((err) => {
  173. this.$refs.uToast.show({
  174. title: err.msg,
  175. type: 'error'
  176. });
  177. console.log('vehicleList ', err);
  178. });
  179. },
  180. /**
  181. * 获取停车场我的停车
  182. */
  183. getParkingLotParkingList({ num, size }) {
  184. this.$u.api
  185. .getRoomParkingApi({
  186. orderStatus: 1,
  187. pageNum: num,
  188. pageSize: size
  189. })
  190. .then((res) => {
  191. //设置列表数据
  192. let curPageData = res.data.pageInfo.rows;
  193. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  194. let curPageLen = curPageData.length;
  195. let totalPage = res.data.pageInfo.pages;
  196. if (num == 1) this.parkinglist = []; //如果是第一页需手动置空列表
  197. this.parkinglist = this.parkinglist.concat(curPageData); //追加新数据
  198. // 请求成功,隐藏加载状态
  199. //后台接口有返回列表的总页数 totalPage
  200. this.mescroll.endByPage(curPageLen, totalPage);
  201. if (this.parkinglist.length <= 0) {
  202. this.listEmpty = true;
  203. }
  204. })
  205. .catch((err) => {
  206. this.$refs.uToast.show({
  207. title: err.msg,
  208. type: 'error'
  209. });
  210. });
  211. }
  212. }
  213. };
  214. </script>
  215. <style lang="scss">
  216. @import './searchparking.scss';
  217. </style>