x
This commit is contained in:
@@ -14,10 +14,12 @@ const {
|
||||
|
||||
const showModal = ref(false)
|
||||
const editingItem = ref<any>(null)
|
||||
const saving = ref(false)
|
||||
const form = ref<any>({})
|
||||
const showRestockModal = ref(false)
|
||||
const restockItems = ref<any[]>([])
|
||||
const restockSupplierId = ref<number | null>(null)
|
||||
const restocking = ref(false)
|
||||
|
||||
function openCreateMaterial() {
|
||||
editingItem.value = null
|
||||
@@ -42,6 +44,7 @@ async function editMaterial(product: any) {
|
||||
}
|
||||
|
||||
async function saveProduct() {
|
||||
if (saving.value) return
|
||||
if (!form.value.sku) {
|
||||
addNotification('请输入SKU', 'warning')
|
||||
return
|
||||
@@ -50,6 +53,7 @@ async function saveProduct() {
|
||||
addNotification('请输入名称', 'warning')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
if (editingItem.value) {
|
||||
await apiRequest(`/api/products/${editingItem.value.id}`, {
|
||||
@@ -70,6 +74,8 @@ async function saveProduct() {
|
||||
loadMaterials()
|
||||
} catch (e) {
|
||||
handleApiError(e, '保存物料')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +117,11 @@ const restockTotalAmount = computed(() => {
|
||||
})
|
||||
|
||||
async function saveRestock() {
|
||||
if (restocking.value) return
|
||||
if (!restockSupplierId.value) {
|
||||
addNotification('请选择供应商', 'warning')
|
||||
return
|
||||
}
|
||||
if (!restockItems.value || restockItems.value.length === 0) {
|
||||
addNotification('请至少添加一个补货物料', 'warning')
|
||||
return
|
||||
@@ -130,9 +141,10 @@ async function saveRestock() {
|
||||
return
|
||||
}
|
||||
}
|
||||
restocking.value = true
|
||||
try {
|
||||
const payload = {
|
||||
supplier_id: restockSupplierId.value || state.suppliers[0]?.id || null,
|
||||
supplier_id: restockSupplierId.value,
|
||||
expected_date: new Date().toISOString().split('T')[0],
|
||||
remark: '物料补货',
|
||||
items: restockItems.value.map((item: any) => ({
|
||||
@@ -142,10 +154,6 @@ async function saveRestock() {
|
||||
remark: item.remark
|
||||
}))
|
||||
}
|
||||
if (!payload.supplier_id) {
|
||||
addNotification('请先添加供应商', 'warning')
|
||||
return
|
||||
}
|
||||
await apiRequest('/api/purchase-orders', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload)
|
||||
@@ -153,9 +161,12 @@ async function saveRestock() {
|
||||
addNotification('采购订单创建成功', 'success')
|
||||
showRestockModal.value = false
|
||||
restockItems.value = []
|
||||
restockSupplierId.value = null
|
||||
loadPurchaseOrders()
|
||||
} catch (e) {
|
||||
handleApiError(e, '保存补货订单')
|
||||
} finally {
|
||||
restocking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,8 +245,8 @@ onMounted(() => { loadMaterials() })
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<template #footer>
|
||||
<t-button @click="showModal = false">取消</t-button>
|
||||
<t-button type="primary" @click="saveProduct">保存</t-button>
|
||||
<t-button @click="showModal = false" :disabled="saving">取消</t-button>
|
||||
<t-button type="primary" :loading="saving" :disabled="saving" @click="saveProduct">保存</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
|
||||
@@ -246,7 +257,7 @@ onMounted(() => { loadMaterials() })
|
||||
@closed="closeRestockModal"
|
||||
>
|
||||
<t-form label-width="100px" style="margin-bottom: 16px;">
|
||||
<t-form-item label="供应商">
|
||||
<t-form-item label="供应商" required>
|
||||
<t-select v-model="restockSupplierId" placeholder="请选择供应商" style="width:100%">
|
||||
<t-option
|
||||
v-for="supplier in state.suppliers"
|
||||
@@ -304,8 +315,8 @@ onMounted(() => { loadMaterials() })
|
||||
补货总金额:{{ formatCurrency(restockTotalAmount) }}
|
||||
</div>
|
||||
<template #footer>
|
||||
<t-button @click="showRestockModal = false">取消</t-button>
|
||||
<t-button type="primary" @click="saveRestock">创建采购订单</t-button>
|
||||
<t-button @click="showRestockModal = false" :disabled="restocking">取消</t-button>
|
||||
<t-button type="primary" :loading="restocking" :disabled="restocking" @click="saveRestock">创建采购订单</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user