优化商品关联
This commit is contained in:
@@ -234,13 +234,13 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="center">
|
<div class="center">
|
||||||
<el-button type="primary" @click="selecProductDialogRef?.show()"
|
<el-button type="primary" @click="selecProductDialogRef?.show()"
|
||||||
:disabled="goodsList.length >= goodsListMax">添加商品</el-button>
|
:disabled="ruleForm.relatedRecommendJson.length >= goodsListMax">添加商品</el-button>
|
||||||
<div class="tips">设置商品后,用户可以在商品详情页中看到推荐商品可拖动调整顺序,最多设置{{ goodsListMax }}个商品</div>
|
<div class="tips">设置商品后,用户可以在商品详情页中看到推荐商品可拖动调整顺序,最多设置{{ goodsListMax }}个商品</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div id="goods_table_drag">
|
<div id="goods_table_drag">
|
||||||
<el-table :data="goodsList" border stripe style="width: 500px;" row-key="id">
|
<el-table :data="ruleForm.relatedRecommendJson" border stripe style="width: 500px;" row-key="id">
|
||||||
<!-- 拖拽列 -->
|
<!-- 拖拽列 -->
|
||||||
<el-table-column label="排序" width="60">
|
<el-table-column label="排序" width="60">
|
||||||
<template v-slot="scope">
|
<template v-slot="scope">
|
||||||
@@ -256,7 +256,8 @@
|
|||||||
<el-table-column label="商品名称" prop="name"></el-table-column>
|
<el-table-column label="商品名称" prop="name"></el-table-column>
|
||||||
<el-table-column label="操作" width="100">
|
<el-table-column label="操作" width="100">
|
||||||
<template v-slot="scope">
|
<template v-slot="scope">
|
||||||
<el-button link type="danger" @click="goodsList.splice(scope.$index, 1)">删除</el-button>
|
<el-button link type="danger"
|
||||||
|
@click="ruleForm.relatedRecommendJson.splice(scope.$index, 1)">删除</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -314,7 +315,6 @@ import selecProductDialog from "@/views/marketing_center/group_booking/component
|
|||||||
|
|
||||||
const selecProductDialogRef = ref(null)
|
const selecProductDialogRef = ref(null)
|
||||||
const goodsListMax = ref(9)
|
const goodsListMax = ref(9)
|
||||||
const goodsList = ref<any[]>([]);
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// Sortable 需要在 el-table 渲染 tbody 后初始化,尝试多次以确保 DOM 可用
|
// Sortable 需要在 el-table 渲染 tbody 后初始化,尝试多次以确保 DOM 可用
|
||||||
@@ -343,11 +343,11 @@ onMounted(() => {
|
|||||||
if (e.oldIndex === e.newIndex) return;
|
if (e.oldIndex === e.newIndex) return;
|
||||||
const from = e.oldIndex;
|
const from = e.oldIndex;
|
||||||
const to = e.newIndex;
|
const to = e.newIndex;
|
||||||
const item = goodsList.value.splice(from, 1)[0];
|
const item = ruleForm.relatedRecommendJson.splice(from, 1)[0];
|
||||||
goodsList.value.splice(to, 0, item);
|
ruleForm.relatedRecommendJson.splice(to, 0, item);
|
||||||
// 触发响应式更新
|
// 触发响应式更新
|
||||||
goodsList.value = goodsList.value.slice();
|
ruleForm.relatedRecommendJson = ruleForm.relatedRecommendJson.slice();
|
||||||
console.log("排序后的数据", goodsList.value);
|
console.log("排序后的数据", ruleForm.relatedRecommendJson);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -359,12 +359,17 @@ onMounted(() => {
|
|||||||
|
|
||||||
// 已选择的商品
|
// 已选择的商品
|
||||||
function selecProductSuccess(res: any) {
|
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) {
|
if (obj && obj.id) {
|
||||||
ElMessage.error("该商品已选择");
|
ElMessage.error("该商品已选择");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
goodsList.value.push({ ...res });
|
ruleForm.relatedRecommendJson.push({ ...res });
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagsViewStore = useTagsViewStore();
|
const tagsViewStore = useTagsViewStore();
|
||||||
@@ -432,6 +437,7 @@ interface datasForm {
|
|||||||
addGroupIndex: any;
|
addGroupIndex: any;
|
||||||
}
|
}
|
||||||
interface RuleForm {
|
interface RuleForm {
|
||||||
|
id: number | string;
|
||||||
name: string;
|
name: string;
|
||||||
shortTitle: string;
|
shortTitle: string;
|
||||||
unitId: string;
|
unitId: string;
|
||||||
@@ -456,9 +462,11 @@ interface RuleForm {
|
|||||||
sort: Number;
|
sort: Number;
|
||||||
proGroupVo: any[];
|
proGroupVo: any[];
|
||||||
selectSpecInfo: any;
|
selectSpecInfo: any;
|
||||||
|
relatedRecommendJson: any[];
|
||||||
}
|
}
|
||||||
const ruleFormRef = ref<FormInstance>();
|
const ruleFormRef = ref<FormInstance>();
|
||||||
const ruleForm = reactive<RuleForm>({
|
const ruleForm = reactive<RuleForm>({
|
||||||
|
id: '',
|
||||||
//商品名称
|
//商品名称
|
||||||
name: "",
|
name: "",
|
||||||
//商品介绍
|
//商品介绍
|
||||||
@@ -512,6 +520,7 @@ const ruleForm = reactive<RuleForm>({
|
|||||||
// 排序值
|
// 排序值
|
||||||
sort: 1,
|
sort: 1,
|
||||||
selectSpecInfo: {},
|
selectSpecInfo: {},
|
||||||
|
relatedRecommendJson: [] // 关联推荐商品
|
||||||
});
|
});
|
||||||
const rules = reactive<FormRules<RuleForm>>({
|
const rules = reactive<FormRules<RuleForm>>({
|
||||||
name: [{ required: true, message: "请输入商品名称", trigger: "blur" }],
|
name: [{ required: true, message: "请输入商品名称", trigger: "blur" }],
|
||||||
|
|||||||
Reference in New Issue
Block a user