|
@@ -15,7 +15,7 @@
|
|
<view class="time_x"
|
|
<view class="time_x"
|
|
:class="{
|
|
:class="{
|
|
'time_x_sty': item?.checked,
|
|
'time_x_sty': item?.checked,
|
|
- 'disabled-time': item?.disabled
|
|
|
|
|
|
+ 'disabled-time': item?.disabled || item?.hasReservation === 1
|
|
}"
|
|
}"
|
|
v-for="(item, index) in timeHostArr[day_index]"
|
|
v-for="(item, index) in timeHostArr[day_index]"
|
|
:key="index"
|
|
:key="index"
|
|
@@ -27,6 +27,7 @@
|
|
</scroll-view>
|
|
</scroll-view>
|
|
</view>
|
|
</view>
|
|
<view class="calendar_footer">
|
|
<view class="calendar_footer">
|
|
|
|
+ {{ selectRange }}
|
|
<view class="remark_content">{{remark}}</view>
|
|
<view class="remark_content">{{remark}}</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
@@ -69,7 +70,7 @@
|
|
watch: {
|
|
watch: {
|
|
timeArr: {
|
|
timeArr: {
|
|
handler(newVal) {
|
|
handler(newVal) {
|
|
- console.log(newVal, '>>>>>>>时间范围');
|
|
|
|
|
|
+ // console.log(newVal, '>>>>>>>时间范围');
|
|
let dateArr = newVal.map(item => {
|
|
let dateArr = newVal.map(item => {
|
|
let day = new Date(item)
|
|
let day = new Date(item)
|
|
const daysOfWeek = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
|
|
const daysOfWeek = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
|
|
@@ -85,7 +86,7 @@
|
|
},
|
|
},
|
|
timeHostArr: {
|
|
timeHostArr: {
|
|
handler(newVal) {
|
|
handler(newVal) {
|
|
- console.log(newVal, '>>>>>>>时间更新');
|
|
|
|
|
|
+ // console.log(newVal, '>>>>>>>时间更新');
|
|
// 当timeHostArr更新时,恢复之前的选择状态
|
|
// 当timeHostArr更新时,恢复之前的选择状态
|
|
if (newVal && newVal.length > 0) {
|
|
if (newVal && newVal.length > 0) {
|
|
this.restoreSelections();
|
|
this.restoreSelections();
|
|
@@ -95,21 +96,62 @@
|
|
}
|
|
}
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ computed: {
|
|
|
|
+ // 计算选中区域
|
|
|
|
+ selectRange() {
|
|
|
|
+ const reservations = this.timeHostArr[this.day_index]
|
|
|
|
+ console.log(reservations, '>>>>>reservations');
|
|
|
|
+ // console.log(JSON.stringify(current), '>>>>>current');
|
|
|
|
+ // return current
|
|
|
|
+ const result = [];
|
|
|
|
+ let currentGroup = null;
|
|
|
|
+
|
|
|
|
+ for (const item of reservations) {
|
|
|
|
+ if (item.checked) {
|
|
|
|
+ // 遇到新的checked项,创建新组
|
|
|
|
+ if (currentGroup) {
|
|
|
|
+ result.push(currentGroup);
|
|
|
|
+ }
|
|
|
|
+ currentGroup = [item];
|
|
|
|
+ } else if (currentGroup && item.disabled && item.hasReservation === 0) {
|
|
|
|
+ // 如果当前有活跃的组,且符合disabled和hasReservation条件,加入当前组
|
|
|
|
+ currentGroup.push(item);
|
|
|
|
+ } else if (currentGroup) {
|
|
|
|
+ // 不符合连续条件,结束当前组
|
|
|
|
+ result.push(currentGroup);
|
|
|
|
+ currentGroup = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 添加最后一组(如果有)
|
|
|
|
+ if (currentGroup) {
|
|
|
|
+ result.push(currentGroup);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const timeRangeArr = result.map(arr => {
|
|
|
|
+ return arr[0].hours + '-' +arr[arr.length -1].hours
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return timeRangeArr;
|
|
|
|
+ }
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
// 恢复选择状态
|
|
// 恢复选择状态
|
|
restoreSelections() {
|
|
restoreSelections() {
|
|
- console.log('>>>>>>执行了', this.selectedTimeSlots);
|
|
|
|
|
|
+ // console.log('>>>>>>执行了', this.selectedTimeSlots);
|
|
if (!this.timeHostArr[this.day_index]) return;
|
|
if (!this.timeHostArr[this.day_index]) return;
|
|
|
|
|
|
- console.log('>>>>>>执行了2', this.selectedTimeSlots);
|
|
|
|
|
|
+ // console.log('>>>>>>执行了2', this.selectedTimeSlots);
|
|
|
|
|
|
// 遍历当前日期的时间槽
|
|
// 遍历当前日期的时间槽
|
|
this.timeHostArr[this.day_index].forEach(slot => {
|
|
this.timeHostArr[this.day_index].forEach(slot => {
|
|
// 检查这个时间槽是否在之前被选中
|
|
// 检查这个时间槽是否在之前被选中
|
|
const dateKey = this.timeArr[this.day_index];
|
|
const dateKey = this.timeArr[this.day_index];
|
|
- console.log(dateKey, '>>>>dateKey');
|
|
|
|
- console.log(this.selectedTimeSlots[dateKey], '>>>>this.selectedTimeSlots[dateKey]');
|
|
|
|
|
|
+ // console.log(dateKey, '>>>>dateKey');
|
|
|
|
+ // console.log(this.selectedTimeSlots[dateKey], '>>>>this.selectedTimeSlots[dateKey]');
|
|
if (this.selectedTimeSlots[dateKey] &&
|
|
if (this.selectedTimeSlots[dateKey] &&
|
|
this.selectedTimeSlots[dateKey].includes(slot.timeStamp)) {
|
|
this.selectedTimeSlots[dateKey].includes(slot.timeStamp)) {
|
|
slot.checked = true;
|
|
slot.checked = true;
|
|
@@ -127,7 +169,7 @@
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
});
|
|
});
|
|
},
|
|
},
|
|
@@ -175,29 +217,35 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // 3. 其他逻辑保持不变
|
|
|
|
|
|
+ // 3. 检查当前时间到结束是否有足够的时间段
|
|
const seconds = this.businessDuration * this.minQuantity * 60;
|
|
const seconds = this.businessDuration * this.minQuantity * 60;
|
|
const endTimestamp = (item.timeStamp + seconds);
|
|
const endTimestamp = (item.timeStamp + seconds);
|
|
|
|
+
|
|
|
|
+ // 找出当前时间到服务结束时间之间的所有时间段
|
|
const filteredSlots = this.timeHostArr[this.day_index].filter(i => {
|
|
const filteredSlots = this.timeHostArr[this.day_index].filter(i => {
|
|
- return (i.timeStamp > item.timeStamp &&
|
|
|
|
- i.timeStamp <= endTimestamp)
|
|
|
|
|
|
+ return (i.timeStamp > item.timeStamp && i.timeStamp <= endTimestamp);
|
|
});
|
|
});
|
|
- this.filteredSlots = filteredSlots
|
|
|
|
|
|
+ this.filteredSlots = filteredSlots;
|
|
|
|
|
|
- console.log(filteredSlots, '》》》》》》filteredSlots');
|
|
|
|
|
|
+ // 检查这些时间段中是否有已预约的时间
|
|
|
|
+ const hasReservedSlot = filteredSlots.some(slot => slot.hasReservation === 1);
|
|
|
|
+ if (hasReservedSlot) {
|
|
|
|
+ uni.showToast({ title: '所选时间段内有已预约时间,请选择其他时间', icon: 'none' });
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
// 时间差值(数组中的最后一项 - 当前点击项)
|
|
// 时间差值(数组中的最后一项 - 当前点击项)
|
|
- const timestampDifferenceValue = filteredSlots.length ? (filteredSlots[filteredSlots.length - 1].timeStamp - item.timeStamp) * 1000 : 0
|
|
|
|
|
|
+ const timestampDifferenceValue = filteredSlots.length ? (filteredSlots[filteredSlots.length - 1].timeStamp - item.timeStamp) * 1000 : 0;
|
|
|
|
|
|
// 选择时间,后续服务时间是否充足,不充足结束逻辑执行 timeStamp
|
|
// 选择时间,后续服务时间是否充足,不充足结束逻辑执行 timeStamp
|
|
if (timestampDifferenceValue < durationMs) { // 所选时间差值 小于 服务时间值 结束执行
|
|
if (timestampDifferenceValue < durationMs) { // 所选时间差值 小于 服务时间值 结束执行
|
|
uni.showToast({ title: '所选时间的服务时间不充足!', icon: 'none' });
|
|
uni.showToast({ title: '所选时间的服务时间不充足!', icon: 'none' });
|
|
- return false
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (!item.checked) {
|
|
if (!item.checked) {
|
|
filteredSlots.forEach(v => {
|
|
filteredSlots.forEach(v => {
|
|
- v.disabled = true
|
|
|
|
|
|
+ v.disabled = true;
|
|
});
|
|
});
|
|
item.checked = true;
|
|
item.checked = true;
|
|
if (!this.selectedTimeSlots[currentDate]) {
|
|
if (!this.selectedTimeSlots[currentDate]) {
|
|
@@ -206,7 +254,7 @@
|
|
this.selectedTimeSlots[currentDate].push(item.timeStamp);
|
|
this.selectedTimeSlots[currentDate].push(item.timeStamp);
|
|
} else {
|
|
} else {
|
|
filteredSlots.forEach(v => {
|
|
filteredSlots.forEach(v => {
|
|
- if (v.hasReservation !== 1) v.disabled = false
|
|
|
|
|
|
+ if (v.hasReservation !== 1) v.disabled = false;
|
|
});
|
|
});
|
|
item.checked = false;
|
|
item.checked = false;
|
|
if (this.selectedTimeSlots[currentDate]) {
|
|
if (this.selectedTimeSlots[currentDate]) {
|
|
@@ -220,25 +268,22 @@
|
|
},
|
|
},
|
|
|
|
|
|
async handleTimeClick2() {
|
|
async handleTimeClick2() {
|
|
|
|
+ if (!this.upItem) return;
|
|
|
|
|
|
- let item = this.upItem
|
|
|
|
-
|
|
|
|
- // console.log(this.timeHostArr[this.day_index], '>>>this.timeHostArr[this.day_index]');
|
|
|
|
|
|
+ let item = this.upItem;
|
|
|
|
+ const currentDate = this.timeArr[this.day_index];
|
|
|
|
+ const durationMs = this.businessDuration * this.minQuantity * 60 * 1000;
|
|
|
|
+ const itemTime = item.timeStamp > 9999999999 ? item.timeStamp : item.timeStamp * 1000;
|
|
|
|
+ const slots = this.timeHostArr[this.day_index] || [];
|
|
|
|
|
|
- // 处理减法时 (选中状态重置)
|
|
|
|
|
|
+ // 保留之前的选择状态,只重置disabled状态
|
|
this.timeHostArr[this.day_index].forEach(s => {
|
|
this.timeHostArr[this.day_index].forEach(s => {
|
|
- s.disabled = item.hasReservation === 1
|
|
|
|
|
|
+ if (s.hasReservation !== 1 && !s.checked) {
|
|
|
|
+ s.disabled = false;
|
|
|
|
+ }
|
|
});
|
|
});
|
|
- // this.hosts(item);
|
|
|
|
-
|
|
|
|
- // console.log(this.timeArr, '.>>>>item1111');
|
|
|
|
-
|
|
|
|
- const durationMs = this.businessDuration * this.minQuantity * 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. 判断当前时间是否在任何已预约时间段的服务时长范围内
|
|
|
|
|
|
+ // 1. 检查是否与已预约时间冲突
|
|
let inReservedRange = false;
|
|
let inReservedRange = false;
|
|
for (let slot of slots) {
|
|
for (let slot of slots) {
|
|
if (slot.hasReservation === 1) {
|
|
if (slot.hasReservation === 1) {
|
|
@@ -256,57 +301,38 @@
|
|
return false;
|
|
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 * this.minQuantity * 60;
|
|
|
|
- // console.log(this.businessDuration, this.minQuantity, '>>>>>9999');
|
|
|
|
|
|
+ // 2. 检查是否有足够的后续时间段
|
|
|
|
+ const seconds = this.businessDuration * this.minQuantity * 60;
|
|
const endTimestamp = (item.timeStamp + seconds);
|
|
const endTimestamp = (item.timeStamp + seconds);
|
|
- // console.log(endTimestamp, '>>>>>>endTimestamp');
|
|
|
|
- const filteredSlots = this.timeHostArr[this.day_index].filter(i => {
|
|
|
|
- return (i.timeStamp > item.timeStamp &&
|
|
|
|
- i.timeStamp <= endTimestamp)
|
|
|
|
- });
|
|
|
|
- this.filteredSlots = filteredSlots
|
|
|
|
-
|
|
|
|
- // console.log(filteredSlots, '》》》》》》filteredSlots');
|
|
|
|
-
|
|
|
|
- // 时间差值(数组中的最后一项 - 当前点击项)
|
|
|
|
- const timestampDifferenceValue = filteredSlots.length ? (filteredSlots[filteredSlots.length - 1].timeStamp - item.timeStamp) * 1000 : 0
|
|
|
|
-
|
|
|
|
- // 选择时间,后续服务时间是否充足,不充足结束逻辑执行 timeStamp
|
|
|
|
- if (timestampDifferenceValue < durationMs) { // 所选时间差值 小于 服务时间值 结束执行
|
|
|
|
- uni.showToast({ title: '所选时间的服务时间不充足!', icon: 'none' });
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
|
|
|
|
- filteredSlots.forEach(v => {
|
|
|
|
- v.disabled = true
|
|
|
|
|
|
+ // 找出从当前时间到结束时间之间的所有时间段
|
|
|
|
+ const filteredSlots = this.timeHostArr[this.day_index].filter(i => {
|
|
|
|
+ return (i.timeStamp > item.timeStamp && i.timeStamp <= endTimestamp);
|
|
});
|
|
});
|
|
|
|
+ this.filteredSlots = filteredSlots;
|
|
|
|
|
|
- console.log('>>>>>执行');
|
|
|
|
|
|
+ // 检查这些时间段中是否有已预约的时间
|
|
|
|
+ const hasReservedSlot = filteredSlots.some(slot => slot.hasReservation === 1);
|
|
|
|
+ if (hasReservedSlot) {
|
|
|
|
+ uni.showToast({ title: '所选时间段内有已预约时间,请选择其他时间', icon: 'none' });
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- if (!this.selectedTimeSlots[currentDate]) {
|
|
|
|
- this.selectedTimeSlots[currentDate] = [];
|
|
|
|
|
|
+ // 检查时间是否足够
|
|
|
|
+ const timestampDifferenceValue = filteredSlots.length ? (filteredSlots[filteredSlots.length - 1].timeStamp - item.timeStamp) * 1000 : 0;
|
|
|
|
+ if (timestampDifferenceValue < durationMs) {
|
|
|
|
+ uni.showToast({ title: '所选时间的服务时间不充足!', icon: 'none' });
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
- this.selectedTimeSlots[currentDate].push(item.timeStamp);
|
|
|
|
|
|
|
|
- // this.hosts(item);
|
|
|
|
|
|
+ // 所有检查通过,更新disabled状态
|
|
|
|
+ // filteredSlots.forEach(v => {
|
|
|
|
+ // if (v.hasReservation !== 1 && !v.checked) {
|
|
|
|
+ // v.disabled = true;
|
|
|
|
+ // }
|
|
|
|
+ // });
|
|
|
|
+
|
|
|
|
+ this.hosts(item);
|
|
},
|
|
},
|
|
|
|
|
|
// 点击日期
|
|
// 点击日期
|