charging.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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" @touchend="exiting.lock=false">
  9. <view class="_half left" @animationend="submitExit()"></view>
  10. <view class="_half right"></view>
  11. <view class="_button"><view>停止</view><view>充电</view></view>
  12. </view>
  13. <view class="close" @click="exiting.visible=false">取消</view>
  14. </view>
  15. <view @click="exiting.visible=false" class="mask"></view>
  16. </view>
  17. <!-- 计时器 -->
  18. <view v-if="orderInfo.status == 1" class="timer">
  19. <view class="value">{{timer.text}}</view>
  20. <view class="name">充电时间</view>
  21. </view>
  22. <view v-if="orderInfo.status == 0" class="timer">
  23. <view class="value" style="font-size: 22px;">充电正在启动中......</view>
  24. <view v-if="isShowBtn" class="name" style="color: red;font-size: 14px;">长时间无法启动可点击“长按结束充电”按钮结束订单。</view>
  25. </view>
  26. <!-- 主图 -->
  27. <view class="app-flex c-center host-graph">
  28. <image src="@/static/img/charging-01.png" mode="widthFix" class="image"></image>
  29. </view>
  30. <!-- 主参数 -->
  31. <view class="parameter">
  32. <view class="param"><view class="value">{{deviceInfo.current}}</view><view class="name">电流A</view></view>
  33. <view class="param"><view class="value">{{getVolt()}}</view><view class="name">电压V</view></view>
  34. <view class="param"><view class="value">{{deviceInfo.power}}</view><view class="name">功率KW</view></view>
  35. </view>
  36. <!-- 统计兰 -->
  37. <view class="statbar">
  38. <view class="sta"><view class="value">{{statInfo.electricity}}</view><view class="name">电量/度</view></view>
  39. <view class="split"></view>
  40. <view class="sta"><view class="value">{{statInfo.cost}}</view><view class="name">费用/元</view></view>
  41. </view>
  42. <!-- 信息 -->
  43. <view id="info" class="info">
  44. <view>
  45. <view class="cell"><view class="lable">订单编号</view><view class="contet">{{orderInfo.id}}</view></view>
  46. <view class="cell"><view class="lable">终端编号</view><view class="contet">{{deviceInfo.deviceNo}}</view></view>
  47. <view class="cell"><view class="lable">充电电站</view><view class="contet">{{deviceInfo.thirdPartyStationName}}</view></view>
  48. <view class="cell"><view class="lable">充电终端</view><view class="contet">{{deviceInfo.deviceName}}</view></view>
  49. </view>
  50. <view class="tips">账单信息可能会有所延迟,具体以实际结算为准</view>
  51. <view>
  52. <button @click="exiting.visible=true" :disabled="!isShowBtn" class="end">结束充电</button>
  53. <ax-ios-indicator min="10"></ax-ios-indicator>
  54. </view>
  55. </view>
  56. </view>
  57. </ax-body>
  58. </template>
  59. <script>
  60. export default {
  61. onLoad(opts) {
  62. console.log("启动充值页面的参数:", opts)
  63. this.orderInfo.id = opts.orderId;
  64. this.deviceInfo.id = opts.deviceId;
  65. },
  66. onShow() {
  67. this.getDeviceInfo();
  68. this.getOrderInfo();
  69. },
  70. data() {
  71. return {
  72. exiting:{
  73. visible: false,
  74. lock: false
  75. },
  76. timer:{
  77. id: 0,
  78. start: '2024/08/07 09:00:00',
  79. text: '00:00:00',
  80. isSatrt : false,
  81. },
  82. orderTimer:{
  83. id: 0,
  84. isSatrt : false,
  85. timeInterval : 10,//每隔多少秒查询一次订单(单位秒:s)
  86. },
  87. statInfo:{
  88. electricity : 0,
  89. cost : 0
  90. },//统计信息,电量,费用
  91. nowPriceTime : {},//当前价格时间段信息
  92. deviceInfo : {},//充电桩的信息
  93. orderInfo : {id:1},//订单信息
  94. isShowBtn : true,//是否显示长按结束按钮
  95. }
  96. },
  97. destroyed(){
  98. console.log("关闭页面了。。。。。。")
  99. //关闭页面了,要清除定时器
  100. clearInterval(this.timer.id);
  101. clearInterval(this.orderTimer.id);
  102. },
  103. methods: {
  104. //获取设备的详情信息
  105. getDeviceInfo(deviceId){
  106. this.$api.base("post","/chargeApi/getDevicesDetial",{"deviceId":this.deviceInfo.id},{}).then(res=>{
  107. this.deviceInfo = res.device;
  108. this.nowPriceTime = res.nowPriceTime;
  109. })
  110. },
  111. //是否显示长按结束按钮
  112. isShowEendBtn(orderTime){
  113. var t1 = new Date(orderTime).getTime();
  114. var t2 = new Date().getTime();
  115. var t = (t2 - t1)/1000;//单位秒
  116. if(t >= 60||this.orderInfo.status == 1){
  117. //启动时间大于一分钟,可以显示长按结束按钮
  118. this.isShowBtn = true;
  119. }
  120. },
  121. //查询订单详情并进行订单状态的检测
  122. getOrderInfo(){
  123. this.$api.base("post","/chargeApi/queryIsSuccessStop",{"id":this.orderInfo.id},{loading:false}).then(res=>{
  124. this.orderInfo = res.obj.orderInfo;
  125. this.timer.start = res.obj.orderInfo.startTime.replaceAll("-","/");
  126. this.isShowEendBtn(res.obj.orderInfo.startTime.replaceAll("-","/"));
  127. //充电的度数
  128. if(this.orderInfo.totalCharge!=null){
  129. this.statInfo.electricity = this.orderInfo.totalCharge;
  130. }
  131. //费用
  132. let cost = (this.statInfo.electricity * this.nowPriceTime.price).toFixed(2);
  133. if(!isNaN(cost) && this.orderInfo.thirdPartyElecfee == 0){
  134. //如果后台,第三方返回的电费是0按照自己的方式进行计算
  135. this.statInfo.cost = cost
  136. }
  137. if(!isNaN(this.orderInfo.realCost) && this.orderInfo.thirdPartyElecfee > 0){
  138. //如果后台有返回第三方的电费,取后台计算的值
  139. this.statInfo.cost = this.orderInfo.realCost.toFixed(4);
  140. }
  141. if( this.orderInfo.status == 3 || this.orderInfo.status == 5){
  142. uni.hideLoading();
  143. clearInterval(this.timer.id);
  144. clearInterval(this.orderTimer.id);
  145. this.$app.url.goto('/pages/order-detail/order-detail?orderId='+this.orderInfo.id,false);
  146. return ;
  147. }
  148. if(this.orderInfo.status == 1 && !this.timer.isSatrt){
  149. //状态为充电中
  150. this.startup();
  151. }
  152. if(!this.orderTimer.isSatrt){
  153. this.orderTimer.isSatrt = true;
  154. //开启定时器每隔5s查询订单
  155. this.startCheckOrderTimer();
  156. }
  157. })
  158. },
  159. getVolt(){
  160. if(!this.deviceInfo.power){
  161. return 0;
  162. }
  163. var v = this.deviceInfo.power/this.deviceInfo.current * 1000;
  164. return v;
  165. },
  166. //启动检测订单的定时器,每隔5S
  167. startCheckOrderTimer(){
  168. clearInterval(this.orderTimer.id);
  169. this.orderTimer.id = setInterval(()=>{
  170. this.getOrderInfo(this.orderInfo.id)
  171. },this.orderTimer.timeInterval * 1000);
  172. },
  173. // 启动定时器
  174. startup(){
  175. const start = new Date(this.timer.start);
  176. const obj = {hour:0,minute:0,second:0};
  177. const handle = ()=>{
  178. this.timer.isSatrt = true;
  179. const diff = Date.now() - start.getTime();
  180. obj.hour = Math.floor(diff / 1000 / 60 / 60);
  181. obj.minute= Math.floor(diff / 1000 / 60 % 60);
  182. obj.second = Math.floor(diff / 1000 % 60);
  183. this.timer.text = `${String(obj.hour).padStart(2,'0')}:${String(obj.minute).padStart(2,'0')}:${String(obj.second).padStart(2,'0')}`;
  184. //console.log(diff,Math.floor(diff / 1000 ))
  185. /* //计算在该功率下,
  186. var mill = diff / 1000;//充电时间秒
  187. if(!this.deviceInfo.power){
  188. return;
  189. }
  190. //充电的度数
  191. this.statInfo.electricity = (this.deviceInfo.power/3600 * mill).toFixed(2);
  192. //费用
  193. this.statInfo.cost = (this.statInfo.electricity * this.nowPriceTime.price).toFixed(2); */
  194. }
  195. clearInterval(this.timer.id);
  196. this.timer.id = setInterval(handle,1000);
  197. handle();
  198. },
  199. // 退出充电
  200. exit(){
  201. /* this.$app.popup.toast("测试环境,请等待自动结束")
  202. return; */
  203. var _this = this;
  204. this.$api.base("post","/chargeApi/stopCharge",{"id":this.orderInfo.id},{}).then(res=>{
  205. this.exiting.lock = false;
  206. clearInterval(this.orderTimer.id);
  207. this.orderTimer.isSatrt = false;
  208. this.orderTimer.timeInterval = 2;
  209. this.$app.popup.loading(true,{title:"结算中,请稍候",timeout:120*1000})
  210. setTimeout(()=>{
  211. this.getOrderInfo(this.orderInfo.id)
  212. },2000)
  213. /* clearInterval(this.timer.id);
  214. clearInterval(this.orderTimer.id);
  215. this.$app.url.goto('/pages/order-detail/order-detail?orderId='+this.orderInfo.id,false); */
  216. })
  217. },
  218. // 长按动画结束
  219. submitExit(){
  220. this.exiting.lock = false;
  221. this.exiting.visible = false;
  222. this.exit();
  223. }
  224. }
  225. }
  226. </script>
  227. <style scoped>
  228. @import url("charging.css");
  229. </style>