|
@@ -49,30 +49,11 @@
|
|
|
<el-form ref="skuForm" :model="skuForm" :rules="skuRules" label-width="80px">
|
|
<el-form ref="skuForm" :model="skuForm" :rules="skuRules" label-width="80px">
|
|
|
<el-radio-group v-model="skuMode" size="small" class="mb-16">
|
|
<el-radio-group v-model="skuMode" size="small" class="mb-16">
|
|
|
<el-radio-button label="spec">规格变体</el-radio-button>
|
|
<el-radio-button label="spec">规格变体</el-radio-button>
|
|
|
- <el-radio-button label="linked">关联商品</el-radio-button>
|
|
|
|
|
<el-radio-button label="combo">商品组合</el-radio-button>
|
|
<el-radio-button label="combo">商品组合</el-radio-button>
|
|
|
</el-radio-group>
|
|
</el-radio-group>
|
|
|
|
|
|
|
|
- <!-- 关联商品模式 -->
|
|
|
|
|
- <template v-if="skuMode === 'linked'">
|
|
|
|
|
- <el-form-item label="显示标签">
|
|
|
|
|
- <el-input v-model="skuForm.label" placeholder="默认使用关联商品名称" />
|
|
|
|
|
- </el-form-item>
|
|
|
|
|
- <el-form-item label="关联商品">
|
|
|
|
|
- <el-button size="small" @click="openProductPicker">选择商品</el-button>
|
|
|
|
|
- <div v-if="skuForm.linkedProductId" class="linked-card">
|
|
|
|
|
- <img v-if="skuForm.linkedProductImage" :src="skuForm.linkedProductImage" class="linked-thumb" />
|
|
|
|
|
- <div>
|
|
|
|
|
- <div>{{ skuForm.linkedProductName }}</div>
|
|
|
|
|
- <div class="linked-info">¥{{ skuForm.linkedProductPrice ? (skuForm.linkedProductPrice/100).toFixed(2) : '0.00' }} | 库存 {{ skuForm.linkedProductStock }}</div>
|
|
|
|
|
- </div>
|
|
|
|
|
- <el-button size="mini" type="text" @click="openProductPicker">更换</el-button>
|
|
|
|
|
- </div>
|
|
|
|
|
- </el-form-item>
|
|
|
|
|
- </template>
|
|
|
|
|
-
|
|
|
|
|
<!-- 规格变体模式(原有) -->
|
|
<!-- 规格变体模式(原有) -->
|
|
|
- <template v-else-if="skuMode === 'spec'">
|
|
|
|
|
|
|
+ <template v-if="skuMode === 'spec'">
|
|
|
<el-form-item label="规格" prop="specs">
|
|
<el-form-item label="规格" prop="specs">
|
|
|
<el-input v-model="skuForm.specs" placeholder="例如:颜色:红色;尺码:M" />
|
|
<el-input v-model="skuForm.specs" placeholder="例如:颜色:红色;尺码:M" />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
@@ -275,23 +256,22 @@ export default {
|
|
|
price: it.childProductPrice || 0,
|
|
price: it.childProductPrice || 0,
|
|
|
childSkuSpecs: it.childSkuSpecs
|
|
childSkuSpecs: it.childSkuSpecs
|
|
|
}))
|
|
}))
|
|
|
- this.skuMode = comboRaw.length ? 'combo' : (sku.linkedProductId != null ? 'linked' : 'spec')
|
|
|
|
|
- if (this.skuMode === 'linked') {
|
|
|
|
|
- this.skuForm = {
|
|
|
|
|
- label: sku.label || '',
|
|
|
|
|
- linkedProductId: sku.linkedProductId,
|
|
|
|
|
- linkedProductName: sku.linkedProductName || '',
|
|
|
|
|
- linkedProductPrice: sku.linkedProductPrice || 0,
|
|
|
|
|
- linkedProductImage: sku.linkedProductImage || '',
|
|
|
|
|
- linkedProductStock: sku.linkedProductStock || 0,
|
|
|
|
|
- enabled: sku.enabled !== undefined ? (sku.enabled ? 1 : 0) : 1,
|
|
|
|
|
- specs: '',
|
|
|
|
|
- price: 0,
|
|
|
|
|
- originalPrice: 0,
|
|
|
|
|
- stock: 0,
|
|
|
|
|
- image: ''
|
|
|
|
|
- }
|
|
|
|
|
- } else if (this.skuMode === 'spec') {
|
|
|
|
|
|
|
+ if (sku.linkedProductId != null && !comboRaw.length) {
|
|
|
|
|
+ // 旧「关联商品」SKU → 转换为单条商品组合(保留关联,不丢数据)
|
|
|
|
|
+ this.skuMode = 'combo'
|
|
|
|
|
+ this.comboItems = [{
|
|
|
|
|
+ childProductId: sku.linkedProductId,
|
|
|
|
|
+ childSkuId: null,
|
|
|
|
|
+ quantity: 1,
|
|
|
|
|
+ name: sku.linkedProductName || ('商品#' + sku.linkedProductId),
|
|
|
|
|
+ coverImage: sku.linkedProductImage || '',
|
|
|
|
|
+ price: sku.linkedProductPrice || 0,
|
|
|
|
|
+ childSkuSpecs: ''
|
|
|
|
|
+ }]
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.skuMode = comboRaw.length ? 'combo' : 'spec'
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.skuMode === 'spec') {
|
|
|
this.skuForm = {
|
|
this.skuForm = {
|
|
|
specs: this.formatSpecsForInput(sku.specs),
|
|
specs: this.formatSpecsForInput(sku.specs),
|
|
|
price: sku.price ? (sku.price / 100) : 0,
|
|
price: sku.price ? (sku.price / 100) : 0,
|
|
@@ -321,6 +301,10 @@ export default {
|
|
|
linkedProductImage: '',
|
|
linkedProductImage: '',
|
|
|
linkedProductStock: 0
|
|
linkedProductStock: 0
|
|
|
}
|
|
}
|
|
|
|
|
+ if (sku.linkedProductId != null && !comboRaw.length) {
|
|
|
|
|
+ if (!this.skuForm.price) this.skuForm.price = (sku.linkedProductPrice || 0) / 100
|
|
|
|
|
+ if (!this.skuForm.stock) this.skuForm.stock = sku.linkedProductStock || 0
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
this.editingId = null
|
|
this.editingId = null
|
|
@@ -475,52 +459,6 @@ export default {
|
|
|
}))
|
|
}))
|
|
|
},
|
|
},
|
|
|
async handleSave() {
|
|
async handleSave() {
|
|
|
- // Linked SKU 模式不校验 specs/price/stock
|
|
|
|
|
- if (this.skuMode === 'linked') {
|
|
|
|
|
- if (!this.skuForm.linkedProductId) {
|
|
|
|
|
- this.$message.warning('请选择关联商品')
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- this.saving = true
|
|
|
|
|
- try {
|
|
|
|
|
- const payload = {
|
|
|
|
|
- productId: this.productId,
|
|
|
|
|
- linkedProductId: this.skuForm.linkedProductId,
|
|
|
|
|
- label: this.skuForm.label || null,
|
|
|
|
|
- enabled: this.skuForm.enabled,
|
|
|
|
|
- comboItems: []
|
|
|
|
|
- }
|
|
|
|
|
- if (!this.productId) {
|
|
|
|
|
- payload.id = Date.now()
|
|
|
|
|
- delete payload.productId
|
|
|
|
|
- this.pendingSkus.push(payload)
|
|
|
|
|
- this.dialogVisible = false
|
|
|
|
|
- this.$message.success('添加成功,保存商品时将自动创建SKU')
|
|
|
|
|
- this.saving = false
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- let res
|
|
|
|
|
- if (this.editingId) {
|
|
|
|
|
- payload.id = this.editingId
|
|
|
|
|
- delete payload.productId
|
|
|
|
|
- res = await updateProductSku(payload)
|
|
|
|
|
- } else {
|
|
|
|
|
- res = await createProductSku(payload)
|
|
|
|
|
- }
|
|
|
|
|
- if (res.code === 200) {
|
|
|
|
|
- await this.loadSkus()
|
|
|
|
|
- this.$message.success('保存成功')
|
|
|
|
|
- this.dialogVisible = false
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$message.error(res.message || '保存失败')
|
|
|
|
|
- }
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- this.$message.error('保存失败')
|
|
|
|
|
- } finally {
|
|
|
|
|
- this.saving = false
|
|
|
|
|
- }
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
// 商品组合模式:手填售价 + 组合明细(多商品+数量),不校验 specs
|
|
// 商品组合模式:手填售价 + 组合明细(多商品+数量),不校验 specs
|
|
|
if (this.skuMode === 'combo') {
|
|
if (this.skuMode === 'combo') {
|
|
|
if (!this.comboItems.length) { this.$message.warning('请至少添加一个组合商品'); return }
|
|
if (!this.comboItems.length) { this.$message.warning('请至少添加一个组合商品'); return }
|