Bläddra i källkod

优化页面冗余代码,提高阅读性,方便排查错误

Guos 1 vecka sedan
förälder
incheckning
e482e8fde5
2 ändrade filer med 24 tillägg och 205 borttagningar
  1. 22 119
      src/views/store/storeConfig/userInfo.vue
  2. 2 86
      src/views/store/storeProduct/index.vue

+ 22 - 119
src/views/store/storeConfig/userInfo.vue

@@ -472,18 +472,12 @@ export default {
         drugLicenseExpiry: [
           { required: true, message: '药品经营许可证有效期不能为空', trigger: 'blur' }
         ],
-        // medicalLicense: [
-        //   { required: true, message: '医疗机构执业许可证不能为空', trigger: 'blur' }
+        // medicalDevice2: [
+        //   { required: true, message: '2类医疗器械备案证不能为空', trigger: 'blur' }
         // ],
-        // medicalLicenseExpiry: [
-        //   { required: true, message: '医疗机构执业许可证有效期不能为空', trigger: 'blur' }
+        // medicalDevice2Expiry: [
+        //   { required: true, message: '2类医疗器械备案证有效期不能为空', trigger: 'blur' }
         // ],
-        medicalDevice2: [
-          { required: true, message: '2类医疗器械备案证不能为空', trigger: 'blur' }
-        ],
-        medicalDevice2Expiry: [
-          { required: true, message: '2类医疗器械备案证有效期不能为空', trigger: 'blur' }
-        ],
         logoUrl: [
           { required: true, message: '店铺LOGO不能为空', trigger: 'blur' }
         ],
@@ -934,135 +928,44 @@ export default {
     switchChange(){
       console.log(this.form.isBusinessLicensePermanent);
     },
-    // 修复LOGO删除逻辑:确保删除后可重新上传
+    // 优化所有图片的删除逻辑,避免冗余代码、阅读困难
     handleDeleteLogo() {
-      this.isDeleting = true; // 临时禁用上传组件
-      this.$confirm('确定要删除这张图片吗?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning'
-      }).then(() => {
-        this.form.logoUrl = ''; // 清空图片URL
-        this.$message.success('图片已删除');
-      }).catch(() => {
-        this.$message.info('已取消删除');
-      }).finally(() => {
-        this.isDeleting = false; // 无论操作结果,恢复上传组件可用
-        this.$forceUpdate(); // 强制刷新确保状态同步
-      });
-    },
-    handleDelete1() {
-      this.isDeleting = true; // 临时禁用上传组件
-      this.$confirm('确定要删除这张图片吗?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning'
-      }).then(() => {
-        this.form.medicalDevice1 = ''; // 清空图片URL
-        this.$message.success('图片已删除');
-      }).catch(() => {
-        this.$message.info('已取消删除');
-      }).finally(() => {
-        this.isDeleting = false; // 无论操作结果,恢复上传组件可用
-        this.$forceUpdate(); // 强制刷新确保状态同步
-      });
+      this.deleteImage('logoUrl', '图片');
     },
     handleDelete2() {
-      this.isDeleting = true; // 临时禁用上传组件
-      this.$confirm('确定要删除这张图片吗?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning'
-      }).then(() => {
-        this.form.medicalDevice3 = ''; // 清空图片URL
-        this.$message.success('图片已删除');
-      }).catch(() => {
-        this.$message.info('已取消删除');
-      }).finally(() => {
-        this.isDeleting = false; // 无论操作结果,恢复上传组件可用
-        this.$forceUpdate(); // 强制刷新确保状态同步
-      });
+      this.deleteImage('medicalDevice3', '3类器械经营许可证');
     },
     handleDelete3() {
-      this.isDeleting = true; // 临时禁用上传组件
-      this.$confirm('确定要删除这张图片吗?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning'
-      }).then(() => {
-        this.form.foodLicense = ''; // 清空图片URL
-        this.$message.success('图片已删除');
-      }).catch(() => {
-        this.$message.info('已取消删除');
-      }).finally(() => {
-        this.isDeleting = false; // 无论操作结果,恢复上传组件可用
-        this.$forceUpdate(); // 强制刷新确保状态同步
-      });
+      this.deleteImage('foodLicense', '食品经营许可证');
     },
     handleDelete4() {
-      this.isDeleting = true; // 临时禁用上传组件
-      this.$confirm('确定要删除这张图片吗?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning'
-      }).then(() => {
-        this.form.medicalLicense = ''; // 清空图片URL
-        this.$message.success('图片已删除');
-      }).catch(() => {
-        this.$message.info('已取消删除');
-      }).finally(() => {
-        this.isDeleting = false; // 无论操作结果,恢复上传组件可用
-        this.$forceUpdate(); // 强制刷新确保状态同步
-      });
-    }
-    , handleDelete5() {
-      this.isDeleting = true; // 临时禁用上传组件
-      this.$confirm('确定要删除这张图片吗?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning'
-      }).then(() => {
-        this.form.businessLicense = ''; // 清空图片URL
-        this.$message.success('图片已删除');
-      }).catch(() => {
-        this.$message.info('已取消删除');
-      }).finally(() => {
-        this.isDeleting = false; // 无论操作结果,恢复上传组件可用
-        this.$forceUpdate(); // 强制刷新确保状态同步
-      });
-    }
-    , handleDelete6() {
-      this.isDeleting = true; // 临时禁用上传组件
-      this.$confirm('确定要删除这张图片吗?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning'
-      }).then(() => {
-        this.form.drugLicense = ''; // 清空图片URL
-        this.$message.success('图片已删除');
-      }).catch(() => {
-        this.$message.info('已取消删除');
-      }).finally(() => {
-        this.isDeleting = false; // 无论操作结果,恢复上传组件可用
-        this.$forceUpdate(); // 强制刷新确保状态同步
-      });
+      this.deleteImage('medicalLicense', '医疗机构执业许可证');
+    },
+    handleDelete5() {
+      this.deleteImage('businessLicense', '营业执照');
+    },
+    handleDelete6() {
+      this.deleteImage('drugLicense', '药品经营许可证');
     },
     handleDelete7() {
+      this.deleteImage('medicalDevice2', '2类医疗器械备案证书');
+    },
+    deleteImage(fieldName, displayName) {
       this.isDeleting = true; // 临时禁用上传组件
-      this.$confirm('确定要删除这张图片吗?', '提示', {
+      this.$confirm(`确定要删除${displayName}吗?`, '提示', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
       }).then(() => {
-        this.form.medicalDevice2 = ''; // 清空图片URL
-        this.$message.success('图片已删除');
+        this.form[fieldName] = ''; // 清空图片URL
+        this.$message.success(`${displayName}已删除`);
       }).catch(() => {
         this.$message.info('已取消删除');
       }).finally(() => {
         this.isDeleting = false; // 无论操作结果,恢复上传组件可用
         this.$forceUpdate(); // 强制刷新确保状态同步
       });
-    },
+    }
   }
 }
 </script>

