charging.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <ax-body blank="0" hideIndicatorArea>
  3. <image src="@/static/img/page-bg01.png" class="page-background"></image>
  4. <view class="body">
  5. <view v-if="exiting.visible" class="exiting">
  6. <view class="app-flex c-center column contet">
  7. <view class="exiting-title">长按停止按钮结束充电</view>
  8. <view class="countdown-ring" :class="{ active: exiting.lock }" @touchstart="exiting.lock = true"
  9. @touchend="exiting.lock = false">
  10. <view class="_half left" @animationend="submitExit()"></view>
  11. <view class="_half right"></view>
  12. <view class="_button">
  13. <view>停止</view>
  14. <view>充电</view>
  15. </view>
  16. </view>
  17. <view class="close" @click="exiting.visible = false">取消</view>
  18. </view>
  19. <view @click="exiting.visible = false" class="mask"></view>
  20. </view>
  21. <view v-if="deviceInfo.orderStatus == 1" class="timer">
  22. <view class="value" style="font-size: 22px;">充电正在启动中......</view>
  23. <view v-if="isShowBtn" class="name" style="color: red;font-size: 14px;">长时间无法启动可点击“长按结束充电”按钮结束订单。</view>
  24. </view>
  25. <!-- 主图 -->
  26. <view class="app-flex c-center host-graph">
  27. <image
  28. src="https://national-motion.oss-cn-beijing.aliyuncs.com/20251230/9ca38a2aa5784e06b9cac31587b188b3.png"
  29. mode="widthFix" class="image"></image>
  30. </view>
  31. <!-- 主参数 -->
  32. <view class="parameter-info-box">
  33. <!-- 充电动画 -->
  34. <view class="charge-loading-box" v-if="deviceInfo.orderStatus == 2">
  35. <view class="charge-loading">
  36. <image class="charge-icon" src="../../static/img/charge_loading.svg" mode=""></image>
  37. <view class="c-loading"></view>
  38. </view>
  39. </view>
  40. <!-- 计时器 -->
  41. <view class="timer" v-if="deviceInfo.orderStatus == 2">
  42. <view class="value">{{ timer.text }}</view>
  43. <view class="name">充电时间</view>
  44. </view>
  45. <view class="parameter">
  46. <view class="param">
  47. <view class="name">电流A</view>
  48. <view class="value">{{ deviceInfo.current || '0' }}</view>
  49. </view>
  50. <view class="split"></view>
  51. <view class="param">
  52. <view class="name">电压V</view>
  53. <view class="value">{{ deviceInfo.voltage || '0' }}</view>
  54. </view>
  55. <view class="split"></view>
  56. <view class="param">
  57. <view class="name">功率KW</view>
  58. <view class="value">{{ deviceInfo.power || '0' }}</view>
  59. </view>
  60. <view class="split"></view>
  61. <view class="param">
  62. <view class="name">电量/度</view>
  63. <view class="value">{{ deviceInfo.totalPower || '0' }}</view>
  64. </view>
  65. <view class="split"></view>
  66. <view class="param">
  67. <view class="name">费用/元</view>
  68. <view class="value">{{ deviceInfo.totalMoney || '0' }}</view>
  69. </view>
  70. </view>
  71. <view class="end-charge-box">
  72. <button @click="exiting.visible = true" :disabled="!isShowBtn" class="end-charge">结束充电</button>
  73. </view>
  74. </view>
  75. <!-- 信息 -->
  76. <view id="info" class="info">
  77. <view>
  78. <view class="cell">
  79. <view class="lable">订单编号</view>
  80. <view class="contet">{{ deviceInfo.chargeOrderNo }}</view>
  81. </view>
  82. <view class="cell">
  83. <view class="lable">终端编号</view>
  84. <view class="contet">{{ deviceInfo.connectorCode }}</view>
  85. </view>
  86. <view class="cell">
  87. <view class="lable">充电电站</view>
  88. <view class="contet">{{ deviceInfo.stationName }}</view>
  89. </view>
  90. <view class="cell">
  91. <view class="lable">充电终端</view>
  92. <view class="contet">{{ deviceInfo.connectorName }}</view>
  93. </view>
  94. </view>
  95. <view class="tips">账单信息可能会有所延迟,具体以实际结算为准</view>
  96. <!-- <view>
  97. <button @click="exiting.visible=true" :disabled="!isShowBtn" class="end">结束充电</button>
  98. <ax-ios-indicator min="10"></ax-ios-indicator>
  99. </view> -->
  100. </view>
  101. </view>
  102. </ax-body>
  103. </template>
  104. <script>
  105. export default {
  106. onLoad(opts) {
  107. console.log("启动充值页面的参数:", opts)
  108. this.orderInfo.id = opts.orderId;
  109. this.deviceInfo.id = opts.deviceId;
  110. },
  111. onShow() {
  112. this.getDeviceInfo();
  113. // this.getOrderInfo();
  114. },
  115. data() {
  116. return {
  117. exiting: {
  118. visible: false,
  119. lock: false
  120. },
  121. timer: {
  122. id: 0,
  123. start: '2024/08/07 09:00:00',
  124. text: '00:00:00',
  125. isSatrt: false,
  126. },
  127. pollingTimer: null, //轮询定时器ID
  128. deviceInfo: {}, //充电桩的信息
  129. orderInfo: {
  130. id: 1
  131. }, //订单信息
  132. isShowBtn: true, //是否显示长按结束按钮
  133. }
  134. },
  135. destroyed() {
  136. console.log("关闭页面了。。。。。。")
  137. //关闭页面了,要清除定时器
  138. this.stopPolling();
  139. clearInterval(this.timer.id);
  140. },
  141. methods: {
  142. //获取设备的详情信息(含轮询)
  143. getDeviceInfo(showLoading = true) {
  144. this.$api.base("get", "/applet/v1/station/charging-cost", {}, {
  145. loading: showLoading
  146. }).then(res => {
  147. this.deviceInfo = res.data;
  148. // 检查订单状态,已完成或已结束则跳转订单详情
  149. if (res.data.orderStatus == 4 || res.data.orderStatus == 5) {
  150. uni.hideLoading();
  151. this.stopPolling();
  152. clearInterval(this.timer.id);
  153. this.$app.url.goto('/subPackages/order/order-detail?chargeOrderNo=' + res.data.chargeOrderNo, false);
  154. return;
  155. }
  156. // 充电中状态,启动计时器
  157. if (res.data.orderStatus == 2 && !this.timer.isSatrt) {
  158. this.startup();
  159. }
  160. // 检查是否显示结束按钮
  161. this.checkShowEndBtn(res.data.startTime);
  162. // 启动轮询
  163. this.startPolling();
  164. })
  165. },
  166. //启动轮询定时器,每5秒查询一次
  167. startPolling() {
  168. if (this.pollingTimer) return; // 已启动则不重复
  169. this.pollingTimer = setInterval(() => {
  170. this.getDeviceInfo(false);
  171. }, 5000);
  172. },
  173. //停止轮询
  174. stopPolling() {
  175. if (this.pollingTimer) {
  176. clearInterval(this.pollingTimer);
  177. this.pollingTimer = null;
  178. }
  179. },
  180. //检查是否显示长按结束按钮
  181. checkShowEndBtn(orderTime) {
  182. if (!orderTime) return;
  183. const t1 = new Date(orderTime.replace(/-/g, '/')).getTime();
  184. const t2 = Date.now();
  185. const diffSeconds = (t2 - t1) / 1000;
  186. // 启动时间大于60秒或状态为充电中,显示结束按钮
  187. if (diffSeconds >= 60 || this.deviceInfo.orderStatus == 2) {
  188. this.isShowBtn = true;
  189. }
  190. },
  191. // 启动定时器
  192. startup() {
  193. // 使用 this.deviceInfo.startTime 替代 this.timer.start
  194. const start = new Date(this.deviceInfo.startTime);
  195. const obj = {
  196. hour: 0,
  197. minute: 0,
  198. second: 0
  199. };
  200. const handle = () => {
  201. this.timer.isSatrt = true;
  202. const diff = Date.now() - start.getTime();
  203. obj.hour = Math.floor(diff / 1000 / 60 / 60);
  204. obj.minute = Math.floor(diff / 1000 / 60 % 60);
  205. obj.second = Math.floor(diff / 1000 % 60);
  206. this.timer.text =
  207. `${String(obj.hour).padStart(2, '0')}:${String(obj.minute).padStart(2, '0')}:${String(obj.second).padStart(2, '0')}`;
  208. }
  209. clearInterval(this.timer.id);
  210. this.timer.id = setInterval(handle, 1000);
  211. handle();
  212. },
  213. // 退出充电
  214. exit() {
  215. this.$api.base("post", "/applet/v1/charge/stopCharge", {
  216. "chargeOrderNo": this.deviceInfo.chargeOrderNo
  217. }, {}).then(res => {
  218. this.exiting.lock = false;
  219. this.stopPolling();
  220. // 显示结算中loading
  221. this.$app.popup.loading(true, {
  222. title: "结算中,请稍候",
  223. timeout: 120 * 1000
  224. });
  225. // 2秒后开始轮询查询订单状态
  226. setTimeout(() => {
  227. this.getDeviceInfo(false);
  228. }, 2000);
  229. }).catch(() => {
  230. this.exiting.lock = false;
  231. })
  232. },
  233. // 长按动画结束
  234. submitExit() {
  235. this.exiting.lock = false;
  236. this.exiting.visible = false;
  237. this.exit();
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="less" scoped>
  243. @import url("charging.css");
  244. /* 充电loading动画 */
  245. .charge-loading-box {
  246. text-align: center;
  247. margin-top: 20rpx;
  248. }
  249. .charge-loading {
  250. width: 364rpx;
  251. height: 36rpx;
  252. background: #FFFFFF;
  253. border-radius: 18rpx;
  254. overflow: hidden;
  255. position: relative;
  256. margin: auto;
  257. }
  258. .charge-icon {
  259. width: 28rpx;
  260. height: 28rpx;
  261. z-index: 1000;
  262. position: absolute;
  263. left: 20rpx;
  264. top: 5rpx;
  265. }
  266. .c-loading {
  267. width: 100%;
  268. height: 100%;
  269. background: linear-gradient(66deg,
  270. rgba(139, 243, 251, 0),
  271. #60C8FE,
  272. #53D4FF,
  273. rgba(139, 243, 251, 0.7), );
  274. border-radius: 18rpx;
  275. animation: loading 3s linear infinite;
  276. background-size: 200% 100%;
  277. }
  278. @keyframes loading {
  279. 0% {
  280. background-position: 100% 0;
  281. }
  282. 100% {
  283. background-position: -100% 0;
  284. }
  285. }
  286. </style>