- 新增出入库记录页:先用商品编码/名称关键词搜索锁定 product_id,再按商品查询流水; 列表展示变动数量与总数量/锁定数量/可用数量「前→后」;菜单兜底同步 - 新增入库单/出库单创建独立页,出库单列表与明细适配快递、运单号字段 - 外部仓库页新增仓库快递映射配置;发货单列表支持运单号展示,恢复时提示换号后的新单号 - 登录失效处理:区分登录页校验失败与登录态失效,提示后端返回的具体原因
548 lines
18 KiB
Vue
548 lines
18 KiB
Vue
<script setup lang="ts">
|
||
import { computed, onMounted, reactive, ref } from 'vue'
|
||
import { useRouter } from 'vue-router'
|
||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||
import { inboundOrderApi } from '@/api/inboundOrder'
|
||
import { getWarehouseOptions, type WarehouseOption } from '@/api/warehouse'
|
||
import type { ProductSearchItem } from '@/api/product'
|
||
import ProductSelect from '@/components/ProductSelect.vue'
|
||
import VirtualSelect from '@/components/VirtualSelect.vue'
|
||
|
||
/** 入库类型:RK 组(WMS 编码,与入库单列表保持一致) */
|
||
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 INVENTORY_TYPE_OPTIONS = [
|
||
{ label: '正品(ZP)', value: 'ZP' },
|
||
{ label: '残次(CC)', value: 'CC' },
|
||
]
|
||
/** 发件人 / 收件人共用字段(奇门 senderInfo / receiverInfo 子集) */
|
||
const PARTY_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 router = useRouter()
|
||
const warehouses = ref<WarehouseOption[]>([])
|
||
|
||
/* -------------------- 单据信息(页面头部) -------------------- */
|
||
interface HeaderForm {
|
||
warehouse_id: number | null
|
||
inbound_type: string
|
||
supplier: string
|
||
supplier_code: string
|
||
purchase_order_code: string
|
||
operator: string
|
||
operator_code: string
|
||
express_code: string
|
||
logistics_code: string
|
||
logistics_name: string
|
||
operate_time: string
|
||
expect_start_time: string
|
||
expect_end_time: string
|
||
total_amount: number
|
||
remark: string
|
||
}
|
||
|
||
function emptyForm(): HeaderForm {
|
||
return {
|
||
warehouse_id: null,
|
||
inbound_type: 'CGRK',
|
||
supplier: '',
|
||
supplier_code: '',
|
||
purchase_order_code: '',
|
||
operator: '',
|
||
operator_code: '',
|
||
express_code: '',
|
||
logistics_code: '',
|
||
logistics_name: '',
|
||
operate_time: '',
|
||
expect_start_time: '',
|
||
expect_end_time: '',
|
||
total_amount: 0,
|
||
remark: '',
|
||
}
|
||
}
|
||
|
||
const formRef = ref<FormInstance>()
|
||
const form = reactive(emptyForm())
|
||
const rules: FormRules = {
|
||
warehouse_id: [{ required: true, message: '请选择仓库', trigger: 'change' }],
|
||
}
|
||
|
||
/** WMS 扩展信息(选填,折叠区):发件人 / 收件人 / 扩展属性 */
|
||
function emptyParty(): Record<string, string> {
|
||
return Object.fromEntries(PARTY_FIELDS.map(f => [ f.key, '' ]))
|
||
}
|
||
const senderInfo = reactive(emptyParty())
|
||
const receiverInfo = reactive(emptyParty())
|
||
const extendProps = ref<Array<{ key: string; value: string }>>([])
|
||
|
||
/* -------------------- 商品明细(内联,随单创建) -------------------- */
|
||
interface LineItem {
|
||
product_id: number | null
|
||
name: string
|
||
code: string
|
||
spec: string
|
||
unit: string
|
||
quantity: number
|
||
price: number | null
|
||
inventory_type: 'ZP' | 'CC'
|
||
remark: string
|
||
}
|
||
|
||
const lines = ref<LineItem[]>([])
|
||
|
||
function addLine() {
|
||
lines.value.push({
|
||
product_id: null, name: '', code: '', spec: '', unit: '',
|
||
quantity: 1, price: null, inventory_type: 'ZP', remark: '',
|
||
})
|
||
}
|
||
|
||
function removeLine(index: number) {
|
||
lines.value.splice(index, 1)
|
||
}
|
||
|
||
function onLineProductSelect(index: number, p: ProductSearchItem) {
|
||
const line = lines.value[index]
|
||
if (!line) return
|
||
line.product_id = p.id
|
||
line.name = p.item_name || ''
|
||
line.code = p.item_code || ''
|
||
line.spec = p.sku_property || ''
|
||
if (line.price == null) line.price = 0
|
||
}
|
||
|
||
const itemsTotal = computed(() =>
|
||
lines.value.reduce((sum, line) => sum + (Number(line.quantity) || 0) * (Number(line.price) || 0), 0),
|
||
)
|
||
|
||
/* -------------------- 提交 -------------------- */
|
||
const submitting = ref(false)
|
||
|
||
/** 过滤空值:全部为空时返回 null(不下发空对象) */
|
||
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 submit() {
|
||
if (!formRef.value) return
|
||
await formRef.value.validate(async (valid) => {
|
||
if (!valid) return
|
||
if (!lines.value.length) {
|
||
ElMessage.warning('请至少添加一行商品明细')
|
||
return
|
||
}
|
||
for (const [ i, line ] of lines.value.entries()) {
|
||
if (!line.product_id && !line.code) {
|
||
ElMessage.warning(`第 ${i + 1} 行:请选择系统商品`)
|
||
return
|
||
}
|
||
if (!(Number(line.quantity) > 0)) {
|
||
ElMessage.warning(`第 ${i + 1} 行:数量需大于 0`)
|
||
return
|
||
}
|
||
}
|
||
|
||
submitting.value = true
|
||
try {
|
||
await inboundOrderApi.create({
|
||
warehouse_id: form.warehouse_id,
|
||
inbound_type: form.inbound_type,
|
||
supplier: form.supplier || null,
|
||
supplier_code: form.supplier_code || null,
|
||
purchase_order_code: form.purchase_order_code || null,
|
||
operator: form.operator || null,
|
||
operator_code: form.operator_code || null,
|
||
express_code: form.express_code || null,
|
||
logistics_code: form.logistics_code || null,
|
||
logistics_name: form.logistics_name || null,
|
||
operate_time: form.operate_time || 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(senderInfo),
|
||
receiver_info: cleanObject(receiverInfo),
|
||
extend_props: propsToObject(extendProps.value),
|
||
items: lines.value.map(line => ({
|
||
product_id: line.product_id,
|
||
name: line.name || null,
|
||
code: line.code || null,
|
||
spec: line.spec || null,
|
||
unit: line.unit || null,
|
||
quantity: Number(line.quantity),
|
||
price: line.price == null ? null : Number(line.price),
|
||
inventory_type: line.inventory_type,
|
||
remark: line.remark || null,
|
||
})),
|
||
})
|
||
ElMessage.success('入库单创建成功')
|
||
router.push('/inbound-order')
|
||
} catch {
|
||
// 拦截器已提示
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
})
|
||
}
|
||
|
||
function cancel() {
|
||
router.push('/inbound-order')
|
||
}
|
||
|
||
async function fetchOptions() {
|
||
try {
|
||
warehouses.value = await getWarehouseOptions()
|
||
} catch {
|
||
// 拦截器已提示
|
||
}
|
||
}
|
||
|
||
onMounted(async () => {
|
||
await fetchOptions()
|
||
addLine()
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<el-card class="create-card">
|
||
<template #header>
|
||
<div class="page-header">
|
||
<span>创建入库单</span>
|
||
<div>
|
||
<el-button @click="cancel">取消</el-button>
|
||
<el-button type="primary" :loading="submitting" @click="submit">保存</el-button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<div class="page-scroll">
|
||
<el-form ref="formRef" :model="form" :rules="rules" size="small" label-width="96px" class="compact-form">
|
||
<el-divider content-position="left">单据信息</el-divider>
|
||
<el-row :gutter="16">
|
||
<el-col :span="6">
|
||
<el-form-item label="仓库" prop="warehouse_id">
|
||
<VirtualSelect
|
||
v-model="form.warehouse_id"
|
||
:options="warehouses"
|
||
label-key="name"
|
||
value-key="id"
|
||
placeholder="请选择仓库"
|
||
clearable
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<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="6">
|
||
<el-form-item label="供应商">
|
||
<el-input v-model="form.supplier" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="供应商编码">
|
||
<el-input v-model="form.supplier_code" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="采购单号">
|
||
<el-input v-model="form.purchase_order_code" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="操作人">
|
||
<el-input v-model="form.operator" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="操作员编码">
|
||
<el-input v-model="form.operator_code" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<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="6">
|
||
<el-form-item label="运单号">
|
||
<el-input v-model="form.express_code" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="物流公司编码">
|
||
<el-input v-model="form.logistics_code" placeholder="选填,如 SF/YTO" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="物流公司名称">
|
||
<el-input v-model="form.logistics_name" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<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="6">
|
||
<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="6">
|
||
<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 v-model="form.remark" placeholder="选填" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-divider content-position="left">商品明细</el-divider>
|
||
<div class="items-toolbar">
|
||
<span class="items-title">共 {{ lines.length }} 项</span>
|
||
<span class="items-total">合计金额:{{ itemsTotal.toFixed(2) }}</span>
|
||
<el-button type="primary" size="small" @click="addLine">添加商品</el-button>
|
||
</div>
|
||
<el-table :data="lines" size="small" border max-height="240">
|
||
<el-table-column label="商品" min-width="170">
|
||
<template #default="{ row, $index }">
|
||
<ProductSelect
|
||
v-model="row.product_id"
|
||
@select="(p: ProductSearchItem) => onLineProductSelect($index, p)"
|
||
/>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="商品编码" width="120">
|
||
<template #default="{ row }">
|
||
<el-input v-model="row.code" placeholder="自动带出" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="商品名称" min-width="140">
|
||
<template #default="{ row }">
|
||
<el-input v-model="row.name" placeholder="自动带出" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="库存类型" width="110">
|
||
<template #default="{ row }">
|
||
<el-select v-model="row.inventory_type" style="width: 100%">
|
||
<el-option v-for="o in INVENTORY_TYPE_OPTIONS" :key="o.value" :label="o.label" :value="o.value" />
|
||
</el-select>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="数量" width="100">
|
||
<template #default="{ row }">
|
||
<el-input-number v-model="row.quantity" :min="0" :precision="3" style="width: 100%" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="单价" width="110">
|
||
<template #default="{ row }">
|
||
<el-input-number v-model="row.price" :min="0" :precision="2" style="width: 100%" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="金额" width="100" align="right">
|
||
<template #default="{ row }">
|
||
{{ ((Number(row.quantity) || 0) * (Number(row.price) || 0)).toFixed(2) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="64" fixed="right">
|
||
<template #default="{ $index }">
|
||
<el-button link type="danger" @click="removeLine($index)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
|
||
<!-- 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 v-for="f in PARTY_FIELDS" :key="'s' + f.key" :span="6">
|
||
<el-form-item :label="f.label" label-width="70px">
|
||
<el-input v-model="senderInfo[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 v-for="f in PARTY_FIELDS" :key="'r' + f.key" :span="6">
|
||
<el-form-item :label="f.label" label-width="70px">
|
||
<el-input v-model="receiverInfo[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="extendProps.push({ key: '', value: '' })">添加</el-button>
|
||
</div>
|
||
<el-table :data="extendProps" size="small" border>
|
||
<el-table-column label="键" width="220">
|
||
<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="64">
|
||
<template #default="{ $index }">
|
||
<el-button link type="danger" @click="extendProps.splice($index, 1)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
</el-collapse-item>
|
||
</el-collapse>
|
||
</el-form>
|
||
</div>
|
||
</el-card>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.page-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
font-weight: 600;
|
||
}
|
||
/* 紧凑排版:压缩表单项行距、分割线边距与卡片内边距(与创建发货单一致) */
|
||
.compact-form :deep(.el-form-item) {
|
||
margin-bottom: 6px;
|
||
}
|
||
.compact-form :deep(.el-form-item__label) {
|
||
padding-right: 6px;
|
||
}
|
||
/* 数值字段(金额)不必占满整列 */
|
||
.compact-form :deep(.el-input-number) {
|
||
max-width: 124px;
|
||
}
|
||
/* 明细表格内控件本身列宽已很窄,不做限制 */
|
||
.compact-form :deep(.el-table .el-input-number) {
|
||
max-width: none;
|
||
}
|
||
.compact-form :deep(.el-table .cell) {
|
||
padding: 0 6px;
|
||
}
|
||
.compact-form :deep(.el-divider--horizontal) {
|
||
margin: 6px 0 8px;
|
||
}
|
||
.compact-form :deep(.el-divider__text) {
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
.compact-form :deep(.el-collapse) {
|
||
margin-top: 8px;
|
||
border-top: none;
|
||
}
|
||
.create-card {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
.create-card :deep(.el-card__header) {
|
||
padding: 10px 12px;
|
||
}
|
||
.create-card :deep(.el-card__body) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
padding: 10px 12px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
.page-scroll {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow-y: auto;
|
||
}
|
||
.items-toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
margin-bottom: 8px;
|
||
}
|
||
.items-title {
|
||
color: #606266;
|
||
font-size: 13px;
|
||
}
|
||
.items-total {
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
.ext-block {
|
||
margin-bottom: 6px;
|
||
}
|
||
.ext-subtitle {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
margin-bottom: 4px;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
color: #606266;
|
||
}
|
||
</style>
|