needcode před 2 roky
rodič
revize
9581768c9e

+ 6 - 2
src/api/charge.ts

@@ -111,8 +111,12 @@ export function fetchChargeStatus(
       statusCodeHandle: false,
     })
     .then((res) => {
+      if (res) {
+        res.isAppointment = [0].includes(res.chargeStatus)
+        res.isStarted = [1, 2, 3].includes(res.chargeStatus)
+      }
       // 充电状态:0:预约中 1:启动中 2:充电中 3:停止中 4:已结束 5:未知
-      if (checkAppointment && res && [0].includes(res.chargeStatus)) {
+      if (checkAppointment && res && res.isAppointment) {
         uni.hideLoading();
         uni.showModal({
           title: "温馨提示",
@@ -129,7 +133,7 @@ export function fetchChargeStatus(
           },
         });
       }
-      if (checkCharge && res && [1, 2, 3].includes(res.chargeStatus)) {
+      if (checkCharge && res && res.isStarted) {
         uni.hideLoading();
         uni.showModal({
           title: "温馨提示",

+ 34 - 18
src/pages-charge/appointment/appointment.vue

@@ -273,7 +273,7 @@ import { ref } from "vue";
 import ChargeMachine from "../machines/charge-machine/charge-machine.vue";
 import PriceDesc from "../machines/price-desc/price-desc.vue";
 import { format } from "@/utils/date";
-import { to, reLaunch } from "../../utils/navigate";
+import { to } from "../../utils/navigate";
 
 const DAY = 24 * 60 * 60 * 1000;
 const options = ref<any>();
@@ -470,7 +470,7 @@ const changeHour = (index: number) => {
             })
             .then((res) => {
               uni.hideLoading();
-              if (res && [0].includes(res.chargeStatus)) {
+              if (res && res.isAppointment) {
                 uni.showToast({
                   icon: "success",
                   title: "修改成功",
@@ -578,9 +578,21 @@ const startAppointmentCountDown = () => {
   appointmentCountDown.value = formatAppointmentCountDown(
     appointmentData.value.startTime
   );
-  appointmentCountDownTimer = setTimeout(() => {
-    startAppointmentCountDown();
-  }, 1000);
+  if (appointmentCountDown.value) {
+    appointmentCountDownTimer = setTimeout(() => {
+      startAppointmentCountDown();
+    }, 1000);
+  } else {
+    uni.showModal({
+      content: "当前预约时间已到,将开始进行充电",
+      showCancel: false,
+      success() {
+        uni.switchTab({
+          url: "/pages/map/map",
+        });
+      },
+    });
+  }
 };
 
 const formatAppointmentCountDown = (time: string) => {
@@ -588,14 +600,7 @@ const formatAppointmentCountDown = (time: string) => {
   const date = new Date(time.replace(/-/g, "/"));
   let secondTime = parseInt(`${(date.getTime() - now.getTime()) / 1000}`);
   if (secondTime <= 0) {
-    uni.showModal({
-      content: "当前预约时间已到,将开始进行充电",
-      showCancel: false,
-      success() {
-        reLaunch();
-      },
-    });
-    return;
+    return "";
   }
   let hourTime = 0;
   let minuteTime = 0; // 分
@@ -661,7 +666,7 @@ const submit = () => {
       if (chargeType.value === 0) {
         fetchChargeStatus()
           .then((res) => {
-            if (res && [0].includes(res.chargeStatus)) {
+            if (res && res.isAppointment) {
               uni.hideLoading();
               uni.showToast({
                 icon: "success",
@@ -697,9 +702,7 @@ const submitNow = () => {
   });
   startAppointmentCharge(options.value.sn)
     .then(() => {
-      uni.navigateTo({
-        url: `/pages-charge/ordering/ordering?sn=${options.value.sn}&start=1`,
-      });
+      _checkStartCharge();
     })
     .catch((err) => {
       uni.hideLoading();
@@ -710,6 +713,19 @@ const submitNow = () => {
     });
 };
 
+const _checkStartCharge = () => {
+  fetchChargeStatus().then((res) => {
+    if (res && [2].includes(res.chargeStatus)) {
+      uni.hideLoading();
+      uni.navigateTo({
+        url: `/pages-charge/ordering/ordering?sn=${options.value.sn}&start=1`,
+      });
+    } else {
+      _checkStartCharge();
+    }
+  });
+};
+
 onLoad((_options: any) => {
   // sn=SN100523042860091 测试环境
   console.log("options", _options);
@@ -739,7 +755,7 @@ onLoad((_options: any) => {
       return fetchChargeStatus(false, true);
     })
     .then((res) => {
-      if (res && [0].includes(res.chargeStatus)) {
+      if (res && res.isAppointment) {
         appointmentData.value = res;
         startAppointmentCountDown();
       }

+ 5 - 5
src/pages-charge/ordering/ordering.vue

@@ -123,7 +123,7 @@ const startStatusTimer = () => {
         if (status.value.cancel) {
           return;
         }
-        if ([1, 2].includes(res.chargeStatus)) {
+        if (res.isStarted) {
           setChargeData(res);
         }
         startStatusTimer();
@@ -210,7 +210,7 @@ const finish = () => {
   });
   fetchChargeStatus()
     .then((res) => {
-      if ([1, 2].includes(res.chargeStatus)) {
+      if (res.isStarted) {
         // 当前充电中
         const start = new Date(res.startTime.replace(/-/g, "/"));
         const end = new Date();
@@ -343,7 +343,7 @@ const fetchStatus = (data?: any) => {
   const promise = data ? Promise.resolve(data) : fetchChargeStatus();
   promise
     .then((res) => {
-      if ([1, 2].includes(res.chargeStatus)) {
+      if (res.isStarted) {
         // 当前充电中
         status.value.start = true;
         step.value = 2;
@@ -361,11 +361,11 @@ const fetchStatus = (data?: any) => {
 const onImgLoad = () => {
   fetchChargeStatus()
     .then((res) => {
-      if (res && res.isBooking === 1) {
+      if (res && res.isAppointment) {
         to(`/pages-charge/appointment/appointment?sn=${options.value.sn}`);
         return;
       }
-      if ([1, 2].includes(res.chargeStatus)) {
+      if (res && res.isStarted) {
         if (options.value && options.value.sn === res.connectorId) {
           fetchStatus(res);
           return;

+ 4 - 7
src/pages/map/map.vue

@@ -251,7 +251,7 @@
         mode="widthFix"
       ></image>
       <view class="fs-26 color-fff ml-12">{{
-        charging.isBooking === 0 ? "充电中" : "已预约"
+        charging.chargeStatus === 0 ? "已预约" : "充电中"
       }}</view>
     </view>
   </view>
@@ -592,6 +592,7 @@ onLoad((query: any) => {
 
 onShow(() => {
   if (token.value) {
+    charging.value = undefined;
     setTimeout(() => {
       fetchCharging();
     }, 2000);
@@ -600,11 +601,7 @@ onShow(() => {
 
 const fetchCharging = () => {
   fetchChargeStatus().then((res) => {
-    if (res && [1, 2, 3].includes(res.chargeStatus)) {
-      charging.value = res;
-      return;
-    }
-    if (res && [0].includes(res.chargeStatus)) {
+    if (res && [0, 1, 2, 3].includes(res.chargeStatus)) {
       charging.value = res;
     }
   });
@@ -754,7 +751,7 @@ const touchCardMove = (e: any) => {
 
 const toCharging = () => {
   to(
-    charging.value.isBooking === 1
+    charging.value.chargeStatus === 0
       ? `/pages-charge/appointment/appointment?sn=${charging.value.connectorId}`
       : `/pages-charge/ordering/ordering?sn=${charging.value.connectorId}&start=1`
   );