feat: 积分商品增删改

This commit is contained in:
lzhizhao 2025-08-11 23:44:14 +08:00
parent f0bc66d982
commit 5ea8ca7e63
3 changed files with 205 additions and 45 deletions

View File

@ -112,21 +112,37 @@ export default {
: 2,
marketId: this.marketId,
shopId: this.shopId,
shopIdList: this.shopId ? [this.shopId] : []
shopIdList: [] // storeList
};
this.$nextTick(() => {
this.$refs.oTable.reload();
});
},
watch: {
// storeList
storeList: {
handler(newStoreList) {
if (
newStoreList &&
newStoreList.length > 0 &&
this.formInline.shopIdList.length === 0
) {
//
this.formInline.shopIdList = newStoreList.map(store => store.shopId);
}
},
immediate: true //
}
},
methods: {
queryList(pageNo, pageSize) {
// 使
const queryParams = {
shopIdList: this.formInline.shopIdList || [],
productId: this.formInline.productId || 0,
productId: this.formInline.productId || "",
productName: this.formInline.productName || "",
productSpecId: this.formInline.productSpecId || 0,
productSpecName: this.formInline.productSpecName || "",
// productSpecId: this.formInline.productSpecId || "",
// productSpecName: this.formInline.productSpecName || "",
// 使
pageNumber: pageNo,
pageSize: pageSize
@ -136,7 +152,10 @@ export default {
.membershipPointsProductPage(queryParams)
.then(res => {
console.log(res);
this.$refs.oTable.complete(res.data || [], Number(res.total || 0));
this.$refs.oTable.complete(
res.data.data.data || [],
Number(res.data.data.total || 0)
);
})
.catch(err => {
console.error("查询积分商品失败:", err);
@ -161,7 +180,7 @@ export default {
: 2,
marketId: this.marketId,
shopId: this.shopId,
shopIdList: this.shopId ? [this.shopId] : [],
shopIdList: this.storeList.map(store => store.shopId), //
productId: "",
productName: "",
productSpecId: "",
@ -251,22 +270,27 @@ export default {
width: "200px",
render: ({ row }) => {
let edit = () => {
this.$api.marketing
.PointsProductDetail({
id: row.id
})
.then(res => {
const productData = {
productId: row.productId,
productName: row.productName,
shopName: row.shopName
};
this.$refs.pointsProductConfig.show(
productData,
res.data.data
);
})
.catch(err => {});
// 使
const productData = {
productId: row.productId,
productName: row.productName,
shopName: row.shopName,
productSpecName: row.productSpecName
};
// 使
const editData = {
id: row.id,
shopId: row.shopId,
productId: row.productId,
productSpecId: row.productSpecId,
exchangeRequiredPoints: row.exchangeRequiredPoints,
exchangeInventory: row.exchangeInventory,
exchangeRestrictions: row.exchangeRestrictions,
exchangeRestrictionsType: row.exchangeRestrictionsType
};
this.$refs.pointsProductConfig.show(productData, editData);
};
let deleteProduct = () => {
this.$api.marketing

View File

@ -7,20 +7,44 @@
:close-on-click-modal="false"
@close="handleClose"
>
<!-- 已选择商品信息 -->
<div class="selected-product" v-if="!isEdit">
<!-- 商品信息显示 -->
<div class="selected-product">
<div class="product-info">
<div class="info-item">
<span class="label">商品ID</span>
<span class="value">{{ productData.productId }}</span>
<span class="value">{{
isEdit ? editProductData.productId : productData.id
}}</span>
</div>
<div class="info-item">
<span class="label">商品名称</span>
<span class="value">{{ productData.productName }}</span>
<span class="value">{{
isEdit ? editProductData.productName : productData.name
}}</span>
</div>
<div class="info-item">
<span class="label">归属摊位</span>
<span class="value">{{ productData.shopName }}</span>
<span class="value">{{
isEdit ? editProductData.shopName : productData.shopId
}}</span>
</div>
<div class="info-item" v-if="!isEdit && productData.description">
<span class="label">商品描述</span>
<span class="value">{{ productData.description }}</span>
</div>
<div class="info-item" v-if="!isEdit">
<span class="label">价格范围</span>
<span class="value"
>¥{{ productData.minSalePrice }} - ¥{{
productData.maxSalePrice
}}</span
>
</div>
<div class="info-item" v-if="isEdit">
<span class="label">商品规格</span>
<span class="value">{{
editProductData.productSpecName || "默认规格"
}}</span>
</div>
</div>
</div>
@ -29,10 +53,37 @@
<el-form
ref="configForm"
:model="configForm"
:rules="configRules"
:rules="dynamicRules"
label-width="140px"
style="margin-top: 20px"
>
<!-- 商品规格选择 -->
<el-form-item
label="商品规格"
prop="productSpecId"
required
v-if="!isEdit && productSpecificationList.length > 0"
>
<el-select
v-model="configForm.productSpecId"
placeholder="请选择商品规格"
style="width: 100%"
@change="handleSpecChange"
>
<el-option
v-for="spec in productSpecificationList"
:key="spec.id"
:label="`${spec.attributeValue} - ¥${spec.salePrice}`"
:value="spec.id"
>
<span style="float: left">{{ spec.attributeValue }}</span>
<span style="float: right; color: #8492a6; font-size: 13px"
>¥{{ spec.salePrice }}</span
>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="兑换所需积分" prop="exchangeRequiredPoints" required>
<div class="points-input">
<el-button
@ -121,11 +172,13 @@ export default {
isEdit: false,
submitting: false,
productData: {},
editProductData: {}, //
productSpecificationList: [],
configForm: {
id: 0,
shopId: 0,
productId: 0,
productSpecId: 0,
id: undefined,
shopId: undefined,
productId: undefined,
productSpecId: undefined,
exchangeRequiredPoints: 1,
exchangeInventory: 10,
exchangeRestrictions: 0,
@ -147,19 +200,58 @@ export default {
}
};
},
computed: {
//
dynamicRules() {
const rules = {
exchangeRequiredPoints: [
{ required: true, message: "请设置兑换所需积分", trigger: "blur" }
],
exchangeInventory: [
{ required: true, message: "请设置兑换库存", trigger: "blur" }
],
exchangeRestrictions: [
{ required: true, message: "请设置兑换限制", trigger: "blur" }
],
exchangeRestrictionsType: [
{ required: true, message: "请选择兑换限制类型", trigger: "change" }
]
};
//
if (!this.isEdit && this.productSpecificationList.length > 1) {
rules.productSpecId = [
{ required: true, message: "请选择商品规格", trigger: "change" }
];
}
return rules;
}
},
methods: {
show(productData, editData = null) {
this.visible = true;
this.isEdit = !!editData;
this.productData = productData;
//
this.productSpecificationList =
productData.productSpecificationList || [];
if (editData) {
//
this.editProductData = {
productId: productData.productId,
productName: productData.productName,
shopName: productData.shopName,
productSpecName: productData.productSpecName
};
this.configForm = {
id: editData.id || 0,
shopId: editData.shopId || 0,
productId: editData.productId || 0,
productSpecId: editData.productSpecId || 0,
id: editData.id || undefined,
shopId: editData.shopId || undefined,
productId: editData.productId || undefined,
productSpecId: editData.productSpecId || undefined,
exchangeRequiredPoints: editData.exchangeRequiredPoints || 1,
exchangeInventory: editData.exchangeInventory || 10,
exchangeRestrictions: editData.exchangeRestrictions || 0,
@ -167,11 +259,16 @@ export default {
};
} else {
// 使
const defaultSpecId =
this.productSpecificationList.length === 1
? this.productSpecificationList[0].id
: undefined;
this.configForm = {
id: 0,
shopId: productData.shopId || 0,
productId: productData.productId || 0,
productSpecId: productData.productSpecId || 0,
id: undefined,
shopId: productData.shopId || undefined,
productId: productData.id || undefined,
productSpecId: defaultSpecId,
exchangeRequiredPoints: 1,
exchangeInventory: 10,
exchangeRestrictions: 0,
@ -185,11 +282,13 @@ export default {
},
resetForm() {
this.productData = {};
this.editProductData = {};
this.productSpecificationList = [];
this.configForm = {
id: 0,
shopId: 0,
productId: 0,
productSpecId: 0,
id: undefined,
shopId: undefined,
productId: undefined,
productSpecId: undefined,
exchangeRequiredPoints: 1,
exchangeInventory: 10,
exchangeRestrictions: 0,
@ -206,6 +305,7 @@ export default {
const submitData = {
...this.configForm
};
console.log(submitData);
// API
const apiCall = this.isEdit
@ -250,6 +350,18 @@ export default {
},
increaseLimitQuantity() {
this.configForm.exchangeRestrictions++;
},
//
handleSpecChange(specId) {
const selectedSpec = this.productSpecificationList.find(
spec => spec.id === specId
);
if (selectedSpec) {
//
console.log("选中的规格:", selectedSpec);
//
// this.configForm.exchangeInventory = Math.min(selectedSpec.stockNum, 10);
}
}
}
};

View File

@ -9,7 +9,7 @@
<!-- 查询条件 -->
<div class="search-form">
<el-form :inline="true" :model="searchForm" class="demo-form-inline">
<el-form-item label="店铺">
<el-form-item label="店铺" v-if="storeList.length">
<el-select v-model="searchForm.shopId" placeholder="请选择店铺">
<el-option
v-for="item in storeList"
@ -58,6 +58,30 @@
<el-table-column prop="salePrice" label="商品价格" align="center">
<template slot-scope="scope"> ¥{{ scope.row.salePrice }} </template>
</el-table-column>
<el-table-column label="规格" align="center" width="120">
<template slot-scope="scope">
<span
v-if="
scope.row.productSpecificationList &&
scope.row.productSpecificationList.length <= 1
"
>
{{
scope.row.productSpecificationList[0]?.attributeValue ||
"默认规格"
}}
</span>
<span
v-else-if="
scope.row.productSpecificationList &&
scope.row.productSpecificationList.length > 1
"
>
多规格
</span>
<span v-else>默认规格</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="150">
<template slot-scope="scope">
<el-button