|
|
@@ -480,7 +480,7 @@
|
|
|
<el-row>
|
|
|
<el-col :span="12">
|
|
|
<el-form-item label="商品名称" prop="productName">
|
|
|
- <el-input v-model="form.productName" placeholder="请输入商品名称"/>
|
|
|
+ <el-input v-model="form.productName" @blur="handleProductNameBlur" placeholder="请输入商品名称" @input="onProductNameInput"/>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
<el-col :span="12">
|
|
|
@@ -1447,6 +1447,8 @@ export default {
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
+ ingredientError: '', // 成分禁止提示
|
|
|
+ productNameError: '', // 商品名称禁止提示
|
|
|
certificateValue:false,
|
|
|
licenseValue:false,
|
|
|
businessValue:false,
|
|
|
@@ -1460,7 +1462,6 @@ export default {
|
|
|
storeLicenseCheckFailed: false, // 店铺许可证接口检查是否失败
|
|
|
auditLogs:[],
|
|
|
titleValue:null,
|
|
|
- ingredientError: '', // 成分禁止提示
|
|
|
displayDemo: false,
|
|
|
cateIdToNameMap: {},
|
|
|
showMedicalDeviceCode: false, // 是否显示器械编码输入框
|
|
|
@@ -1661,7 +1662,17 @@ export default {
|
|
|
{required: true, message: "轮播图不能为空", trigger: "blur"}
|
|
|
],
|
|
|
productName: [
|
|
|
- {required: true, message: "商品名称不能为空", trigger: "blur"}
|
|
|
+ {required: true, message: "商品名称不能为空", trigger: "blur"},
|
|
|
+ {
|
|
|
+ validator: (rule, value, callback) => {
|
|
|
+ if (this.productNameError) {
|
|
|
+ callback(new Error(this.productNameError));
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ trigger: "blur"
|
|
|
+ }
|
|
|
],
|
|
|
productInfo: [
|
|
|
{required: true, message: "商品简介不能为空", trigger: "blur"}
|
|
|
@@ -1853,27 +1864,49 @@ export default {
|
|
|
this.isCheckingLicense = false;
|
|
|
});
|
|
|
},
|
|
|
- // 成分输入框失焦时的处理方法关键字检查
|
|
|
+ // 成分输入框失焦时的处理方法
|
|
|
handleIngredientBlur() {
|
|
|
- // 检查成分是否包含禁用关键字
|
|
|
- if (this.form.ingredient && this.form.ingredient.trim() !== '' && this.form.productName && this.form.productName.trim() !== '') {
|
|
|
- // 创建包含成分和商品名称的参数对象
|
|
|
- selectForbiddenKeywords(this.form.ingredient, this.form.productName).then(response => {
|
|
|
+ this.checkForbiddenKeywords('ingredient', this.form.ingredient);
|
|
|
+ },
|
|
|
+ // 商品名称输入框失焦时的处理方法
|
|
|
+ handleProductNameBlur() {
|
|
|
+ this.checkForbiddenKeywords('productName', this.form.productName);
|
|
|
+ },
|
|
|
+ // 通用关键字检查方法 - 根据字段类型分别处理错误提示
|
|
|
+ checkForbiddenKeywords(fieldName, fieldValue) {
|
|
|
+ // 检查内容是否包含禁用关键字
|
|
|
+ if (fieldValue && fieldValue.trim() !== '') {
|
|
|
+ // 统一使用 keywords 参数传递当前失去焦点的值
|
|
|
+ selectForbiddenKeywords(fieldValue).then(response => {
|
|
|
if (response.code === 200 && !response.data) {
|
|
|
// 包含禁用词
|
|
|
- this.ingredientError = response.data.msg || '成分包含禁用关键字';
|
|
|
+ const errorMsg = response.msg || '内容包含禁用关键字';
|
|
|
+
|
|
|
+ // 根据字段类型设置不同的错误提示变量
|
|
|
+ if (fieldName === 'ingredient') {
|
|
|
+ this.ingredientError = errorMsg;
|
|
|
+ } else if (fieldName === 'productName') {
|
|
|
+ this.productNameError = errorMsg;
|
|
|
+ }
|
|
|
+
|
|
|
// 设置表单验证错误状态
|
|
|
this.$nextTick(() => {
|
|
|
if (this.$refs.form) {
|
|
|
- this.$refs.form.validateField('ingredient');
|
|
|
+ this.$refs.form.validateField(fieldName);
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
- this.ingredientError = '';
|
|
|
+ // 清除对应字段的错误提示
|
|
|
+ if (fieldName === 'ingredient') {
|
|
|
+ this.ingredientError = '';
|
|
|
+ } else if (fieldName === 'productName') {
|
|
|
+ this.productNameError = '';
|
|
|
+ }
|
|
|
+
|
|
|
// 清除验证状态
|
|
|
this.$nextTick(() => {
|
|
|
if (this.$refs.form) {
|
|
|
- this.$refs.form.clearValidate('ingredient');
|
|
|
+ this.$refs.form.clearValidate(fieldName);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -1883,7 +1916,7 @@ export default {
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
- //用来清除验证信息
|
|
|
+ // 用来清除验证信息
|
|
|
onIngredientInput() {
|
|
|
if (this.ingredientError) {
|
|
|
this.ingredientError = '';
|
|
|
@@ -1894,6 +1927,17 @@ export default {
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
+ // 添加清除商品名称验证信息的方法
|
|
|
+ onProductNameInput() {
|
|
|
+ if (this.productNameError) {
|
|
|
+ this.productNameError = '';
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (this.$refs.form) {
|
|
|
+ this.$refs.form.clearValidate('productName');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
// 当商品分类或所属店铺改变时触发
|
|
|
onCategoryOrStoreChange() {
|
|
|
// 使用防抖机制,避免频繁调用
|