- 新增出入库记录页:先用商品编码/名称关键词搜索锁定 product_id,再按商品查询流水; 列表展示变动数量与总数量/锁定数量/可用数量「前→后」;菜单兜底同步 - 新增入库单/出库单创建独立页,出库单列表与明细适配快递、运单号字段 - 外部仓库页新增仓库快递映射配置;发货单列表支持运单号展示,恢复时提示换号后的新单号 - 登录失效处理:区分登录页校验失败与登录态失效,提示后端返回的具体原因
1005 lines
42 KiB
Vue
1005 lines
42 KiB
Vue
<script setup lang="ts">
|
||
import { computed, onMounted, reactive, ref } from 'vue'
|
||
import { useRouter } from 'vue-router'
|
||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||
import {
|
||
inboundOrderApi,
|
||
type InboundOrder,
|
||
type InboundItemPayload,
|
||
} from '@/api/inboundOrder'
|
||
import type { StockItemLine } from '@/api/stockOrder'
|
||
import { getWarehouseOptions, type WarehouseOption } from '@/api/warehouse'
|
||
import { type ProductSearchItem } from '@/api/product'
|
||
import SplitLayout from '@/components/SplitLayout.vue'
|
||
import ProductSelect from '@/components/ProductSelect.vue'
|
||
import DataTable from '@/components/DataTable.vue'
|
||
import ListPager from '@/components/ListPager.vue'
|
||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||
import VirtualSelect from '@/components/VirtualSelect.vue'
|
||
|
||
const STATUS_LABELS: Record<number, string> = {
|
||
1: '待入库', 2: '已审核', 3: '已推送', 4: '已完成', 5: '已作废', 9: '已取消',
|
||
}
|
||
const STATUS_TAGS: Record<number, string> = { 1: 'info', 2: 'warning', 3: 'primary', 4: 'success', 5: 'danger', 9: 'danger' }
|
||
|
||
const TYPE_OPTIONS = [
|
||
{ label: 'B2B入库(B2BRK)', value: 'B2BRK' },
|
||
{ label: '生产入库(SCRK)', value: 'SCRK' },
|
||
{ label: '领用入库(LYRK)', value: 'LYRK' },
|
||
{ label: '残次品入库(CCRK)', value: 'CCRK' },
|
||
{ label: '采购入库(CGRK)', value: 'CGRK' },
|
||
{ label: '调拨入库(DBRK)', value: 'DBRK' },
|
||
{ label: '其他入库(QTRK)', value: 'QTRK' },
|
||
]
|
||
const INV_TYPE_OPTIONS = [
|
||
{ label: '正品(ZP)', value: 'ZP' },
|
||
{ label: '残次(CC)', value: 'CC' },
|
||
]
|
||
const SENDER_FIELDS: Array<{ key: string; label: string }> = [
|
||
{ key: 'company', label: '公司' },
|
||
{ key: 'name', label: '姓名' },
|
||
{ key: 'mobile', label: '手机' },
|
||
{ key: 'tel', label: '电话' },
|
||
{ key: 'province', label: '省' },
|
||
{ key: 'city', label: '市' },
|
||
{ key: 'detailAddress', label: '详细地址' },
|
||
{ key: 'zipCode', label: '邮编' },
|
||
]
|
||
|
||
const warehouses = ref<WarehouseOption[]>([])
|
||
const warehouseSelectOptions = computed(() =>
|
||
warehouses.value.map((w) => ({ label: `${w.code} ${w.name}`, value: w.id })),
|
||
)
|
||
|
||
/* -------------------- 列表 -------------------- */
|
||
const query = reactive({
|
||
page: 1,
|
||
pageSize: DEFAULT_PAGE_SIZE,
|
||
bill_no: '',
|
||
status: '' as string | number,
|
||
inbound_type: '' as string | number,
|
||
})
|
||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
|
||
query,
|
||
fetcher: () => {
|
||
const params: Record<string, unknown> = { ...query }
|
||
if (!params.bill_no) delete params.bill_no
|
||
if (params.status === '') delete params.status
|
||
if (params.inbound_type === '') delete params.inbound_type
|
||
return inboundOrderApi.getList(params)
|
||
},
|
||
})
|
||
async function fetchWarehouses() {
|
||
try { warehouses.value = await getWarehouseOptions() } catch { warehouses.value = [] }
|
||
}
|
||
function reset() {
|
||
query.bill_no = ''
|
||
query.status = ''
|
||
query.inbound_type = ''
|
||
search()
|
||
}
|
||
function typeLabel(row: InboundOrder) {
|
||
return TYPE_OPTIONS.find((o) => o.value === row.inbound_type)?.label || String(row.inbound_type)
|
||
}
|
||
/** 是否已录入明细:无明细不允许审核 */
|
||
function hasItems(row: { item_kind?: number | string | null }) {
|
||
return Number(row.item_kind) > 0
|
||
}
|
||
|
||
/* -------------------- 新增 / 编辑 单据头 + 随单明细 -------------------- */
|
||
const dialogVisible = ref(false)
|
||
const submitting = ref(false)
|
||
const formRef = ref<FormInstance>()
|
||
const editId = ref<number | null>(null)
|
||
const form = reactive({
|
||
warehouse_id: null as number | null,
|
||
inbound_type: 'CGRK',
|
||
supplier: '',
|
||
supplier_code: '',
|
||
operator: '',
|
||
operator_code: '',
|
||
operate_time: '',
|
||
purchase_order_code: '',
|
||
logistics_code: '',
|
||
logistics_name: '',
|
||
express_code: '',
|
||
expect_start_time: '',
|
||
expect_end_time: '',
|
||
total_amount: 0,
|
||
remark: '',
|
||
sender_info: { name: '', mobile: '', company: '', province: '', city: '', detailAddress: '' } as Record<string, string>,
|
||
receiver_info: { name: '', mobile: '', company: '', province: '', city: '', detailAddress: '' } as Record<string, string>,
|
||
extend_props: [] as Array<{ key: string; value: string }>,
|
||
})
|
||
const rules: FormRules = {
|
||
warehouse_id: [{ required: true, message: '请选择仓库', trigger: 'change' }],
|
||
}
|
||
const router = useRouter()
|
||
/** 新增入库单改为独立整页(菜单「创建入库单」),此处仅跳转 */
|
||
function openCreate() {
|
||
router.push('/inbound-order-create')
|
||
}
|
||
async function openEdit(row: InboundOrder) {
|
||
const full = await inboundOrderApi.get(row.id)
|
||
editId.value = full.id
|
||
Object.assign(form, {
|
||
warehouse_id: full.warehouse_id ?? null,
|
||
inbound_type: full.inbound_type || 'CGRK',
|
||
supplier: full.supplier || '',
|
||
supplier_code: full.supplier_code || '',
|
||
operator: full.operator || '',
|
||
operator_code: full.operator_code || '',
|
||
operate_time: full.operate_time || '',
|
||
purchase_order_code: full.purchase_order_code || '',
|
||
logistics_code: full.logistics_code || '',
|
||
logistics_name: full.logistics_name || '',
|
||
express_code: full.express_code || '',
|
||
expect_start_time: full.expect_start_time || '',
|
||
expect_end_time: full.expect_end_time || '',
|
||
total_amount: Number(full.total_amount) || 0,
|
||
remark: full.remark || '',
|
||
sender_info: { name: '', mobile: '', company: '', province: '', city: '', detailAddress: '', ...(full.sender_info || {}) },
|
||
receiver_info: { name: '', mobile: '', company: '', province: '', city: '', detailAddress: '', ...(full.receiver_info || {}) },
|
||
extend_props: full.extend_props
|
||
? Object.entries(full.extend_props).map(([key, value]) => ({ key, value: String(value) }))
|
||
: [],
|
||
})
|
||
dialogVisible.value = true
|
||
}
|
||
|
||
function cleanObject(obj: Record<string, string>) {
|
||
const r: Record<string, string> = {}
|
||
let has = false
|
||
for (const k in obj) {
|
||
const v = obj[k]
|
||
if (v != null && String(v).trim() !== '') { r[k] = v; has = true }
|
||
}
|
||
return has ? r : null
|
||
}
|
||
function propsToObject(rows: Array<{ key: string; value: string }>) {
|
||
const r: Record<string, string> = {}
|
||
let has = false
|
||
for (const { key, value } of rows) {
|
||
if (key && key.trim()) { r[key.trim()] = value; has = true }
|
||
}
|
||
return has ? r : null
|
||
}
|
||
async function submitForm() {
|
||
if (!formRef.value) return
|
||
await formRef.value.validate(async (valid) => {
|
||
if (!valid) return
|
||
submitting.value = true
|
||
try {
|
||
const payload = {
|
||
warehouse_id: form.warehouse_id,
|
||
inbound_type: form.inbound_type,
|
||
supplier: form.supplier || null,
|
||
supplier_code: form.supplier_code || null,
|
||
operator: form.operator || null,
|
||
operator_code: form.operator_code || null,
|
||
operate_time: form.operate_time || null,
|
||
purchase_order_code: form.purchase_order_code || null,
|
||
logistics_code: form.logistics_code || null,
|
||
logistics_name: form.logistics_name || null,
|
||
express_code: form.express_code || null,
|
||
expect_start_time: form.expect_start_time || null,
|
||
expect_end_time: form.expect_end_time || null,
|
||
total_amount: form.total_amount,
|
||
remark: form.remark || null,
|
||
sender_info: cleanObject(form.sender_info),
|
||
receiver_info: cleanObject(form.receiver_info),
|
||
extend_props: propsToObject(form.extend_props),
|
||
} as Record<string, unknown>
|
||
await inboundOrderApi.update(editId.value as number, payload as any)
|
||
ElMessage.success('保存成功')
|
||
dialogVisible.value = false
|
||
await fetchList()
|
||
} catch {
|
||
// 拦截器已提示
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
})
|
||
}
|
||
|
||
/* -------------------- 状态流转 -------------------- */
|
||
const transiting = ref(false)
|
||
async function transit(action: 'audit' | 'push' | 'complete' | 'cancel' | 'restore') {
|
||
if (!currentOrder.value) return
|
||
transiting.value = true
|
||
try {
|
||
const id = currentOrder.value.id
|
||
let pushReused = false
|
||
if (action === 'audit') await inboundOrderApi.audit(id)
|
||
else if (action === 'push') {
|
||
const res = await inboundOrderApi.push(id)
|
||
pushReused = !!res?.reused
|
||
} else if (action === 'complete') await inboundOrderApi.complete(id)
|
||
else if (action === 'cancel') await inboundOrderApi.cancel(id)
|
||
else if (action === 'restore') await inboundOrderApi.restore(id)
|
||
if (pushReused) ElMessage.warning('外部仓库已存在该入库单,已按「已推送」处理(明细以仓库侧单据为准)')
|
||
else ElMessage.success('操作成功')
|
||
const map: Record<string, number> = { audit: 2, push: 3, complete: 4, cancel: 9, restore: 1 }
|
||
if (currentOrder.value) currentOrder.value.status = map[action]
|
||
// 重新拉取整单,刷新推送结果等字段
|
||
if (currentOrder.value) {
|
||
await inboundOrderApi.get(id).then(r => { currentOrder.value = r }).catch(() => {})
|
||
}
|
||
await fetchItems()
|
||
await fetchList()
|
||
} catch {
|
||
// 拦截器已提示
|
||
} finally {
|
||
transiting.value = false
|
||
}
|
||
}
|
||
async function handleDelete(row: InboundOrder) {
|
||
try {
|
||
await ElMessageBox.confirm(`确认删除入库单「${row.bill_no}」?`, '删除确认', {
|
||
type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消',
|
||
})
|
||
} catch { return }
|
||
try {
|
||
await inboundOrderApi.remove(row.id)
|
||
ElMessage.success('已删除')
|
||
if (currentOrder.value && currentOrder.value.id === row.id) {
|
||
currentOrder.value = null
|
||
editItems.value = []
|
||
}
|
||
await fetchList()
|
||
} catch {
|
||
// 拦截器已提示
|
||
}
|
||
}
|
||
/** 作废:仅「已审核(2)」可作废,需确认并可填写作废原因;作废后不可恢复 */
|
||
async function handleVoid(row: InboundOrder) {
|
||
let reason = ''
|
||
try {
|
||
const res = await ElMessageBox.prompt(
|
||
`确认作废入库单「${row.bill_no}」?作废后不可恢复。`,
|
||
'作废确认',
|
||
{
|
||
type: 'warning',
|
||
confirmButtonText: '确认作废',
|
||
cancelButtonText: '取消',
|
||
inputType: 'textarea',
|
||
inputPlaceholder: '作废原因(选填)',
|
||
inputValidator: () => true,
|
||
},
|
||
)
|
||
reason = (res.value || '').trim()
|
||
} catch { return }
|
||
try {
|
||
await inboundOrderApi.voidOrder(row.id, reason ? { void_reason: reason } : {})
|
||
ElMessage.success('已作废')
|
||
await refreshCurrent(row.id)
|
||
await fetchList()
|
||
} catch {
|
||
// 拦截器已提示
|
||
}
|
||
}
|
||
/** 驳回:已审核/已推送且未完成 -> 回到待入库;已推送的会先调外部接口取消单据 */
|
||
async function handleReject(row: InboundOrder) {
|
||
const tip = row.status === 3
|
||
? `确认驳回入库单「${row.bill_no}」?将调用外部仓库接口取消已推送的单据,并退回「待入库」。驳回后单号会自动加后缀(如 _1),再次推送将使用新单号。`
|
||
: `确认驳回入库单「${row.bill_no}」?驳回后回到「待入库」并自动加单号后缀(如 _1),可重新编辑后再次审核。`
|
||
try {
|
||
await ElMessageBox.confirm(tip, '驳回确认', {
|
||
type: 'warning', confirmButtonText: '确认驳回', cancelButtonText: '取消',
|
||
})
|
||
} catch { return }
|
||
try {
|
||
const res = await inboundOrderApi.reject(row.id)
|
||
const base = res?.cancel?.success ? '已驳回,外部入库单已取消' : '已驳回'
|
||
ElMessage.success(res?.bill_no ? `${base},单号已变更为 ${res.bill_no}` : base)
|
||
await refreshCurrent(row.id)
|
||
await fetchList()
|
||
} catch {
|
||
// 拦截器已提示
|
||
}
|
||
}
|
||
/** 若当前查看的正是被操作的这一单,重新拉取以刷新状态与统计 */
|
||
async function refreshCurrent(id: number) {
|
||
if (!currentOrder.value || currentOrder.value.id !== id) return
|
||
await inboundOrderApi.get(id).then((r) => { currentOrder.value = r }).catch(() => {})
|
||
}
|
||
|
||
/* -------------------- 明细(标签内行内编辑) -------------------- */
|
||
const itemsLoading = ref(false)
|
||
const itemSaving = ref(false)
|
||
const currentOrder = ref<InboundOrder | null>(null)
|
||
const activeDetailTab = ref('info')
|
||
const initialItemIds = ref<number[]>([])
|
||
interface EditItem {
|
||
id: number | null
|
||
product_id: number | null
|
||
name: string
|
||
code: string
|
||
spec: string
|
||
unit: string
|
||
inventory_type: 'ZP' | 'CC'
|
||
quantity: number
|
||
/** 应/已数量(系统维护,只读展示) */
|
||
plan_in_qty: number
|
||
actual_in_qty: number
|
||
plan_out_qty: number
|
||
actual_out_qty: number
|
||
price: number
|
||
remark: string
|
||
_label: string
|
||
}
|
||
function emptyRow(): EditItem {
|
||
return { id: null, product_id: null, name: '', code: '', spec: '', unit: '', inventory_type: 'ZP', quantity: 1, price: 0, remark: '', _label: '', plan_in_qty: 0, actual_in_qty: 0, plan_out_qty: 0, actual_out_qty: 0 }
|
||
}
|
||
function isEmptyRow(it: EditItem) {
|
||
return !it.product_id && !it.name && !it.code
|
||
}
|
||
const editItems = ref<EditItem[]>([])
|
||
const editTotal = computed(() =>
|
||
editItems.value.reduce((s, it) => s + (Number(it.quantity) || 0) * (Number(it.price) || 0), 0),
|
||
)
|
||
/** 明细锁定:仅「待入库(1)」可增删改明细,已审核及之后锁定(需先驳回) */
|
||
const itemsLocked = computed(() => !!currentOrder.value && currentOrder.value.status !== 1)
|
||
// 始终保留一行空行在末尾,选商品填充后可继续往下添加
|
||
function ensureTrailingEmptyRow() {
|
||
const arr = editItems.value
|
||
const last = arr[arr.length - 1]
|
||
if (!last || !isEmptyRow(last)) arr.push(emptyRow())
|
||
}
|
||
async function handleRowClick(row: InboundOrder) {
|
||
currentOrder.value = row
|
||
await fetchItems()
|
||
}
|
||
/** 列表行内直接执行状态流转,作用于对应行 */
|
||
async function transitRow(action: 'audit' | 'push' | 'complete' | 'cancel' | 'restore', row: InboundOrder) {
|
||
currentOrder.value = row
|
||
await transit(action)
|
||
}
|
||
async function fetchItems() {
|
||
if (!currentOrder.value) {
|
||
editItems.value = [emptyRow()]
|
||
initialItemIds.value = []
|
||
return
|
||
}
|
||
itemsLoading.value = true
|
||
try {
|
||
const res = await inboundOrderApi.getItems(currentOrder.value.id, { pageSize: 200 })
|
||
editItems.value = (res.list || []).map((row: StockItemLine) => ({
|
||
id: row.id,
|
||
product_id: row.product_id,
|
||
name: row.name || '',
|
||
code: row.code || '',
|
||
spec: row.spec || '',
|
||
unit: row.unit || '',
|
||
inventory_type: (row.inventory_type as 'ZP' | 'CC') || 'ZP',
|
||
quantity: Number(row.quantity) || 0,
|
||
plan_in_qty: Number(row.plan_in_qty) || 0,
|
||
actual_in_qty: Number(row.actual_in_qty) || 0,
|
||
plan_out_qty: Number(row.plan_out_qty) || 0,
|
||
actual_out_qty: Number(row.actual_out_qty) || 0,
|
||
price: Number(row.price) || 0,
|
||
remark: row.remark || '',
|
||
_label: row.product ? `${row.product.item_code} ${row.product.item_name}` : (row.code ? `${row.code} ${row.name}` : ''),
|
||
}))
|
||
initialItemIds.value = editItems.value.filter((it) => it.id != null).map((it) => it.id as number)
|
||
} catch {
|
||
editItems.value = []
|
||
} finally {
|
||
itemsLoading.value = false
|
||
ensureTrailingEmptyRow()
|
||
}
|
||
}
|
||
function onEditItemSelect(idx: number, p: ProductSearchItem) {
|
||
const it = editItems.value[idx]
|
||
if (!it) return
|
||
it.product_id = p.id
|
||
it.name = p.item_name || ''
|
||
it.code = p.item_code || ''
|
||
it.spec = p.sku_property || ''
|
||
it.unit = p.stock_unit || ''
|
||
it._label = p.item_code ? `${p.item_code} ${p.item_name}` : p.item_name
|
||
ensureTrailingEmptyRow()
|
||
}
|
||
function removeEditItem(idx: number) {
|
||
editItems.value.splice(idx, 1)
|
||
ensureTrailingEmptyRow()
|
||
}
|
||
async function saveItems() {
|
||
if (!currentOrder.value) return
|
||
itemSaving.value = true
|
||
try {
|
||
const current = editItems.value.filter((it) => !isEmptyRow(it))
|
||
const currentIds = new Set(current.filter((it) => it.id != null).map((it) => it.id as number))
|
||
// 删除已移除的明细
|
||
for (const id of initialItemIds.value) {
|
||
if (!currentIds.has(id)) await inboundOrderApi.removeItem(id)
|
||
}
|
||
// 新增 / 更新
|
||
for (const it of current) {
|
||
const payload = {
|
||
bill_id: currentOrder.value.id,
|
||
product_id: it.product_id,
|
||
name: it.name || null,
|
||
code: it.code || null,
|
||
spec: it.spec || null,
|
||
unit: it.unit || null,
|
||
quantity: it.quantity,
|
||
price: it.price,
|
||
inventory_type: it.inventory_type,
|
||
remark: it.remark || null,
|
||
} as InboundItemPayload
|
||
if (it.id != null) await inboundOrderApi.updateItem(it.id, payload)
|
||
else await inboundOrderApi.createItem(payload)
|
||
}
|
||
ElMessage.success('明细已保存')
|
||
await fetchItems()
|
||
// 刷新当前单据,使 item_kind 等统计字段同步(影响审核按钮可用状态)
|
||
if (currentOrder.value) {
|
||
await inboundOrderApi.get(currentOrder.value.id).then((r) => { currentOrder.value = r }).catch(() => {})
|
||
}
|
||
await fetchList()
|
||
} catch {
|
||
// 拦截器已提示
|
||
} finally {
|
||
itemSaving.value = false
|
||
}
|
||
}
|
||
|
||
onMounted(async () => {
|
||
await fetchWarehouses()
|
||
await fetchList()
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<el-card class="stock-card">
|
||
<template #header>
|
||
<div class="page-header">
|
||
<span>入库单</span>
|
||
<el-button type="primary" @click="openCreate">新增入库单</el-button>
|
||
</div>
|
||
</template>
|
||
|
||
<SplitLayout :first-size="400" storage-key="inbound-order-split" :show-second="!!currentOrder">
|
||
<template #first>
|
||
<el-form :inline="true" class="search-bar">
|
||
<el-form-item label="单号">
|
||
<el-input v-model="query.bill_no" placeholder="支持模糊匹配" clearable @keyup.enter="search" />
|
||
</el-form-item>
|
||
<el-form-item label="状态">
|
||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 130px">
|
||
<el-option v-for="(label, val) in STATUS_LABELS" :key="val" :label="label" :value="Number(val)" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="入库类型">
|
||
<el-select v-model="query.inbound_type" placeholder="全部" clearable style="width: 140px">
|
||
<el-option v-for="o in TYPE_OPTIONS" :key="o.value" :label="o.label" :value="o.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" @click="search">查询</el-button>
|
||
<el-button @click="reset">重置</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<div class="top-table-wrap">
|
||
<DataTable
|
||
:loading="loading"
|
||
:data="list"
|
||
highlight-current-row
|
||
class="fill-table"
|
||
@row-click="handleRowClick"
|
||
>
|
||
<el-table-column prop="bill_no" label="单号" min-width="160" />
|
||
<el-table-column label="仓库" width="150">
|
||
<template #default="{ row }">{{ row.warehouse?.name || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="类型" width="110">
|
||
<template #default="{ row }">{{ typeLabel(row) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="状态" width="90">
|
||
<template #default="{ row }">
|
||
<el-tag :type="STATUS_TAGS[row.status]">{{ STATUS_LABELS[row.status] || row.status }}</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="供应商" width="140">
|
||
<template #default="{ row }">{{ row.supplier || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作人" width="100">
|
||
<template #default="{ row }">{{ row.operator || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="创建人" width="100">
|
||
<template #default="{ row }">{{ row.creator?.nickname || row.creator?.username || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="金额" width="110" align="right">
|
||
<template #default="{ row }">{{ row.total_amount }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="商品总数" width="100" align="right">
|
||
<template #default="{ row }">{{ row.item_total ?? 0 }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="商品种类" width="100" align="right">
|
||
<template #default="{ row }">{{ row.item_kind ?? 0 }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="created_at" label="创建时间" width="180" />
|
||
<el-table-column label="操作" width="300" fixed="right">
|
||
<template #default="{ row }">
|
||
<el-button v-if="row.status === 1" link type="primary" size="small" :disabled="transiting || !hasItems(row)" @click="transitRow('audit', row)">审核</el-button>
|
||
<el-button v-if="row.status === 2" link type="primary" size="small" :disabled="transiting" @click="transitRow('push', row)">推送</el-button>
|
||
<el-button v-if="row.status === 3" link type="primary" size="small" :disabled="transiting" @click="transitRow('complete', row)">完成</el-button>
|
||
<el-button v-if="row.status === 9" link type="primary" size="small" :disabled="transiting" @click="transitRow('restore', row)">恢复</el-button>
|
||
<el-button v-if="row.status === 2 || row.status === 3" link type="warning" size="small" :disabled="transiting" @click="handleReject(row)">驳回</el-button>
|
||
<el-button v-if="row.status === 2" link type="danger" size="small" :disabled="transiting" @click="handleVoid(row)">作废</el-button>
|
||
<el-button v-if="row.status === 1 || row.status === 3" link type="danger" size="small" :disabled="transiting" @click="transitRow('cancel', row)">取消</el-button>
|
||
<el-button v-if="row.status === 1" link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
|
||
<el-button v-if="row.status === 1 || row.status === 9" link type="danger" size="small" @click="handleDelete(row)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</DataTable>
|
||
</div>
|
||
|
||
<ListPager
|
||
:total="total"
|
||
:elapsed="elapsed"
|
||
:page="query.page"
|
||
:page-size="query.pageSize"
|
||
@page-change="handlePageChange"
|
||
@size-change="handleSizeChange"
|
||
/>
|
||
</template>
|
||
|
||
<template #second>
|
||
<div class="detail-wrap" v-if="currentOrder">
|
||
<el-tabs v-model="activeDetailTab" type="border-card" class="detail-tabs">
|
||
<el-tab-pane label="单据信息" name="info">
|
||
<div class="info-pane">
|
||
<div class="order-head">
|
||
<div class="order-head-left">
|
||
<span class="order-bill-no">{{ currentOrder.bill_no }}</span>
|
||
<el-tag :type="STATUS_TAGS[currentOrder.status]" effect="dark" size="small">
|
||
{{ STATUS_LABELS[currentOrder.status] || currentOrder.status }}
|
||
</el-tag>
|
||
<span class="order-meta">{{ typeLabel(currentOrder) }}</span>
|
||
</div>
|
||
<div class="status-actions">
|
||
<el-tooltip :content="currentOrder.status !== 1 ? '仅「待入库」状态可以审核' : (!hasItems(currentOrder) ? '单据无明细,请先录入明细' : '')" :disabled="currentOrder.status === 1 && hasItems(currentOrder)">
|
||
<el-button size="small" :disabled="transiting || currentOrder.status !== 1 || !hasItems(currentOrder)" @click="transit('audit')">审核</el-button>
|
||
</el-tooltip>
|
||
<el-tooltip :content="currentOrder.status === 2 ? '' : '请先审核,仅「已审核」状态可推送到外部仓库'" :disabled="currentOrder.status === 2">
|
||
<el-button size="small" type="primary" :disabled="transiting || currentOrder.status !== 2" @click="transit('push')">推送到外部仓库</el-button>
|
||
</el-tooltip>
|
||
<el-tooltip :content="currentOrder.status === 3 ? '' : '仅「已推送」状态可完成入库'" :disabled="currentOrder.status === 3">
|
||
<el-button size="small" :disabled="transiting || currentOrder.status !== 3" @click="transit('complete')">完成</el-button>
|
||
</el-tooltip>
|
||
<el-tooltip :content="currentOrder.status === 9 ? '' : '仅「已取消」状态可恢复'" :disabled="currentOrder.status === 9">
|
||
<el-button size="small" :disabled="transiting || currentOrder.status !== 9" @click="transit('restore')">恢复</el-button>
|
||
</el-tooltip>
|
||
<el-tooltip :content="(currentOrder.status === 2 || currentOrder.status === 3) ? '' : '仅「已审核」「已推送」状态可驳回'" :disabled="currentOrder.status === 2 || currentOrder.status === 3">
|
||
<el-button size="small" type="warning" plain :disabled="transiting || (currentOrder.status !== 2 && currentOrder.status !== 3)" @click="handleReject(currentOrder)">驳回</el-button>
|
||
</el-tooltip>
|
||
<el-tooltip :content="currentOrder.status === 2 ? '' : '仅「已审核」状态可作废'" :disabled="currentOrder.status === 2">
|
||
<el-button size="small" type="danger" plain :disabled="transiting || currentOrder.status !== 2" @click="handleVoid(currentOrder)">作废</el-button>
|
||
</el-tooltip>
|
||
<el-tooltip :content="(currentOrder.status === 2 || currentOrder.status === 4 || currentOrder.status === 9) ? '已审核请使用驳回/作废;已完成/已取消不可取消' : ''" :disabled="currentOrder.status !== 2 && currentOrder.status !== 4 && currentOrder.status !== 9">
|
||
<el-button size="small" type="danger" plain :disabled="transiting || currentOrder.status === 2 || currentOrder.status === 4 || currentOrder.status === 9" @click="transit('cancel')">取消</el-button>
|
||
</el-tooltip>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="ext-wrap">
|
||
<h4>基本信息</h4>
|
||
<el-descriptions :column="3" border size="small">
|
||
<el-descriptions-item label="仓库">{{ currentOrder.warehouse?.name || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="供应商">{{ currentOrder.supplier || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="操作人">{{ currentOrder.operator || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="审核人">{{ currentOrder.auditor?.nickname || currentOrder.auditor?.username || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="审核时间">{{ currentOrder.audit_time || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="总金额">{{ currentOrder.total_amount }}</el-descriptions-item>
|
||
<el-descriptions-item v-if="currentOrder.status === 5" label="作废人">{{ currentOrder.voider?.nickname || currentOrder.voider?.username || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item v-if="currentOrder.status === 5" label="作废时间">{{ currentOrder.void_at || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item v-if="currentOrder.status === 5" label="作废原因">{{ currentOrder.void_reason || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="备注" :span="3">{{ currentOrder.remark || '-' }}</el-descriptions-item>
|
||
</el-descriptions>
|
||
|
||
<h4>收件信息 <span class="hint">receiverInfo</span></h4>
|
||
<el-descriptions v-if="currentOrder.receiver_info" :column="2" border size="small">
|
||
<el-descriptions-item v-for="f in SENDER_FIELDS" :key="'r' + f.key" :label="f.label">
|
||
{{ currentOrder.receiver_info[f.key] || '-' }}
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
<p v-else class="muted">无</p>
|
||
|
||
<h4>WMS 推送结果</h4>
|
||
<template v-if="currentOrder.wms_push_result">
|
||
<el-descriptions :column="2" border size="small">
|
||
<el-descriptions-item label="推送时间">{{ currentOrder.pushed_at || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="结果">
|
||
<el-tag :type="currentOrder.wms_push_result.success ? 'success' : 'danger'">
|
||
{{ currentOrder.wms_push_result.success ? '成功' : '失败' }}
|
||
</el-tag>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="外部单号">{{ currentOrder.wms_push_result.entryOrderCode || '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="返回码">{{ currentOrder.wms_push_result.code ?? '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="消息" :span="2">{{ currentOrder.wms_push_result.message || currentOrder.wms_push_result.error || '-' }}</el-descriptions-item>
|
||
</el-descriptions>
|
||
</template>
|
||
<p v-else class="muted">尚未推送到外部仓库</p>
|
||
</div>
|
||
</div>
|
||
</el-tab-pane>
|
||
<el-tab-pane label="明细" name="detail">
|
||
<div class="items-toolbar">
|
||
<span class="items-title">入库明细</span>
|
||
<span class="total">合计金额:{{ editTotal.toFixed(2) }}</span>
|
||
<span v-if="itemsLocked" class="lock-hint">单据已审核/已结束,明细已锁定(仅「待入库」可增删改)</span>
|
||
<el-button type="primary" :disabled="!currentOrder || itemSaving || itemsLocked" :loading="itemSaving" @click="saveItems">保存明细</el-button>
|
||
</div>
|
||
<div class="bottom-table-wrap" v-loading="itemsLoading">
|
||
<el-table :data="editItems" size="small" border class="fill-table">
|
||
<el-table-column type="index" label="行号" width="60" align="center" />
|
||
<el-table-column label="系统商品" min-width="220">
|
||
<template #default="{ row, $index }">
|
||
<ProductSelect
|
||
v-model="row.product_id"
|
||
:model-label="row._label"
|
||
:disabled="itemsLocked"
|
||
@select="(p: ProductSearchItem) => onEditItemSelect($index, p)"
|
||
/>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="名称" min-width="140">
|
||
<template #default="{ row }"><el-input v-model="row.name" placeholder="自动带出" :disabled="itemsLocked" /></template>
|
||
</el-table-column>
|
||
<el-table-column label="编码" width="110">
|
||
<template #default="{ row }"><el-input v-model="row.code" placeholder="自动带出" :disabled="itemsLocked" /></template>
|
||
</el-table-column>
|
||
<el-table-column label="规格" width="100">
|
||
<template #default="{ row }"><el-input v-model="row.spec" :disabled="itemsLocked" /></template>
|
||
</el-table-column>
|
||
<el-table-column label="单位" width="80">
|
||
<template #default="{ row }"><el-input v-model="row.unit" :disabled="itemsLocked" /></template>
|
||
</el-table-column>
|
||
<el-table-column label="库存类型" width="110">
|
||
<template #default="{ row }">
|
||
<el-select v-model="row.inventory_type" :disabled="itemsLocked" style="width: 100%">
|
||
<el-option v-for="o in INV_TYPE_OPTIONS" :key="o.value" :label="o.label" :value="o.value" />
|
||
</el-select>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="数量" width="110">
|
||
<template #default="{ row }">
|
||
<el-input-number v-model="row.quantity" :min="0" :precision="0" :disabled="itemsLocked" style="width: 100%" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="应入数量" width="100" align="right">
|
||
<template #default="{ row }">{{ row.plan_in_qty ?? 0 }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="已入数量" width="100" align="right">
|
||
<template #default="{ row }">{{ row.actual_in_qty ?? 0 }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="单价" width="120">
|
||
<template #default="{ row }">
|
||
<el-input-number v-model="row.price" :min="0" :precision="2" :disabled="itemsLocked" style="width: 100%" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="金额" width="110" align="right">
|
||
<template #default="{ row }">{{ ((Number(row.quantity) || 0) * (Number(row.price) || 0)).toFixed(2) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="70" fixed="right">
|
||
<template #default="{ $index }">
|
||
<el-button link type="danger" :disabled="itemsLocked" @click="removeEditItem($index)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
</el-tab-pane>
|
||
</el-tabs>
|
||
</div>
|
||
<el-empty v-else description="请点击上方单据查看明细" />
|
||
</template>
|
||
</SplitLayout>
|
||
|
||
<!-- 新增 / 编辑 对话框 -->
|
||
<el-dialog
|
||
v-model="dialogVisible"
|
||
:title="'编辑入库单'"
|
||
width="880px"
|
||
>
|
||
<el-form ref="formRef" :model="form" :rules="rules" label-width="110px">
|
||
<el-row :gutter="12">
|
||
<el-col :span="12">
|
||
<el-form-item label="仓库" prop="warehouse_id">
|
||
<VirtualSelect
|
||
v-model="form.warehouse_id"
|
||
:options="warehouseSelectOptions"
|
||
placeholder="请选择仓库"
|
||
clearable
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="入库类型">
|
||
<el-select v-model="form.inbound_type" style="width: 100%">
|
||
<el-option v-for="o in TYPE_OPTIONS" :key="o.value" :label="o.label" :value="o.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="供应商">
|
||
<el-input v-model="form.supplier" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="供应商编码">
|
||
<el-input v-model="form.supplier_code" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="采购单号">
|
||
<el-input v-model="form.purchase_order_code" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="操作人">
|
||
<el-input v-model="form.operator" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="操作员编码">
|
||
<el-input v-model="form.operator_code" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="运单号">
|
||
<el-input v-model="form.express_code" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="物流公司编码">
|
||
<el-input v-model="form.logistics_code" placeholder="选填,如 SF/YTO" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="物流公司名称">
|
||
<el-input v-model="form.logistics_name" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="操作时间">
|
||
<el-date-picker v-model="form.operate_time" type="datetime" placeholder="选填" style="width: 100%" value-format="YYYY-MM-DD HH:mm:ss" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="预期到货(起)">
|
||
<el-date-picker v-model="form.expect_start_time" type="datetime" placeholder="选填" style="width: 100%" value-format="YYYY-MM-DD HH:mm:ss" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="预期到货(止)">
|
||
<el-date-picker v-model="form.expect_end_time" type="datetime" placeholder="选填" style="width: 100%" value-format="YYYY-MM-DD HH:mm:ss" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="单据金额">
|
||
<el-input-number v-model="form.total_amount" :min="0" :precision="2" style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="24">
|
||
<el-form-item label="备注">
|
||
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<!-- WMS 扩展信息 -->
|
||
<el-collapse class="ext-collapse">
|
||
<el-collapse-item title="WMS 扩展信息(选填)" name="ext">
|
||
<div class="ext-block">
|
||
<div class="ext-subtitle"><span>发件人 (senderInfo)</span></div>
|
||
<el-row :gutter="12">
|
||
<el-col :span="8" v-for="f in SENDER_FIELDS" :key="'s' + f.key">
|
||
<el-form-item :label="f.label" label-width="70px" style="margin-bottom: 8px">
|
||
<el-input v-model="form.sender_info[f.key]" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</div>
|
||
|
||
<div class="ext-block">
|
||
<div class="ext-subtitle"><span>收件人 (receiverInfo)</span></div>
|
||
<el-row :gutter="12">
|
||
<el-col :span="8" v-for="f in SENDER_FIELDS" :key="'r' + f.key">
|
||
<el-form-item :label="f.label" label-width="70px" style="margin-bottom: 8px">
|
||
<el-input v-model="form.receiver_info[f.key]" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</div>
|
||
|
||
<div class="ext-block">
|
||
<div class="ext-subtitle">
|
||
<span>扩展属性 (extendProps)</span>
|
||
<el-button size="small" @click="form.extend_props.push({ key: '', value: '' })">添加</el-button>
|
||
</div>
|
||
<el-table :data="form.extend_props" size="small" border>
|
||
<el-table-column label="键" width="200">
|
||
<template #default="{ row }"><el-input v-model="row.key" placeholder="key" /></template>
|
||
</el-table-column>
|
||
<el-table-column label="值">
|
||
<template #default="{ row }"><el-input v-model="row.value" placeholder="value" /></template>
|
||
</el-table-column>
|
||
<el-table-column label="" width="60">
|
||
<template #default="{ $index }">
|
||
<el-button link type="danger" @click="form.extend_props.splice($index, 1)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
</el-collapse-item>
|
||
</el-collapse>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="dialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="submitting" @click="submitForm">保存</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</el-card>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.stock-card {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
.stock-card :deep(.el-card__header) {
|
||
padding: 8px 14px;
|
||
}
|
||
.stock-card :deep(.el-card__body) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
padding: 10px 14px;
|
||
}
|
||
.page-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
font-weight: 600;
|
||
}
|
||
.search-bar {
|
||
margin-bottom: 8px;
|
||
}
|
||
.top-table-wrap {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
.items-toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
margin-bottom: 8px;
|
||
}
|
||
.status-actions {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
.detail-wrap {
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
min-height: 0;
|
||
}
|
||
.order-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
flex-wrap: wrap;
|
||
padding-bottom: 10px;
|
||
margin-bottom: 12px;
|
||
border-bottom: 1px solid #ebeef5;
|
||
}
|
||
.order-head-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
min-width: 0;
|
||
}
|
||
.order-bill-no {
|
||
font-size: 15px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
word-break: break-all;
|
||
}
|
||
.order-meta {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
.items-title {
|
||
font-weight: 600;
|
||
}
|
||
.total {
|
||
color: #e6a23c;
|
||
font-weight: 600;
|
||
}
|
||
.lock-hint {
|
||
color: #e6a23c;
|
||
}
|
||
.bottom-table-wrap {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
.detail-tabs {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
.detail-tabs :deep(.el-tabs__content) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
.detail-tabs :deep(.el-tab-pane) {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
}
|
||
.fill-table {
|
||
height: 100%;
|
||
}
|
||
.info-pane {
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
min-height: 0;
|
||
}
|
||
.ext-wrap {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: auto;
|
||
padding: 8px 4px 4px;
|
||
}
|
||
.ext-wrap h4 {
|
||
margin: 16px 0 8px;
|
||
padding-left: 8px;
|
||
border-left: 3px solid #409eff;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
.ext-wrap > h4:first-child {
|
||
margin-top: 0;
|
||
}
|
||
.hint {
|
||
font-weight: 400;
|
||
color: #c0c4cc;
|
||
}
|
||
.ext-collapse {
|
||
margin-top: 8px;
|
||
}
|
||
.ext-block {
|
||
margin-bottom: 8px;
|
||
}
|
||
.ext-subtitle {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 8px;
|
||
font-weight: 600;
|
||
color: #606266;
|
||
}
|
||
.muted {
|
||
color: #909399;
|
||
}
|
||
</style>
|