charging.vue 9.1 KB

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