index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <template>
  2. <view>
  3. <ujp-navbar title="充电中" :is-back="false">
  4. <view class="slot-wrap">
  5. <view class="navbar-left"></view>
  6. <view class="navbar-right" @click="f5(true)" style=" color: #1d7cff;">
  7. <u-icon name="shuaxin" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>刷新
  8. </view>
  9. </view>
  10. </ujp-navbar>
  11. <view class="chargeInfoNull" v-if="list.length==0">
  12. <img height="80" width="80" src="@/assets/img/ddc.png" alt="">
  13. <p>暂无充电车辆</p>
  14. </view>
  15. <swiper class="swiper" :current="current" @change="changeswiper" style=" height: 700px;"
  16. v-if="list.length!=0">
  17. <swiper-item v-for="(item,i) in list" :key="i">
  18. <view class="chargeInfo">
  19. <view class="chargeInfo-text">
  20. <p>桩名:{{item.deviceName}}</p>
  21. <p>桩号:{{item.deviceNo}}</p>
  22. </view>
  23. <view class="chargeInfo-btn">
  24. 通道:{{item.channelNo}}
  25. </view>
  26. </view>
  27. <view class="chargeImg">
  28. <img v-if="item.status==0" src="@/assets/img/charge-0.png" alt="">
  29. <img v-if="item.status==1" src="@/assets/img/charge-1.png" alt="">
  30. <img v-if="item.status==2" src="@/assets/img/charge-2.png" alt="">
  31. <img v-if="item.status==3" src="@/assets/img/charge-3.png" alt="">
  32. <div class="JPTIME JPTIME1" v-if="item.status==0||item.status==3" v-text="showtime[i]"></div>
  33. </view>
  34. <view class="chargeTime" v-if="item.status==3">
  35. <h1>关闭中...</h1>
  36. </view>
  37. <view class="chargeTime" v-if="item.status==0">
  38. <h1>启动中...</h1>
  39. 请在2分钟内接入电源!
  40. </view>
  41. <view class="chargeTime" v-if="item.status==2">
  42. <h1>充电结束</h1>
  43. {{item.updateTime}}{{item.remark?':'+item.remark:''}}
  44. </view>
  45. <view class="chargeTime" v-if="item.status==1">
  46. <p v-if="item.templateCode==3&&item.estimateFee<=5">预充金额:{{item.estimateFee?item.estimateFee+'元':'充满自停'}}</p>
  47. <p v-if="item.templateCode!=3" >剩余时长<span>({{getPercent(item).time}})</span></p>
  48. <u-line-progress v-if="(item.templateCode==3&&item.estimateFee<=5)||item.templateCode!=3" active-color="#ececec" height="48" :percent="getPercent(item).percent">
  49. <div style="
  50. border-radius: 100px;
  51. min-width: 100px; width: 100%;background-color: rgba(51, 136, 255, 100);height: 8px;">
  52. &nbsp;
  53. <div class="" style="float: right;
  54. padding: 0 8px;
  55. border-radius: 100px;
  56. background-color: rgba(51, 136, 255, 100);
  57. color: rgb(255, 255, 255);
  58. font-size: 12px;
  59. text-align: center;
  60. font-family: -apple-system;
  61. top: -5px;
  62. position: relative;
  63. ">{{getPercent(item).value}}</div>
  64. </div>
  65. </u-line-progress>
  66. </view>
  67. <view class="chargeData">
  68. <view class="chargeData-item">
  69. <u-icon name="jiagebaohu" custom-prefix="custom-icon" color="#1677ff" size="56"></u-icon>
  70. <h2 v-if="item.templateCode==3">{{item.dueFee?(item.dueFee):0}}元</h2>
  71. <h2 v-else >{{item.actualFee?(item.actualFee):0}}元</h2>
  72. <p>消费金额</p>
  73. </view>
  74. <view class="chargeData-item">
  75. <u-icon name="dian" custom-prefix="custom-icon" color="#1677ff" size="56"></u-icon>
  76. <h2>{{item.chargingPower?item.chargingPower:0}}W</h2>
  77. <p>充电功率</p>
  78. </view>
  79. </view>
  80. <view class="chargeBtn">
  81. <view class="chargeBtn-item" v-if="item.status==1||item.status==0" @click="returnMoney(item)">终止并退款
  82. </view>
  83. <view class="chargeBtn-item" v-if="item.status==2" @click="f5(true)">刷新</view>
  84. <view class="chargeBtn-item" v-if="item.templateCode!=3" @click="showTips(item)">费用说明</view>
  85. </view>
  86. <view class="chargeNext">{{i+1}}/{{list.length}}</view>
  87. </swiper-item>
  88. </swiper>
  89. <u-modal v-model="showmodel" title="费用说明">
  90. <p v-for="(item,i) in showitem" class="showmodel" :key="i">{{item.minPower}}W-{{item.maxPower}}W
  91. <span>{{item.price}}元每小时</span></p>
  92. <p style=" padding: 20rpx;" v-if="(showObj.electricityPrice&&showObj.servicePrice)">
  93. 电费单价:{{showObj.electricityPrice}}元/千瓦时;服务费单价:{{showObj.servicePrice}}元/千瓦时 </p>
  94. <p style=" padding: 15px;" v-if="roundingMinute!=null&&roundingMinute!=-1">超过{{roundingMinute}}分钟,按1小时记,不足{{roundingMinute}}分钟,不计费</p>
  95. <p style=" padding: 15px;" v-if="showitem.length==0">无费用说明或为免费充电模式</p>
  96. </u-modal>
  97. <Tabbar :current="0" ref="tabbarMain" :id="id"></Tabbar>
  98. </view>
  99. </template>
  100. <script>
  101. import Tabbar from '@/components/Tabbar.vue'
  102. import * as API from '@/apis/index.js'
  103. import {
  104. secondsDistance,
  105. hourDistanceArr
  106. } from '@/utils'
  107. export default {
  108. data() {
  109. return {
  110. k: 0,
  111. id: "",
  112. current: "0",
  113. showmodel: false,
  114. showObj:{},
  115. showitem: [],
  116. percent: 0,
  117. list: [],
  118. showtime: {},
  119. isReady: false,
  120. isCharge: false,
  121. roundingMinute:-1,
  122. detail: {
  123. },
  124. detailIng: {
  125. },
  126. setTimeoutId: ""
  127. }
  128. },
  129. onLoad(op) {
  130. if (op.k) {
  131. this.k = op.k;
  132. //如果是扫码 ,或者登陆进来的, 并且没有充电,就跳转到充电页面 k= null
  133. //如果是在系统内部访问的, k=1 不跳转;
  134. }
  135. if (op.id) {
  136. this.id = op.id;
  137. this.carhelp.set("qr-default-id",op.id);
  138. }else{
  139. //用于支付后返回系统 -- 点金计划
  140. this.id =this.carhelp.get("qr-default-id");
  141. }
  142. uni.showLoading({
  143. title: "加载中",
  144. mask: true,
  145. })
  146. this.init(op.phone)
  147. setInterval(this.formatDate, 500);
  148. },
  149. beforeDestroy() {
  150. if (this.formatDate) {
  151. clearInterval(this.formatDate); // 在Vue实例销毁前,清除时间定时器
  152. }
  153. },
  154. methods: {
  155. changeswiper(e) {
  156. this.current = e.detail.current;
  157. },
  158. formatDate() {
  159. for (var i in this.list) {
  160. var obj = this.list[i];
  161. var second = 0;
  162. if (obj.status == 0) {
  163. second = secondsDistance(obj.createTime);
  164. }
  165. if (obj.status == 3) {
  166. second = secondsDistance(obj.updateTime);
  167. }
  168. //obj.showtime=this.getShowTime(obj);
  169. var ms = 60 * 2 - second;
  170. if (ms > 0) {
  171. var Hour = parseInt(Math.floor(ms / (60)));
  172. var Fen = parseInt(Math.floor(ms % 60));
  173. this.showtime[i] = (Hour > 9 ? "" : "0") + Hour + ":" + (Fen > 9 ? "" : "0") + Fen
  174. } else {
  175. this.showtime[i] = "00:00";
  176. }
  177. this.$forceUpdate()
  178. }
  179. },
  180. getPercent1(item) {
  181. var obj = {
  182. }
  183. if (item.status == 1) {
  184. var second = secondsDistance(item.startTime);
  185. if (second > 0) {
  186. obj.percent = (second / 60) / item.estimateMinute * 100;
  187. var ms = item.estimateMinute * 60 - second
  188. if (ms > 0) {
  189. var Hour = parseInt(Math.floor(ms / (60 * 60)));
  190. var Fen = parseInt(Math.floor(ms % (60 * 60) / 60));
  191. var miao =ms%60 ;
  192. obj.value = "充电中"
  193. obj.time = (Hour > 9 ? "" : "0") + Hour + ":" + (Fen > 9 ? "" : "0") + Fen+":"+miao
  194. }
  195. }
  196. }
  197. if (item.status == 0) {
  198. obj.value = "启动中"
  199. obj.percent = "50";
  200. }
  201. if (item.status == 2) {
  202. obj.value = "关闭中"
  203. obj.percent = "50";
  204. }
  205. //特殊情况默认值
  206. if (!obj.time) {
  207. obj.time = "00:00:00"
  208. }
  209. if (!obj.percent) {
  210. obj.percent = "100";
  211. }
  212. return obj;
  213. },
  214. getPercent3(item) {
  215. var obj = {
  216. }
  217. if (item.status == 1) {
  218. obj.percent=item.dueFee/item.estimateFee*100
  219. obj.value = "充电中("+parseInt(obj.percent)+'%)'
  220. obj.time = ""
  221. if(obj.percent<25){
  222. obj.percent=25
  223. }
  224. }
  225. if (item.status == 0) {
  226. obj.value = "启动中"
  227. obj.percent = "50";
  228. }
  229. if (item.status == 2) {
  230. obj.value = "关闭中"
  231. obj.percent = "50";
  232. }
  233. if (!obj.percent) {
  234. obj.percent = "100";
  235. }
  236. obj.time = ""
  237. return obj;
  238. },
  239. getPercent(item) {
  240. if(!item){
  241. return {}
  242. }
  243. if(item.templateCode==3){
  244. return this.getPercent3(item)
  245. }else{
  246. return this.getPercent1(item)
  247. }
  248. },
  249. showTips(item) {
  250. this.showmodel = true;
  251. this.roundingMinute=item.roundingMinute;
  252. if(this.roundingMinute==null){
  253. this.roundingMinute=5;
  254. }
  255. this.showitem = item.chargingPriceList;
  256. this.showObj=item
  257. },
  258. returnMoney(item) {
  259. uni.showModal({
  260. title: '停止充电确认',
  261. showCancel: true,
  262. content: '您确定要停止充电吗?停止后将不再充电并退款到余额',
  263. success: res => {
  264. if (res.confirm) {
  265. this.stopCharging(item)
  266. } else if (res.cancel) {
  267. console.log('用户点击取消');
  268. }
  269. }
  270. });
  271. },
  272. stopCharging(item) {
  273. uni.showLoading({
  274. title: "加载中",
  275. mask: true,
  276. })
  277. var data = {
  278. chargingRecordId: item.id,
  279. channelNo: item.channelNo,
  280. deviceNo: item.deviceNo,
  281. };
  282. API.stopCharging(data).then((res) => {
  283. this.f5(true)
  284. }).catch(error => {
  285. uni.showToast({
  286. title: error
  287. })
  288. })
  289. },
  290. init(phone) {
  291. if (!phone) {
  292. phone = ""
  293. }
  294. // uni.showLoading({
  295. // title: "加载中",
  296. // mask: true,
  297. // })
  298. var data = {
  299. phone: phone
  300. };
  301. API.findChargeData(data).then((res) => {
  302. if (res.data.chargingRecordList.length != this.list.length) {
  303. this.current = 0;
  304. }
  305. this.list = res.data.chargingRecordList;
  306. this.isCharge = res.data.isCharge;
  307. this.isReady = true;
  308. if (!this.isCharge && this.k != 1) {
  309. if( this.id){
  310. this.gotoUrl("pages/charge/index?id=" + this.id)
  311. }else{
  312. uni.hideLoading()
  313. }
  314. return
  315. } else {
  316. uni.hideLoading()
  317. }
  318. if (this.list.length > 0) {
  319. //防止定时器重复调用
  320. if (this.setTimeoutId == "") {
  321. for (var i in this.list) {
  322. var item = this.list[i];
  323. if (item.status == 0 || item.status == 3) {
  324. this.setTimeoutId = setTimeout(() => {
  325. this.setTimeoutId = "";
  326. this.f5()
  327. }, 5 * 1000)
  328. } else if (item.status == 1 && item.startTime) {
  329. var second = secondsDistance(item.startTime);
  330. var ms = item.estimateMinute * 60 - second
  331. console.log(ms)
  332. if (ms < 60 * 10) {
  333. }
  334. this.setTimeoutId = setTimeout(() => {
  335. this.setTimeoutId = "";
  336. this.f5()
  337. }, 5 * 1000)
  338. }
  339. }
  340. }
  341. } else {
  342. this.setTimeoutId = ""
  343. }
  344. }).catch(error => {
  345. uni.showToast({
  346. title: error
  347. })
  348. })
  349. },
  350. f5(bl) {
  351. if (bl) {
  352. uni.showLoading({
  353. title: "加载中",
  354. mask: true,
  355. })
  356. }
  357. this.k = 1;
  358. this.init()
  359. },
  360. },
  361. components: {
  362. Tabbar
  363. },
  364. onShow() {
  365. if (this.isReady) {
  366. this.f5(true)
  367. }
  368. if(this.$refs.tabbarMain){
  369. this.$refs.tabbarMain.setcount(0);
  370. }
  371. }
  372. }
  373. </script>
  374. <style lang="scss" scoped>
  375. @import '@/assets/font/jptime.css';
  376. .JPTIME1 {
  377. position: relative;
  378. bottom: 170px;
  379. font-size: 40px;
  380. text-align: center;
  381. color: #eee;
  382. }
  383. .showmodel {
  384. margin-left: 20px;
  385. margin-right: 20px;
  386. span {
  387. float: right;
  388. }
  389. }
  390. .slot-wrap {
  391. display: flex;
  392. align-items: center;
  393. justify-content: space-between;
  394. flex: 1;
  395. }
  396. .chargeNext {
  397. background: rgba(0, 0, 0, 0.5);
  398. color: #fff;
  399. float: right;
  400. padding: 5px 15px;
  401. border-radius: 15px;
  402. font-size: 12px;
  403. margin-bottom: 10px;
  404. margin-right: 10px;
  405. }
  406. .navbar-right {
  407. display: flex;
  408. margin-right: 20rpx;
  409. align-items: center;
  410. }
  411. .chargeInfoNull {
  412. text-align: center;
  413. padding: 100px 0 50px;
  414. p {
  415. color: #999;
  416. font-size: 20px;
  417. margin-top: 10px;
  418. }
  419. }
  420. .chargeInfo {
  421. padding: 10px;
  422. position: relative;
  423. .chargeInfo-text {
  424. p {
  425. color: #777;
  426. margin-bottom: 5px;
  427. }
  428. }
  429. .chargeInfo-btn {
  430. background-color: #E0EDFF;
  431. width: 72px;
  432. height: 32px;
  433. border-radius: 16px 0 0 16px;
  434. line-height: 32px;
  435. text-align: center;
  436. position: absolute;
  437. right: 0;
  438. top: 16px;
  439. color: #1677FF;
  440. }
  441. }
  442. .chargeImg {
  443. height: 300px;
  444. width: 300px;
  445. margin: 10px auto 0;
  446. img {
  447. height: 100%;
  448. width: 100%;
  449. }
  450. }
  451. .chargeTime {
  452. padding: 20px 30px;
  453. text-align: center;
  454. p {
  455. color: #999;
  456. margin-bottom: 10px;
  457. }
  458. }
  459. .chargeBtn {
  460. display: flex;
  461. justify-content: space-around;
  462. padding: 20px 50px;
  463. .chargeBtn-item {
  464. width: 80px;
  465. height: 32px;
  466. background-color: #1677FF;
  467. line-height: 32px;
  468. color: #fff;
  469. text-align: center;
  470. border-radius: 16px;
  471. }
  472. }
  473. .chargeData {
  474. display: flex;
  475. justify-content: space-around;
  476. .chargeData-item {
  477. text-align: center;
  478. h2 {
  479. font-size: 24px;
  480. font-weight: normal;
  481. color: #1677FF;
  482. margin: 10px 0;
  483. }
  484. .chargeData-power {
  485. display: flex;
  486. align-items: center;
  487. display: flex;
  488. width: 120px;
  489. text-align: center;
  490. height: 31px;
  491. margin: 10px 0;
  492. span {
  493. font-size: 14px;
  494. color: #1677FF;
  495. margin: 0 5px;
  496. }
  497. }
  498. p {
  499. color: #999;
  500. }
  501. }
  502. }
  503. </style>