index.vue 12 KB

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