|
@@ -119,46 +119,67 @@
|
|
|
},
|
|
|
|
|
|
handleTimeClick(item) {
|
|
|
- console.log(this.businessDuration, '>>>>>>businessDuration');
|
|
|
- // 禁用点击,取消点击触发
|
|
|
- if (item.disabled) return false
|
|
|
-
|
|
|
- // 计算服务时间秒
|
|
|
- const seconds = this.businessDuration * 60
|
|
|
- // 计算最终服务时间
|
|
|
- const endTimestamp = (item.timeStamp + seconds)
|
|
|
-
|
|
|
- // 禁用区域/释放区域数据
|
|
|
+ const durationMs = this.businessDuration * 60 * 1000;
|
|
|
+ const itemTime = item.timeStamp > 9999999999 ? item.timeStamp : item.timeStamp * 1000;
|
|
|
+ const slots = this.timeHostArr[this.day_index] || [];
|
|
|
+ const currentDate = this.timeArr[this.day_index];
|
|
|
+
|
|
|
+ // 1. 判断当前时间是否在任何已预约时间段的服务时长范围内
|
|
|
+ let inReservedRange = false;
|
|
|
+ for (let slot of slots) {
|
|
|
+ if (slot.hasReservation === 1) {
|
|
|
+ const reservedTime = slot.timeStamp > 9999999999 ? slot.timeStamp : slot.timeStamp * 1000;
|
|
|
+ const start = reservedTime - durationMs;
|
|
|
+ const end = reservedTime + durationMs;
|
|
|
+ if (itemTime >= start && itemTime < end) {
|
|
|
+ inReservedRange = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (inReservedRange) {
|
|
|
+ uni.showToast({ title: '该时间段已被预约', icon: 'none' });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 判断当前点击时间与所有已选时间段的服务时长有无重叠(多选判断)
|
|
|
+ const selectedArr = this.selectedTimeSlots[currentDate] || [];
|
|
|
+ if (!item.checked) { // 只在选中时判断
|
|
|
+ for (let t of selectedArr) {
|
|
|
+ if (t === item.timeStamp) continue; // 跳过自己
|
|
|
+ const tStart = t > 9999999999 ? t : t * 1000;
|
|
|
+ const tEnd = tStart + durationMs;
|
|
|
+ if (
|
|
|
+ (itemTime >= tStart && itemTime < tEnd) ||
|
|
|
+ (itemTime < tStart && itemTime + durationMs > tStart)
|
|
|
+ ) {
|
|
|
+ uni.showToast({ title: '时间段不在服务范围内', icon: 'none' });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 其他逻辑保持不变
|
|
|
+ const seconds = this.businessDuration * 60;
|
|
|
+ const endTimestamp = (item.timeStamp + seconds);
|
|
|
const filteredSlots = this.timeHostArr[this.day_index].filter(i => {
|
|
|
return (i.timeStamp > item.timeStamp &&
|
|
|
i.timeStamp <= endTimestamp)
|
|
|
- })
|
|
|
-
|
|
|
- console.log(filteredSlots, '>>>>>filteredSlots');
|
|
|
-
|
|
|
- // 当前日期
|
|
|
- const currentDate = this.timeArr[this.day_index];
|
|
|
-
|
|
|
+ });
|
|
|
if (!item.checked) {
|
|
|
- // 计算禁用时间区域
|
|
|
filteredSlots.forEach(v => {
|
|
|
v.disabled = true
|
|
|
- })
|
|
|
- item.checked = true
|
|
|
-
|
|
|
- // 保存选择状态
|
|
|
+ });
|
|
|
+ item.checked = true;
|
|
|
if (!this.selectedTimeSlots[currentDate]) {
|
|
|
this.selectedTimeSlots[currentDate] = [];
|
|
|
}
|
|
|
this.selectedTimeSlots[currentDate].push(item.timeStamp);
|
|
|
} else {
|
|
|
- // 释放禁用区域
|
|
|
filteredSlots.forEach(v => {
|
|
|
if (v.hasReservation !== 1) v.disabled = false
|
|
|
- })
|
|
|
- item.checked = false
|
|
|
-
|
|
|
- // 移除选择状态
|
|
|
+ });
|
|
|
+ item.checked = false;
|
|
|
if (this.selectedTimeSlots[currentDate]) {
|
|
|
const index = this.selectedTimeSlots[currentDate].indexOf(item.timeStamp);
|
|
|
if (index > -1) {
|
|
@@ -166,7 +187,6 @@
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
this.hosts(item);
|
|
|
},
|
|
|
// 点击日期
|