charging.vue 9.8 KB

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