x
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user