index.vue 6.8 KB

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