diff --git a/src/api/modules/marketing.js b/src/api/modules/marketing.js index 1b80e14..ea1e4b4 100644 --- a/src/api/modules/marketing.js +++ b/src/api/modules/marketing.js @@ -215,6 +215,15 @@ export const marketing = { }); }, + // 积分商品启用状态切换 + reverseEnableMemberUnitPointsProduct: data => { + return $http.request({ + url: `/merchant-api/memberUnitPointsProduct/reverseEnable`, + method: "post", + data + }); + }, + // 修改积分商品 updateMembershipPointsProduct: data => { return $http.request({ diff --git a/src/api/modules/mer_admin.js b/src/api/modules/mer_admin.js index d7afd13..3055847 100644 --- a/src/api/modules/mer_admin.js +++ b/src/api/modules/mer_admin.js @@ -51,6 +51,10 @@ export const mer_admin = { data ); }, + //商品规格分页 + getProductSpecificationPage: data => { + return $http.post(`/merchant-api/product/specification/page`, data); + }, //商品概况 getProductOverview: data => { return $http.post(`/merchant-api/product/overview`, data); diff --git a/src/views/modules/marketing/points-mall/index.vue b/src/views/modules/marketing/points-mall/index.vue index 7e047a5..ded4900 100644 --- a/src/views/modules/marketing/points-mall/index.vue +++ b/src/views/modules/marketing/points-mall/index.vue @@ -172,6 +172,21 @@ export default { : []; this.$refs.productSelector.show(shopIdList); }, + handleEnableChange(row) { + // 调用启用状态切换接口 + this.$api.marketing + .reverseEnableMemberUnitPointsProduct({ id: row.id }) + .then(() => { + this.$message.success("状态切换成功"); + this.$refs.oTable.reload(); + }) + .catch(err => { + console.error("状态切换失败:", err); + this.$message.error("状态切换失败"); + // 恢复原状态 + row.enable = !row.enable; + }); + }, reset() { this.formInline = { unitType: @@ -258,7 +273,16 @@ export default { { title: "启用状态", align: "center", - field: "enable" + field: "enable", + type: "jsx", + render: ({ row }) => { + return ( + this.handleEnableChange(row)} + > + ); + } }, { title: "操作", @@ -273,7 +297,11 @@ export default { productId: row.productId, productName: row.productName, shopName: row.shopName, - productSpecName: row.productSpecName + productSpecName: row.productSpecName, + productSpecId: row.productSpecId, + attributeValue: row.productSpecName, + marketPrice: row.marketPrice, + surplusInventory: row.surplusInventory }; // 直接使用列表中的数据作为编辑数据 @@ -282,6 +310,8 @@ export default { shopId: row.shopId, productId: row.productId, productSpecId: row.productSpecId, + attributeValue: row.productSpecName, + marketPrice: row.marketPrice, exchangeRequiredPoints: row.exchangeRequiredPoints, exchangeInventory: row.exchangeInventory, exchangeRestrictions: row.exchangeRestrictions, diff --git a/src/views/modules/marketing/points-mall/popup/points-product-config.vue b/src/views/modules/marketing/points-mall/popup/points-product-config.vue index df46400..4db8a84 100644 --- a/src/views/modules/marketing/points-mall/popup/points-product-config.vue +++ b/src/views/modules/marketing/points-mall/popup/points-product-config.vue @@ -12,39 +12,31 @@
商品ID: - {{ - isEdit ? editProductData.productId : productData.id - }} + {{ productData.productId }}
商品名称: - {{ - isEdit ? editProductData.productName : productData.name - }} + {{ productData.productName }}
归属摊位: - {{ - isEdit ? editProductData.shopName : productData.shopId - }} + {{ productData.shopName }}
-
- 商品描述: - {{ productData.description }} +
+ 规格名称: + {{ productData.attributeValue }}
-
- 价格范围: - ¥{{ productData.minSalePrice }} - ¥{{ - productData.maxSalePrice - }} +
+ SKU-ID: + {{ productData.productSpecId }} +
+
+ 商品原价: + ¥{{ productData.marketPrice }}
- 商品规格: - {{ - editProductData.productSpecName || "默认规格" - }} + 当前剩余库存: + {{ productData.surplusInventory }}
@@ -53,38 +45,45 @@ - - - + - - {{ spec.attributeValue }} - ¥{{ spec.salePrice }} - - + + + +
- + + + 积分优惠购 + 积分换购 + + + +
- -
+ +
- - + -
-
- - -
- - - - + + +
- - - - + > @@ -172,8 +156,6 @@ export default { isEdit: false, submitting: false, productData: {}, - editProductData: {}, // 编辑模式下的商品数据 - productSpecificationList: [], configForm: { id: undefined, shopId: undefined, @@ -181,98 +163,66 @@ export default { productSpecId: undefined, exchangeRequiredPoints: 1, exchangeInventory: 10, - exchangeRestrictions: 0, - exchangeRestrictionsType: 1 + exchangePointsType: 1, // 1: 积分换购, 2: 积分优惠购 + exchangeRequiredAmount: "" }, configRules: { exchangeRequiredPoints: [ - { required: true, message: "请设置兑换所需积分", trigger: "blur" } + { required: true, message: "请设置所需积分", trigger: "blur" } ], exchangeInventory: [ - { required: true, message: "请设置兑换库存", trigger: "blur" } + { required: true, message: "请设置库存", trigger: "blur" } ], - exchangeRestrictions: [ - { required: true, message: "请设置兑换限制", trigger: "blur" } + exchangePointsType: [ + { required: true, message: "请选择积分类型", trigger: "change" } ], - exchangeRestrictionsType: [ - { required: true, message: "请选择兑换限制类型", trigger: "change" } + exchangeRequiredAmount: [ + { + required: true, + message: "请输入优惠购价格", + trigger: "blur", + validator: (rule, value, callback) => { + if (this.configForm.exchangePointsType === 2 && !value) { + callback(new Error("请输入优惠购价格")); + } else { + callback(); + } + } + } ] } }; }, - 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) { + show(productData, editData = null, exchangeType = 1) { 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 || 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, - exchangeRestrictionsType: editData.exchangeRestrictionsType || 1 + exchangeInventory: 0, // 编辑模式下默认为0,表示增加库存 + exchangePointsType: editData.exchangePointsType || 1, + exchangeRequiredAmount: editData.exchangeRequiredAmount || "" }; } else { // 新增模式,使用默认值 - const defaultSpecId = - this.productSpecificationList.length === 1 - ? this.productSpecificationList[0].id - : undefined; - this.configForm = { id: undefined, shopId: productData.shopId || undefined, - productId: productData.id || undefined, - productSpecId: defaultSpecId, + productId: productData.productId || undefined, + productSpecId: productData.id || undefined, // 使用规格ID exchangeRequiredPoints: 1, exchangeInventory: 10, - exchangeRestrictions: 0, - exchangeRestrictionsType: 1 + exchangePointsType: exchangeType, // 使用传入的积分类型 + exchangeRequiredAmount: "" }; } }, @@ -282,8 +232,6 @@ export default { }, resetForm() { this.productData = {}; - this.editProductData = {}; - this.productSpecificationList = []; this.configForm = { id: undefined, shopId: undefined, @@ -291,8 +239,8 @@ export default { productSpecId: undefined, exchangeRequiredPoints: 1, exchangeInventory: 10, - exchangeRestrictions: 0, - exchangeRestrictionsType: 1 + exchangePointsType: 1, + exchangeRequiredAmount: "" }; this.isEdit = false; this.$refs.configForm && this.$refs.configForm.clearValidate(); @@ -302,9 +250,23 @@ export default { if (valid) { this.submitting = true; - const submitData = { - ...this.configForm - }; + let submitData; + if (this.isEdit) { + // 编辑模式使用新的参数格式 + submitData = { + id: this.configForm.id, + exchangeRequiredPoints: this.configForm.exchangeRequiredPoints, + increaseInventory: this.configForm.exchangeInventory, // 增加库存 + exchangeRequiredAmount: + this.configForm.exchangeRequiredAmount || 0, + enable: true // 默认启用 + }; + } else { + // 新增模式使用原有格式 + submitData = { + ...this.configForm + }; + } console.log(submitData); // 根据是否编辑模式调用不同的API @@ -336,7 +298,9 @@ export default { this.configForm.exchangeRequiredPoints++; }, decreaseInventory() { - if (this.configForm.exchangeInventory > 1) { + if (this.isEdit) { + this.configForm.exchangeInventory--; + } else if (this.configForm.exchangeInventory > 1) { this.configForm.exchangeInventory--; } }, @@ -350,18 +314,6 @@ 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); - } } } }; diff --git a/src/views/modules/marketing/points-mall/popup/product-selector.vue b/src/views/modules/marketing/points-mall/popup/product-selector.vue index 4a58375..73f2733 100644 --- a/src/views/modules/marketing/points-mall/popup/product-selector.vue +++ b/src/views/modules/marketing/points-mall/popup/product-selector.vue @@ -9,16 +9,12 @@
- - - - - + + - + - + - + - - + + - - - - + @@ -140,7 +120,7 @@ export default { visible: false, loading: false, searchForm: { - shopId: "", + shopName: "", productName: "", productId: "" }, @@ -155,12 +135,6 @@ export default { methods: { show(shopIdList) { this.visible = true; - // 如果传入的是数组,取第一个作为默认选中,如果是单个值则直接使用 - if (Array.isArray(shopIdList) && shopIdList.length > 0) { - this.searchForm.shopId = shopIdList[0]; - } else if (shopIdList) { - this.searchForm.shopId = shopIdList; - } this.loadProducts(); }, handleClose() { @@ -169,7 +143,7 @@ export default { }, resetData() { this.searchForm = { - shopId: "", + shopName: "", productName: "", productId: "" }; @@ -185,38 +159,33 @@ export default { this.loadProducts(); }, resetSearch() { + this.searchForm.shopName = ""; this.searchForm.productName = ""; this.searchForm.productId = ""; this.searchProducts(); }, loadProducts() { this.loading = true; - // 调用真实的商品分页API + // 调用新的商品规格分页接口 this.$api.mer_admin - .getProductPage({ - p: { - pageNumber: this.pagination.currentPage, - pageSize: this.pagination.pageSize - }, - shopId: this.searchForm.shopId, - productName: this.searchForm.productName, - productId: this.searchForm.productId, - productFilterType: "SALE", - merchantId: JSON.parse(sessionStorage.getItem("userInfo")).merchantId, - productQuerySortParam: [] + .getProductSpecificationPage({ + shopIdList: [], // 暂时忽略 + shopName: this.searchForm.shopName || "", + productName: this.searchForm.productName || "", + productId: this.searchForm.productId || "" }) .then(res => { - console.log("商品列表:", res); + console.log("商品规格列表:", res); this.productList = res.data.data.data || []; - this.pagination.total = Number(res.data.data.total || 0); + this.pagination.total = this.productList.length; // 暂时使用数组长度作为总数 this.loading = false; }) .catch(err => { - console.error("获取商品列表失败:", err); + console.error("获取商品规格列表失败:", err); this.productList = []; this.pagination.total = 0; this.loading = false; - this.$message.error("获取商品列表失败"); + this.$message.error("获取商品规格列表失败"); }); }, handleSizeChange(val) { @@ -227,9 +196,16 @@ export default { this.pagination.currentPage = val; this.loadProducts(); }, - addToPointsMall(product) { - // 打开积分商品配置弹框 - this.$refs.pointsProductConfig.show(product); + addToPointsMall(product, exchangeType) { + // 打开积分商品配置弹框,传递积分类型 + this.$refs.pointsProductConfig.show( + { + ...product, + productSpecId: product.id + }, + null, + exchangeType + ); }, handleConfigSuccess() { this.$emit("success");