index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <view class="main">
  3. <top-box :token="token" :userinfo="userinfo"></top-box>
  4. <view class="main-box">
  5. <view class="carinfo">
  6. <view class="norecord" v-if="noData">{{noData}}</view>
  7. <uni-swiper-dot :info="datalist" :current="current" field="content" mode="default"
  8. :dots-styles="dotsStyles">
  9. <swiper class="swiper-box" @change="change">
  10. <swiper-item v-for="(item ,index) in datalist" :key="index">
  11. <view class="swiper-item">
  12. <view class="plate">
  13. <view>车牌号</view>
  14. <view>
  15. <image src="../../static/icon1.png"></image>
  16. </view>
  17. <view>电池AI云管理监控中</view>
  18. </view>
  19. <view class="plate-number">
  20. <view>{{item.plate || '暂无信息'}}</view>
  21. <view>
  22. <image src="../../static/icon2.png"></image>
  23. </view>
  24. </view>
  25. <view class="battery-soc">
  26. <view>电池SOC</view>
  27. <view>
  28. <view class="strip">
  29. <!-- 第二层进度条的颜色 -->
  30. <view class="blue" :style="'width:'+item.soc+'%'">
  31. <!-- (进度条显示的图片 样式:根据父元素进行相对定位 ,本身绝对定位 ) -->
  32. <text class="protext" :style="'left:'+item.soc+'%'"></text>
  33. <view class="pronumber" :style="'left:'+(item.soc-6)+'%'">
  34. {{item.soc || 0}}%
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="battery-info">
  41. <view>
  42. <view>{{item.drivingMileage || 0}}km</view>
  43. <view>已行驶里程</view>
  44. </view>
  45. <view>
  46. <view>{{item.current || 0}}km</view>
  47. <view>预计剩余里程</view>
  48. </view>
  49. <view>
  50. <view>{{item.voltage || 0}}V</view>
  51. <view>电压</view>
  52. </view>
  53. <view>
  54. <view>{{item.drivingMileage || 0}}A</view>
  55. <view>电流</view>
  56. </view>
  57. </view>
  58. </view>
  59. </swiper-item>
  60. </swiper>
  61. </uni-swiper-dot>
  62. </view>
  63. <view class="change-title">
  64. <view>
  65. <image src="../../static/icon3.png"></image>
  66. </view>
  67. <view>换电站信息</view>
  68. </view>
  69. <view class="change-box" v-for="(item,index) in stationDataVoList" :key="item.stationInfo.id">
  70. <view class="title">{{item.stationInfo.stationName}}</view>
  71. <view class="tags">
  72. <view>常去地点</view>
  73. <view>24小时营业</view>
  74. </view>
  75. <view class="piclist">
  76. <view v-for="(img,index) in item.urlList" :key="index">
  77. <image :src="img"></image>
  78. </view>
  79. </view>
  80. <view class="address">
  81. <view v-if="item.stationInfo.distance">{{item.stationInfo.distance >= 1000 ? (item.stationInfo.distance/1000).toFixed(1)+'km' : item.stationInfo.distance+'m'}} · {{item.stationInfo.address}}</view>
  82. <view v-else>{{item.stationInfo.address}}</view>
  83. <view @click="makePhone(item.stationInfo.phoneNum)">
  84. <image src="../../static/icon4.png"></image>
  85. <view>电话</view>
  86. </view>
  87. <view @click="jumpmaps">
  88. <image src="../../static/icon5.png"></image>
  89. <view>路线</view>
  90. </view>
  91. </view>
  92. <view class="battery-num">
  93. <view>可换电池</view>
  94. <view>{{item.batteryNum}}</view>
  95. </view>
  96. </view>
  97. </view>
  98. <view class="grace-loading" v-if="isLoadAll">{{ loadingTxt }}</view>
  99. <tab-bar></tab-bar>
  100. </view>
  101. </template>
  102. <script>
  103. export default {
  104. data() {
  105. return {
  106. isAuthShow: false,
  107. token: null,
  108. userinfo: null,
  109. latitude: 29.632675, //纬度参数
  110. longitude: 106.569374, //经度参数
  111. datalist: [],
  112. current: 0,
  113. dotsStyles: {
  114. backgroundColor: 'rgba(88, 190, 107,0.6)',
  115. selectedBackgroundColor: 'rgba(88, 190, 107,0.9)',
  116. },
  117. params: {
  118. lat: null,
  119. lng: null,
  120. page: 1,
  121. pageSize: 1,
  122. orderByWays: 'desc'
  123. },
  124. noData: null,
  125. stationDataVoList: [],
  126. isLoadAll: false,
  127. totalPages: 1, // 总页数
  128. loadingTxt: '加载中...',
  129. pageState:0,
  130. }
  131. },
  132. onShow() {
  133. this.$store.dispatch("usersToken").then(() => {
  134. //微信用户第二次登录
  135. this.isAuthShow = false;
  136. this.token = this.$store.getters.getToken;
  137. this.userinfo = this.$store.getters.getUser;
  138. }).catch(() => {
  139. //微信用户首次登录
  140. this.isAuthShow = true;
  141. });
  142. },
  143. beforeMount() {
  144. this.mapSelect()
  145. },
  146. mounted() {
  147. this.getHomePage()
  148. },
  149. onReachBottom() {
  150. this.pageState=1
  151. if (this.totalPages <= this.params.page) {
  152. if(this.$storage.getJson("token")!=null){
  153. this.$utils.msg('没有更多了...')
  154. }
  155. } else {
  156. this.params.page++
  157. this.$utils.msg('数据加载中...')
  158. this.getStationInfo() // 每次滑动请求接口,实现上拉加载更多数据
  159. }
  160. },
  161. methods: {
  162. //拨打电话
  163. makePhone(num) {
  164. uni.makePhoneCall({
  165. phoneNumber: num.toString(), //电话号码
  166. })
  167. },
  168. //获取换电站信息
  169. getStationInfo() {
  170. this.$http.homepage(this.params).then(res => {
  171. console.log(res)
  172. if (res.code === 0) {
  173. if (res.data.stationDataVoList.list.length == 0) {
  174. this.loadingTxt = '暂无数据'
  175. } else {
  176. if(this.pageState === 1){
  177. this.stationDataVoList = [...this.stationDataVoList, ...res.data.stationDataVoList.list]
  178. }else{
  179. this.stationDataVoList = res.data.stationDataVoList.list
  180. }
  181. }
  182. } else {
  183. this.loadingTxt = '暂无数据'
  184. // this.$utils.msg(res.msg)
  185. }
  186. })
  187. },
  188. //获取车辆信息
  189. getHomePage() {
  190. this.$http.homepage(this.params).then(res => {
  191. console.log(res)
  192. if (res.code === 0) {
  193. if (res.data.vehDataVoList.length == 0) {
  194. this.noData = '暂无记录'
  195. } else {
  196. this.datalist = res.data.vehDataVoList
  197. }
  198. if (res.data.stationDataVoList.list.length == 0) {
  199. this.loadingTxt = '暂无数据'
  200. this.isLoadAll = true;
  201. } else {
  202. this.stationDataVoList = res.data.stationDataVoList.list
  203. this.totalPages = res.data.stationDataVoList.total
  204. }
  205. } else {
  206. this.noData = '暂无记录'
  207. this.loadingTxt = '暂无数据'
  208. this.isLoadAll = true;
  209. let token = this.$storage.getJson("token");
  210. if(token == null){
  211. this.$utils.msg('请先登录')
  212. }else{
  213. this.$utils.msg(res.msg)
  214. }
  215. }
  216. })
  217. },
  218. change(e) {
  219. this.current = e.detail.current;
  220. },
  221. //打开地图导航
  222. jumpmaps() {
  223. if (this.params.lat && this.params.lng) {
  224. uni.openLocation({
  225. latitude: this.params.lat,
  226. longitude: this.params.lng,
  227. name: '渝北区风暴之眼电竞酒店(机场路南)',
  228. address: '重庆市重庆市渝北区汇流路1号'
  229. })
  230. } else {
  231. this.$utils.msg("未获取到您的位置信息");
  232. }
  233. },
  234. //获取用户经纬度
  235. mapSelect() {
  236. const that = this
  237. uni.getLocation({
  238. type: 'gcj02',
  239. isHighAccuracy: true,
  240. success: function(res) {
  241. that.params.lat = res.latitude
  242. that.params.lng = res.longitude
  243. console.log(res, 'getLocation')
  244. that.getStationInfo()
  245. },
  246. fail: () => {
  247. },
  248. })
  249. },
  250. //提示用户打开位置信息
  251. getMapLocation() {
  252. uni.getSetting({
  253. success: (res) => {
  254. var status = res.authSetting
  255. if (!status['scope.userLocation']) {
  256. // 如果授权信息中没有地理位置的授权,则需要弹窗提示用户需要授权地理信息
  257. uni.showModal({
  258. title: '是否授权当前位置',
  259. content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
  260. success: (tip) => {
  261. if (tip.confirm) {
  262. // 如果用户同意授权地理信息,则打开授权设置页面,判断用户的操作
  263. uni.openSetting({
  264. success: (data) => {
  265. // 如果用户授权了地理信息在,则提示授权成功
  266. if (data.authSetting[
  267. 'scope.userLocation'] ===
  268. true) {
  269. uni.showToast({
  270. title: '授权成功',
  271. icon: 'success',
  272. duration: 1000,
  273. })
  274. // 授权成功后,然后再次chooseLocation获取信息
  275. this.mapSelect()
  276. } else {
  277. uni.showToast({
  278. title: '授权失败',
  279. icon: 'none',
  280. duration: 1000,
  281. })
  282. }
  283. },
  284. })
  285. }
  286. },
  287. })
  288. }
  289. if (status['scope.userLocation'] === true && this.params.lat === null && this.params.lng === null) {
  290. uni.showToast({
  291. title: '请开启您手机的位置信息!',
  292. icon: 'none',
  293. duration: 5000,
  294. })
  295. }
  296. },
  297. fail: (res) => {
  298. uni.showToast({
  299. title: '调用授权窗口失败',
  300. icon: 'none',
  301. duration: 1000,
  302. })
  303. },
  304. })
  305. },
  306. }
  307. }
  308. </script>
  309. <style lang="scss" scoped>
  310. .main{
  311. height: 100vh;
  312. }
  313. .authorization {
  314. width: 640rpx;
  315. height: 840rpx;
  316. background-color: #fff;
  317. border-radius: 20rpx;
  318. }
  319. .grace-loading{
  320. position: relative;
  321. text-align: center;
  322. margin-top: 200rpx;
  323. color: #979797;
  324. }
  325. .main-box {
  326. padding: 0 30rpx 30rpx 30rpx;
  327. .carinfo {
  328. width: 100%;
  329. height: 350rpx;
  330. }
  331. .norecord {
  332. text-align: center;
  333. color: #86909c;
  334. position: relative;
  335. top: 40%;
  336. }
  337. .swiper-box {
  338. height: 380rpx;
  339. .swiper-item {
  340. width: 690rpx;
  341. height: 350rpx;
  342. padding: 32rpx;
  343. box-sizing: border-box;
  344. background-image: url('https://xcx.xnymzx.com/zkstation/car-bg.png');
  345. background-size: 100% 100%;
  346. display: flex;
  347. flex-direction: column;
  348. justify-content: space-between;
  349. .plate {
  350. display: flex;
  351. justify-content: space-between;
  352. view:first-child {
  353. flex: 1;
  354. }
  355. image {
  356. width: 24rpx;
  357. height: 24rpx;
  358. vertical-align: middle;
  359. }
  360. view:last-child {
  361. width: 280rpx;
  362. text-align: right;
  363. color: #6cc57d;
  364. font-size: 30rpx;
  365. }
  366. }
  367. .plate-number {
  368. display: flex;
  369. image {
  370. width: 26rpx;
  371. height: 26rpx;
  372. vertical-align: middle;
  373. }
  374. view:first-child {
  375. font-weight: 600;
  376. font-size: 32rpx;
  377. padding-right: 15rpx;
  378. }
  379. }
  380. .battery-soc {
  381. display: flex;
  382. view:first-child {
  383. width: 138rpx;
  384. }
  385. view:last-child {
  386. flex: 1;
  387. .strip {
  388. /* 父元素相对定位 */
  389. position: relative;
  390. width: 480rpx;
  391. height: 18rpx;
  392. background-color: #fff;
  393. top: 10rpx;
  394. }
  395. .blue {
  396. height: 18rpx;
  397. background-color: #ff7d00;
  398. font-size: 28rpx;
  399. }
  400. .protext {
  401. width: 2rpx;
  402. height: 32rpx;
  403. background: #86909c;
  404. /* 子元素绝对定位 */
  405. position: absolute;
  406. /* 定位方向:属性值 */
  407. top: -9rpx
  408. }
  409. .pronumber {
  410. font-size: 26rpx;
  411. font-weight: bold;
  412. position: absolute;
  413. /* 定位方向:属性值 */
  414. top: 30rpx;
  415. }
  416. }
  417. }
  418. .battery-info {
  419. display: flex;
  420. justify-content: space-between;
  421. text-align: center;
  422. line-height: 36rpx;
  423. view>view:first-child {
  424. font-weight: bold;
  425. }
  426. view>view:last-child {
  427. color: #939da7;
  428. font-size: 26rpx;
  429. margin-top: 8rpx;
  430. }
  431. }
  432. }
  433. }
  434. .change-title {
  435. width: 100%;
  436. padding: 0 20rpx;
  437. box-sizing: border-box;
  438. display: flex;
  439. margin: 30rpx 0;
  440. image {
  441. width: 9rpx;
  442. height: 39rpx;
  443. }
  444. view:first-child {
  445. padding-right: 12rpx;
  446. }
  447. view:last-child {
  448. font-weight: bold;
  449. font-size: 32rpx;
  450. line-height: 32rpx;
  451. }
  452. }
  453. .change-box:last-child{
  454. margin-bottom: 100rpx !important;
  455. }
  456. .change-box {
  457. width: 690rpx;
  458. box-sizing: border-box;
  459. border-radius: 25rpx;
  460. background-color: #fff;
  461. padding: 20rpx 30rpx;
  462. display: flex;
  463. flex-direction: column;
  464. overflow: hidden;
  465. margin-bottom: 30rpx;
  466. .title {
  467. font-weight: bold;
  468. color: #110d2e;
  469. font-size: 34rpx;
  470. }
  471. .tags {
  472. display: flex;
  473. view {
  474. background: #f5f5f5;
  475. color: #979797;
  476. font-size: 24rpx;
  477. padding: 8rpx 15rpx;
  478. margin: 15rpx 12rpx 15rpx 0rpx;
  479. border-radius: 5rpx;
  480. }
  481. }
  482. .piclist {
  483. display: flex;
  484. justify-content: space-between;
  485. margin: 18rpx 0rpx;
  486. width: 630rpx;
  487. overflow: hidden;
  488. // view{
  489. // margin-right: 15rpx;
  490. // }
  491. image {
  492. width: 298rpx;
  493. height: 189rpx;
  494. box-sizing: border-box;
  495. border-radius: 15rpx;
  496. }
  497. }
  498. .address {
  499. display: flex;
  500. justify-content: space-between;
  501. text-align: center;
  502. color: #86909c;
  503. font-size: 24rpx;
  504. view:first-child {
  505. width: 445rpx;
  506. text-align: left;
  507. font-size: 28rpx;
  508. color: #333333;
  509. line-height: 40rpx;
  510. }
  511. image {
  512. width: 44rpx;
  513. height: 44rpx;
  514. }
  515. }
  516. .battery-num {
  517. color: #86909c;
  518. font-size: 30rpx;
  519. margin-top: 12rpx;
  520. display: flex;
  521. line-height: 36rpx;
  522. view:last-child {
  523. color: #000000;
  524. font-weight: 600;
  525. margin-left: 15rpx;
  526. font-size: 36rpx;
  527. }
  528. }
  529. }
  530. }
  531. </style>