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