index.vue 7.5 KB

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