+ 2 - 86
src/views/store/storeProduct/index.vue

@@ -217,17 +217,6 @@
           />
         </el-form-item>
       </div>
-      <!-- <el-form-item label="状态" prop="isShow">
-         <el-select style="width: 240px" v-model="queryParams.isShow" placeholder="请选择状态" clearable size="small" >
-         <el-option
-                v-for="item in isShowOptions"
-                :key="item.dictValue"
-                :label="item.dictLabel"
-                :value="item.dictValue"
-              />
-        </el-select>
-      </el-form-item> -->
-
       <el-form-item>
         <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
@@ -443,16 +432,7 @@
             <el-radio :label="item.dictValue" v-for="item in isDisplayOptions">{{ item.dictLabel }}</el-radio>
           </el-radio-group>
         </el-form-item>
-        <!--        <el-form-item label="所属公司" prop="companyId">-->
-        <!--          <el-select style="width: 220px" filterable multiple v-model="form1.companyId" placeholder="请选择公司名" clearable size="small">-->
-        <!--            <el-option-->
-        <!--              v-for="item in companyOptions"-->
-        <!--              :key="item.companyId"-->
-        <!--              :label="item.companyName"-->
-        <!--              :value="item.companyId"-->
-        <!--            />-->
-        <!--          </el-select>-->
-        <!--        </el-form-item>-->
+
       </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button type="primary" @click="submitForm1">确 定</el-button>
