This commit is contained in:
2026-06-09 15:44:17 +08:00
parent dadde0ed5c
commit 4151e4963b
21 changed files with 112 additions and 68 deletions
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { ElMessageBox } from 'element-plus'
import { useInventory } from '../composables/useInventory'
import { apiRequest } from '@/shared/api'
import { addNotification, handleApiError } from '@/shared/notification'
@@ -139,7 +140,11 @@ async function savePurchaseOrder() {
}
async function deleteOrder(id: number) {
if (!confirm('确定要删除这个采购订单吗?')) return
try {
await ElMessageBox.confirm('确定要删除这个采购订单吗?', '删除确认', {
confirmButtonText: '删除', cancelButtonText: '取消', type: 'warning'
})
} catch { return }
try {
await apiRequest(`/api/purchase-orders/${id}`, { method: 'DELETE' })
addNotification('采购订单已删除', 'success')
@@ -205,24 +210,35 @@ async function receivePurchaseOrder() {
}
}
async function markAsPaid(orderId: number) {
if (!confirm('确认标记为已付款?')) return
try {
await apiRequest(`/api/purchase-orders/${orderId}/status`, {
method: 'PATCH',
body: JSON.stringify({ status: 'paid' })
})
addNotification('已标记为已付款', 'success')
loadPurchaseOrders()
loadMovements()
} catch (e) {
handleApiError(e, '更新状态')
async function markAsPaid(orderId: number, receiptStatus: string) {
if (receiptStatus !== 'received') {
try {
await ElMessageBox.confirm(
'该订单尚未全部收货,确定要提前付款吗?建议先完成收货后再付款。',
'非标准流程提醒',
{ confirmButtonText: '仍要付款', cancelButtonText: '取消', type: 'warning' }
)
} catch { return }
} else {
try {
await ElMessageBox.confirm('确认已向供应商支付该订单款项?', '付款确认', {
confirmButtonText: '确认付款', cancelButtonText: '取消', type: 'success'
})
} catch { return }
}
await doUpdateStatus(orderId, 'paid', '已付款')
}
async function updateStatus(orderId: number, status: string) {
const label = status === 'cancelled' ? '作废' : status
if (!confirm(`确认${label}该订单?`)) return
async function cancelOrder(orderId: number) {
try {
await ElMessageBox.confirm('确定要作废该订单吗?此操作不可撤销。', '作废确认', {
confirmButtonText: '确认作废', cancelButtonText: '取消', type: 'error'
})
} catch { return }
await doUpdateStatus(orderId, 'cancelled', '已作废')
}
async function doUpdateStatus(orderId: number, status: string, label: string) {
try {
await apiRequest(`/api/purchase-orders/${orderId}/status`, {
method: 'PATCH',
@@ -343,18 +359,18 @@ onMounted(() => {
到货入库
</el-button>
<el-button
v-if="row.receipt_status === 'received' && row.payment_status !== 'paid'"
v-if="row.payment_status !== 'paid' && row.receipt_status !== 'cancelled'"
type="warning"
size="small"
@click="markAsPaid(row.id)"
@click="markAsPaid(row.id, row.receipt_status)"
>
标记为已付款
标记已付款
</el-button>
<el-button
v-if="row.payment_status !== 'paid' && row.receipt_status !== 'cancelled'"
type="info"
size="small"
@click="updateStatus(row.id, 'cancelled')"
@click="cancelOrder(row.id)"
>
作废
</el-button>
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { ElMessageBox } from 'element-plus'
import { useInventory } from '../composables/useInventory'
import { apiRequest } from '@/shared/api'
import { addNotification, handleApiError } from '@/shared/notification'
@@ -155,7 +156,11 @@ async function saveSalesOrder() {
}
async function deleteOrder(id: number) {
if (!confirm('确定要删除这个销售订单吗?')) return
try {
await ElMessageBox.confirm('确定要删除这个销售订单吗?', '删除确认', {
confirmButtonText: '删除', cancelButtonText: '取消', type: 'warning'
})
} catch { return }
try {
await apiRequest(`/api/sales-orders/${id}`, { method: 'DELETE' })
addNotification('销售订单已删除', 'success')
@@ -167,15 +172,50 @@ async function deleteOrder(id: number) {
}
}
async function updateStatus(orderId: number, status: string) {
const label = status === 'delivered' ? '已交付' : '已收款'
if (!confirm(`确认标记为${label}?`)) return
async function markDelivered(orderId: number) {
try {
await ElMessageBox.confirm('确认该订单已交付?', '交付确认', {
confirmButtonText: '确认交付', cancelButtonText: '取消', type: 'success'
})
} catch { return }
await doUpdateStatus(orderId, 'delivered', '已交付')
}
async function markPaid(orderId: number, deliveryStatus: string) {
if (deliveryStatus !== 'delivered') {
try {
await ElMessageBox.confirm(
'当前订单尚未交付,确定要提前收款吗?建议先确认交付后再收款。',
'非标准流程提醒',
{ confirmButtonText: '仍要收款', cancelButtonText: '取消', type: 'warning' }
)
} catch { return }
} else {
try {
await ElMessageBox.confirm('确认已收到该订单款项?', '收款确认', {
confirmButtonText: '确认收款', cancelButtonText: '取消', type: 'success'
})
} catch { return }
}
await doUpdateStatus(orderId, 'paid', '已收款')
}
async function cancelOrder(orderId: number) {
try {
await ElMessageBox.confirm('确定要作废该订单吗?此操作不可撤销。', '作废确认', {
confirmButtonText: '确认作废', cancelButtonText: '取消', type: 'error'
})
} catch { return }
await doUpdateStatus(orderId, 'cancelled', '已作废')
}
async function doUpdateStatus(orderId: number, status: string, label: string) {
try {
await apiRequest(`/api/sales-orders/${orderId}/status`, {
method: 'PATCH',
body: JSON.stringify({ status })
})
addNotification(`已标记为${label}`, 'success')
addNotification(`订单已${label}`, 'success')
loadProductionOrders()
loadMovements()
} catch (e) {
@@ -325,33 +365,29 @@ onMounted(() => {
</div>
</template>
</el-table-column>
<el-table-column label="操作" width="240">
<el-table-column label="操作" width="280">
<template #default="{ row }">
<el-dropdown style="margin-right: 8px;" v-if="row.delivery_status !== 'cancelled' && row.payment_status !== 'paid'">
<el-button size="small">状态 ▾</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item v-if="row.delivery_status === 'manufacturing'" @click="updateStatus(row.id, 'delivered')">已交付</el-dropdown-item>
<el-dropdown-item v-if="row.delivery_status === 'delivered' && row.payment_status !== 'paid'" @click="updateStatus(row.id, 'paid')">已收款</el-dropdown-item>
<el-dropdown-item v-if="row.payment_status !== 'paid'" @click="updateStatus(row.id, 'cancelled')" style="color: #f56c6c;">作废</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<el-button
type="primary"
size="small"
v-if="row.delivery_status === 'manufacturing'"
type="success" size="small"
@click="markDelivered(row.id)"
>已交付</el-button>
<el-button
v-if="row.payment_status !== 'paid' && row.delivery_status !== 'cancelled'"
type="warning" size="small"
@click="markPaid(row.id, row.delivery_status)"
>已收款</el-button>
<el-button
type="primary" size="small"
:disabled="row.payment_status === 'paid' || row.delivery_status === 'cancelled'"
@click="editOrder(row)"
>
编辑
</el-button>
>编辑</el-button>
<el-button type="danger" size="small" @click="deleteOrder(row.id)">删除</el-button>
<el-button
type="danger"
size="small"
@click="deleteOrder(row.id)"
>
删除
</el-button>
v-if="row.payment_status !== 'paid' && row.delivery_status !== 'cancelled'"
type="info" size="small"
@click="cancelOrder(row.id)"
>作废</el-button>
</template>
</el-table-column>
</el-table>