yin 60a7db4085 refactor(frontend): 业务弹窗统一为 task-panel 面板,统一确认框样式
新增统一弹窗外壳与样式:
- 新增 TaskPanelDialog.vue(自绘标题+副标题 / 可滚动内容区 / 底部提示+操作区),
  默认点遮罩不关闭,内容区 max-height 内部滚动
- 新增 styles/task-panel.css 并在 main.ts 引入:section 分组、栅格字段行
  (88px 标签 + 控件)、提示条、表格区、底部按钮区(small / gap 6)
- 新增 ReasonPromptDialog.vue:替换 ElMessageBox.prompt,用于作废 / 取消 /
  手工标记推送失败等需填原因的操作,支持必填校验、多行、按钮类型与提示

页面改造(el-dialog / el-drawer → TaskPanelDialog + task-panel 栅格):
- 订单、发货单、状态面板、订单同步、入库单(列表/新建)、出库单(列表/新建)、
  库存单据、导出任务、导出按钮、商品查询、单据选择、商品(新增/编辑/批量导入,
  抽屉改弹窗)、店铺、店铺商品、组合商品、自定义快递、外接 API、
  外接打印平台/快递接口、组织(集团设置/下属公司)、权限角色组、主体、主体用户、
  商品属性、用户资料

交互与样式统一:
- ElMessageBox.confirm 统一挂 customClass="app-confirm-box"(App.vue 中定义按钮
  高度/内边距/间距),状态面板封装 ElMessageBox 别名统一注入
- 侧边栏 BasicLayout:加 contain: layout、菜单内部 overflow 滚动、
  关闭子菜单折叠过渡,避免展开时逐帧重排扩散到主内容区
2026-11-19 18:00:54 +08:00

