| | |
| | | }] |
| | | } |
| | | }, |
| | | created() { |
| | | async created() { |
| | | await this.getActiveList() |
| | | this.getDetail() |
| | | this.getActiveList() |
| | | }, |
| | | methods: { |
| | | // 获取详情 |
| | |
| | | } |
| | | PlusApi.productDetail({ groupbuy_product_id: productId }).then(res => { |
| | | const detail = res.data.detail |
| | | // 在展开detail时,确保保留groupbuy_active_id的值 |
| | | this.form = { |
| | | ...this.form, // 保留初始表单结构 |
| | | ...detail, |
| | | product_name: detail.product.product_name |
| | | product_name: (detail.product && detail.product.product_name) || detail.product_name, |
| | | groupbuy_active_id: detail.groupbuy_active_id || this.form.groupbuy_active_id |
| | | } |
| | | |
| | | // 初始化表格数据 |
| | | this.form.tableData = []; |
| | | if (res.data.product_list && res.data.product_list.length > 0) { |
| | | // 使用 detail.groupbuySku 来构建表格数据 |
| | | if (detail.groupbuySku && detail.groupbuySku.length > 0) { |
| | | let arr = []; |
| | | for (let i = 0; i < res.data.product_list.length; i++) { |
| | | let item = res.data.product_list[i]; |
| | | for (let j = 0; j < item.groupbuySku.length; j++) { |
| | | let sku = item.groupbuySku[j]; |
| | | let obj = { |
| | | product_name: item.product.product_name, |
| | | product_id: item.product.product_id, |
| | | stock_num: item.product.product_stock, |
| | | spec_name: sku.product_attr, |
| | | product_price: item.product.product_price, |
| | | spec_type: item.product.spec_type, |
| | | is_delete: item.is_delete, |
| | | product_sku_id: sku.product_sku_id, |
| | | groupbuy_product_sku_id: sku.groupbuy_product_sku_id, |
| | | sales_num: item.total_sales, |
| | | groupbuy_price: sku.groupbuy_price, |
| | | groupbuy_stock: sku.groupbuy_stock, |
| | | groupbuy_product_id: sku.groupbuy_product_id, |
| | | join_num: item.join_num, |
| | | limit_num: j == 0 ? item.limit_num : 2, |
| | | groupbuy_num: j == 0 ? item.groupbuy_num : 2, |
| | | sort: j == 0 ? item.sort : 2, |
| | | sales_initial: j == 0 ? item.sales_initial : 2, |
| | | }; |
| | | arr.push(obj); |
| | | } |
| | | // 这里我们只有一个商品,但可能有多个SKU |
| | | for (let j = 0; j < detail.groupbuySku.length; j++) { |
| | | let sku = detail.groupbuySku[j]; |
| | | let obj = { |
| | | product_name: (detail.product && detail.product.product_name) || detail.product_name, |
| | | product_id: (detail.product && detail.product.product_id) || detail.product_id, |
| | | stock_num: (detail.product && detail.product.product_stock) || detail.stock_num, |
| | | spec_name: sku.product_attr, |
| | | product_price: (detail.product && detail.product.product_price) || detail.product_price, |
| | | spec_type: (detail.product && detail.product.spec_type) || detail.spec_type, |
| | | is_delete: detail.is_delete, |
| | | product_sku_id: sku.product_sku_id, |
| | | groupbuy_product_sku_id: sku.groupbuy_product_sku_id, |
| | | sales_num: detail.total_sales, |
| | | groupbuy_price: sku.groupbuy_price, |
| | | groupbuy_stock: sku.groupbuy_stock, |
| | | groupbuy_product_id: sku.groupbuy_product_id, |
| | | join_num: detail.join_num, |
| | | limit_num: detail.limit_num, |
| | | groupbuy_num: detail.groupbuy_num, |
| | | sort: detail.sort, |
| | | sales_initial: detail.sales_initial, |
| | | }; |
| | | arr.push(obj); |
| | | } |
| | | this.form.tableData = mergeTable(arr); |
| | | } else if (detail.product) { |
| | | // 如果没有SKU,使用商品信息构建一行数据 |
| | | let obj = { |
| | | product_name: detail.product && detail.product.product_name, |
| | | product_id: detail.product && detail.product.product_id, |
| | | stock_num: detail.product && detail.product.product_stock, |
| | | spec_name: "", |
| | | product_price: detail.product && detail.product.product_price, |
| | | spec_type: detail.product && detail.product.spec_type, |
| | | is_delete: detail.is_delete, |
| | | product_sku_id: (detail.product && detail.product.product_sku_id) || 0, |
| | | groupbuy_product_sku_id: 0, |
| | | sales_num: detail.total_sales, |
| | | groupbuy_price: (detail.groupbuySku && detail.groupbuySku[0] && detail.groupbuySku[0].groupbuy_price) || detail.groupbuy_price, |
| | | groupbuy_stock: (detail.groupbuySku && detail.groupbuySku[0] && detail.groupbuySku[0].groupbuy_stock) || detail.groupbuy_stock, |
| | | groupbuy_product_id: detail.groupbuy_product_id, |
| | | join_num: detail.join_num, |
| | | limit_num: detail.limit_num, |
| | | groupbuy_num: detail.groupbuy_num, |
| | | sort: detail.sort, |
| | | sales_initial: detail.sales_initial, |
| | | }; |
| | | this.form.tableData = [obj]; |
| | | } |
| | | }) |
| | | }, |
| | | // 获取活动列表 |
| | | getActiveList() { |
| | | PlusApi.activeList({}).then(res => { |
| | | return PlusApi.activeList({}).then(res => { |
| | | this.activeList = res.data.list.data |
| | | // 如果当前有选定的活动ID,确保在列表加载后仍然保留 |
| | | if (this.form && this.form.groupbuy_active_id) { |
| | | this.$nextTick(() => { |
| | | // 确保下拉框显示正确的值 |
| | | this.$set(this.form, 'groupbuy_active_id', this.form.groupbuy_active_id) |
| | | }) |
| | | } |
| | | return res |
| | | }) |
| | | }, |
| | | |
| | |
| | | this.$refs.form.validate(valid => { |
| | | if (valid) { |
| | | // 整理SKU数据 |
| | | const skuData = this.form.tableData.map(item => ({ |
| | | product_sku_id: item.product_sku_id, |
| | | groupbuy_price: item.groupbuy_price, |
| | | groupbuy_stock: item.groupbuy_stock, |
| | | product_attr: item.spec_name, |
| | | product_price: item.product_price, |
| | | groupbuy_num: item.groupbuy_num, |
| | | limit_num: item.limit_num, |
| | | sales_initial: item.sales_initial, |
| | | sort: item.sort |
| | | })); |
| | | const skuData = this.form.tableData.map(item => { |
| | | const skuItem = { |
| | | product_sku_id: item.product_sku_id, |
| | | groupbuy_price: item.groupbuy_price, |
| | | groupbuy_stock: item.groupbuy_stock, |
| | | product_attr: item.spec_name, |
| | | product_price: item.product_price, |
| | | groupbuy_num: item.groupbuy_num, |
| | | limit_num: item.limit_num, |
| | | sales_initial: item.sales_initial, |
| | | sort: item.sort |
| | | }; |
| | | |
| | | // 如果是已有SKU,保留其ID |
| | | if (item.groupbuy_product_sku_id) { |
| | | skuItem.groupbuy_product_sku_id = item.groupbuy_product_sku_id; |
| | | } |
| | | |
| | | return skuItem; |
| | | }); |
| | | |
| | | const params = { |
| | | ...this.form, |
| | |
| | | product_list: undefined // 移除临时数据 |
| | | } |
| | | |
| | | // 如果有要删除的商品ID,也要一并提交 |
| | | if (this.form.product_del_ids && this.form.product_del_ids.length > 0) { |
| | | params.product_del_ids = this.form.product_del_ids |
| | | } |
| | | |
| | | PlusApi.updateProduct(params).then(res => { |
| | | this.$message.success('更新成功') |
| | | this.$router.back() |