调整库存算法
This commit is contained in:
@@ -143,14 +143,15 @@
|
|||||||
</el-col> -->
|
</el-col> -->
|
||||||
<el-col :span="6">
|
<el-col :span="6">
|
||||||
<el-form-item label="库存数量" prop="stock">
|
<el-form-item label="库存数量" prop="stock">
|
||||||
<el-input-number
|
<!-- <el-input-number
|
||||||
v-model="form.stock"
|
v-model="form.stock"
|
||||||
:min="0"
|
:min="0"
|
||||||
placeholder="请输入库存数量"
|
placeholder="请输入库存数量"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
|
|
||||||
/>
|
/> -->
|
||||||
<div class="field-tip">商品可售库存数量</div>
|
库存:{{ combinationsStock }}
|
||||||
|
<div class="field-tip">商品可售库存数量,当商品样式被设置时自动计算</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
@@ -771,6 +772,7 @@ const form = reactive({
|
|||||||
status: 'pending',
|
status: 'pending',
|
||||||
free_shipping: false
|
free_shipping: false
|
||||||
})
|
})
|
||||||
|
const combinationsStock = ref(0)
|
||||||
|
|
||||||
// 规格管理相关数据
|
// 规格管理相关数据
|
||||||
const specNames = ref([])
|
const specNames = ref([])
|
||||||
@@ -1038,11 +1040,15 @@ const loadSpecValues = async () => {
|
|||||||
|
|
||||||
// 加载规格组合
|
// 加载规格组合
|
||||||
const loadCombinations = async (productId) => {
|
const loadCombinations = async (productId) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data } = await api.specifications.getCombinations(productId === undefined ? route.params.id : productId)
|
const { data } = await api.specifications.getCombinations(productId === undefined ? route.params.id : productId)
|
||||||
combinations.value = data.data || []
|
combinations.value = data.data || []
|
||||||
|
combinationsStock.value = 0
|
||||||
|
for(const item of combinations.value){
|
||||||
|
combinationsStock.value += item.stock
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('加载规格组合失败:', error)
|
||||||
combinations.value = []
|
combinations.value = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1069,10 +1075,17 @@ 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(newProductId.value)
|
|
||||||
|
// 确保使用正确的产品ID重新加载组合
|
||||||
|
const productId = newProductId.value || route.params.id
|
||||||
|
if (productId) {
|
||||||
|
await loadCombinations(productId)
|
||||||
ElMessage.success('删除规格组合成功')
|
ElMessage.success('删除规格组合成功')
|
||||||
// console.log('删除规格组合:', combination.id)
|
} else {
|
||||||
|
ElMessage.error('无法确定产品ID,请刷新页面')
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('删除规格组合失败:', error)
|
||||||
ElMessage.error('删除规格组合失败')
|
ElMessage.error('删除规格组合失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1176,7 +1189,7 @@ const submitForm = async () => {
|
|||||||
price: form.price,
|
price: form.price,
|
||||||
points_price: form.points, // 前端 points -> 后端 points_price
|
points_price: form.points, // 前端 points -> 后端 points_price
|
||||||
rongdou_price: form.rongdou_price || 0,
|
rongdou_price: form.rongdou_price || 0,
|
||||||
stock: form.stock,
|
stock: combinationsStock.value,
|
||||||
image_url: form.image.replace('https://minio.zrbjr.com', ''), // 前端 image -> 后端 image_url
|
image_url: form.image.replace('https://minio.zrbjr.com', ''), // 前端 image -> 后端 image_url
|
||||||
images: JSON.stringify(form.images.map(img => img.replace('https://minio.zrbjr.com', ''))),
|
images: JSON.stringify(form.images.map(img => img.replace('https://minio.zrbjr.com', ''))),
|
||||||
videos: JSON.stringify(form.videos),
|
videos: JSON.stringify(form.videos),
|
||||||
|
|||||||
Reference in New Issue
Block a user