Browse Source

feat(store): 添加营业时间限制与重复检查功能

- 添加正常营业时间数量检查,防止重复添加
- 添加特殊营业时间数量限制,最多允许5个
- 实现特殊营业时间日期重复性检查逻辑
- 在确认特殊营业时间前增加日期重复验证
- 提供更明确的用户提示信息避免无效操作
spy 3 weeks ago
parent
commit
dc7241f677
1 changed files with 33 additions and 0 deletions
  1. 33 0
      src/views/storeDecoration/businessHours/index.vue

+ 33 - 0
src/views/storeDecoration/businessHours/index.vue

@@ -269,6 +269,11 @@ const toggleHoliday = (holiday: string) => {
 
 // 打开添加正常营业时间对话框
 const openAddNormalDialog = () => {
+  // 检查是否已有正常营业时间(添加时检查,编辑时不检查)
+  if (normalHours.value.length > 0) {
+    ElMessage.warning("已有正常营业时间");
+    return;
+  }
   normalEditIndex.value = null;
   resetNormalForm();
   normalDialogVisible.value = true;
@@ -345,6 +350,11 @@ const confirmNormalHours = () => {
 
 // 打开添加特殊营业时间对话框
 const openAddSpecialDialog = () => {
+  // 检查是否已有5个特殊营业时间(添加时检查,编辑时不检查)
+  if (specialHours.value.length >= 5) {
+    ElMessage.warning("最多添加5个特殊营业时间");
+    return;
+  }
   specialEditIndex.value = null;
   resetSpecialForm();
   specialDialogVisible.value = true;
@@ -383,6 +393,23 @@ const resetSpecialForm = () => {
   specialEditIndex.value = null;
 };
 
+// 检查特殊营业时间日期是否重复
+const checkDateDuplicate = (holidays: string[]): boolean => {
+  // 过滤出其他特殊营业时间(排除当前编辑的项)
+  const otherSpecialHours = specialHours.value.filter((item, index) => index !== specialEditIndex.value);
+
+  // 检查新添加/编辑的特殊营业时间的日期是否与其他特殊营业时间的日期有重复
+  for (let i = 0; i < otherSpecialHours.length; i++) {
+    const item = otherSpecialHours[i];
+    // 检查是否有任何节假日重复
+    if (holidays.some(holiday => item.holidays.includes(holiday))) {
+      return true;
+    }
+  }
+
+  return false;
+};
+
 // 确认特殊营业时间
 const confirmSpecialHours = () => {
   if (specialForm.selectedHolidays.length === 0) {
@@ -394,6 +421,12 @@ const confirmSpecialHours = () => {
     return;
   }
 
+  // 检查日期是否重复
+  if (checkDateDuplicate(specialForm.selectedHolidays)) {
+    ElMessage.warning("特殊营业时间的日期不能重复");
+    return;
+  }
+
   const newItem: SpecialHoursItem = {
     holidays: [...specialForm.selectedHolidays],
     timeType: specialForm.timeType,