index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. <template>
  2. <view class="main">
  3. <top-box :userinfo="userinfo" :days="days" keys="1"></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="indexes"
  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-3)+'%'">
  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. <mescroll-body
  70. ref="mescrollRef"
  71. @init="mescrollInit"
  72. @down="downCallback"
  73. @up="upCallback"
  74. :up="upOption"
  75. :height="(screenHeight-200)+'rpx'"
  76. >
  77. <view class="change-box" v-for="(item,index) in stationDataVoList" :key="item.stationInfo.id">
  78. <view class="title">{{item.stationInfo.stationName}}</view>
  79. <view class="tags">
  80. <view>常去地点</view>
  81. <view>24小时营业</view>
  82. </view>
  83. <view class="piclist">
  84. <view v-for="(img,index) in item.urlList" :key="index">
  85. <image :src="img"></image>
  86. </view>
  87. </view>
  88. <view class="address">
  89. <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>
  90. <view v-else>{{item.stationInfo.stationName || ''}}</view>
  91. <view @click="makePhone(item.stationInfo.phoneNum)">
  92. <image src="../../static/icon4.png"></image>
  93. <view>电话</view>
  94. </view>
  95. <view @click="jumpmaps(item.stationInfo.lat,item.stationInfo.lng,item.stationInfo.address,item.stationInfo.name)">
  96. <image src="../../static/icon5.png"></image>
  97. <view>路线</view>
  98. </view>
  99. </view>
  100. <view class="battery-num">
  101. <view>可换电池</view>
  102. <view>{{item.batteryNum}}</view>
  103. </view>
  104. </view>
  105. </mescroll-body>
  106. <view class="grace-loading" @click="resetPosition" v-if="noposition">{{noposition}}</view>
  107. </view>
  108. <tab-bar></tab-bar>
  109. </view>
  110. </template>
  111. <script>
  112. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  113. export default {
  114. mixins: [MescrollMixin],
  115. data() {
  116. return {
  117. token: null,
  118. userinfo: null,
  119. // latitude: 29.632675, //纬度参数
  120. // longitude: 106.569374, //经度参数
  121. datalist: [],
  122. current: 0,
  123. dotsStyles: {
  124. backgroundColor: 'rgba(88, 190, 107,0.6)',
  125. selectedBackgroundColor: 'rgba(88, 190, 107,0.9)',
  126. },
  127. params: {
  128. lat: null,
  129. lng: null,
  130. page: 1,
  131. pageSize: 10,
  132. orderByWays: 'desc'
  133. },
  134. noData: null,
  135. stationDataVoList: [],
  136. isLoadAll: false,
  137. totalPages: 1, // 总页数
  138. upOption:{
  139. page:{
  140. size:1,
  141. num:0,
  142. },
  143. noMoreSize:2,
  144. empty:'暂无相关数据'
  145. },
  146. noposition:null,
  147. days:0,
  148. Authorize:false,
  149. }
  150. },
  151. onShow() {
  152. this.$store.dispatch("usersStatus").then(()=>{
  153. //微信用户第二次登录
  154. this.token=this.$store.state.users.token
  155. this.userinfo=this.$store.state.users
  156. this.getHomeCar()
  157. this.getUserDays()
  158. this.reloadList()
  159. this.noData=null
  160. }).catch(()=>{
  161. //微信用户首次登录
  162. this.noData='请先登录'
  163. });
  164. },
  165. onLoad() {
  166. let systemInfoSync = uni.getSystemInfoSync();
  167. this.screenHeight = systemInfoSync.screenHeight - 300;
  168. },
  169. mounted() {
  170. this.mapSelect()
  171. },
  172. methods: {
  173. //重新获取定位
  174. resetPosition(){
  175. this.mapSelect()
  176. },
  177. //获取加入天数
  178. getUserDays(){
  179. this.$http.getDays().then(res=>{
  180. if(res.code === 0){
  181. this.days=res.data
  182. }else{
  183. this.$utils.msg(res.msg);
  184. }
  185. })
  186. },
  187. //拨打电话
  188. makePhone(num) {
  189. uni.makePhoneCall({
  190. phoneNumber: num.toString(), //电话号码
  191. })
  192. },
  193. reloadList(){
  194. this.canReset && this.mescroll.resetUpScroll()
  195. this.canReset && this.mescroll.scrollTo(0,0)
  196. this.canReset = true
  197. },
  198. //获取换电站信息
  199. upCallback(page) {
  200. if(this.Authorize==true){
  201. this.params.page=page.num
  202. this.params.pageSize=page.size
  203. this.$http.homeStation(this.params).then(res => {
  204. // console.log(res.data)
  205. uni.hideLoading();
  206. if (res.code === 0) {
  207. this.totalPages = res.data.total
  208. if(page.num == 1) this.stationDataVoList = []
  209. this.stationDataVoList=this.stationDataVoList.concat(res.data.list)
  210. this.mescroll.endBySize(res.data.list.length, res.data.total);
  211. } else {
  212. this.mescroll.endErr();
  213. }
  214. })
  215. }else{
  216. this.mescroll.endErr();
  217. }
  218. },
  219. //获取车辆信息
  220. getHomeCar() {
  221. let params={
  222. page: 1,
  223. pageSize: 10,
  224. orderByWays: 'desc'
  225. }
  226. this.$http.homeCar(params).then(res => {
  227. if (res.code === 0) {
  228. if (res.data.length == 0) {
  229. this.noData = '暂无记录'
  230. } else {
  231. this.datalist = res.data
  232. }
  233. } else {
  234. this.$utils.msg(res.msg)
  235. }
  236. })
  237. },
  238. change(e) {
  239. this.current = e.detail.current;
  240. },
  241. //打开地图导航
  242. jumpmaps(lat,lng,address,name) {
  243. if (lat && lng && address && name) {
  244. uni.openLocation({
  245. latitude:lat,
  246. longitude:lng,
  247. name: name,
  248. address: address
  249. })
  250. } else {
  251. this.$utils.msg("位置信息丢失");
  252. }
  253. },
  254. //获取用户经纬度
  255. mapSelect() {
  256. uni.showLoading({
  257. title: '加载中'
  258. });
  259. const that = this
  260. uni.getLocation({
  261. type: 'gcj02',
  262. isHighAccuracy: true,
  263. success: function(res) {
  264. that.params.lat = res.latitude
  265. that.params.lng = res.longitude
  266. that.Authorize=true
  267. that.noposition=null
  268. that.mescroll.resetUpScroll()
  269. console.log(res, 'getLocation')
  270. },
  271. fail: () => {
  272. uni.hideLoading();
  273. this.noposition='定位失败'
  274. that.getMapLocation()
  275. },
  276. })
  277. },
  278. //提示用户打开位置信息
  279. getMapLocation() {
  280. uni.getSetting({
  281. success: (res) => {
  282. var status = res.authSetting
  283. if (!status['scope.userLocation']) {
  284. // 如果授权信息中没有地理位置的授权,则需要弹窗提示用户需要授权地理信息
  285. uni.showModal({
  286. title: '是否授权当前位置',
  287. content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
  288. success: (tip) => {
  289. if (tip.confirm) {
  290. // 如果用户同意授权地理信息,则打开授权设置页面,判断用户的操作
  291. uni.openSetting({
  292. success: (data) => {
  293. // 如果用户授权了地理信息在,则提示授权成功
  294. if (data.authSetting['scope.userLocation'] ===true) {
  295. uni.showToast({
  296. title: '授权成功',
  297. icon: 'success',
  298. duration: 1000,
  299. })
  300. // 授权成功后,然后再次chooseLocation获取信息
  301. this.mapSelect()
  302. } else {
  303. uni.hideLoading();
  304. this.noposition='授权失败'
  305. this.Authorize=false
  306. }
  307. },
  308. })
  309. }else{
  310. uni.hideLoading();
  311. this.noposition='授权失败'
  312. this.Authorize=false
  313. }
  314. },
  315. })
  316. }
  317. if (status['scope.userLocation'] === true && this.params.lat === null && this.params.lng === null) {
  318. uni.showToast({
  319. title: '请开启您手机的位置信息!',
  320. icon: 'none',
  321. duration: 5000,
  322. })
  323. }
  324. },
  325. fail: (res) => {
  326. uni.showToast({
  327. title: '调用授权窗口失败',
  328. icon: 'none',
  329. duration: 1000,
  330. })
  331. },
  332. })
  333. },
  334. }
  335. }
  336. </script>
  337. <style lang="scss" scoped>
  338. .main{
  339. height: 100vh;
  340. }
  341. .authorization {
  342. width: 640rpx;
  343. height: 840rpx;
  344. background-color: #fff;
  345. border-radius: 20rpx;
  346. }
  347. .grace-loading{
  348. position: relative;
  349. text-align: center;
  350. padding-top: 100rpx;
  351. height: 300rpx;
  352. color: #979797;
  353. }
  354. .main-box {
  355. padding: 0 30rpx;
  356. background: linear-gradient(180deg, #FFFFFF 0%, #F8F9FB 100%);
  357. .carinfo {
  358. width: 100%;
  359. height: 350rpx;
  360. }
  361. .norecord {
  362. text-align: center;
  363. color: #86909c;
  364. position: relative;
  365. top: 40%;
  366. }
  367. .swiper-box {
  368. height: 380rpx;
  369. .swiper-item {
  370. width: 690rpx;
  371. height: 350rpx;
  372. padding: 32rpx;
  373. box-sizing: border-box;
  374. background-image: url('https://xcx.xnymzx.com/zkstation/car-bg.png');
  375. background-size: 100% 100%;
  376. display: flex;
  377. flex-direction: column;
  378. justify-content: space-between;
  379. .plate {
  380. display: flex;
  381. justify-content: space-between;
  382. view:first-child {
  383. flex: 1;
  384. }
  385. image {
  386. width: 24rpx;
  387. height: 24rpx;
  388. vertical-align: middle;
  389. }
  390. view:last-child {
  391. width: 280rpx;
  392. text-align: left;
  393. padding-left: 10rpx;
  394. color: #6cc57d;
  395. font-size: 30rpx;
  396. padding-top: 2rpx;
  397. }
  398. }
  399. .plate-number {
  400. display: flex;
  401. image {
  402. width: 26rpx;
  403. height: 26rpx;
  404. vertical-align: middle;
  405. }
  406. view:first-child {
  407. font-weight: 600;
  408. font-size: 36rpx;
  409. padding-right: 15rpx;
  410. }
  411. }
  412. .battery-soc {
  413. display: flex;
  414. margin-bottom: 22rpx;
  415. view:first-child {
  416. width: 105rpx;
  417. font-size: 22rpx;
  418. }
  419. view:last-child {
  420. flex: 1;
  421. .strip {
  422. /* 父元素相对定位 */
  423. position: relative;
  424. width: 525rpx;
  425. height: 18rpx;
  426. background-color: #fff;
  427. top: 10rpx;
  428. }
  429. .blue {
  430. height: 18rpx;
  431. background-color: #ff7d00;
  432. font-size: 28rpx;
  433. }
  434. .protext {
  435. width: 2rpx;
  436. height: 32rpx;
  437. background: #86909c;
  438. /* 子元素绝对定位 */
  439. position: absolute;
  440. /* 定位方向:属性值 */
  441. top: -9rpx
  442. }
  443. .pronumber {
  444. font-size: 26rpx;
  445. font-weight: bold;
  446. position: absolute;
  447. /* 定位方向:属性值 */
  448. top: 30rpx;
  449. }
  450. }
  451. }
  452. .battery-info {
  453. display: flex;
  454. justify-content: space-between;
  455. text-align: center;
  456. line-height: 36rpx;
  457. view>view:first-child {
  458. font-weight: bold;
  459. }
  460. view>view:last-child {
  461. color: #939da7;
  462. font-size: 26rpx;
  463. }
  464. }
  465. }
  466. }
  467. .change-title {
  468. width: 100%;
  469. padding: 0 20rpx;
  470. box-sizing: border-box;
  471. display: flex;
  472. margin: 24rpx 0;
  473. image {
  474. width: 9rpx;
  475. height: 39rpx;
  476. }
  477. view:first-child {
  478. padding-right: 12rpx;
  479. }
  480. view:last-child {
  481. font-weight: bold;
  482. font-size: 32rpx;
  483. line-height: 32rpx;
  484. }
  485. }
  486. .change-box:last-child{
  487. margin-bottom: 140rpx !important;
  488. }
  489. .change-box {
  490. width: 690rpx;
  491. box-sizing: border-box;
  492. border-radius: 25rpx;
  493. box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(226,226,226,0.25);
  494. background-color: #fff;
  495. padding: 20rpx 30rpx;
  496. display: flex;
  497. flex-direction: column;
  498. overflow: hidden;
  499. margin-bottom: 30rpx;
  500. .title {
  501. font-weight: bold;
  502. color: #110d2e;
  503. font-size: 34rpx;
  504. }
  505. .tags {
  506. display: flex;
  507. view {
  508. background: #f5f5f5;
  509. color: #979797;
  510. font-size: 24rpx;
  511. padding: 8rpx 15rpx;
  512. margin: 15rpx 12rpx 15rpx 0rpx;
  513. border-radius: 5rpx;
  514. }
  515. }
  516. .piclist {
  517. display: flex;
  518. justify-content: space-between;
  519. margin: 18rpx 0rpx;
  520. width: 630rpx;
  521. overflow: hidden;
  522. // view{
  523. // margin-right: 15rpx;
  524. // }
  525. image {
  526. width: 298rpx;
  527. height: 189rpx;
  528. box-sizing: border-box;
  529. border-radius: 15rpx;
  530. }
  531. }
  532. .address {
  533. display: flex;
  534. justify-content: space-between;
  535. text-align: center;
  536. color: #86909c;
  537. font-size: 24rpx;
  538. view:first-child {
  539. width: 445rpx;
  540. text-align: left;
  541. font-size: 28rpx;
  542. color: #333333;
  543. line-height: 40rpx;
  544. }
  545. image {
  546. width: 44rpx;
  547. height: 44rpx;
  548. }
  549. }
  550. .battery-num {
  551. color: #86909c;
  552. font-size: 30rpx;
  553. margin-top: 12rpx;
  554. display: flex;
  555. line-height: 36rpx;
  556. view:last-child {
  557. color: #000000;
  558. font-weight: 600;
  559. margin-left: 15rpx;
  560. font-size: 36rpx;
  561. }
  562. }
  563. }
  564. }
  565. </style>