Ver Fonte

fix:预约状态问题

needcode há 2 anos atrás
pai
commit
47be629f9e
3 ficheiros alterados com 32 adições e 19 exclusões
  1. 7 7
      src/api/charge.ts
  2. 16 8
      src/pages-charge/appointment/appointment.vue
  3. 9 4
      src/pages/map/map.vue

+ 7 - 7
src/api/charge.ts

@@ -18,6 +18,10 @@ export async function cancelAppointmentCharge() {
   return cHttp.get("/charge/cancelBooking");
 }
 
+export async function startAppointmentCharge(connectorId: string) {
+  return cHttp.get(`/charge/immediatelyCharge/${connectorId}`);
+}
+
 export async function searchQRCode(imgUrl: string) {
   return cHttp.get(`/charge/qrCode?imgUrl=${imgUrl}`);
 }
@@ -107,7 +111,8 @@ export function fetchChargeStatus(
       statusCodeHandle: false,
     })
     .then((res) => {
-      if (checkAppointment && res && res.isBooking === 1) {
+      // 充电状态:0:预约中 1:启动中 2:充电中 3:停止中 4:已结束 5:未知
+      if (checkAppointment && res && [0].includes(res.chargeStatus)) {
         uni.hideLoading();
         uni.showModal({
           title: "温馨提示",
@@ -124,12 +129,7 @@ export function fetchChargeStatus(
           },
         });
       }
-      if (
-        checkCharge &&
-        res &&
-        res.isBooking === 0 &&
-        [1, 2].includes(res.chargeStatus)
-      ) {
+      if (checkCharge && res && [1, 2, 3].includes(res.chargeStatus)) {
         uni.hideLoading();
         uni.showModal({
           title: "温馨提示",

+ 16 - 8
src/pages-charge/appointment/appointment.vue

@@ -263,6 +263,7 @@ import {
   fetchStationByConnectorIdOrShortId,
   fetchStationPriceDesc,
   startCharge,
+  startAppointmentCharge,
   cancelAppointmentCharge,
   changeAppointmentTime,
 } from "@/api/charge";
@@ -272,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 } from "../../utils/navigate";
+import { to, reLaunch } from "../../utils/navigate";
 
 const DAY = 24 * 60 * 60 * 1000;
 const options = ref<any>();
@@ -469,7 +470,7 @@ const changeHour = (index: number) => {
             })
             .then((res) => {
               uni.hideLoading();
-              if (res && res.isBooking === 1) {
+              if (res && [0].includes(res.chargeStatus)) {
                 uni.showToast({
                   icon: "success",
                   title: "修改成功",
@@ -586,6 +587,16 @@ const formatAppointmentCountDown = (time: string) => {
   const now = new Date();
   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;
+  }
   let hourTime = 0;
   let minuteTime = 0; // 分
   if (secondTime >= 60) {
@@ -650,7 +661,7 @@ const submit = () => {
       if (chargeType.value === 0) {
         fetchChargeStatus()
           .then((res) => {
-            if (res && res.isBooking === 1) {
+            if (res && [0].includes(res.chargeStatus)) {
               uni.hideLoading();
               uni.showToast({
                 icon: "success",
@@ -684,10 +695,7 @@ const submitNow = () => {
     title: "提交中",
     mask: true,
   });
-  cancelAppointmentCharge()
-    .then(() => {
-      return startCharge(options.value.sn, "isBooking=false");
-    })
+  startAppointmentCharge(options.value.sn)
     .then(() => {
       uni.navigateTo({
         url: `/pages-charge/ordering/ordering?sn=${options.value.sn}&start=1`,
@@ -731,7 +739,7 @@ onLoad((_options: any) => {
       return fetchChargeStatus(false, true);
     })
     .then((res) => {
-      if (res && res.isBooking === 1) {
+      if (res && [0].includes(res.chargeStatus)) {
         appointmentData.value = res;
         startAppointmentCountDown();
       }

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

@@ -231,7 +231,11 @@
             mode="widthFix"
           />
           <view class="fs-22 mt-14 color-000-5">{{
-            loading ? "加载中" : token ? "暂无充电站信息" : "登录后查看更多电站信息"
+            loading
+              ? "加载中"
+              : token
+              ? "暂无充电站信息"
+              : "登录后查看更多电站信息"
           }}</view>
         </view>
       </block>
@@ -510,7 +514,7 @@ const refresh = () => {
 const handleNavReady = (e: any) => {
   styleData.value.dialog = `padding-top:${e.detail.statusBarHeight - 6}px;`;
   const searchHeight = rpxToPx(88);
-  const filterHeight = 0 // rpxToPx(72);
+  const filterHeight = 0; // rpxToPx(72);
   styleData.value.dialogHeight =
     e.detail.statusBarHeight - 6 + searchHeight + filterHeight;
   styleData.value.dialogPlaceHolderHeight =
@@ -596,10 +600,11 @@ onShow(() => {
 
 const fetchCharging = () => {
   fetchChargeStatus().then((res) => {
-    if (res && [1, 2].includes(res.chargeStatus)) {
+    if (res && [1, 2, 3].includes(res.chargeStatus)) {
       charging.value = res;
+      return;
     }
-    if (res && res.isBooking) {
+    if (res && [0].includes(res.chargeStatus)) {
       charging.value = res;
     }
   });