index.vue 6.0 KB

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