|
@@ -151,7 +151,7 @@
|
|
|
<div class="sa-m-r-16"><span class="required">*</span>{{ t('modules.goods.specificationName') }}
|
|
|
</div>
|
|
|
<el-input v-model="s.name" :placeholder="t('form.inputSpecificationName')" class="sku-key-input"
|
|
|
- @input="buildSkuPriceTable"></el-input>
|
|
|
+ @blur="handleSkuNameBlur(s)"></el-input>
|
|
|
</div>
|
|
|
<el-icon @click="deleteMainSku(k)" class="sku-key-icon">
|
|
|
<CircleCloseFilled />
|
|
@@ -164,7 +164,7 @@
|
|
|
<div v-for="(sc, c) in s.children" :key="c" class="sku-value-box sa-m-b-16">
|
|
|
<div class="sku-value-content">
|
|
|
<el-input v-model="sc.name" :placeholder="t('form.inputSpecificationValue')"
|
|
|
- class="sku-value-input" @input="buildSkuPriceTable"></el-input>
|
|
|
+ class="sku-value-input" @blur="handleSkuValueBlur(sc)"></el-input>
|
|
|
<div class="sku-value-image sa-m-l-8">
|
|
|
<sa-upload-image v-model="sc.imageList" :max-count="1" :accept="['jpg', 'jpeg', 'png']"
|
|
|
:max-size="5" :direct-upload="true" :size="30" :show-tip="false" :compact="true"
|
|
@@ -463,6 +463,22 @@ const allEditObj = ref({
|
|
|
stockThreshold: null,
|
|
|
});
|
|
|
|
|
|
+// 处理规格名称失焦 - 去除首尾空格并重新生成SKU组合
|
|
|
+const handleSkuNameBlur = (sku) => {
|
|
|
+ if (sku.name) {
|
|
|
+ sku.name = sku.name.trim();
|
|
|
+ }
|
|
|
+ buildSkuPriceTable();
|
|
|
+};
|
|
|
+
|
|
|
+// 处理规格值失焦 - 去除首尾空格并重新生成SKU组合
|
|
|
+const handleSkuValueBlur = (skuChild) => {
|
|
|
+ if (skuChild.name) {
|
|
|
+ skuChild.name = skuChild.name.trim();
|
|
|
+ }
|
|
|
+ buildSkuPriceTable();
|
|
|
+};
|
|
|
+
|
|
|
// 添加主规格
|
|
|
const addMainSku = () => {
|
|
|
formData.skus.push({
|
|
@@ -597,7 +613,9 @@ const recursionSku = (arr, k, temp) => {
|
|
|
if (found) break;
|
|
|
for (let child of sku.children) {
|
|
|
if (item == child.temp_id) {
|
|
|
- tempDetail.push(child.name);
|
|
|
+ // 确保规格值去除首尾空格
|
|
|
+ const trimmedName = child.name ? child.name.trim() : '';
|
|
|
+ tempDetail.push(trimmedName);
|
|
|
tempDetailIds.push(child.temp_id);
|
|
|
found = true;
|
|
|
break;
|
|
@@ -745,7 +763,7 @@ const dataConverter = {
|
|
|
const children = attrItem.attrValues.split(',').map((value) => ({
|
|
|
id: 0, // 子规格值没有单独的ID,保持为0
|
|
|
temp_id: tempId++,
|
|
|
- name: value.trim(),
|
|
|
+ name: value.trim(), // 确保去除首尾空格
|
|
|
pid: attrItem.id, // 使用父规格的ID
|
|
|
imageList: attrImgMap[value.trim()] || [], // 添加图片列表
|
|
|
}));
|
|
@@ -753,7 +771,7 @@ const dataConverter = {
|
|
|
skus.push({
|
|
|
id: attrItem.id || 0, // 保留原有的规格ID
|
|
|
temp_id: tempId++,
|
|
|
- name: attrItem.attrName,
|
|
|
+ name: attrItem.attrName.trim(), // 确保规格名称去除首尾空格
|
|
|
batchId: '',
|
|
|
pid: 0,
|
|
|
children: children,
|
|
@@ -812,17 +830,14 @@ const dataConverter = {
|
|
|
|
|
|
// 根据 skus 的顺序构建 goods_sku_text
|
|
|
skus.forEach((sku) => {
|
|
|
- const value = attrValueObj[sku.name];
|
|
|
+ const trimmedSkuName = sku.name ? sku.name.trim() : '';
|
|
|
+ const value = attrValueObj[trimmedSkuName] || attrValueObj[sku.name];
|
|
|
if (value) {
|
|
|
// 去除首尾空格,确保数据一致性
|
|
|
const trimmedValue = value.trim();
|
|
|
goods_sku_text.push(trimmedValue);
|
|
|
- // 找到对应的 temp_id,优先匹配trim后的值,如果找不到则匹配原值
|
|
|
- let child = sku.children.find((c) => c.name === trimmedValue);
|
|
|
- if (!child) {
|
|
|
- // 如果trim后找不到,尝试匹配原值
|
|
|
- child = sku.children.find((c) => c.name.trim() === trimmedValue);
|
|
|
- }
|
|
|
+ // 找到对应的 temp_id,优先匹配trim后的值
|
|
|
+ let child = sku.children.find((c) => c.name && c.name.trim() === trimmedValue);
|
|
|
if (child) {
|
|
|
goods_sku_temp_ids.push(child.temp_id);
|
|
|
} else {
|
|
@@ -857,14 +872,14 @@ const dataConverter = {
|
|
|
convertFrontendToBackend: (skus, sku_prices) => {
|
|
|
// 生成 attr 数据
|
|
|
const attr = skus
|
|
|
- .filter((sku) => sku.name && sku.children.length > 0)
|
|
|
+ .filter((sku) => sku.name && sku.name.trim() && sku.children.length > 0)
|
|
|
.map((sku) => ({
|
|
|
id: sku.id || 0, // 保留规格ID,新增时为0
|
|
|
- attrName: sku.name,
|
|
|
- attrValues: sku.children.map((child) => child.name).join(','),
|
|
|
+ attrName: sku.name.trim(), // 确保规格名称去除首尾空格
|
|
|
+ attrValues: sku.children.map((child) => child.name ? child.name.trim() : '').filter(name => name).join(','), // 确保规格值去除首尾空格
|
|
|
// 生成 attrImgValues 数据 - 为所有规格值生成结构,没有图片时img为空字符串
|
|
|
attrImgValues: sku.children.map((child) => ({
|
|
|
- name: child.name,
|
|
|
+ name: child.name ? child.name.trim() : '', // 确保规格值去除首尾空格
|
|
|
img: child.imageList && child.imageList.length > 0 ? child.imageList[0] : '', // 有图片取第一张,没有则为空字符串
|
|
|
})),
|
|
|
}));
|
|
@@ -878,8 +893,11 @@ const dataConverter = {
|
|
|
item.goods_sku_text.forEach((value, index) => {
|
|
|
const specName = skus[index]?.name;
|
|
|
if (specName) {
|
|
|
- attrObj[specName] = value;
|
|
|
- attrValueObj[specName] = value;
|
|
|
+ // 确保规格名称和规格值都去除首尾空格
|
|
|
+ const trimmedSpecName = specName.trim();
|
|
|
+ const trimmedValue = value ? value.trim() : '';
|
|
|
+ attrObj[trimmedSpecName] = trimmedValue;
|
|
|
+ attrValueObj[trimmedSpecName] = trimmedValue;
|
|
|
}
|
|
|
});
|
|
|
|