入库路由

This commit is contained in:
tzy 2026-08-08 09:10:31 +08:00
parent a9aa3706d7
commit 828cf4ad09
3 changed files with 734 additions and 1 deletions

92
src/api/stockIn.ts Normal file
View File

@ -0,0 +1,92 @@
import { request } from '@/utils/request'
/** 入库申请单 */
export interface StockIn {
id?: number
inboundCode?: string
subjectName?: string
/** 1生产入库 2委外收货 3采购入库 */
inboundType?: number
sourceOrderNo?: string
orderItemId?: number
workOrderCode?: string
processPlanId?: number
qcId?: number
materialCode?: string
materialName?: string
quantity?: number | string
progress?: number
warehouseId?: number
warehouseName?: string
/** 0草稿 1待确认 2上架入库 3已撤回 */
status?: number
/** 金蝶入库单编码 */
kingdeeInboundNo?: string
remark?: string
createTime?: string
createBy?: string
updateTime?: string
updateBy?: string
}
export type StockInSave = Omit<StockIn, 'inboundCode' | 'status' | 'progress' | 'createTime' | 'updateTime'>
export const STOCK_IN_TYPE_MAP: Record<number, { label: string; type: 'default' | 'info' | 'success' | 'warning' | 'error' }> = {
1: { label: '生产入库', type: 'success' },
2: { label: '委外收货', type: 'warning' },
3: { label: '采购入库', type: 'info' },
}
export const STOCK_IN_STATUS_MAP: Record<number, { label: string; type: 'default' | 'info' | 'success' | 'warning' | 'error' }> = {
0: { label: '草稿', type: 'default' },
1: { label: '待确认', type: 'info' },
2: { label: '上架入库', type: 'success' },
3: { label: '已撤回', type: 'warning' },
}
export const stockInApi = {
page(params: {
page: number
pageSize: number
inboundCode?: string
sourceOrderNo?: string
inboundType?: number
status?: number
warehouseName?: string
kingdeeInboundNo?: string
}) {
return request<{ list: StockIn[]; total: number; page: number; pageSize: number }>({
url: '/biz/stockIn/page',
method: 'get',
params,
})
},
detail(id: number | string) {
return request<StockIn>({ url: `/biz/stockIn/${id}`, method: 'get' })
},
create(data: StockInSave) {
return request<number>({ url: '/biz/stockIn', method: 'post', data })
},
update(data: StockInSave) {
return request({ url: '/biz/stockIn', method: 'put', data })
},
delete(ids: number[]) {
return request({ url: `/biz/stockIn/${ids.join(',')}`, method: 'delete' })
},
confirm(id: number, kingdeeInboundNo?: string | null) {
return request({
url: `/biz/stockIn/confirm/${id}`,
method: 'post',
data: kingdeeInboundNo ? { kingdeeInboundNo } : {},
})
},
revoke(id: number) {
return request({ url: `/biz/stockIn/revoke/${id}`, method: 'post' })
},
}

View File

