ソースを参照

fix:省电模式

needcode 2 年 前
コミット
31fb8c646e

+ 53 - 42
src/pages-charge/appointment/appointment.vue

@@ -59,7 +59,7 @@
         <view class="mt-40 flex-center">
           <view
             class="flex-center height-68 br-68 fs-26 color-666"
-            style="width: 184rpx; border: 1rpx solid rgba(0, 0, 0, 0.3)"
+            style="width: 184rpx; border: 1px solid rgba(0, 0, 0, 0.3)"
             @click="cancelAppointment"
             >取消预约</view
           >
@@ -164,7 +164,9 @@
     <style-dialog
       v-if="chargeTimeDialog"
       @close="closeTime"
-      title="请选择充电时间"
+      :title="
+        '请选择' + (chargeTime.isPowerSaving ? '省电模式' : '') + '充电时间'
+      "
     >
       <view class="flex" style="border-top: 1rpx solid rgba(0, 0, 0, 0.1)">
         <view
@@ -282,13 +284,10 @@ const changeType = (index: number) => {
   chargeType.value = index;
 };
 
-const isPassTime = (hour: string, time: number) => {
+const isPassTime = (hour: string, day: number) => {
   const now = new Date();
-  const _hour = Number(hour.substring(0, 2));
-  if (typeof _hour !== "number") {
-    return true;
-  }
-  return now.getHours() >= _hour && now.getDate() === Number(format("d", time));
+  const time = new Date(format("y/M/d", day) + " " + hour + ":00");
+  return now > time;
 };
 
 const getHourPrice = (hour: string) => {
@@ -301,30 +300,37 @@ const getHourPrice = (hour: string) => {
   return price;
 };
 
-const rebuildHours = (now: Date) => {
+const rebuildHours = (day: Date) => {
   timesInfo.value.hour = [];
-  let hourTemp = "";
-  let priceTemp = "";
-  for (let index = 0; index < 24; index++) {
-    hourTemp = index >= 10 ? `${index}` : `0${index}`;
-    priceTemp = getHourPrice(hourTemp);
-    timesInfo.value.hour.push({
-      format: `${hourTemp}:00`,
-      formatPrice: priceTemp,
-      disabled: isPassTime(
-        `${hourTemp}:00`,
-        chargeTime.value.time ? chargeTime.value.time : now.getTime()
-      ),
-    });
-    timesInfo.value.hour.push({
-      format: `${hourTemp}:30`,
+  const nowHour = format("h");
+  const isTaday = format("d") === format("d", day.getTime());
+  // 当前时间的24小时内
+  let startHour = isTaday ? Number(nowHour) : 0;
+  let endHour = isTaday ? 24 : Number(nowHour) + 1;
+  if (chargeTime.value.isPowerSaving) {
+    startHour = 0;
+    endHour = 8;
+  }
+  for (let index = startHour; index < endHour; index++) {
+    timesInfo.value.hour = [...timesInfo.value.hour, ...buildHours(index, day)];
+  }
+};
+
+const buildHours = (hour: number, day: Date) => {
+  let res: any[] = [];
+  let hourTemp = hour >= 10 ? `${hour}` : `0${hour}`;
+  let priceTemp = getHourPrice(hourTemp);
+  for (let index = 0; index < 12; index++) {
+    res.push({
+      format: `${hourTemp}:${index * 5 >= 10 ? index * 5 : `0${index * 5}`}`,
       formatPrice: priceTemp,
       disabled: isPassTime(
-        `${hourTemp}:30`,
-        chargeTime.value.time ? chargeTime.value.time : now.getTime()
+        `${hourTemp}:${index * 5 >= 10 ? index * 5 : `0${index * 5}`}`,
+        chargeTime.value.time ? chargeTime.value.time : day.getTime()
       ),
     });
   }
+  return res;
 };
 
 const selectTime = () => {
@@ -354,17 +360,6 @@ const selectTime = () => {
       year: year === nextyear ? "" : nextyear.slice(2),
     },
   ];
-  // 时间
-  // timesInfo.value.hour = priceInfo.value.policyInfos.map((item: any) => {
-  //   return {
-  //     format: item.startTime,
-  //     formatPrice: item.totalPrice,
-  //     disabled: isPassTime(
-  //       item.startTime,
-  //       chargeTime.value.time ? chargeTime.value.time : now.getTime()
-  //     ),
-  //   };
-  // });
   rebuildHours(now);
 
   // 预约时间
@@ -406,7 +401,9 @@ const changeDay = (index: number) => {
   }
   const now = new Date(chargeTime.value.time);
   rebuildHours(now);
-  chargeTime.value.scrollId = "";
+  setTimeout(() => {
+    chargeTime.value.scrollId = `hour-${timesInfo.value.hour[0].format}`;
+  }, 0);
 };
 
 const changeHour = (index: number) => {
@@ -466,6 +463,18 @@ const changeHour = (index: number) => {
 
 const changePowerSaving = (e: any) => {
   chargeTime.value.isPowerSaving = e.detail.value;
+  chargeTime.value = {
+    time: 0, // 时间戳
+    day: "",
+    hour: "",
+    isPowerSaving: chargeTime.value.isPowerSaving, // 省电模式
+    format: "",
+    formatPrice: "",
+    scrollId: "",
+  };
+  if (chargeTime.value.isPowerSaving) {
+    selectTime();
+  }
 };
 
 const closeTime = () => {
@@ -583,11 +592,13 @@ const submit = () => {
   let query = "";
   if (chargeType.value === 0) {
     query += "isBooking=true";
+    if (chargeTime.value.isPowerSaving && !chargeTime.value.hour) {
+      query += `&startTime=${format("y-M-d", startTime)} 00:00:00`;
+    } else {
+    }
     query += `&startTime=${format("y-M-d", startTime)} ${
-      chargeTime.value.isPowerSaving
-        ? "00:00:00"
-        : `${chargeTime.value.hour}:00`
-    }`;
+      chargeTime.value.hour
+    }:00`;
     if (chargeTime.value.isPowerSaving) {
       query += `&endTime=${format("y-M-d", startTime)} 08:00:00`;
     }

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

@@ -62,7 +62,7 @@
         type="warning"
         size="small"
         @click="cancel"
-        >取消充电</style-button
+        >停止充电</style-button
       >
       <style-button
         v-if="step === 3"
@@ -181,7 +181,7 @@ const cancel = () => {
                 // console.log(res)
                 uni.hideLoading();
                 uni.showToast({
-                  title: "已取消充电",
+                  title: "已停止充电",
                   icon: "none",
                 });
                 setTimeout(() => {
@@ -191,7 +191,7 @@ const cancel = () => {
               .catch(() => {
                 uni.hideLoading();
                 uni.showToast({
-                  title: "已取消充电",
+                  title: "已停止充电",
                   icon: "none",
                 });
                 setTimeout(() => {
@@ -274,7 +274,7 @@ const finish = () => {
             console.log(err);
             uni.hideLoading();
             uni.showToast({
-              title: "已取消充电",
+              title: "已停止充电",
               icon: "none",
             });
             setTimeout(() => {