feat(frontend): 发货单批量操作弹窗与店铺下拉默认首项

- 表头「批量操作」下拉:批量审核(入推送队列)/ 批量推送仓库 / 切换发货仓库 / 设置所属店铺

  弹窗统一支持「已选中 N 条」或「当前筛选条件(忽略勾选)」,先预览影响范围再确认执行

- 状态列新增推送失败标记(悬浮显示原因);审核文案改为进入推送队列

- 店铺下拉默认命中第一个、不可清除、无店铺时禁用且禁止提交(创建页与编辑弹窗、批量设置店铺一致)

- api/orderDelivery.ts 补充批量接口、批量结果与店铺相关类型,筛选用 from_shop_id
This commit is contained in:
liufumingren 2026-09-13 02:42:27 +08:00
parent 77da5e1c69
commit 0e100b9698
3 changed files with 118 additions and 24 deletions

View File

@ -194,7 +194,8 @@ export interface WarehouseChangeParams {
delivery_order_code?: string
status?: number
order_type?: string
shop_id?: number
/** 原店铺ID(筛选条件) */
from_shop_id?: number
/** 原发货仓库ID */
from_warehouse_id?: number
}
@ -224,6 +225,34 @@ export function changeDeliveryWarehouse(data: WarehouseChangeParams) {
return post<WarehouseChangeResult>('/order-deliveries/change-warehouse', data)
}
/** 批量设置所属店铺的入参(shopNick 取店铺名称,推送时用于匹配快递策略) */
export interface ShopChangeParams extends BatchScopeParams {
/** 目标店铺ID(必填,需属于当前主体) */
shop_id: number
}
/** 批量设置所属店铺的结果 */
export interface ShopChangeResult {
target_shop: { id: number; name: string }
/** 命中范围条数(已排除本就属于目标店铺的单据) */
matched: number
/** 可设置条数:待处理(1) / 已审核(2) / 已推送(3) */
switchable: number
/** 不可设置条数:已完成(4) / 已作废(5) / 已取消(9) */
blocked: number
blocked_reason: Record<string, number>
/** 范围内已属于目标店铺的条数(无需处理) */
same_shop: number
scope: { by: 'ids' | 'filter'; ids: number[] }
samples?: { id: number; delivery_order_code: string; status: number; shop_nick: string | null }[]
updated?: number
}
/** 批量设置所属店铺(dry_run=true 时只预览影响范围) */
export function changeDeliveryShop(data: ShopChangeParams) {
return post<ShopChangeResult>('/order-deliveries/change-shop', data)
}
/** 发货单列表(principal_id 由请求拦截器自动注入) */
export function getOrderDeliveries(params?: object) {
return get<{ list: OrderDelivery[]; total: number; page: number; pageSize: number }>(
@ -269,7 +298,8 @@ export interface BatchScopeParams {
delivery_order_code?: string
status?: number
order_type?: string
shop_id?: number
/** 原店铺ID(筛选条件;设置店铺时 shop_id 是目标店铺,故筛选用本字段) */
from_shop_id?: number
/** 原发货仓库ID */
from_warehouse_id?: number
}

View File

@ -98,6 +98,8 @@ function validateTelOrMobile(_rule: unknown, _value: unknown, callback: (error?:
const rules: FormRules = {
// 仓库必填:推送 WMS 需要 warehouseCode,且仓库接口配置(app_key/base_url)按仓库维度配置
warehouse_id: [{ required: true, message: '请选择仓库', trigger: 'change' }],
// 店铺必填:shopNick 取所选店铺名称,WMS 侧靠它匹配快递策略
shop_id: [{ required: true, message: '请选择店铺', trigger: 'change' }],
name: [{ required: true, message: '请输入收件人姓名', trigger: 'blur' }],
province: [{ required: true, message: '请输入省份', trigger: 'blur' }],
city: [{ required: true, message: '请输入城市', trigger: 'blur' }],
@ -209,6 +211,16 @@ const submitting = ref(false)
async function submit() {
if (!formRef.value) return
// 店铺必选(手工单必须选店铺):下拉默认命中第一个,不可清除;无店铺则不允许提交
if (!shops.value.length) {
ElMessage.warning('暂无可用店铺,请先在「店铺管理」中新建店铺后再创建发货单')
return
}
if (!form.shop_id) {
ElMessage.warning('请选择店铺')
return
}
const valid = await formRef.value.validate().catch(() => false)
if (!valid) return
@ -296,6 +308,10 @@ async function fetchOptions() {
shops.value = shopRes.list
warehouses.value = warehouseRes
expressCompanies.value = expressRes
// 店铺默认命中第一个(下拉不可清除,必须显式选择才能提交)
if (!form.shop_id && shops.value.length) {
form.shop_id = shops.value[0].id
}
} catch {
// 拦截器已提示
}
@ -324,14 +340,14 @@ onMounted(async () => {
<el-divider content-position="left">订单信息</el-divider>
<el-row :gutter="16">
<el-col :span="6">
<el-form-item label="店铺">
<el-form-item label="店铺" prop="shop_id">
<VirtualSelect
v-model="form.shop_id"
:options="shops"
label-key="name"
value-key="id"
placeholder="未关联店铺"
clearable
:placeholder="shops.length ? '请选择店铺' : '暂无店铺,请先新建店铺'"
:disabled="!shops.length"
style="width: 100%"
/>
</el-form-item>

View File

@ -17,10 +17,13 @@ import {
updateOrderDeliveryItem,
deleteOrderDeliveryItem,
changeDeliveryWarehouse,
changeDeliveryShop,
auditBatchOrderDeliveries,
pushBatchOrderDeliveries,
type BatchOperationResult,
type BatchScopeParams,
type ShopChangeParams,
type ShopChangeResult,
type WarehouseChangeParams,
type WarehouseChangeResult,
type OrderDelivery,
@ -207,9 +210,10 @@ function validateTelOrMobile(_rule: unknown, _value: unknown, callback: (error?:
else callback(new Error('电话与手机至少填写一个'))
}
/** 必填规则:单号系统生成故不校验;收件人姓名/省/市/区/镇 必填,电话手机二选一;仓库必填(推送依赖仓库) */
/** 必填规则:单号系统生成故不校验;收件人姓名/省/市/区/镇 必填,电话手机二选一;仓库/店铺必填(推送依赖仓库与 shopNick) */
const rules: FormRules = {
warehouse_id: [{ required: true, message: '请选择仓库', trigger: 'change' }],
shop_id: [{ required: true, message: '请选择店铺', trigger: 'change' }],
name: [{ required: true, message: '请输入收件人姓名', trigger: 'blur' }],
province: [{ required: true, message: '请输入省份', trigger: 'blur' }],
city: [{ required: true, message: '请输入城市', trigger: 'blur' }],
@ -247,13 +251,14 @@ function openCreate() {
router.push('/order-create')
}
/* -------------------- 批量操作(批量审核 / 批量推送 / 切换发货仓库) -------------------- */
type BatchAction = 'audit' | 'push' | 'warehouse'
/* -------------------- 批量操作(批量审核 / 批量推送 / 切换发货仓库 / 设置所属店铺) -------------------- */
type BatchAction = 'audit' | 'push' | 'warehouse' | 'shop'
const BATCH_ACTION_LABELS: Record<BatchAction, string> = {
audit: '批量审核',
push: '批量推送',
warehouse: '切换发货仓库',
shop: '设置所属店铺',
}
const selectedRows = ref<OrderDelivery[]>([])
@ -261,8 +266,9 @@ const batchDialog = reactive({
visible: false,
action: 'audit' as BatchAction,
targetWarehouseId: null as number | null,
targetShopId: null as number | null,
mode: 'filter' as 'selected' | 'filter',
preview: null as (WarehouseChangeResult | BatchOperationResult) | null,
preview: null as (WarehouseChangeResult | ShopChangeResult | BatchOperationResult) | null,
previewing: false,
submitting: false,
})
@ -274,18 +280,21 @@ function onSelectionChange(rows: OrderDelivery[]) {
function openBatchDialog(action: BatchAction) {
batchDialog.action = action
batchDialog.targetWarehouseId = null
// 店铺下拉默认命中第一个(不可清除)
batchDialog.targetShopId = (action === 'shop' && shops.value.length) ? shops.value[0].id : null
batchDialog.mode = selectedRows.value.length ? 'selected' : 'filter'
batchDialog.preview = null
batchDialog.visible = true
}
/** 目标仓库或范围变化后旧的影响范围失效:自动重新预览(未选目标仓库/未勾选时跳过) */
/** 目标仓库/店铺或范围变化后旧的影响范围失效:自动重新预览(未选目标/未勾选时跳过) */
watch(
() => [ batchDialog.targetWarehouseId, batchDialog.mode, batchDialog.action ],
() => [ batchDialog.targetWarehouseId, batchDialog.targetShopId, batchDialog.mode, batchDialog.action ],
() => {
batchDialog.preview = null
if (!batchDialog.visible) return
if (batchDialog.action === 'warehouse' && !batchDialog.targetWarehouseId) return
if (batchDialog.action === 'shop' && !batchDialog.targetShopId) return
if (batchDialog.mode === 'selected' && !selectedRows.value.length) return
previewBatch()
},
@ -306,9 +315,9 @@ const scopeText = computed(() => {
return selectedRows.value.length ? `${base}(本次忽略已勾选的 ${selectedRows.value.length} 条)` : base
})
/** 不可操作的原因分布(仅切换仓库返回) */
/** 不可操作的原因分布(切换仓库 / 设置店铺返回) */
const blockedText = computed(() => {
const preview = batchDialog.preview as WarehouseChangeResult | null
const preview = batchDialog.preview as WarehouseChangeResult | ShopChangeResult | null
const reason = preview?.blocked_reason || {}
return Object.entries(reason)
.map(([ status, count ]) => `${STATUS_LABELS[Number(status)] || status} ${count} 条`)
@ -337,6 +346,10 @@ const previewText = computed<{ hitLabel: string, hit: number, skip: number }>(()
const p = preview as BatchOperationResult
return { hitLabel: '可推送', hit: p.pushable || 0, skip: p.skipped }
}
if (batchDialog.action === 'shop') {
const p = preview as ShopChangeResult
return { hitLabel: '可设置', hit: p.switchable || 0, skip: p.blocked }
}
const p = preview as WarehouseChangeResult
return { hitLabel: '可切换', hit: p.switchable || 0, skip: p.blocked }
})
@ -355,7 +368,7 @@ function buildScopeParams(dryRun: boolean): BatchScopeParams {
if (query.delivery_order_code) payload.delivery_order_code = String(query.delivery_order_code)
if (query.status !== '') payload.status = Number(query.status)
if (query.order_type) payload.order_type = String(query.order_type)
if (query.shop_id !== '') payload.shop_id = Number(query.shop_id)
if (query.shop_id !== '') payload.from_shop_id = Number(query.shop_id)
if (query.warehouse_id !== '') payload.from_warehouse_id = Number(query.warehouse_id)
return payload
}
@ -363,11 +376,13 @@ function buildScopeParams(dryRun: boolean): BatchScopeParams {
/** 预览影响范围(dry_run,不写库) */
async function previewBatch() {
const scope = buildScopeParams(true)
if (batchDialog.action === 'warehouse') {
if (!batchDialog.targetWarehouseId) {
ElMessage.warning('请先选择目标仓库')
return
}
if (batchDialog.action === 'warehouse' && !batchDialog.targetWarehouseId) {
ElMessage.warning('请先选择目标仓库')
return
}
if (batchDialog.action === 'shop' && !batchDialog.targetShopId) {
ElMessage.warning('请先选择目标店铺')
return
}
if (batchDialog.mode === 'selected' && !selectedRows.value.length) {
ElMessage.warning('未勾选任何单据,请先勾选或改为按筛选条件')
@ -379,6 +394,9 @@ async function previewBatch() {
if (batchDialog.action === 'warehouse') {
const payload: WarehouseChangeParams = { ...scope, warehouse_id: Number(batchDialog.targetWarehouseId) }
batchDialog.preview = await changeDeliveryWarehouse(payload)
} else if (batchDialog.action === 'shop') {
const payload: ShopChangeParams = { ...scope, shop_id: Number(batchDialog.targetShopId) }
batchDialog.preview = await changeDeliveryShop(payload)
} else if (batchDialog.action === 'audit') {
batchDialog.preview = await auditBatchOrderDeliveries(scope)
} else {
@ -404,6 +422,9 @@ async function submitBatch() {
if (batchDialog.action === 'warehouse') {
const targetName = warehouses.value.find(w => w.id === batchDialog.targetWarehouseId)?.name || `#${batchDialog.targetWarehouseId}`
tips += `目标仓库「${targetName}」。`
} else if (batchDialog.action === 'shop') {
const targetName = shops.value.find(s => s.id === batchDialog.targetShopId)?.name || `#${batchDialog.targetShopId}`
tips += `目标店铺「${targetName}」(shopNick 取该名称,已推送的单据仅更新 OMS 记录)。`
} else if (batchDialog.action === 'audit') {
tips += '审核后进入推送队列,由定时任务自动推送仓库。'
} else {
@ -418,6 +439,11 @@ async function submitBatch() {
const res = await changeDeliveryWarehouse(payload)
const targetName = warehouses.value.find(w => w.id === batchDialog.targetWarehouseId)?.name || `#${batchDialog.targetWarehouseId}`
ElMessage.success(`已切换 ${res.updated || 0} 条发货单的仓库为「${targetName}」`)
} else if (batchDialog.action === 'shop') {
const payload: ShopChangeParams = { ...buildScopeParams(false), shop_id: Number(batchDialog.targetShopId) }
const res = await changeDeliveryShop(payload)
const targetName = shops.value.find(s => s.id === batchDialog.targetShopId)?.name || `#${batchDialog.targetShopId}`
ElMessage.success(`已设置 ${res.updated || 0} 条发货单的店铺为「${targetName}」`)
} else if (batchDialog.action === 'audit') {
const res = await auditBatchOrderDeliveries(buildScopeParams(false))
ElMessage.success(`已审核 ${res.affected || 0} 条,已进入推送队列(定时任务将自动推送仓库)`)
@ -479,6 +505,10 @@ function openEdit(row: OrderDelivery) {
detail_address: row.detail_address || '',
zip_code: row.zip_code || '',
})
// 店铺下拉默认命中第一个(历史单据可能没存店铺,不可清除,必须显式选择)
if (!form.shop_id && shops.value.length) {
form.shop_id = shops.value[0].id
}
dialogVisible.value = true
}
@ -810,6 +840,7 @@ onMounted(async () => {
<el-dropdown-item command="audit">批量审核(入推送队列)</el-dropdown-item>
<el-dropdown-item command="push">批量推送仓库</el-dropdown-item>
<el-dropdown-item command="warehouse" divided>切换发货仓库</el-dropdown-item>
<el-dropdown-item command="shop">设置所属店铺</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
@ -989,14 +1020,14 @@ onMounted(async () => {
<el-form-item v-if="editId != null" label="发货单号">
<el-tag type="info">{{ form.delivery_order_code }}</el-tag>
</el-form-item>
<el-form-item label="店铺">
<el-form-item label="店铺" prop="shop_id">
<VirtualSelect
v-model="form.shop_id"
:options="shops"
label-key="name"
value-key="id"
placeholder="未关联店铺"
clearable
:placeholder="shops.length ? '请选择店铺' : '暂无店铺,请先新建店铺'"
:disabled="!shops.length"
style="width: 100%"
/>
</el-form-item>
@ -1199,6 +1230,17 @@ onMounted(async () => {
style="width: 100%"
/>
</el-form-item>
<el-form-item v-if="batchDialog.action === 'shop'" label="目标店铺" required>
<VirtualSelect
v-model="batchDialog.targetShopId"
:options="shops"
label-key="name"
value-key="id"
:placeholder="shops.length ? '请选择目标店铺(shopNick 取该名称)' : '暂无店铺,请先新建店铺'"
:disabled="!shops.length"
style="width: 100%"
/>
</el-form-item>
<el-form-item label="操作范围">
<el-radio-group v-model="batchDialog.mode">
<el-radio value="selected" :disabled="!selectedRows.length">
@ -1218,8 +1260,11 @@ onMounted(async () => {
<div v-if="batchDialog.action === 'warehouse' && previewText.skip" class="dim">
不可切换:{{ blockedText }}
</div>
<div v-else-if="batchDialog.action === 'shop' && previewText.skip" class="dim">
不可设置:{{ blockedText }}(已完成/已作废/已取消)
</div>
<div v-else-if="batchDialog.action === 'audit' && previewText.skip" class="dim">
跳过 {{ previewText.skip }} 条(非「待处理」状态)
跳过 {{ previewText.skip }} 条(非「待处理」状态或未设置店铺)
</div>
<div v-else-if="batchDialog.action === 'push' && previewText.skip" class="dim">
跳过 {{ previewText.skip }} 条(非「已审核」状态)
@ -1227,6 +1272,9 @@ onMounted(async () => {
<div v-if="batchDialog.action === 'warehouse' && (batchDialog.preview as WarehouseChangeResult).same_warehouse" class="dim">
其中 {{ (batchDialog.preview as WarehouseChangeResult).same_warehouse }} 条已属于目标仓库,无需切换(不计入命中)
</div>
<div v-if="batchDialog.action === 'shop' && (batchDialog.preview as ShopChangeResult).same_shop" class="dim">
其中 {{ (batchDialog.preview as ShopChangeResult).same_shop }} 条已属于目标店铺,无需设置(不计入命中)
</div>
<div v-if="batchDialog.preview.samples && batchDialog.preview.samples.length" class="dim">
样例:{{ samplesText }}
</div>
@ -1238,7 +1286,7 @@ onMounted(async () => {
<el-button @click="batchDialog.visible = false">取消</el-button>
<el-button
:loading="batchDialog.previewing"
:disabled="batchDialog.action === 'warehouse' && !batchDialog.targetWarehouseId"
:disabled="(batchDialog.action === 'warehouse' && !batchDialog.targetWarehouseId) || (batchDialog.action === 'shop' && !batchDialog.targetShopId)"
@click="previewBatch"
>
预览影响范围