摘要:
货品的拼接规则是:【品牌】+货名称/假如货品名称为空时,直接选择品牌为【品牌】赋值给货品,再选择品牌,会替换【品牌】;假如货名称为【品牌】+名称,再选择品牌只会替换【品牌】,名称保留;假如删掉【品牌】+名称的【品牌】再去选择品牌,会把选中的品牌追加到名称的前面形成新的【品牌】+名称!
<el-col :span="8"><el-form-item label="品牌" prop="goodsSku.brandId"><el-select :remote-method="queryBrandList" :loading="loading" @change="handleChangeBrandName" v-model="formData.goodsSku.brandId" remote filterable placeholder="请选择品牌" clearable class="!w-240px"><el-option v-for="item in brandList" :key="item.id" :label="item.brandName" :value="item.id" /></el-select></el-form-item>
</el-col>
<el-col :span="8"><el-form-item label="货品名称" prop="goodsSku.goodsName"><el-input @change="assemblySku" v-model="formData.goodsSku.goodsName" placeholder="请输入货品名称" class="!w-240px" :disabled="disEditable" /></el-form-item>
</el-col>
// 检查商品规格中的商品名称是否存在
if (formData.value.goodsSku.goodsName) {// 获取品牌名称const brandName = formData.value.goodsSku.brandName;// 如果商品名称中已包含 [品牌名称] 格式,则替换为新的品牌名称// 否则,在商品名称前插入 [品牌名称]formData.value.goodsSku.goodsName = formData.value.goodsSku.goodsName.replace(/\[.*?\]/, `[${brandName}]`) || `[${brandName}] ${formData.value.goodsSku.goodsName}`;
} else {// 如果商品名称不存在,则创建一个新的商品名称格式,包含品牌名称formData.value.goodsSku.goodsName = `[${formData.value.goodsSku.brandName}] ${formData.value.goodsSku.goodsName}`;
}
const handleChangeBrandName = (values) => {brandList.value.forEach((date) => {if (date.id == values) {formData.value.goodsSku.brandName = date.brandName}})// assemblySku()// 处理货名if (formData.value.goodsSku.goodsName) {const brandName = formData.value.goodsSku.brandName;if(formData.value.goodsSku.goodsName.includes('[')) {formData.value.goodsSku.goodsName = formData.value.goodsSku.goodsName.replace(/\[.*?\]/, `[${brandName}]`)}else{formData.value.goodsSku.goodsName = `[${brandName}] ${formData.value.goodsSku.goodsName}`;}} else {formData.value.goodsSku.goodsName = `[${formData.value.goodsSku.brandName}] ${formData.value.goodsSku.goodsName}`;}
}