index.vue 7.5 KB

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