Compare commits

...

2 Commits

Author SHA1 Message Date
liufumingren
4ecf3c32b8 1 2026-09-15 09:04:56 +08:00
liufumingren
2cc558be60 1 2026-09-15 09:04:25 +08:00
3 changed files with 154 additions and 0 deletions

View File

@ -188,12 +188,21 @@ export const stockoutConfirm = (data: StockoutConfirmParams) => {
export type StockoutUpdateExpressParams = {
/** 出库单ID(必填) */
id: number
<<<<<<< HEAD
/** 快递公司编码(非运单号,如 SF/STO/ZT);传入后自动解析 express_name,传空值置 NULL */
express_code?: string
/** 运单号(单个);storage.stockout.confirm 前必须已填写该字段 */
waybill_code?: string
/** 运单号列表(JSON 数组或 null,支持多包裹场景);非数组返回 400 */
waybill_codes?: string[] | null
=======
/** 快递公司编码(**非运单号**,如 SF/STO/ZT):传入后后端自动解析 express_name,传空值则 express_code/express_name 置 NULL */
express_code?: string
/** 运单号列表(JSON 数组或 null,支持一单多运单);回传与确认校验以此为准,传空数组或 null 表示清空;非数组返回 400 */
waybill_codes?: string[] | null
/** 【已弃用】单数运单号:仅作 waybill_codes 首个的镜像,勿单独使用 */
waybill_code?: string
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
}
/** storage.stockout.updateExpress 响应 */
@ -202,6 +211,19 @@ export type StockoutUpdateExpressResponse = {
stockout_order_code: string
/** 更新后的快递公司编码 */
express_code?: string
<<<<<<< HEAD
/** 由 express_code 解析出的快递公司名称 */
express_name?: string
/** 更新后的运单号 */
waybill_code?: string
/** 更新后的运单号列表 */
waybill_codes?: string[]
}
/**
* 更新出库单的快递公司与运单号(express_code / waybill_code / waybill_codes),用于在确认前填写运单信息。
* 未传入的字段不更新,三个字段都未传时返回「没有需要更新的字段」;已废弃字段 express_codes 不在本接口读写范围内。
=======
/** 由 express_code 解析出的快递公司名称(未匹配到为空串) */
express_name?: string
/** 更新后的运单号列表(以此为准) */
@ -214,6 +236,7 @@ export type StockoutUpdateExpressResponse = {
* 更新出库单的快递公司与运单号(确认前填写运单信息)
* - `express_code` 是**快递公司编码**,不是运单号
* - 运单号统一走 `waybill_codes`(复数数组);`waybill_code` 已弃用,`express_codes` 已废弃(不在本接口读写范围内)
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
*/
export const stockoutUpdateExpress = (data: StockoutUpdateExpressParams) => {
return request({

View File

@ -393,7 +393,11 @@
<el-dialog
v-model="updateExpressDialogVisible"
<<<<<<< HEAD
title="更新快递与运单号"
=======
title="更新快递公司与运单号"
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
width="520px"
align-center
append-to-body
@ -408,16 +412,31 @@
:title="`更新出库单「${updateExpressTargetRow?.stockout_order_code || updateExpressTargetRow?.id || ''}」的运单号。`"
style="margin-bottom: 16px;"
/> -->
<el-alert
type="info"
:closable="false"
show-icon
title="快递公司填编码(如 SF/STO/ZT),运单号填 waybill_code;出库确认前必须已填写运单号。"
style="margin-bottom: 16px;"
/>
<el-form :model="updateExpressForm" label-width="100px">
<el-form-item label="快递公司">
<el-select
v-model="updateExpressForm.express_code"
<<<<<<< HEAD
placeholder="快递公司编码(如 SF/STO/ZT),清空则置空"
=======
placeholder="选择快递公司编码(如 SF/STO/ZT)"
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
clearable
filterable
allow-create
default-first-option
<<<<<<< HEAD
style="width:100%"
=======
style="width: 100%"
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
>
<el-option
v-for="opt in updateInfoExpressOptions"
@ -426,14 +445,24 @@
:value="opt.value"
/>
</el-select>
<<<<<<< HEAD
</el-form-item>
<el-form-item label="运单号">
<el-input v-model="updateExpressForm.waybill_code" placeholder="运单号(单个)" clearable />
=======
<div class="update-express-tip">传编码即可,后端自动解析快递名称;清空表示置空</div>
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
</el-form-item>
<el-form-item label="运单号">
<el-input
v-model="updateExpressForm.waybill_codes"
type="textarea"
:rows="3"
<<<<<<< HEAD
placeholder="多包裹运单号,用逗号或换行分隔(可选)"
=======
placeholder="支持一单多运单,多个运单号用逗号、分号或换行分隔(可选)"
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
/>
<div class="update-express-tip">清空后提交空数组,将清空原有运单号</div>
</el-form-item>
@ -462,7 +491,11 @@ import { safeInvoke } from '@/utils/safe-invoke'
import * as XLSX from 'xlsx'
import * as indexApi from '@/api/index/index'
import * as stockoutApi from '@/api/storage.stockout/stockout' //现有的对应API
<<<<<<< HEAD
import type { StockoutToOrderParams, StockoutUpdateExpressParams, StockoutUpdateInfoParams } from '@/api/storage.stockout/stockout'
=======
import type { StockoutToOrderParams, StockoutUpdateInfoParams, StockoutUpdateExpressParams, StockoutConfirmResponse } from '@/api/storage.stockout/stockout'
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
import {
availableFields,
entryColums,
@ -794,16 +827,40 @@ async function handleSingleRowCancel(row: any) {
}
}
<<<<<<< HEAD
// ── 更新快递与运单号(storage.stockout.updateExpress)──
=======
// ── 更新快递公司与运单号(storage.stockout.updateExpress)──
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
const updateExpressDialogVisible = ref(false)
const updateExpressLoading = ref(false)
const updateExpressTargetRow = ref<any>(null)
const updateExpressForm = reactive({
<<<<<<< HEAD
/** 快递公司编码(如 SF/STO/ZT),非运单号 */
express_code: '',
/** 运单号(单个) */
waybill_code: '',
/** 运单号列表(多包裹,文本按逗号/换行分隔) */
=======
/** 快递公司编码(express_code,非运单号) */
express_code: '',
/** 运单号多行文本,提交时拆分为 waybill_codes 数组 */
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
waybill_codes: ''
})
/** 弹窗打开时的快递公司编码,用于判断是否需要提交 express_code(支持传空值置 NULL) */
let updateExpressOriginalExpressCode = ''
/** 运单号列表归一化为字符串数组(兼容 JSON 数组 / 分隔字符串) */
function normalizeWaybillCodes(v: any): string[] {
if (Array.isArray(v)) return v.map((item) => String(item).trim()).filter(Boolean)
if (v === null || v === undefined || v === '') return []
return String(v)
.split(/[,;,;\n]+/)
.map((s) => s.trim())
.filter(Boolean)
}
function openUpdateExpressDialog() {
const rows = selectionRows.value
@ -819,7 +876,14 @@ function openUpdateExpressDialog() {
updateExpressTargetRow.value = row
// 快递公司编码回填;运单号以 waybill_codes 为准(兼容单数 waybill_code)
updateExpressForm.express_code = String(row?.express_code ?? '')
<<<<<<< HEAD
updateExpressOriginalExpressCode = updateExpressForm.express_code
updateExpressForm.waybill_code = String(row?.waybill_code ?? '')
updateExpressForm.waybill_codes = normalizeWaybillCodes(row?.waybill_codes).join('\n')
// 快递公司下拉复用「修改出库单信息」的 index.getExpressList 选项,首次打开时加载
=======
updateExpressForm.waybill_codes = normalizeStockoutWaybillCodes(row).join('\n')
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
if (!updateInfoExpressOptions.value.length) void loadUpdateInfoSelectOptions()
updateExpressDialogVisible.value = true
}
@ -828,6 +892,19 @@ async function handleUpdateExpressSubmit() {
const row = updateExpressTargetRow.value
if (!row) return
<<<<<<< HEAD
const payload: StockoutUpdateExpressParams = { id: row.id }
// express_code 是快递公司编码:传空值可将 express_code / express_name 置 NULL,
// 因此仅在值发生变化时提交,避免误清空
const expressCode = updateExpressForm.express_code.trim()
if (expressCode !== updateExpressOriginalExpressCode.trim()) payload.express_code = expressCode
const waybillCode = updateExpressForm.waybill_code.trim()
if (waybillCode) payload.waybill_code = waybillCode
const waybillCodes = normalizeWaybillCodes(updateExpressForm.waybill_codes)
if (waybillCodes.length) payload.waybill_codes = waybillCodes
if (payload.express_code === undefined && !payload.waybill_code && !payload.waybill_codes) {
=======
// 未传入的字段不会被更新;与原值不同才提交(空值表示清空)
const payload: StockoutUpdateExpressParams = { id: Number(row.id) }
let changed = false
@ -846,6 +923,7 @@ async function handleUpdateExpressSubmit() {
}
if (!changed) {
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
ElMessage.warning('没有需要更新的字段')
return
}
@ -854,12 +932,22 @@ async function handleUpdateExpressSubmit() {
try {
const res: any = await stockoutApi.stockoutUpdateExpress(payload)
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
<<<<<<< HEAD
const data = res?.data || res
// 用响应同步当前行展示(列表字段与接口字段同名)
if (data?.express_code !== undefined) row.express_code = data.express_code
if (data?.express_name !== undefined) row.express_name = data.express_name
if (data?.waybill_code !== undefined) row.waybill_code = data.waybill_code
if (data?.waybill_codes !== undefined) row.waybill_codes = data.waybill_codes
ElMessage.success('快递与运单号更新成功')
=======
const data = res.data ?? res
const expressName = String(data?.express_name ?? '').trim()
const codeCount = Array.isArray(data?.waybill_codes) ? data.waybill_codes.length : 0
ElMessage.success(
`更新成功${expressName ? `:${expressName}` : ''}${codeCount ? `(${codeCount} 个运单号)` : ''}`
)
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
updateExpressDialogVisible.value = false
loadData()
} else {
@ -1115,10 +1203,17 @@ async function fetchPrintData(row: any, _index: number) {
// 其余单据信息
stockout_order_code: row.stockout_order_code || '',
express_code: row.express_code || '',
<<<<<<< HEAD
waybill_code: row.waybill_code || '',
waybill_codes: row.waybill_codes || '',
// 旧字段(已废弃),保留以兼容历史模板
express_codes: row.express_codes || '',
=======
// 运单号:模板字段名 express_codes 保留以兼容旧模板,取值以 waybill_codes 口径为准
express_codes: waybillCodes.join(','),
waybill_code: waybillCodes[0] || '',
waybill_codes: waybillCodes.join(','),
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
order_type: row.order_type || '',
source_type: row.source_type || '',
order_status: row.order_status || '',
@ -1166,9 +1261,15 @@ async function fetchPrintData(row: any, _index: number) {
create_at: pick(['create_at', 'created_at'], formData.create_at),
stockout_order_code: order.stockout_order_code || formData.stockout_order_code,
express_code: order.express_code ?? formData.express_code,
<<<<<<< HEAD
waybill_code: order.waybill_code ?? formData.waybill_code,
waybill_codes: order.waybill_codes ?? formData.waybill_codes,
express_codes: order.express_codes ?? formData.express_codes,
=======
express_codes: orderWaybillCodes.length ? orderWaybillCodes.join(',') : formData.express_codes,
waybill_code: orderWaybillCodes[0] || formData.waybill_code,
waybill_codes: orderWaybillCodes.length ? orderWaybillCodes.join(',') : formData.waybill_codes,
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
order_type: order.order_type ?? formData.order_type,
source_type: order.source_type ?? formData.source_type,
order_status: order.order_status ?? formData.order_status,
@ -1300,6 +1401,19 @@ async function handleSingleRowStockout(row: any) {
} else {
ElMessage.success('出库成功')
}
<<<<<<< HEAD
if (data?.expressCodes) {
row.express_codes = data.expressCodes
}
if (data?.waybillCode) {
row.waybill_code = data.waybillCode
}
if (data?.waybillCodes) {
row.waybill_codes = data.waybillCodes
}
ElMessage.success('出库成功')
=======
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
loadData()
} else {
ElMessage.error(res?.message || '出库失败')

View File

@ -159,6 +159,22 @@ export function formatDateTime(dateStr: string): string {
}
}
<<<<<<< HEAD
// 运单号列:优先 waybill_code / waybill_codes(当前接口字段),兼容旧字段 express_codes(数组或分隔字符串),去重后展示
export function formatExpressCodes(row: any): string {
const flatten = (v: any): string[] => {
if (v === null || v === undefined || v === '') return []
if (Array.isArray(v)) {
return v.map(item => String(item).trim()).filter(Boolean)
}
return String(v)
.split(/[,;,;\n]+/)
.map(s => s.trim())
.filter(Boolean)
}
const codes = [...flatten(row?.waybill_code), ...flatten(row?.waybill_codes), ...flatten(row?.express_codes)]
const unique = [...new Set(codes)]
=======
/** 运单号拆分:支持数组、以及逗号/分号/顿号/换行分隔的字符串 */
export function splitStockoutWaybillCodes(value: unknown): string[] {
if (value === null || value === undefined || value === '') return []
@ -194,6 +210,7 @@ export function isSameStockoutWaybillCodes(a: string[], b: string[]): boolean {
// 运单号列:以 waybill_codes 为准,回退单数 waybill_code / 旧 express_codes(数组或分隔字符串),去重后展示
export function formatExpressCodes(row: any): string {
const unique = normalizeStockoutWaybillCodes(row, { includeLegacy: true })
>>>>>>> f4db2401638744bb2c1a5d132f23f0f470b76598
if (!unique.length) return '--'
const escapeHtml = (s: string) =>
s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')