|
|
@@ -23,17 +23,59 @@ Page({
|
|
|
show: false,
|
|
|
date: '',
|
|
|
offlineId: "",
|
|
|
+ // 是否为修改预约模式,以及原始预约时间(用于高亮和对比是否有改动)
|
|
|
+ isEditMode: false,
|
|
|
+ originalAppointmentTime: "",
|
|
|
},
|
|
|
onLoad(options: any) {
|
|
|
- // 初始化日期列表(从今天开始5天)
|
|
|
- this.initDateList();
|
|
|
- if (options.goodsInfo) {
|
|
|
- const goodsInfo = JSON.parse(options.goodsInfo);
|
|
|
+ console.log(options, "options===");
|
|
|
+ const goodsInfoFromStorage = wx.getStorageSync('goodsInfo');
|
|
|
+ console.log(goodsInfoFromStorage, "goodsInfo===from storage");
|
|
|
+
|
|
|
+ let parsedGoodsInfo: any = null;
|
|
|
+ if ( goodsInfoFromStorage) {
|
|
|
+ try {
|
|
|
+ parsedGoodsInfo = JSON.parse(goodsInfoFromStorage || '{}');
|
|
|
+ console.log(parsedGoodsInfo, "parsedGoodsInfo===");
|
|
|
+ } catch (e) {
|
|
|
+ console.error("解析 goodsInfo 失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const originalAppointmentTime =
|
|
|
+ (options.arrangeTime && decodeURIComponent(options.arrangeTime)) ||
|
|
|
+ parsedGoodsInfo?.arrangeTime ||
|
|
|
+ parsedGoodsInfo?.appointmentTime ||
|
|
|
+ "";
|
|
|
+ const isEditMode = options.mode === "edit" || !!originalAppointmentTime;
|
|
|
+
|
|
|
+ // 如果有原始预约时间,则围绕该日期初始化列表;否则从今天开始 5 天
|
|
|
+ if (originalAppointmentTime) {
|
|
|
+ const [datePart] = originalAppointmentTime.split(" ");
|
|
|
+ const baseDate = datePart ? new Date(datePart) : new Date();
|
|
|
+ this.initDateList(baseDate);
|
|
|
+ } else {
|
|
|
+ this.initDateList();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (parsedGoodsInfo) {
|
|
|
+ this.setData({
|
|
|
+ goodsInfo: parsedGoodsInfo,
|
|
|
+ offlineId: parsedGoodsInfo.offlineId || "",
|
|
|
+ isEditMode,
|
|
|
+ originalAppointmentTime,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
this.setData({
|
|
|
- goodsInfo: goodsInfo,
|
|
|
- offlineId: goodsInfo.offlineId,
|
|
|
+ isEditMode,
|
|
|
+ originalAppointmentTime,
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ // 修改预约场景:根据原始预约时间高亮默认选中项
|
|
|
+ if (originalAppointmentTime) {
|
|
|
+ this.highlightOriginalAppointmentTime(originalAppointmentTime);
|
|
|
+ }
|
|
|
},
|
|
|
// 初始化日期列表
|
|
|
initDateList(startDate?: Date) {
|
|
|
@@ -89,7 +131,8 @@ Page({
|
|
|
this.initTimeSlots(dateList[0].date);
|
|
|
},
|
|
|
// 初始化时间列表 - 固定8:00-20:00
|
|
|
- initTimeSlots(selectedDate?: string) {
|
|
|
+ // 可选传入 preSelectedTime,在初始化时高亮该时间段
|
|
|
+ initTimeSlots(selectedDate?: string, preSelectedTime?: string) {
|
|
|
const timeSlots: Array<{
|
|
|
time: string;
|
|
|
isSelected: boolean;
|
|
|
@@ -123,7 +166,7 @@ Page({
|
|
|
|
|
|
timeSlots.push({
|
|
|
time: timeStr,
|
|
|
- isSelected: false,
|
|
|
+ isSelected: preSelectedTime ? timeStr === preSelectedTime : false,
|
|
|
isDisabled,
|
|
|
});
|
|
|
}
|
|
|
@@ -131,6 +174,37 @@ Page({
|
|
|
|
|
|
this.setData({ timeSlots });
|
|
|
},
|
|
|
+ // 根据原始预约时间高亮日期和时间
|
|
|
+ highlightOriginalAppointmentTime(appointmentTime: string) {
|
|
|
+ if (!appointmentTime) return;
|
|
|
+ const [rawDatePart, rawTimePart] = appointmentTime.split(" ");
|
|
|
+ if (!rawDatePart || !rawTimePart) return;
|
|
|
+
|
|
|
+ // 兼容不同格式:2025-03-13 / 2025/03/13 以及带秒的时间 14:30:00
|
|
|
+ const datePart = rawDatePart.replace(/\//g, "-").substring(0, 10);
|
|
|
+ const timePart = rawTimePart.substring(0, 5); // 只取 HH:mm
|
|
|
+
|
|
|
+ // 高亮日期
|
|
|
+ const dateList = this.data.dateList.map((item) => ({
|
|
|
+ ...item,
|
|
|
+ isSelected: item.date === datePart,
|
|
|
+ }));
|
|
|
+
|
|
|
+ // 如果当前 5 天中没有该日期,则直接返回(保持已有逻辑);更复杂的滚动可后续再优化
|
|
|
+ const hasTargetDate = dateList.some((item) => item.isSelected);
|
|
|
+ if (!hasTargetDate) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ dateList,
|
|
|
+ selectedDate: datePart,
|
|
|
+ selectedTime: timePart,
|
|
|
+ });
|
|
|
+
|
|
|
+ // 按该日期重新初始化时间段,并选中对应时间
|
|
|
+ this.initTimeSlots(datePart, timePart);
|
|
|
+ },
|
|
|
// 选择日期
|
|
|
onDateSelect(e: any) {
|
|
|
const index = e.currentTarget.dataset.index;
|
|
|
@@ -194,6 +268,26 @@ Page({
|
|
|
|
|
|
const appointmentTime = `${this.data.selectedDate} ${this.data.selectedTime}`;
|
|
|
console.log(appointmentTime, "appointmentTime");
|
|
|
+
|
|
|
+ // 归一化原始预约时间为 "YYYY-MM-DD HH:mm" 用于对比
|
|
|
+ let normalizedOriginal = "";
|
|
|
+ if (this.data.originalAppointmentTime) {
|
|
|
+ const [rawDatePart, rawTimePart] = this.data.originalAppointmentTime.split(" ");
|
|
|
+ if (rawDatePart && rawTimePart) {
|
|
|
+ const datePart = rawDatePart.replace(/\//g, "-").substring(0, 10);
|
|
|
+ const timePart = rawTimePart.substring(0, 5); // HH:mm
|
|
|
+ normalizedOriginal = `${datePart} ${timePart}`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改预约模式下,如果时间未变化,则提示修改失败,不调接口
|
|
|
+ if (this.data.isEditMode && normalizedOriginal && appointmentTime === normalizedOriginal) {
|
|
|
+ wx.showToast({
|
|
|
+ title: "预约时间未修改",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
console.log(this.data.offlineId, "this.data.offlineId");
|
|
|
this.setData({
|
|
|
goodsInfo: {
|