@@ -1006,42 +986,6 @@
           </el-date-picker>
         </el-form-item>
 
-        <!--        <el-form-item v-if="form.isShow === '1' && displayDemo" label="Ⅰ类Ⅱ类备案凭证" prop="voucher">-->
-        <!--          <Material v-model="voucherArr" type="image" :num="1" :width="150" :height="150"/>-->
-        <!--        </el-form-item>-->
-        <!--        <el-form-item v-if="form.isShow === '1' && voucherArr.length > 0 && displayDemo" prop="voucherExpire">-->
-        <!--          <el-date-picker-->
-        <!--            v-model="form.voucherExpire"-->
-        <!--            type="daterange"-->
-        <!--            value-format="yyyy-MM-dd"-->
-        <!--            range-separator="至"-->
-        <!--            start-placeholder="开始日期"-->
-        <!--            end-placeholder="结束日期">-->
-        <!--          </el-date-picker>-->
-        <!--        </el-form-item>-->
-        <!--GMP/GSP认证证书 start-->
-<!--        <el-form-item v-if="form.isShow === '1'" label="GMP/GSP认证证书" prop="gmpAuth">-->
-<!--          <Material v-model="gmpAuthArr" type="image" :num="1" :width="150" :height="150"/>-->
-<!--        </el-form-item>-->
-<!--        <el-form-item v-if="form.isShow === '1' && gmpAuthArr.length > 0" label="GMP/GSP认证证书是否长期有效" prop="isGmpAuthPermanent">-->
-<!--          <el-switch-->
-<!--            @change="switchChange()"-->
-<!--            v-model="gmpAuthValue"-->
-<!--            active-color="#13ce66"-->
-<!--            inactive-color="#ff4949">-->
-<!--          </el-switch>-->
-<!--        </el-form-item>-->
-<!--        <el-form-item v-if="form.isShow === '1' && gmpAuthArr.length > 0 && !gmpAuthValue" prop="gmpAuthExpire">-->
-<!--          <el-date-picker-->
-<!--            v-model="form.gmpAuthExpire"-->
-<!--            type="daterange"-->
-<!--            value-format="yyyy-MM-dd"-->
-<!--            range-separator="至"-->
-<!--            start-placeholder="开始日期"-->
-<!--            end-placeholder="结束日期">-->
-<!--          </el-date-picker>-->
-<!--        </el-form-item>-->
-        <!--GMP/GSP认证证书 end-->
         <el-form-item label="国药准字" v-if="form.productType==2" prop="prescribeCode">
           <el-input v-model="form.prescribeCode" placeholder="请输入国药准字"/>
         </el-form-item>
@@ -1629,35 +1573,7 @@ export default {
       },
     };
   },
-  // computed: {
-  //   // 动态验证规则 - 返回完整的规则对象
-  //   dynamicRules() {
-  //     // 复制基础规则
-  //     const rules = { ...this.rules };
-  //
-  //     // 判断是否为处方药 (cateId = 224)
-  //     const isPrescriptionDrug = this.form.cateId == 224;
-  //     console.log("分类id"+this.form.cateId);
-  //     // 修改触发时机,只在失去焦点时验证
-  //     Object.keys(rules).forEach(key => {
-  //       if (rules[key] && rules[key].length > 0) {
-  //         rules[key].forEach(rule => {
-  //           rule.trigger = 'blur'; // 只在失去焦点时验证
-  //         });
-  //       }
-  //     });
-  //     // 如果是处方药,取消功能主治和用法用量的校验
-  //     if (isPrescriptionDrug) {
-  //       rules.indications = []; // 空数组表示取消校验
-  //       rules.dosage = []; // 空数组表示取消校验
-  //     }else {
-  //       rules.indications = this.rules.indications
-  //       rules.dosage = this.rules.dosage
-  //     }
-  //
-  //     return rules;
-  //   }
-  // },
+
   methods: {
     // 检查违禁关键词
     checkForbiddenKeywords(ingredient) {