소스 검색

1. 店铺所有执照增加时间检查,已经过期的不允许上传

Guos 2 주 전
부모
커밋
5a417f7a51
1개의 변경된 파일76개의 추가작업 그리고 3개의 파일을 삭제
  1. 76 3
      src/views/store/storeConfig/userInfo.vue

+ 76 - 3
src/views/store/storeConfig/userInfo.vue

@@ -375,7 +375,7 @@
                     </div>
                   </div>
                 </div>
-                
+
                 <!-- 上传控件 - 始终显示 -->
                 <div class="upload-area-wrapper">
                   <el-upload
@@ -740,7 +740,7 @@ export default {
           currentCount = this.form.foodLicense.length;
         }
       }
-      
+
       // 只有当实际图片数量达到上限时才提示
       if (currentCount >= 3) {
         this.$message.warning('最多只能上传3张图片');
@@ -945,6 +945,10 @@ export default {
     },
     submitForm() {
       this.$refs["form"].validate(valid => {
+        // 添加所有执照有效性检查
+        if (!this.validateLicenses()) {
+          return; // 验证失败,停止提交
+        }
         if (valid) {
           // 如果存在营业执照且不为空,先进行校验
           if (this.form.businessLicense) {
@@ -965,6 +969,75 @@ export default {
         }
       });
     },
+    // 验证所有执照有效性验证方法
+    validateLicenses() {
+      // 验证营业执照
+      if (!this.validateSingleLicense(!this.switchValue, this.form.businessLicenseExpire, "营业执照")) {
+        return false;
+      }
+      // 验证2类医疗器械备案
+      if (!this.validateSingleLicense(!this.medicalDevice2ExpiryValue, this.form.medicalDevice2Expiry, "2类医疗器械备案")) {
+        return false;
+      }
+      // 验证食品经营许可证/备案凭证
+      if (!this.validateSingleLicense(!this.foodLicenseExpiryValue, this.form.foodLicenseExpiry, "食品经营许可证/备案凭证")) {
+        return false;
+      }
+      // 验证药品经营许可证(无长期有效开关,直接检查有效期)
+      if (!this.validateLicenseWithoutSwitch(this.form.drugLicenseExpiry, "药品经营许可证")) {
+        return false;
+      }
+      // 验证3类器械经营许可证(无长期有效开关,直接检查有效期)
+      if (!this.validateLicenseWithoutSwitch(this.form.medicalDevice3Expiry, "3类器械经营许可证")) {
+        return false;
+      }
+      return true;
+    },
+    // 验证单个执照的方法(适用于有长期有效开关的证件)
+    validateSingleLicense(isExpiryRequired, expiryDateRange, licenseName) {
+      // 如果不是长期有效,检查是否过期
+      if (isExpiryRequired) {
+        // 检查是否设置了有效期
+        if (!expiryDateRange || expiryDateRange.length !== 2) {
+          this.$message.warning(`请设置${licenseName}的有效期!`);
+          return false;
+        }
+        // 获取结束日期
+        const endDate = new Date(expiryDateRange[1]);
+        // 获取当前日期
+        const currentDate = new Date();
+        // 比较日期(忽略时间部分)
+        endDate.setHours(0, 0, 0, 0);
+        currentDate.setHours(0, 0, 0, 0);
+        // 如果结束日期早于当前日期,说明已过期
+        if (endDate < currentDate) {
+          this.$message.warning(`${licenseName}已过期,请更新${licenseName}有效期时间或设置为长期有效!`);
+          return false;
+        }
+      }
+      return true;
+    },
+    // 验证无开关控制的证件有效期
+    validateLicenseWithoutSwitch(expiryDateRange, licenseName) {
+      // 检查是否设置了有效期
+      if (!expiryDateRange || expiryDateRange.length !== 2) {
+        this.$message.warning(`请设置${licenseName}的有效期!`);
+        return false;
+      }
+      // 获取结束日期
+      const endDate = new Date(expiryDateRange[1]);
+      // 获取当前日期
+      const currentDate = new Date();
+      // 比较日期(忽略时间部分)
+      endDate.setHours(0, 0, 0, 0);
+      currentDate.setHours(0, 0, 0, 0);
+      // 如果结束日期早于当前日期,说明已过期
+      if (endDate < currentDate) {
+        this.$message.warning(`${licenseName}已过期,请更新${licenseName}有效期时间!`);
+        return false;
+      }
+      return true;
+    },
 
     /** 提交按钮 */
     submitFormData() {
@@ -1424,4 +1497,4 @@ export default {
   cursor: pointer;
   font-size: 14px;
 }
-</style>
+</style>