index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view class="jpmain body">
  3. <componentLogin ref="refLogin" @findByOpenId="findByOpenId"></componentLogin>
  4. <view class="Area Area1">
  5. <view class="top">
  6. <view class="name">附近停车场</view>
  7. <view class="value" @click="getUserLocation()">
  8. <img class="img" src="@/assets/img/homepage/riLine-restart-line.png" alt="">
  9. 重新定位
  10. </view>
  11. </view>
  12. <view class="list">
  13. <view class="item" v-for="(item,i) in nearList"
  14. @click="gotoUrl('pages/index/main/parkingDetails?id='+item.id)">
  15. <view class="name">
  16. <img class="img" src="@/assets/img/homepage/stLine-location-l.svg" alt="">
  17. {{item.name}}
  18. </view>
  19. <view class="value">小于50米</view>
  20. </view>
  21. </view>
  22. <u-empty text="列表为空" mode="list" margin-top="80" v-if="!nearList.length">
  23. <view slot="bottom">
  24. <view class="value-slot" @click="getUserLocation()">
  25. <img class="img" src="@/assets/img/homepage/riLine-restart-line.png" alt="">
  26. 重新定位
  27. </view>
  28. </view>
  29. </u-empty>
  30. </view>
  31. <view class="Area Area2" v-if="otherList.length">
  32. <view class="top">
  33. <view class="name">全部停车场</view>
  34. </view>
  35. <view class="list">
  36. <view class="item" v-for="(item,i) in otherList" :key="i"
  37. @click="gotoUrl('pages/index/main/parkingDetails?id='+item.id)">
  38. <view class="name"> <img class="img" src="@/assets/img/homepage/stLine-location-l.svg" alt="">
  39. {{item.name}}
  40. </view>
  41. <view class="value">{{distanceN(item.distance)}}</view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import * as API from '@/apis/pagejs/index.js'
  49. import componentLogin from '@/components/componentLogin.vue';
  50. export default {
  51. components: {
  52. componentLogin,
  53. },
  54. data() {
  55. return {
  56. latitude: 30.337053,
  57. longitude: 112.240222,
  58. allList: [],
  59. point: false, //是否获取了定位
  60. }
  61. },
  62. onLoad() {
  63. this.userInfo = this.jphelp.getPersonInfo()
  64. this.getParkingList()
  65. },
  66. onReady() {
  67. this.$refs.refLogin.findByOpenId()
  68. },
  69. computed: {
  70. otherList() {
  71. var sz = []
  72. for (var i in this.allList) {
  73. var item = this.allList[i]
  74. if (this.point) {
  75. if (item.distance > 1) {
  76. sz.push(item)
  77. }
  78. } else {
  79. sz.push(item)
  80. }
  81. }
  82. return sz
  83. },
  84. nearList() {
  85. var sz = []
  86. for (var i in this.allList) {
  87. var item = this.allList[i]
  88. if (this.point) {
  89. if (item.distance < 1) {
  90. sz.push(item)
  91. }
  92. } else {
  93. }
  94. }
  95. return sz
  96. }
  97. },
  98. methods: {
  99. getParkingList() {
  100. uni.showLoading({
  101. title: "加载中",
  102. mask: true,
  103. })
  104. var obj = {
  105. pageIndex: 1,
  106. pageSize: 20,
  107. radius: 50,
  108. }
  109. if (this.point) {
  110. obj.longitude = this.longitude
  111. obj.latitude = this.latitude
  112. }
  113. API.parkingList(obj).then((res) => {
  114. this.allList = res.data.data
  115. console.log(this.nearList)
  116. uni.hideLoading();
  117. }).catch(error => {
  118. uni.hideLoading();
  119. uni.showToast({
  120. title: error,
  121. icon: "none"
  122. })
  123. })
  124. },
  125. findByOpenId(res) {
  126. },
  127. getUserLocation() {
  128. uni.authorize({
  129. scope: 'scope.userLocation',
  130. success() {
  131. uni.getLocation({
  132. type: 'wgs84',
  133. success: function(res) {
  134. console.log('当前位置的经度:' + res.longitude);
  135. console.log('当前位置的纬度:' + res.latitude);
  136. }
  137. });
  138. }
  139. })
  140. }
  141. }
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. .body {
  146. padding: 32rpx;
  147. }
  148. .value-slot {
  149. color: rgba(22, 119, 255, 1);
  150. font-size: 24rpx;
  151. display: flex;
  152. align-items: center;
  153. .img {
  154. width: 28rpx;
  155. height: 28rpx;
  156. }
  157. }
  158. .Area {
  159. .img {
  160. margin: 0 8rpx;
  161. }
  162. margin-bottom: 32rpx;
  163. .top {
  164. margin-bottom: 8rpx;
  165. display: flex;
  166. justify-content: space-between;
  167. .name {
  168. color: rgba(51, 51, 51, 1);
  169. font-size: 32rpx;
  170. font-weight: bold;
  171. }
  172. .value {
  173. color: rgba(22, 119, 255, 1);
  174. font-size: 24rpx;
  175. display: flex;
  176. align-items: center;
  177. .img {
  178. width: 28rpx;
  179. height: 28rpx;
  180. }
  181. }
  182. }
  183. .list {
  184. .item {
  185. display: flex;
  186. justify-content: space-between;
  187. padding: 16rpx 0;
  188. .name {
  189. color: rgba(51, 51, 51, 1);
  190. font-size: 32rpx;
  191. display: flex;
  192. align-items: center;
  193. .img {
  194. width: 32rpx;
  195. height: 32rpx;
  196. }
  197. }
  198. .value {
  199. color: rgba(119, 119, 119, 1);
  200. font-size: 28rpx;
  201. }
  202. }
  203. }
  204. }
  205. .Area2 {
  206. .list {
  207. .item {
  208. border-bottom: 1px solid rgba(232, 232, 232, 1);
  209. ;
  210. }
  211. }
  212. }
  213. </style>