x
This commit is contained in:
@@ -8,6 +8,7 @@ const { state, loadCustomers } = useInventory()
|
||||
|
||||
const showModal = ref(false)
|
||||
const editingItem = ref<any>(null)
|
||||
const saving = ref(false)
|
||||
const form = reactive({
|
||||
name: '',
|
||||
contact_person: '',
|
||||
@@ -37,6 +38,12 @@ function editCustomer(item: any) {
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
if (!form.name || !form.name.trim()) {
|
||||
addNotification('请输入客户名称', 'warning')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const payload = {
|
||||
name: form.name,
|
||||
@@ -62,6 +69,8 @@ async function save() {
|
||||
loadCustomers()
|
||||
} catch (e) {
|
||||
handleApiError(e, '保存客户')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,8 +137,8 @@ onMounted(() => { loadCustomers() })
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<template #footer>
|
||||
<t-button @click="showModal = false">取消</t-button>
|
||||
<t-button type="primary" @click="save">保存</t-button>
|
||||
<t-button @click="showModal = false" :disabled="saving">取消</t-button>
|
||||
<t-button type="primary" :loading="saving" :disabled="saving" @click="save">保存</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</div>
|
||||
|
||||
@@ -8,6 +8,7 @@ const { state, loadInventory, ensureStockBaseData } = useInventory()
|
||||
|
||||
const showModal = ref(false)
|
||||
const editingItem = ref<any>(null)
|
||||
const saving = ref(false)
|
||||
const form = reactive({
|
||||
product_id: null as number | null,
|
||||
warehouse_id: null as number | null,
|
||||
@@ -42,6 +43,24 @@ function openEdit(item: any) {
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
if (!form.product_id) {
|
||||
addNotification('请选择物料', 'warning')
|
||||
return
|
||||
}
|
||||
if (!form.warehouse_id) {
|
||||
addNotification('请选择仓库', 'warning')
|
||||
return
|
||||
}
|
||||
if (form.quantity < 0) {
|
||||
addNotification('数量不能为负数', 'warning')
|
||||
return
|
||||
}
|
||||
if (form.locked_quantity > form.quantity) {
|
||||
addNotification('锁定数量不能大于库存数量', 'warning')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const payload = {
|
||||
product_id: form.product_id,
|
||||
@@ -68,6 +87,8 @@ async function save() {
|
||||
loadInventory()
|
||||
} catch (e) {
|
||||
handleApiError(e, '保存物料库存')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,8 +160,8 @@ onMounted(() => { loadInventory() })
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<template #footer>
|
||||
<t-button @click="showModal = false">取消</t-button>
|
||||
<t-button type="primary" @click="save">保存</t-button>
|
||||
<t-button @click="showModal = false" :disabled="saving">取消</t-button>
|
||||
<t-button type="primary" :loading="saving" :disabled="saving" @click="save">保存</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</div>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -13,6 +13,7 @@ const {
|
||||
|
||||
const showModal = ref(false)
|
||||
const editingItem = ref<any>(null)
|
||||
const saving = ref(false)
|
||||
const form = ref<any>({})
|
||||
const bomItems = ref<any[]>([])
|
||||
|
||||
@@ -61,6 +62,7 @@ function removeBomItem(index: number) {
|
||||
}
|
||||
|
||||
async function saveProduct() {
|
||||
if (saving.value) return
|
||||
if (!form.value.sku) {
|
||||
addNotification('请输入SKU', 'warning')
|
||||
return
|
||||
@@ -69,6 +71,7 @@ async function saveProduct() {
|
||||
addNotification('请输入名称', 'warning')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
if (editingItem.value) {
|
||||
await apiRequest(`/api/products/${editingItem.value.id}`, {
|
||||
@@ -97,6 +100,8 @@ async function saveProduct() {
|
||||
loadMaterials()
|
||||
} catch (e) {
|
||||
handleApiError(e, '保存成品')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,8 +221,8 @@ onMounted(() => { loadFinishedProducts() })
|
||||
</template>
|
||||
</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>
|
||||
</div>
|
||||
|
||||
@@ -38,12 +38,14 @@ const editingItem = ref<any>(null)
|
||||
const form = ref<any>({})
|
||||
const orderItems = ref<any[]>([])
|
||||
const purchaseWarehouseId = ref<number | null>(null)
|
||||
const saving = ref(false)
|
||||
|
||||
const showReceiveModal = ref(false)
|
||||
const receivingOrder = ref<any>(null)
|
||||
const receiveItems = ref<any[]>([])
|
||||
const receiveWarehouseId = ref<number | null>(null)
|
||||
const receiveRemark = ref('')
|
||||
const receiving = ref(false)
|
||||
|
||||
function openCreateOrder() {
|
||||
editingItem.value = null
|
||||
@@ -99,6 +101,7 @@ async function editOrder(order: any) {
|
||||
}
|
||||
|
||||
async function savePurchaseOrder() {
|
||||
if (saving.value) return
|
||||
if (!form.value.supplier_id) {
|
||||
addNotification('请选择供应商', 'warning')
|
||||
return
|
||||
@@ -117,6 +120,7 @@ async function savePurchaseOrder() {
|
||||
return
|
||||
}
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const payload = {
|
||||
supplier_id: form.value.supplier_id,
|
||||
@@ -148,6 +152,8 @@ async function savePurchaseOrder() {
|
||||
loadPurchaseOrders()
|
||||
} catch (e) {
|
||||
handleApiError(e, '保存采购订单')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +189,7 @@ async function openReceiveDialog(order: any) {
|
||||
}
|
||||
|
||||
async function receivePurchaseOrder() {
|
||||
if (receiving.value) return
|
||||
if (!receiveWarehouseId.value) {
|
||||
addNotification('请选择入库仓库', 'warning')
|
||||
return
|
||||
@@ -197,6 +204,7 @@ async function receivePurchaseOrder() {
|
||||
addNotification('请输入本次入库数量', 'warning')
|
||||
return
|
||||
}
|
||||
receiving.value = true
|
||||
try {
|
||||
await apiRequest(`/api/purchase-orders/${receivingOrder.value.id}/receive`, {
|
||||
method: 'POST',
|
||||
@@ -215,6 +223,8 @@ async function receivePurchaseOrder() {
|
||||
loadMovements()
|
||||
} catch (e) {
|
||||
handleApiError(e, '采购入库')
|
||||
} finally {
|
||||
receiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,8 +466,8 @@ onMounted(() => {
|
||||
订单总金额:{{ formatCurrency(orderTotalAmount) }}
|
||||
</div>
|
||||
<template #footer>
|
||||
<t-button @click="showModal = false">取消</t-button>
|
||||
<t-button type="primary" @click="savePurchaseOrder">保存</t-button>
|
||||
<t-button @click="showModal = false" :disabled="saving">取消</t-button>
|
||||
<t-button type="primary" :loading="saving" :disabled="saving" @click="savePurchaseOrder">保存</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
|
||||
@@ -501,8 +511,8 @@ onMounted(() => {
|
||||
</t-table-column>
|
||||
</t-table>
|
||||
<template #footer>
|
||||
<t-button @click="showReceiveModal = false">取消</t-button>
|
||||
<t-button type="primary" @click="receivePurchaseOrder">确认入库</t-button>
|
||||
<t-button @click="showReceiveModal = false" :disabled="receiving">取消</t-button>
|
||||
<t-button type="primary" :loading="receiving" :disabled="receiving" @click="receivePurchaseOrder">确认入库</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</div>
|
||||
|
||||
@@ -38,10 +38,20 @@ const editingItem = ref<any>(null)
|
||||
const form = ref<any>({})
|
||||
const moldItems = ref<any[]>([])
|
||||
const productionWarehouseId = ref<number | null>(null)
|
||||
const saving = ref(false)
|
||||
|
||||
const showConsumptionModal = ref(false)
|
||||
const consumptionItems = ref<any[]>([])
|
||||
const consumedMaterials = ref<any[]>([])
|
||||
const consuming = ref(false)
|
||||
|
||||
// 删除守卫:已收款/已交付/已作废/有收款记录 的订单禁止删除(与后端一致)
|
||||
function isSalesOrderDeleteLocked(row: any): boolean {
|
||||
return row.payment_status === 'paid'
|
||||
|| row.delivery_status === 'delivered'
|
||||
|| row.delivery_status === 'cancelled'
|
||||
|| (Number(row.received_amount || 0) > 0)
|
||||
}
|
||||
|
||||
function openCreateOrder() {
|
||||
editingItem.value = null
|
||||
@@ -117,6 +127,7 @@ async function editOrder(order: any) {
|
||||
}
|
||||
|
||||
async function saveSalesOrder() {
|
||||
if (saving.value) return
|
||||
if (!form.value.customer_id) {
|
||||
addNotification('请选择客户', 'warning')
|
||||
return
|
||||
@@ -125,6 +136,33 @@ async function saveSalesOrder() {
|
||||
addNotification('请至少添加一个模具', 'warning')
|
||||
return
|
||||
}
|
||||
for (const [i, item] of moldItems.value.entries()) {
|
||||
const idx = i + 1
|
||||
if (item.mold_mode === 'new') {
|
||||
if (!item.mold_sku || !String(item.mold_sku).trim()) {
|
||||
addNotification(`第 ${idx} 行:新模请填写模具SKU`, 'warning')
|
||||
return
|
||||
}
|
||||
if (!item.mold_name || !String(item.mold_name).trim()) {
|
||||
addNotification(`第 ${idx} 行:新模请填写模具名称`, 'warning')
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if (!item.mold_id) {
|
||||
addNotification(`第 ${idx} 行:改模请选择已有模具`, 'warning')
|
||||
return
|
||||
}
|
||||
}
|
||||
if (!item.quantity || item.quantity <= 0) {
|
||||
addNotification(`第 ${idx} 行:数量必须大于 0`, 'warning')
|
||||
return
|
||||
}
|
||||
if (!item.unit_price || item.unit_price < 0) {
|
||||
addNotification(`第 ${idx} 行:单价不能为负`, 'warning')
|
||||
return
|
||||
}
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const payload = {
|
||||
customer_id: form.value.customer_id,
|
||||
@@ -164,13 +202,19 @@ async function saveSalesOrder() {
|
||||
loadMovements()
|
||||
} catch (e) {
|
||||
handleApiError(e, '保存销售订单')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteOrder(id: number) {
|
||||
if (!await confirmDialog('删除确认', '确定要删除这个销售订单吗?', 'warning', '删除', '取消')) return
|
||||
async function deleteOrder(row: any) {
|
||||
if (isSalesOrderDeleteLocked(row)) {
|
||||
addNotification('已收款/已交付/已作废或有收款记录的订单不可删除,请先作废相关收款单', 'warning')
|
||||
return
|
||||
}
|
||||
if (!await confirmDialog('删除确认', '确定要删除这个销售订单吗?删除将自动回补已扣减的物料。', 'warning', '删除', '取消')) return
|
||||
try {
|
||||
await apiRequest(`/api/sales-orders/${id}`, { method: 'DELETE' })
|
||||
await apiRequest(`/api/sales-orders/${row.id}`, { method: 'DELETE' })
|
||||
addNotification('销售订单已删除', 'success')
|
||||
loadProductionOrders()
|
||||
loadInventory()
|
||||
@@ -239,11 +283,24 @@ const consumptionTotalAmount = computed(() => {
|
||||
})
|
||||
|
||||
async function saveConsumption() {
|
||||
if (consuming.value) return
|
||||
if (!editingItem.value) return
|
||||
if (!consumptionItems.value || consumptionItems.value.length === 0) {
|
||||
addNotification('请至少添加一个消耗物料', 'warning')
|
||||
return
|
||||
}
|
||||
for (const [i, item] of consumptionItems.value.entries()) {
|
||||
const idx = i + 1
|
||||
if (!item.material_id) {
|
||||
addNotification(`第 ${idx} 行:请选择物料`, 'warning')
|
||||
return
|
||||
}
|
||||
if (!item.quantity || item.quantity <= 0) {
|
||||
addNotification(`第 ${idx} 行:数量必须大于 0`, 'warning')
|
||||
return
|
||||
}
|
||||
}
|
||||
consuming.value = true
|
||||
try {
|
||||
const payload = {
|
||||
items: consumptionItems.value.map((item: any) => ({
|
||||
@@ -275,6 +332,8 @@ async function saveConsumption() {
|
||||
loadMovements()
|
||||
} catch (e) {
|
||||
handleApiError(e, '保存物料消耗')
|
||||
} finally {
|
||||
consuming.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,7 +431,7 @@ onMounted(() => {
|
||||
:disabled="row.payment_status === 'paid' || row.delivery_status === 'cancelled'"
|
||||
@click="editOrder(row)"
|
||||
>编辑</t-button>
|
||||
<t-button type="danger" size="small" @click="deleteOrder(row.id)">删除</t-button>
|
||||
<t-button type="danger" size="small" :disabled="isSalesOrderDeleteLocked(row)" @click="deleteOrder(row)">删除</t-button>
|
||||
<t-button
|
||||
v-if="row.payment_status !== 'paid' && row.delivery_status !== 'cancelled'"
|
||||
type="info" size="small"
|
||||
@@ -500,8 +559,8 @@ onMounted(() => {
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<t-button @click="showModal = false">取消</t-button>
|
||||
<t-button type="primary" @click="saveSalesOrder">保存</t-button>
|
||||
<t-button @click="showModal = false" :disabled="saving">取消</t-button>
|
||||
<t-button type="primary" :loading="saving" :disabled="saving" @click="saveSalesOrder">保存</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
|
||||
@@ -563,8 +622,8 @@ onMounted(() => {
|
||||
消耗总金额:{{ formatCurrency(consumptionTotalAmount) }}
|
||||
</div>
|
||||
<template #footer>
|
||||
<t-button @click="showConsumptionModal = false">取消</t-button>
|
||||
<t-button type="primary" @click="saveConsumption">保存消耗</t-button>
|
||||
<t-button @click="showConsumptionModal = false" :disabled="consuming">取消</t-button>
|
||||
<t-button type="primary" :loading="consuming" :disabled="consuming" @click="saveConsumption">保存消耗</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</div>
|
||||
|
||||
@@ -8,6 +8,7 @@ const { state, loadSuppliers } = useInventory()
|
||||
|
||||
const showModal = ref(false)
|
||||
const editingItem = ref<any>(null)
|
||||
const saving = ref(false)
|
||||
const form = reactive({
|
||||
name: '',
|
||||
contact_person: '',
|
||||
@@ -37,6 +38,12 @@ function editSupplier(item: any) {
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
if (!form.name || !form.name.trim()) {
|
||||
addNotification('请输入供应商名称', 'warning')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const payload = {
|
||||
name: form.name,
|
||||
@@ -62,6 +69,8 @@ async function save() {
|
||||
loadSuppliers()
|
||||
} catch (e) {
|
||||
handleApiError(e, '保存供应商')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,8 +137,8 @@ onMounted(() => { loadSuppliers() })
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<template #footer>
|
||||
<t-button @click="showModal = false">取消</t-button>
|
||||
<t-button type="primary" @click="save">保存</t-button>
|
||||
<t-button @click="showModal = false" :disabled="saving">取消</t-button>
|
||||
<t-button type="primary" :loading="saving" :disabled="saving" @click="save">保存</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user