| | |
| | | <view class="item-label">SKU列表</view> |
| | | <view class="sku-list"> |
| | | <view class="sku-item" v-for="(sku, index) in form.model.spec_many.spec_list" :key="index"> |
| | | <view class="sku-info">{{ sku.spec_text }}</view> |
| | | <view class="sku-info"> |
| | | <text v-for="(row, rowIdx) in sku.rows" :key="rowIdx">{{ row.spec_value }}{{ rowIdx < sku.rows.length - 1 ? ' ' : '' }}</text> |
| | | </view> |
| | | <view class="form-item"> |
| | | <view class="item-label">规格图片</view> |
| | | <view class="uploader"> |
| | |
| | | placeholderText: '例如:颜色', |
| | | success: (res) => { |
| | | if (res.confirm && res.content.trim()) { |
| | | this.form.model.spec_many.spec_attr.push({ |
| | | name: res.content.trim(), |
| | | values: [] |
| | | const specName = res.content.trim(); |
| | | // 继续输入第一个规格值 |
| | | uni.showModal({ |
| | | title: '添加第一个规格值', |
| | | content: '', |
| | | editable: true, |
| | | placeholderText: '例如:红色', |
| | | success: (valueRes) => { |
| | | if (valueRes.confirm && valueRes.content.trim()) { |
| | | const specValue = valueRes.content.trim(); |
| | | // 调用API添加规格组和第一个规格值 |
| | | this._post('supplier.product.spec/addSpec', { |
| | | spec_name: specName, |
| | | spec_value: specValue |
| | | }, (response) => { |
| | | if (response.code === 1 && response.data) { |
| | | this.form.model.spec_many.spec_attr.push({ |
| | | group_id: response.data.spec_id, |
| | | name: specName, |
| | | values: [specValue], |
| | | items: [{ |
| | | item_id: response.data.spec_value_id, |
| | | spec_value: specValue |
| | | }] |
| | | }); |
| | | // 生成SKU列表 |
| | | this.generateSkuList(); |
| | | uni.showToast({ |
| | | title: '添加成功', |
| | | icon: 'success' |
| | | }); |
| | | } else { |
| | | uni.showToast({ |
| | | title: response.msg || '添加失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | }); |
| | | } else if (valueRes.confirm) { |
| | | uni.showToast({ |
| | | title: '请输入规格值', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | // 生成SKU列表 |
| | | this.generateSkuList(); |
| | | } |
| | | } |
| | | }); |
| | |
| | | placeholderText: '例如:红色', |
| | | success: (res) => { |
| | | if (res.confirm && res.content.trim()) { |
| | | const specValue = res.content.trim(); |
| | | const attr = this.form.model.spec_many.spec_attr[attrIndex]; |
| | | attr.values.push(res.content.trim()); |
| | | // 重新生成SKU列表 |
| | | this.generateSkuList(); |
| | | // 调用API添加规格值 |
| | | this._post('supplier.product.spec/addSpecValue', { |
| | | spec_id: attr.group_id, |
| | | spec_value: specValue |
| | | }, (response) => { |
| | | if (response.code === 1 && response.data) { |
| | | attr.values.push(specValue); |
| | | attr.items.push({ |
| | | item_id: response.data.spec_value_id, |
| | | spec_value: specValue |
| | | }); |
| | | // 重新生成SKU列表 |
| | | this.generateSkuList(); |
| | | uni.showToast({ |
| | | title: '添加成功', |
| | | icon: 'success' |
| | | }); |
| | | } else { |
| | | uni.showToast({ |
| | | title: response.msg || '添加失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | |
| | | // 删除规格值 |
| | | deleteSpecValue(attrIndex, valueIndex) { |
| | | const attr = this.form.model.spec_many.spec_attr[attrIndex]; |
| | | if (attr.values.length > 1) { |
| | | attr.values.splice(valueIndex, 1); |
| | | // 重新生成SKU列表 |
| | | this.generateSkuList(); |
| | | attr.values.splice(valueIndex, 1); |
| | | if (attr.items && attr.items.length > valueIndex) { |
| | | |
| | | attr.items.splice(valueIndex, 1); |
| | | } |
| | | // 重新生成SKU列表 |
| | | this.generateSkuList(); |
| | | }, |
| | | |
| | | // 生成SKU列表 |
| | |
| | | |
| | | // 生成SKU列表 |
| | | const skuList = combinations.map(comb => { |
| | | const spec_text = comb.map((val, idx) => `${attrs[idx].name}:${val}`).join('; '); |
| | | const rows = []; |
| | | const specSkuIdAttr = []; |
| | | |
| | | comb.forEach((val, idx) => { |
| | | const attr = attrs[idx]; |
| | | // 查找对应的 item_id |
| | | const itemIndex = attr.values.indexOf(val); |
| | | const itemId = (attr.items && attr.items[itemIndex]) ? attr.items[itemIndex].item_id : 0; |
| | | |
| | | rows.push({ |
| | | item_id: itemId, |
| | | spec_value: val |
| | | }); |
| | | specSkuIdAttr.push(itemId); |
| | | }); |
| | | |
| | | const spec_sku_id = specSkuIdAttr.join('_'); |
| | | |
| | | return { |
| | | spec_text, |
| | | product_sku_id: 0, |
| | | spec_sku_id, |
| | | rows, |
| | | image: [], |
| | | product_no: '', |
| | | price: '', |
| | | line_price: '', |
| | | stock: '', |
| | | weight: '', |
| | | cost_price: '', |
| | | bar_code: '' |
| | | spec_form: { |
| | | product_no: '', |
| | | product_price: '', |
| | | line_price: '', |
| | | stock_num: '', |
| | | product_weight: '', |
| | | bar_code: '' |
| | | } |
| | | }; |
| | | }); |
| | | |
| | |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // 转换spec_attr数据格式为后端期望的格式 |
| | | let submitData = JSON.parse(JSON.stringify(self.form.model)); |
| | | if (submitData.spec_type == 20 && submitData.spec_many && submitData.spec_many.spec_attr) { |
| | | submitData.spec_many.spec_attr = submitData.spec_many.spec_attr.map(attr => { |
| | | return { |
| | | group_id: attr.group_id || 0, |
| | | name: attr.name, |
| | | spec_items: attr.values.map((val, idx) => ({ |
| | | item_id: (attr.items && attr.items[idx] && attr.items[idx].item_id) ? attr.items[idx].item_id : 0, |
| | | spec_value: val |
| | | })) |
| | | }; |
| | | }); |
| | | } |
| | | |
| | | self.loading = true; |
| | | self._post('supplier.product/edit', { |
| | | product_id: self.productId, |
| | | params: JSON.stringify(self.form.model) |
| | | params: JSON.stringify(submitData) |
| | | }, (res) => { |
| | | if (res.code === 0) { |
| | | if (res.code === 1) { |
| | | uni.showToast({ |
| | | title: '保存成功' |
| | | }); |
| | |
| | | |
| | | .radio-group { |
| | | display: flex; |
| | | gap: 40rpx; |
| | | gap: 15rpx; |
| | | flex-wrap: wrap; |
| | | } |
| | | |
| | | .radio-item { |