576 lines
20 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup lang="ts">
import { computed, nextTick, onMounted, reactive, ref, watch } 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 { getExpressCompanyOptions, type ExpressCompanyOption } from '@/api/expressCompany'
import type { ProductSearchItem } from '@/api/product'
import ProductSelect from '@/components/ProductSelect.vue'
import VirtualSelect from '@/components/VirtualSelect.vue'
import { useWarehouseGoodsScope } from '@/composables/useWarehouseGoodsScope'
/** 入库类型: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' },
]
const router = useRouter()
const warehouses = ref<WarehouseOption[]>([])
/** 快递公司字典(物流公司下拉选项,不区分主体) */
const expressCompanies = ref<ExpressCompanyOption[]>([])
/* -------------------- 单据信息(页面头部) -------------------- */
interface HeaderForm {
warehouse_id: number | null
inbound_type: string
supplier: string
supplier_code: string
purchase_order_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: '',
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' }],
}
/** 选择物流公司后带出名称(下拉已展示「名称(编码)」,名称供推送 logisticsName 与列表展示) */
function handleExpressChange(code: string | null) {
const company = expressCompanies.value.find(c => c.code === code)
form.logistics_name = company ? company.name : ''
}
/* -------------------- 商品明细(内联,随单创建) -------------------- */
interface LineItem {
product_id: number | null
/** 所选商品的所属货主(用于与仓库做同货主校验) */
product_subsidiary_id: number | null
/** 由商品自动带出的编码,用于清除商品时判断快照是否还需要保留 */
autofill_code?: string
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, product_subsidiary_id: null, name: '', code: '', spec: '', unit: '',
quantity: 1, price: null, inventory_type: 'ZP', remark: '',
})
}
function removeLine(index: number) {
lines.value.splice(index, 1)
}
/** 仓库 ↔ 商品双向货主约束:仓库决定单据货主,明细商品必须同货主 */
const { warehouseOwnerId, goodsOwnerId, goodsOwnerConflict, scopeSubsidiaryId, selectableWarehouses, canPickGoods } = useWarehouseGoodsScope({
warehouseId: computed(() => form.warehouse_id),
warehouses,
// 只有仍持有商品的明细才参与货主判定,清空商品后立即解锁仓库下拉
lineOwners: () => lines.value.map(line => (line.product_id ? line.product_subsidiary_id : null)),
clearMismatchedGoods: ownerId => {
let cleared = 0
for (const line of lines.value) {
if (!line.product_id) continue
if (line.product_subsidiary_id != null && Number(line.product_subsidiary_id) === Number(ownerId)) continue
line.product_id = null
line.product_subsidiary_id = null
line.name = ''
line.code = ''
line.spec = ''
cleared += 1
}
return cleared
},
})
// 商品被清空后同步清掉货主快照与自动带出的商品信息,避免仓库下拉仍被锁定、或残留上次商品
watch(
() => lines.value.map(line => line.product_id).join(','),
() => {
for (const line of lines.value) {
if (line.product_id) continue
line.product_subsidiary_id = null
if (line.autofill_code && line.code === line.autofill_code) {
line.code = ''
line.name = ''
line.spec = ''
line.unit = ''
}
line.autofill_code = ''
}
},
)
function onLineProductSelect(index: number, p: ProductSearchItem) {
const line = lines.value[index]
if (!line) return
line.product_id = p.id
line.product_subsidiary_id = p.subsidiary_id == null ? null : Number(p.subsidiary_id)
line.autofill_code = p.item_code || ''
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)
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
}
}
// 明细商品必须与仓库同货主,且同一单据明细之间也不能跨货主
if (goodsOwnerConflict.value) {
ElMessage.warning('明细商品属于不同货主(所属公司),请统一后再提交')
return
}
if (warehouseOwnerId.value !== null
&& lines.value.some(line => line.product_id && line.product_subsidiary_id != null
&& Number(line.product_subsidiary_id) !== warehouseOwnerId.value)) {
ElMessage.warning('存在与仓库货主(所属公司)不一致的商品,请重新选择')
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,
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,
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 handleReset() {
Object.assign(form, emptyForm())
lines.value = []
addLine()
// 清空字段会让下拉等控件回抛 change 校验,等它们处理完再统一清掉错误提示
await nextTick()
setTimeout(() => formRef.value?.clearValidate())
ElMessage.success('表单已重置')
}
async function fetchOptions() {
try {
const [ warehouseRes, expressRes ] = await Promise.all([
getWarehouseOptions(),
getExpressCompanyOptions(),
])
warehouses.value = warehouseRes
expressCompanies.value = expressRes
} catch {
// 拦截器已提示
}
}
onMounted(async () => {
await fetchOptions()
addLine()
})
</script>
<template>
<el-card class="create-card">
<template #header>
<div class="page-header">
<span>创建入库单</span>
<div class="page-actions">
<el-button size="small" @click="handleReset">重置</el-button>
<el-button size="small" @click="cancel">取消</el-button>
<el-button size="small" type="primary" :loading="submitting" @click="submit">保存</el-button>
</div>
</div>
</template>
<div class="page-scroll">
<el-form
ref="formRef"
:model="form"
:rules="rules"
class="task-panel__form create-form"
scroll-to-error
@submit.prevent
>
<div class="task-panel__section">单据信息</div>
<div class="task-panel__grid">
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label is-required">仓库</span>
<div class="task-panel__field-form">
<el-form-item prop="warehouse_id">
<VirtualSelect
v-model="form.warehouse_id"
:options="selectableWarehouses"
label-key="name"
value-key="id"
placeholder="请选择仓库"
clearable
style="width: 100%"
/>
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">入库类型</span>
<div class="task-panel__field-form">
<el-form-item prop="inbound_type">
<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>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">供应商</span>
<div class="task-panel__field-form">
<el-form-item prop="supplier">
<el-input v-model="form.supplier" placeholder="选填" />
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">供应商编码</span>
<div class="task-panel__field-form">
<el-form-item prop="supplier_code">
<el-input v-model="form.supplier_code" placeholder="选填" />
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">采购单号</span>
<div class="task-panel__field-form">
<el-form-item prop="purchase_order_code">
<el-input v-model="form.purchase_order_code" placeholder="选填" />
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">单据金额</span>
<div class="task-panel__field-form">
<el-form-item prop="total_amount">
<el-input-number v-model="form.total_amount" :min="0" :precision="2" style="width: 100%" />
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">运单号</span>
<div class="task-panel__field-form">
<el-form-item prop="express_code">
<el-input v-model="form.express_code" placeholder="选填" />
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">物流公司</span>
<div class="task-panel__field-form">
<el-form-item prop="logistics_code">
<el-select
v-model="form.logistics_code"
placeholder="选填,推送为 logisticsCode"
clearable
filterable
style="width: 100%"
@change="handleExpressChange"
>
<el-option v-for="c in expressCompanies" :key="c.code" :label="`${c.name}(${c.code})`" :value="c.code" />
</el-select>
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">操作时间</span>
<div class="task-panel__field-form">
<el-form-item prop="operate_time">
<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>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">预计到货</span>
<div class="task-panel__field-form">
<el-form-item prop="expect_start_time">
<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>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">最迟到货</span>
<div class="task-panel__field-form">
<el-form-item prop="expect_end_time">
<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>
</div>
</div>
<div class="task-panel__field task-panel__field--input task-panel__field--full">
<span class="task-panel__field-label">备注</span>
<div class="task-panel__field-form">
<el-form-item prop="remark">
<el-input v-model="form.remark" placeholder="选填" />
</el-form-item>
</div>
</div>
</div>
<div class="task-panel__section">商品明细</div>
<div class="items-toolbar">
<span class="items-title">共 {{ lines.length }} 项</span>
<span class="items-total">合计金额:{{ itemsTotal.toFixed(2) }}</span>
<el-button size="small" type="primary" @click="addLine">添加商品</el-button>
</div>
<p
v-if="warehouseOwnerId !== null || goodsOwnerId !== null"
class="task-panel__form-tip"
>
{{ warehouseOwnerId !== null
? '明细商品仅可选与仓库同货主(所属公司)的商品'
: '已按所选商品的货主(所属公司)过滤可选仓库' }}
</p>
<div class="task-panel__table">
<el-table :data="lines" size="small" border max-height="320">
<el-table-column label="商品" min-width="170">
<template #default="{ row, $index }">
<ProductSelect
v-model="row.product_id"
:subsidiary-id="scopeSubsidiaryId"
:before-select="(p: ProductSearchItem) => canPickGoods(p.subsidiary_id, $index)"
@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" size="small" placeholder="自动带出" />
</template>
</el-table-column>
<el-table-column label="商品名称" min-width="140">
<template #default="{ row }">
<el-input v-model="row.name" size="small" placeholder="自动带出" />
</template>
</el-table-column>
<el-table-column label="库存类型" width="110">
<template #default="{ row }">
<el-select v-model="row.inventory_type" size="small" 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" size="small" 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" size="small" 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" size="small" @click="removeLine($index)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
</el-form>
</div>
</el-card>
</template>
<style scoped>
.page-header {
display: flex;
align-items: center;
justify-content: space-between;
font-weight: 600;
}
/* 头部操作按钮:与表单面板底部一致(small / gap 6) */
.page-actions {
display: flex;
align-items: center;
gap: 6px;
}
/* 页面型表单:分组之间留出比弹窗更大的间距 */
.create-form .task-panel__section {
margin-top: 12px;
}
.create-form .task-panel__section:first-child {
margin-top: 0;
}
/* 明细表格内控件本身列宽已很窄,不做限制 */
.create-form :deep(.el-table .cell) {
padding: 0 6px;
}
.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;
padding-right: 4px;
}
.items-toolbar {
display: flex;
align-items: center;
gap: 12px;
}
.items-title {
color: #606266;
font-size: 12px;
line-height: 18px;
}
.items-total {
font-size: 12px;
line-height: 18px;
font-weight: 600;
color: #303133;
}
</style>