From 936832f7ba3fbcc8bdd2aee6d63502a1c09893ae Mon Sep 17 00:00:00 2001
From: gyq <875626088@qq.com>
Date: Thu, 25 Dec 2025 15:38:30 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=95=86=E5=93=81=E5=85=B3?=
=?UTF-8?q?=E8=81=94?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/views/product/indexconfig/addgoods.vue | 29 ++++++++++++++--------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/src/views/product/indexconfig/addgoods.vue b/src/views/product/indexconfig/addgoods.vue
index fc95190..05d6b2b 100644
--- a/src/views/product/indexconfig/addgoods.vue
+++ b/src/views/product/indexconfig/addgoods.vue
@@ -234,13 +234,13 @@
添加商品
+ :disabled="ruleForm.relatedRecommendJson.length >= goodsListMax">添加商品
设置商品后,用户可以在商品详情页中看到推荐商品可拖动调整顺序,最多设置{{ goodsListMax }}个商品
-
+
@@ -256,7 +256,8 @@
- 删除
+ 删除
@@ -314,7 +315,6 @@ import selecProductDialog from "@/views/marketing_center/group_booking/component
const selecProductDialogRef = ref(null)
const goodsListMax = ref(9)
-const goodsList = ref([]);
onMounted(() => {
// Sortable 需要在 el-table 渲染 tbody 后初始化,尝试多次以确保 DOM 可用
@@ -343,11 +343,11 @@ onMounted(() => {
if (e.oldIndex === e.newIndex) return;
const from = e.oldIndex;
const to = e.newIndex;
- const item = goodsList.value.splice(from, 1)[0];
- goodsList.value.splice(to, 0, item);
+ const item = ruleForm.relatedRecommendJson.splice(from, 1)[0];
+ ruleForm.relatedRecommendJson.splice(to, 0, item);
// 触发响应式更新
- goodsList.value = goodsList.value.slice();
- console.log("排序后的数据", goodsList.value);
+ ruleForm.relatedRecommendJson = ruleForm.relatedRecommendJson.slice();
+ console.log("排序后的数据", ruleForm.relatedRecommendJson);
},
});
};
@@ -359,12 +359,17 @@ onMounted(() => {
// 已选择的商品
function selecProductSuccess(res: any) {
- let obj = goodsList.value.find((item) => item.id == res.id);
+ if (res.id == ruleForm.id) {
+ ElMessage.error("不能选择当前商品");
+ return;
+ }
+
+ let obj = ruleForm.relatedRecommendJson.find((item) => item.id == res.id);
if (obj && obj.id) {
ElMessage.error("该商品已选择");
return;
}
- goodsList.value.push({ ...res });
+ ruleForm.relatedRecommendJson.push({ ...res });
}
const tagsViewStore = useTagsViewStore();
@@ -432,6 +437,7 @@ interface datasForm {
addGroupIndex: any;
}
interface RuleForm {
+ id: number | string;
name: string;
shortTitle: string;
unitId: string;
@@ -456,9 +462,11 @@ interface RuleForm {
sort: Number;
proGroupVo: any[];
selectSpecInfo: any;
+ relatedRecommendJson: any[];
}
const ruleFormRef = ref();
const ruleForm = reactive({
+ id: '',
//商品名称
name: "",
//商品介绍
@@ -512,6 +520,7 @@ const ruleForm = reactive({
// 排序值
sort: 1,
selectSpecInfo: {},
+ relatedRecommendJson: [] // 关联推荐商品
});
const rules = reactive>({
name: [{ required: true, message: "请输入商品名称", trigger: "blur" }],