charging.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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="orderInfo.status == 0" 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 src="@/static/img/charging-01.png" mode="widthFix" class="image"></image>
  28. </view>
  29. <!-- 主参数 -->
  30. <view class="parameter-info-box">
  31. <!-- 充电动画 -->
  32. <!-- v-if="orderInfo.status == 1" -->
  33. <view class="charge-loading-box">
  34. <view class="charge-loading">
  35. <image class="charge-icon" src="../../static/img/charge_loading.svg" mode=""></image>
  36. <view class="c-loading"></view>
  37. </view>
  38. </view>
  39. <!-- 计时器 -->
  40. <!-- v-if="orderInfo.status == 1" -->
  41. <view class="timer">
  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">{{ getVolt() || '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">{{ statInfo.electricity || '0' }}</view>
  64. </view>
  65. <view class="split"></view>
  66. <view class="param">
  67. <view class="name">费用/元</view>
  68. <view class="value">{{ statInfo.cost || '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 class="statbar">
  77. <view class="sta">
  78. <view class="value">{{statInfo.electricity}}</view>
  79. <view class="name">电量/度</view>
  80. </view>
  81. <view class="split"></view>
  82. <view class="sta">
  83. <view class="value">{{statInfo.cost}}</view>
  84. <view class="name">费用/元</view>
  85. </view>
  86. </view> -->
  87. <!-- 信息 -->
  88. <view id="info" class="info">
  89. <view>
  90. <view class="cell">
  91. <view class="lable">订单编号</view>
  92. <view class="contet">{{ orderInfo.id }}</view>
  93. </view>
  94. <view class="cell">
  95. <view class="lable">终端编号</view>
  96. <view class="contet">{{ deviceInfo.deviceNo }}</view>
  97. </view>
  98. <view class="cell">
  99. <view class="lable">充电电站</view>
  100. <view class="contet">{{ deviceInfo.thirdPartyStationName }}</view>
  101. </view>
  102. <view class="cell">
  103. <view class="lable">充电终端</view>
  104. <view class="contet">{{ deviceInfo.deviceName }}</view>
  105. </view>
  106. </view>
  107. <view class="tips">账单信息可能会有所延迟,具体以实际结算为准</view>
  108. <!-- <view>
  109. <button @click="exiting.visible=true" :disabled="!isShowBtn" class="end">结束充电</button>
  110. <ax-ios-indicator min="10"></ax-ios-indicator>
  111. </view> -->
  112. </view>
  113. </view>
  114. </ax-body>
  115. </template>
  116. <script>
  117. export default {
  118. onLoad(opts) {
  119. console.log("启动充值页面的参数:", opts)
  120. this.orderInfo.id = opts.orderId;
  121. this.deviceInfo.id = opts.deviceId;
  122. },
  123. onShow() {
  124. this.getDeviceInfo();
  125. this.getOrderInfo();
  126. },
  127. data() {
  128. return {
  129. exiting: {
  130. visible: false,
  131. lock: false
  132. },
  133. timer: {
  134. id: 0,
  135. start: '2024/08/07 09:00:00',
  136. text: '00:00:00',
  137. isSatrt: false,
  138. },
  139. orderTimer: {
  140. id: 0,
  141. isSatrt: false,
  142. timeInterval: 10, //每隔多少秒查询一次订单(单位秒:s)
  143. },
  144. statInfo: {
  145. electricity: 0,
  146. cost: 0
  147. }, //统计信息,电量,费用
  148. nowPriceTime: {}, //当前价格时间段信息
  149. deviceInfo: {}, //充电桩的信息
  150. orderInfo: {
  151. id: 1
  152. }, //订单信息
  153. isShowBtn: true, //是否显示长按结束按钮
  154. }
  155. },
  156. destroyed() {
  157. console.log("关闭页面了。。。。。。")
  158. //关闭页面了,要清除定时器
  159. clearInterval(this.timer.id);
  160. clearInterval(this.orderTimer.id);
  161. },
  162. methods: {
  163. //获取设备的详情信息
  164. getDeviceInfo(deviceId) {
  165. this.$api.base("post", "/chargeApi/getDevicesDetial", {
  166. "deviceId": this.deviceInfo.id
  167. }, {}).then(res => {
  168. this.deviceInfo = res.device;
  169. this.nowPriceTime = res.nowPriceTime;
  170. })
  171. },
  172. //是否显示长按结束按钮
  173. isShowEendBtn(orderTime) {
  174. var t1 = new Date(orderTime).getTime();
  175. var t2 = new Date().getTime();
  176. var t = (t2 - t1) / 1000; //单位秒
  177. if (t >= 60 || this.orderInfo.status == 1) {
  178. //启动时间大于一分钟,可以显示长按结束按钮
  179. this.isShowBtn = true;
  180. }
  181. },
  182. //查询订单详情并进行订单状态的检测
  183. getOrderInfo() {
  184. this.$api.base("post", "/chargeApi/queryIsSuccessStop", {
  185. "id": this.orderInfo.id
  186. }, {
  187. loading: false
  188. }).then(res => {
  189. this.orderInfo = res.obj.orderInfo;
  190. this.timer.start = res.obj.orderInfo.startTime.replaceAll("-", "/");
  191. this.isShowEendBtn(res.obj.orderInfo.startTime.replaceAll("-", "/"));
  192. //充电的度数
  193. if (this.orderInfo.totalCharge != null) {
  194. this.statInfo.electricity = this.orderInfo.totalCharge;
  195. }
  196. //费用
  197. let cost = (this.statInfo.electricity * this.nowPriceTime.price).toFixed(2);
  198. if (!isNaN(cost) && this.orderInfo.thirdPartyElecfee == 0) {
  199. //如果后台,第三方返回的电费是0按照自己的方式进行计算
  200. this.statInfo.cost = cost
  201. }
  202. if (!isNaN(this.orderInfo.realCost) && this.orderInfo.thirdPartyElecfee > 0) {
  203. //如果后台有返回第三方的电费,取后台计算的值
  204. this.statInfo.cost = this.orderInfo.realCost.toFixed(4);
  205. }
  206. if (this.orderInfo.status == 3 || this.orderInfo.status == 5) {
  207. uni.hideLoading();
  208. clearInterval(this.timer.id);
  209. clearInterval(this.orderTimer.id);
  210. this.$app.url.goto('/pages/order-detail/order-detail?orderId=' + this.orderInfo.id, false);
  211. return;
  212. }
  213. if (this.orderInfo.status == 1 && !this.timer.isSatrt) {
  214. //状态为充电中
  215. this.startup();
  216. }
  217. if (!this.orderTimer.isSatrt) {
  218. this.orderTimer.isSatrt = true;
  219. //开启定时器每隔5s查询订单
  220. this.startCheckOrderTimer();
  221. }
  222. })
  223. },
  224. getVolt() {
  225. if (!this.deviceInfo.power) {
  226. return 0;
  227. }
  228. var v = this.deviceInfo.power / this.deviceInfo.current * 1000;
  229. return v;
  230. },
  231. //启动检测订单的定时器,每隔5S
  232. startCheckOrderTimer() {
  233. clearInterval(this.orderTimer.id);
  234. this.orderTimer.id = setInterval(() => {
  235. this.getOrderInfo(this.orderInfo.id)
  236. }, this.orderTimer.timeInterval * 1000);
  237. },
  238. // 启动定时器
  239. startup() {
  240. const start = new Date(this.timer.start);
  241. const obj = {
  242. hour: 0,
  243. minute: 0,
  244. second: 0
  245. };
  246. const handle = () => {
  247. this.timer.isSatrt = true;
  248. const diff = Date.now() - start.getTime();
  249. obj.hour = Math.floor(diff / 1000 / 60 / 60);
  250. obj.minute = Math.floor(diff / 1000 / 60 % 60);
  251. obj.second = Math.floor(diff / 1000 % 60);
  252. this.timer.text =
  253. `${String(obj.hour).padStart(2, '0')}:${String(obj.minute).padStart(2, '0')}:${String(obj.second).padStart(2, '0')}`;
  254. //console.log(diff,Math.floor(diff / 1000 ))
  255. /* //计算在该功率下,
  256. var mill = diff / 1000;//充电时间秒
  257. if(!this.deviceInfo.power){
  258. return;
  259. }
  260. //充电的度数
  261. this.statInfo.electricity = (this.deviceInfo.power/3600 * mill).toFixed(2);
  262. //费用
  263. this.statInfo.cost = (this.statInfo.electricity * this.nowPriceTime.price).toFixed(2); */
  264. }
  265. clearInterval(this.timer.id);
  266. this.timer.id = setInterval(handle, 1000);
  267. handle();
  268. },
  269. // 退出充电
  270. exit() {
  271. /* this.$app.popup.toast("测试环境,请等待自动结束")
  272. return; */
  273. this.$api.base("post", "/applet/v1/charge/stopCharge", {
  274. "chargeOrderId": 1234
  275. }, {}).then(res => {
  276. this.exiting.lock = false;
  277. clearInterval(this.orderTimer.id);
  278. this.orderTimer.isSatrt = false;
  279. this.orderTimer.timeInterval = 2;
  280. this.$app.popup.loading(true, {
  281. title: "结算中,请稍候",
  282. timeout: 120 * 1000
  283. })
  284. setTimeout(() => {
  285. this.getOrderInfo(this.orderInfo.id)
  286. }, 2000)
  287. /* clearInterval(this.timer.id);
  288. clearInterval(this.orderTimer.id);
  289. this.$app.url.goto('/pages/order-detail/order-detail?orderId='+this.orderInfo.id,false); */
  290. })
  291. },
  292. // 长按动画结束
  293. submitExit() {
  294. this.exiting.lock = false;
  295. this.exiting.visible = false;
  296. this.exit();
  297. }
  298. }
  299. }
  300. </script>
  301. <style lang="less" scoped>
  302. @import url("charging.css");
  303. /* 充电loading动画 */
  304. .charge-loading-box {
  305. text-align: center;
  306. margin-top: 20rpx;
  307. }
  308. .charge-loading {
  309. width: 364rpx;
  310. height: 36rpx;
  311. background: #FFFFFF;
  312. border-radius: 18rpx;
  313. overflow: hidden;
  314. position: relative;
  315. margin: auto;
  316. }
  317. .charge-icon {
  318. width: 28rpx;
  319. height: 28rpx;
  320. z-index: 1000;
  321. position: absolute;
  322. left: 20rpx;
  323. top: 5rpx;
  324. }
  325. .c-loading {
  326. width: 100%;
  327. height: 100%;
  328. background: linear-gradient(66deg,
  329. rgba(139, 243, 251, 0),
  330. #60C8FE,
  331. #53D4FF,
  332. rgba(139, 243, 251, 0.7), );
  333. border-radius: 18rpx;
  334. animation: loading 3s linear infinite;
  335. background-size: 200% 100%;
  336. }
  337. @keyframes loading {
  338. 0% {
  339. background-position: 100% 0;
  340. }
  341. 100% {
  342. background-position: -100% 0;
  343. }
  344. }
  345. </style>