+
+
-
- +
-
-
-
-
-
- -
-
- +
+ +
-
-
-
-
+ >
@@ -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 @@
-
-
-
-
-
+
+
-
+
-
+
-
+
-
- ¥{{ scope.row.salePrice }}
+
+ ¥{{ scope.row.marketPrice }}
-
-
-
- {{
- scope.row.productSpecificationList[0]?.attributeValue ||
- "默认规格"
- }}
-
-
- 多规格
-
- 默认规格
-
-
-
+
- 添加为积分商品
+ 添加为积分换购商品
+
+
+ 添加为积分优惠购商品
@@ -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");