@ -215,7 +215,7 @@ const routes: RouteRecordRaw[] = [
component: () => import('@/views/biz/device/board.vue'),
meta: { title: '设备状态监控', icon: 'PulseOutline' }
},
// 入库管理
// 入库 管理
{
path: 'biz/stockIn',
name: 'BizStockIn',

View File

@ -0,0 +1,641 @@
<template>
<div class="page-container">
<n-card>
<div class="table-toolbar">
<n-space>
<n-button type="primary" @click="handleAdd">
<template #icon><n-icon><AddOutline /></n-icon></template>
新建入库单
</n-button>
<n-button type="error" :disabled="selectedIds.length === 0" @click="handleBatchDelete">
<template #icon><n-icon><TrashOutline /></n-icon></template>
批量删除
</n-button>
</n-space>
<n-space>
<n-button quaternary circle @click="loadData">
<template #icon><n-icon><RefreshOutline /></n-icon></template>
</n-button>
</n-space>
</div>
<div class="search-form">
<n-form inline :model="searchForm" label-placement="left" size="small">
<n-form-item label="入库单号">
<n-input v-model:value="searchForm.inboundCode" placeholder="OWR-" clearable style="width: 150px" />
</n-form-item>
<n-form-item label="来源单号">
<n-input v-model:value="searchForm.sourceOrderNo" placeholder="工单/订单号" clearable style="width: 150px" />
</n-form-item>
<n-form-item label="入库类型">
<n-select
v-model:value="searchForm.inboundType"
placeholder="全部"
clearable
style="width: 120px"
:options="typeOptions"
/>
</n-form-item>
<n-form-item label="当前阶段">
<n-select
v-model:value="searchForm.status"
placeholder="全部"
clearable
style="width: 120px"
:options="statusOptions"
/>
</n-form-item>
<n-form-item label="金蝶入库单">
<n-input v-model:value="searchForm.kingdeeInboundNo" placeholder="金蝶编码" clearable style="width: 140px" />
</n-form-item>
<n-form-item>
<n-space>
<n-button type="primary" size="small" @click="handleSearch">
<template #icon><n-icon><SearchOutline /></n-icon></template>
搜索
</n-button>
<n-button size="small" @click="handleReset">重置</n-button>
</n-space>
</n-form-item>
</n-form>
</div>
<n-data-table
:columns="columns"
:data="tableData"
:loading="loading"
:pagination="pagination"
:row-key="(row) => row.id!"
:scroll-x="1680"
@update:page="handlePageChange"
@update:page-size="handlePageSizeChange"
@update:checked-row-keys="handleCheck"
/>
</n-card>
<!-- 详情 -->
<n-modal v-model:show="detailVisible" preset="card" title="入库单详情" style="width: 720px">
<n-descriptions v-if="detailData" :column="2" bordered size="small" label-placement="left">
<n-descriptions-item label="入库单号">{{ detailData.inboundCode || '-' }}</n-descriptions-item>
<n-descriptions-item label="当前阶段">{{ statusLabel(detailData.status) }}</n-descriptions-item>
<n-descriptions-item label="入库类型">{{ typeLabel(detailData.inboundType) }}</n-descriptions-item>
<n-descriptions-item label="来源单号">{{ detailData.sourceOrderNo || '-' }}</n-descriptions-item>
<n-descriptions-item label="工单号">{{ detailData.workOrderCode || '-' }}</n-descriptions-item>
<n-descriptions-item label="金蝶入库单编码">{{ detailData.kingdeeInboundNo || '-' }}</n-descriptions-item>
<n-descriptions-item label="物料编码">{{ detailData.materialCode || '-' }}</n-descriptions-item>
<n-descriptions-item label="物料名称">{{ detailData.materialName || '-' }}</n-descriptions-item>
<n-descriptions-item label="入库数量">{{ formatQty(detailData.quantity) }}</n-descriptions-item>
<n-descriptions-item label="入库仓库">{{ detailData.warehouseName || '-' }}</n-descriptions-item>
<n-descriptions-item label="入库进度">{{ detailData.progress ?? 0 }}%</n-descriptions-item>
<n-descriptions-item label="创建时间">{{ detailData.createTime || '-' }}</n-descriptions-item>
<n-descriptions-item label="更新时间">{{ detailData.updateTime || '-' }}</n-descriptions-item>
<n-descriptions-item label="备注" :span="2">{{ detailData.remark || '-' }}</n-descriptions-item>
</n-descriptions>
</n-modal>
<!-- 新增/编辑 -->
<n-modal v-model:show="modalVisible" preset="card" :title="modalTitle" style="width: 720px">
<n-form ref="formRef" :model="formData" :rules="formRules" label-placement="left" label-width="110px">
<n-grid :cols="2" :x-gap="16">
<n-form-item-gi label="入库类型" path="inboundType">
<n-select v-model:value="formData.inboundType" :options="typeOptions" />
</n-form-item-gi>
<n-form-item-gi label="入库仓库" path="warehouseName">
<n-input v-model:value="formData.warehouseName" placeholder="如:成品仓" />
</n-form-item-gi>
<n-form-item-gi label="来源单号" path="sourceOrderNo">
<n-input v-model:value="formData.sourceOrderNo" placeholder="生产订单号/委外单号" />
</n-form-item-gi>
<n-form-item-gi label="工单号" path="workOrderCode">
<n-input
v-model:value="formData.workOrderCode"
placeholder="工序工单号(保存时后端可补物料/数量)"
@blur="onWorkOrderBlur"
/>
</n-form-item-gi>
<n-form-item-gi label="生产订单ID" path="orderItemId">
<n-input-number v-model:value="formData.orderItemId" :min="1" :precision="0" clearable style="width: 100%" placeholder="mes_order_item.id" />
</n-form-item-gi>
<n-form-item-gi label="入库数量" path="quantity">
<n-input-number v-model:value="formData.quantity" :min="0.0001" :precision="4" style="width: 100%" />
</n-form-item-gi>
<n-form-item-gi label="物料编码" path="materialCode">
<n-input v-model:value="formData.materialCode" placeholder="物料编码" />
</n-form-item-gi>
<n-form-item-gi label="物料名称" path="materialName">
<n-input v-model:value="formData.materialName" placeholder="物料名称" />
</n-form-item-gi>
<n-form-item-gi label="金蝶入库单" path="kingdeeInboundNo">
<n-input v-model:value="formData.kingdeeInboundNo" placeholder="确认入库时可填写" />
</n-form-item-gi>
<n-form-item-gi :span="2" label="备注" path="remark">
<n-input v-model:value="formData.remark" type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" />
</n-form-item-gi>
</n-grid>
</n-form>
<template #footer>
<n-space justify="end">
<n-button @click="modalVisible = false">取消</n-button>
<n-button type="primary" :loading="submitLoading" @click="handleSubmit">保存</n-button>
</n-space>
</template>
</n-modal>
<!-- 确认入库 -->
<n-modal v-model:show="confirmVisible" preset="card" title="确认入库" style="width: 480px">
<n-form label-placement="left" label-width="120px">
<n-form-item label="入库单号">
<n-input :value="confirmRow?.inboundCode" disabled />
</n-form-item>
<n-form-item label="金蝶入库单编码">
<n-input v-model:value="confirmKingdeeNo" placeholder="推送金蝶成功后的单号(可后补)" clearable />
</n-form-item>
</n-form>
<template #footer>
<n-space justify="end">
<n-button @click="confirmVisible = false">取消</n-button>
<n-button type="primary" :loading="submitLoading" @click="doConfirm">确认入库</n-button>
</n-space>
</template>
</n-modal>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, h, onMounted } from 'vue'
import {
NButton, NSpace, NIcon, NTag, NModal, NForm, NFormItem, NFormItemGi, NGrid,
NInput, NInputNumber, NSelect, NDescriptions, NDescriptionsItem, NProgress,
useMessage, useDialog, type DataTableColumns, type FormRules,
} from 'naive-ui'
import {
SearchOutline, RefreshOutline, AddOutline, TrashOutline,
CheckmarkCircleOutline, EllipseOutline, PlayOutline,
} from '@vicons/ionicons5'
import {
stockInApi,
STOCK_IN_TYPE_MAP,
STOCK_IN_STATUS_MAP,
type StockIn,
} from '@/api/stockIn'
const message = useMessage()
const dialog = useDialog()
const searchForm = reactive({
inboundCode: '',
sourceOrderNo: '',
inboundType: null as number | null,
status: null as number | null,
kingdeeInboundNo: '',
})
const typeOptions = Object.entries(STOCK_IN_TYPE_MAP).map(([value, item]) => ({
label: item.label,
value: Number(value),
}))
const statusOptions = Object.entries(STOCK_IN_STATUS_MAP).map(([value, item]) => ({
label: item.label,
value: Number(value),
}))
const tableData = ref<StockIn[]>([])
const loading = ref(false)
const submitLoading = ref(false)
const selectedIds = ref<number[]>([])
const pagination = reactive({
page: 1,
pageSize: 10,
itemCount: 0,
showSizePicker: true,
pageSizes: [10, 20, 50],
})
const detailVisible = ref(false)
const detailData = ref<StockIn | null>(null)
const modalVisible = ref(false)
const modalTitle = ref('')
const formRef = ref()
const confirmVisible = ref(false)
const confirmRow = ref<StockIn | null>(null)
const confirmKingdeeNo = ref('')
const defaultFormData = (): Record<string, any> => ({
id: undefined,
inboundType: 1,
sourceOrderNo: '',
orderItemId: null,
workOrderCode: '',
processPlanId: null,
materialCode: '',
materialName: '',
quantity: null,
warehouseName: '',
subjectName: '',
kingdeeInboundNo: '',
remark: '',
})
const formData = reactive<Record<string, any>>(defaultFormData())
const formRules: FormRules = {
inboundType: [{ required: true, type: 'number', message: '请选择入库类型', trigger: ['blur', 'change'] }],
warehouseName: [{ required: true, message: '请输入入库仓库', trigger: 'blur' }],
quantity: [{ required: true, type: 'number', message: '请输入入库数量', trigger: ['blur', 'change'] }],
}
function formatQty(val?: number | string | null) {
if (val == null || val === '') return '0'
return Number(val).toLocaleString()
}
function typeLabel(type?: number) {
if (type == null) return '-'
return STOCK_IN_TYPE_MAP[type]?.label ?? String(type)
}
function statusLabel(status?: number) {
if (status == null) return '-'
return STOCK_IN_STATUS_MAP[status]?.label ?? String(status)
}
const columns: DataTableColumns<StockIn> = [
{ type: 'selection', width: 48, align: 'center', fixed: 'left' },
{
title: '主体 / 单号',
key: 'inboundCode',
width: 200,
fixed: 'left',
render(row) {
return h('div', { class: 'subject-cell' }, [
h('div', { class: 'subject-name' }, row.subjectName || row.warehouseName || '-'),
h('div', { class: 'subject-code' }, row.inboundCode || '-'),
])
},
},
{
title: '入库类型',
key: 'inboundType',
width: 110,
align: 'center',
render(row) {
const item = STOCK_IN_TYPE_MAP[row.inboundType ?? 1] ?? STOCK_IN_TYPE_MAP[1]
return h(NTag, { type: item.type, size: 'small', round: true }, { default: () => item.label })
},
},
{
title: '来源单号',
key: 'sourceOrderNo',
width: 150,
ellipsis: { tooltip: true },
render: (row) => row.sourceOrderNo || row.workOrderCode || '-',
},
{
title: '入库数量',
key: 'quantity',
width: 100,
align: 'center',
render: (row) => formatQty(row.quantity),
},
{
title: '入库进度',
key: 'progress',
width: 140,
render(row) {
const p = row.progress ?? 0
return h(NProgress, {
type: 'line',
percentage: p,
indicatorPlacement: 'inside',
processing: p > 0 && p < 100,
status: p >= 100 ? 'success' : 'default',
height: 16,
})
},
},
{
title: '入库仓库',
key: 'warehouseName',
width: 110,
ellipsis: { tooltip: true },
render: (row) => row.warehouseName || '-',
},
{
title: '金蝶入库单编码',
key: 'kingdeeInboundNo',
width: 150,
ellipsis: { tooltip: true },
render: (row) => row.kingdeeInboundNo || '-',
},
{
title: '时间',
key: 'createTime',
width: 160,
render: (row) => row.createTime || '-',
},
{
title: '更新时间',
key: 'updateTime',
width: 180,
render(row) {
return h('div', [
h('div', row.updateTime || '-'),
h('div', { class: 'muted' }, row.updateBy ? `更新人 ${row.updateBy}` : ''),
])
},
},
{
title: '当前阶段',
key: 'status',
width: 110,
align: 'center',
render(row) {
const status = row.status ?? 0
const item = STOCK_IN_STATUS_MAP[status] ?? STOCK_IN_STATUS_MAP[0]
const done = status === 2
return h('div', { class: 'status-cell' }, [
h(NIcon, { color: done ? '#18a058' : '#bfbfbf', size: 16 }, {
default: () => h(done ? CheckmarkCircleOutline : EllipseOutline),
}),
h('span', item.label),
])
},
},
{
title: '操作',
key: 'actions',
width: 200,
align: 'center',
fixed: 'right',
render(row) {
const status = row.status ?? 0
const btns = [
h(NButton, { text: true, type: 'primary', size: 'small', onClick: () => openDetail(row) }, { default: () => '详情' }),
]
if (status === 0 || status === 1 || status === 3) {
btns.push(
h(NButton, {
text: true,
type: 'primary',
size: 'small',
onClick: () => openConfirm(row),
}, {
default: () => h('span', { class: 'action-with-icon' }, [
h(NIcon, { size: 14 }, { default: () => h(PlayOutline) }),
' 确认入库',
]),
}),
)
btns.push(
h(NButton, { text: true, type: 'primary', size: 'small', onClick: () => handleEdit(row) }, { default: () => '编辑' }),
)
btns.push(
h(NButton, {
text: true,
type: 'error',
size: 'small',
onClick: () => handleDelete([row.id!]),
}, {
default: () => h(NIcon, { size: 16 }, { default: () => h(TrashOutline) }),
}),
)
}
if (status === 2) {
btns.push(
h(NButton, { text: true, type: 'warning', size: 'small', onClick: () => handleRevoke(row) }, { default: () => '撤回入库' }),
)
}
return h(NSpace, { size: 4, justify: 'center' }, { default: () => btns })
},
},
]
async function loadData() {
loading.value = true
try {
const res = await stockInApi.page({
page: pagination.page,
pageSize: pagination.pageSize,
inboundCode: searchForm.inboundCode || undefined,
sourceOrderNo: searchForm.sourceOrderNo || undefined,
inboundType: searchForm.inboundType ?? undefined,
status: searchForm.status ?? undefined,
kingdeeInboundNo: searchForm.kingdeeInboundNo || undefined,
})
tableData.value = res.list ?? []
pagination.itemCount = res.total ?? 0
} catch (e: any) {
message.error(e?.message || '加载失败')
} finally {
loading.value = false
}
}
function handleSearch() {
pagination.page = 1
loadData()
}
function handleReset() {
searchForm.inboundCode = ''
searchForm.sourceOrderNo = ''
searchForm.inboundType = null
searchForm.status = null
searchForm.kingdeeInboundNo = ''
handleSearch()
}
function handlePageChange(page: number) {
pagination.page = page
loadData()
}
function handlePageSizeChange(pageSize: number) {
pagination.pageSize = pageSize
pagination.page = 1
loadData()
}
function handleCheck(keys: Array<string | number>) {
selectedIds.value = keys as number[]
}
function openDetail(row: StockIn) {
detailData.value = row
detailVisible.value = true
}
function handleAdd() {
Object.assign(formData, defaultFormData())
modalTitle.value = '新建入库单'
modalVisible.value = true
}
function handleEdit(row: StockIn) {
Object.assign(formData, defaultFormData(), {
id: row.id,
inboundType: row.inboundType ?? 1,
sourceOrderNo: row.sourceOrderNo || '',
orderItemId: row.orderItemId ?? null,
workOrderCode: row.workOrderCode || '',
processPlanId: row.processPlanId ?? null,
materialCode: row.materialCode || '',
materialName: row.materialName || '',
quantity: row.quantity != null ? Number(row.quantity) : null,
warehouseName: row.warehouseName || '',
subjectName: row.subjectName || '',
kingdeeInboundNo: row.kingdeeInboundNo || '',
remark: row.remark || '',
})
modalTitle.value = '编辑入库单'
modalVisible.value = true
}
function onWorkOrderBlur() {
const code = (formData.workOrderCode || '').trim()
if (code && !formData.sourceOrderNo) {
formData.sourceOrderNo = code
}
}
async function handleSubmit() {
try {
await formRef.value?.validate()
} catch {
return
}
submitLoading.value = true
try {
const payload = {
id: formData.id,
inboundType: formData.inboundType,
sourceOrderNo: formData.sourceOrderNo || undefined,
orderItemId: formData.orderItemId || undefined,
workOrderCode: formData.workOrderCode || undefined,
processPlanId: formData.processPlanId || undefined,
materialCode: formData.materialCode || undefined,
materialName: formData.materialName || undefined,
quantity: formData.quantity,
warehouseName: formData.warehouseName,
subjectName: formData.subjectName || formData.warehouseName,
kingdeeInboundNo: formData.kingdeeInboundNo || undefined,
remark: formData.remark || undefined,
}
if (formData.id) {
await stockInApi.update(payload)
message.success('保存成功')
} else {
await stockInApi.create(payload)
message.success('创建成功')
}
modalVisible.value = false
loadData()
} catch (e: any) {
message.error(e?.message || '保存失败')
} finally {
submitLoading.value = false
}
}
function openConfirm(row: StockIn) {
confirmRow.value = row
confirmKingdeeNo.value = row.kingdeeInboundNo || ''
confirmVisible.value = true
}
async function doConfirm() {
if (!confirmRow.value?.id) return
submitLoading.value = true
try {
await stockInApi.confirm(confirmRow.value.id, confirmKingdeeNo.value || null)
message.success('已确认入库')
confirmVisible.value = false
loadData()
} catch (e: any) {
message.error(e?.message || '确认失败')
} finally {
submitLoading.value = false
}
}
function handleRevoke(row: StockIn) {
dialog.warning({
title: '撤回入库',
content: `确认撤回入库单 ${row.inboundCode}`,
positiveText: '撤回',
negativeText: '取消',
onPositiveClick: async () => {
try {
await stockInApi.revoke(row.id!)
message.success('已撤回')
loadData()
} catch (e: any) {
message.error(e?.message || '撤回失败')
}
},
})
}
function handleDelete(ids: number[]) {
dialog.warning({
title: '删除确认',
content: `确认删除选中的 ${ids.length} 条入库单?`,
positiveText: '删除',
negativeText: '取消',
onPositiveClick: async () => {
try {
await stockInApi.delete(ids)
message.success('删除成功')
selectedIds.value = []
loadData()
} catch (e: any) {
message.error(e?.message || '删除失败')
}
},
})
}
function handleBatchDelete() {
if (!selectedIds.value.length) return
handleDelete([...selectedIds.value])
}
onMounted(() => {
loadData()
})
</script>
<style scoped>
.table-toolbar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
}
.search-form {
margin-bottom: 12px;
}
.subject-cell .subject-name {
font-weight: 600;
color: #1f2225;
}
.subject-cell .subject-code {
margin-top: 2px;
font-size: 12px;
color: #8b8f97;
}
.status-cell {
display: inline-flex;
align-items: center;
gap: 4px;
}
.muted {
font-size: 12px;
color: #8b8f97;
}
.action-with-icon {
display: inline-flex;
align-items: center;
gap: 2px;
}
</style>