调整部分功能
This commit is contained in:
@@ -379,10 +379,10 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="stock" label="库存" width="80" />
|
||||
<el-table-column prop="is_available" label="状态" width="80">
|
||||
<el-table-column prop="status" label="状态" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.is_available ? 'success' : 'danger'" size="small">
|
||||
{{ row.is_available ? '可用' : '不可用' }}
|
||||
<el-tag :type="row.status === 'active' ? 'success' : 'danger'" size="small">
|
||||
{{ row.status === 'active' ? '可用' : '不可用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -698,6 +698,8 @@ const formRef = ref()
|
||||
const loading = ref(false)
|
||||
const categories = ref([])
|
||||
|
||||
const newProductId = ref(null)
|
||||
|
||||
// 计算属性:一级分类
|
||||
const primaryCategories = computed(() => {
|
||||
return categories.value.filter(cat => cat.level === 1)
|
||||
@@ -971,13 +973,17 @@ const generateCombinations = async () => {
|
||||
|
||||
try {
|
||||
const productId = route.params.id || 'new' // 如果是新建商品,使用 'new'
|
||||
await api.specifications.generateCombinations({
|
||||
const response = await api.specifications.generateCombinations({
|
||||
product_id: productId,
|
||||
spec_name_ids: selectedSpecNames.value,
|
||||
default_stock: defaultStock.value
|
||||
})
|
||||
|
||||
// console.log('生成规格组合响应:', response.data.data.product_id)
|
||||
|
||||
newProductId.value = response.data.data.product_id
|
||||
|
||||
await loadCombinations()
|
||||
loadCombinations(newProductId.value)
|
||||
generateCombinationsDialogVisible.value = false
|
||||
selectedSpecNames.value = []
|
||||
defaultStock.value = 0
|
||||
@@ -1011,14 +1017,12 @@ const loadSpecValues = async () => {
|
||||
}
|
||||
|
||||
// 加载规格组合
|
||||
const loadCombinations = async () => {
|
||||
if (!isEdit.value) return
|
||||
const loadCombinations = async (productId) => {
|
||||
|
||||
try {
|
||||
const { data } = await api.specifications.getCombinations(route.params.id)
|
||||
const { data } = await api.specifications.getCombinations(productId === undefined ? route.params.id : productId)
|
||||
combinations.value = data.data || []
|
||||
} catch (error) {
|
||||
console.error('加载规格组合失败:', error)
|
||||
combinations.value = []
|
||||
}
|
||||
}
|
||||
@@ -1045,8 +1049,9 @@ const validateSpecs = () => {
|
||||
const deleteCombination = async (combination) => {
|
||||
try {
|
||||
await api.specifications.deleteCombination(combination.id)
|
||||
await loadCombinations()
|
||||
await loadCombinations(newProductId.value)
|
||||
ElMessage.success('删除规格组合成功')
|
||||
// console.log('删除规格组合:', combination.id)
|
||||
} catch (error) {
|
||||
ElMessage.error('删除规格组合失败')
|
||||
}
|
||||
@@ -1260,7 +1265,7 @@ onMounted(async () => {
|
||||
await loadSpecNames()
|
||||
await loadSpecValues()
|
||||
if (isEdit.value) {
|
||||
await loadCombinations()
|
||||
await loadCombinations(newProductId.value ? newProductId.value : route.params.id)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -96,10 +96,10 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="stock" label="库存" width="100" />
|
||||
<el-table-column prop="is_available" label="状态" width="100">
|
||||
<el-table-column prop="status" label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.is_available ? 'success' : 'danger'">
|
||||
{{ row.is_available ? '可用' : '不可用' }}
|
||||
<el-tag :type="row.status === 'active' ? 'success' : 'danger'">
|
||||
{{ row.status === 'active' ? '可用' : '不可用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -252,7 +252,9 @@
|
||||
|
||||
<el-form-item label="是否可用">
|
||||
<el-switch
|
||||
v-model="combinationForm.is_available"
|
||||
v-model="combinationForm.status"
|
||||
active-value="active"
|
||||
inactive-value="inactive"
|
||||
active-text="可用"
|
||||
inactive-text="不可用"
|
||||
/>
|
||||
@@ -375,7 +377,7 @@ const combinationForm = reactive({
|
||||
points_adjustment: 0,
|
||||
rongdou_adjustment: 0,
|
||||
stock: 0,
|
||||
is_available: true
|
||||
status: 'active'
|
||||
})
|
||||
|
||||
const combinationRules = {
|
||||
@@ -635,7 +637,7 @@ const editCombination = (combination) => {
|
||||
points_adjustment: combination.points_adjustment || 0,
|
||||
rongdou_adjustment: combination.rongdou_adjustment || 0,
|
||||
stock: combination.stock || 0,
|
||||
is_available: combination.is_available !== false
|
||||
status: combination.status || 'active'
|
||||
})
|
||||
combinationDialogVisible.value = true
|
||||
}
|
||||
@@ -653,7 +655,7 @@ const submitCombinationForm = async () => {
|
||||
points_adjustment: combinationForm.points_adjustment,
|
||||
rongdou_adjustment: combinationForm.rongdou_adjustment,
|
||||
stock: combinationForm.stock,
|
||||
is_available: combinationForm.is_available
|
||||
status: combinationForm.status
|
||||
}
|
||||
|
||||
await api.specifications.updateCombination(combinationForm.id, submitData)
|
||||
|
||||
Reference in New Issue
Block a user