1
This commit is contained in:
parent
cc9c0f71c4
commit
2cc558be60
@ -176,20 +176,31 @@ export const stockoutConfirm = (data: StockoutConfirmParams) => {
|
||||
export type StockoutUpdateExpressParams = {
|
||||
/** 出库单ID(必填) */
|
||||
id: number
|
||||
/** 运单号 */
|
||||
/** 快递公司编码(非运单号,如 SF/STO/ZT);传入后自动解析 express_name,传空值置 NULL */
|
||||
express_code?: string
|
||||
/** 运单号列表(JSON 数组) */
|
||||
express_codes?: string[]
|
||||
/** 运单号(单个);storage.stockout.confirm 前必须已填写该字段 */
|
||||
waybill_code?: string
|
||||
/** 运单号列表(JSON 数组或 null,支持多包裹场景);非数组返回 400 */
|
||||
waybill_codes?: string[] | null
|
||||
}
|
||||
|
||||
export type StockoutUpdateExpressResponse = {
|
||||
id: number
|
||||
stockout_order_code: string
|
||||
/** 更新后的快递公司编码 */
|
||||
express_code?: string
|
||||
express_codes?: string[]
|
||||
/** 由 express_code 解析出的快递公司名称 */
|
||||
express_name?: string
|
||||
/** 更新后的运单号 */
|
||||
waybill_code?: string
|
||||
/** 更新后的运单号列表 */
|
||||
waybill_codes?: string[]
|
||||
}
|
||||
|
||||
/** 更新出库单的运单号字段(express_code / express_codes),用于在确认前填写运单信息 */
|
||||
/**
|
||||
* 更新出库单的快递公司与运单号(express_code / waybill_code / waybill_codes),用于在确认前填写运单信息。
|
||||
* 未传入的字段不更新,三个字段都未传时返回「没有需要更新的字段」;已废弃字段 express_codes 不在本接口读写范围内。
|
||||
*/
|
||||
export const stockoutUpdateExpress = (data: StockoutUpdateExpressParams) => {
|
||||
return request({
|
||||
url: `/system`,
|
||||
|
||||
@ -393,7 +393,7 @@
|
||||
|
||||
<el-dialog
|
||||
v-model="updateExpressDialogVisible"
|
||||
title="更新运单号"
|
||||
title="更新快递与运单号"
|
||||
width="520px"
|
||||
align-center
|
||||
append-to-body
|
||||
@ -408,16 +408,41 @@
|
||||
: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"
|
||||
placeholder="快递公司编码(如 SF/STO/ZT),清空则置空"
|
||||
clearable
|
||||
filterable
|
||||
allow-create
|
||||
default-first-option
|
||||
style="width:100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in updateInfoExpressOptions"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="运单号">
|
||||
<el-input v-model="updateExpressForm.express_code" placeholder="运单号" clearable />
|
||||
<el-input v-model="updateExpressForm.waybill_code" placeholder="运单号(单个)" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="运单号列表">
|
||||
<el-input
|
||||
v-model="updateExpressForm.express_codes"
|
||||
v-model="updateExpressForm.waybill_codes"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="多个运单号用逗号或换行分隔(可选)"
|
||||
placeholder="多包裹运单号,用逗号或换行分隔(可选)"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
@ -445,7 +470,7 @@ 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
|
||||
import type { StockoutToOrderParams, StockoutUpdateInfoParams } from '@/api/storage.stockout/stockout'
|
||||
import type { StockoutToOrderParams, StockoutUpdateExpressParams, StockoutUpdateInfoParams } from '@/api/storage.stockout/stockout'
|
||||
import {
|
||||
availableFields,
|
||||
entryColums,
|
||||
@ -774,14 +799,30 @@ async function handleSingleRowCancel(row: any) {
|
||||
}
|
||||
}
|
||||
|
||||
// ── 更新运单号(storage.stockout.updateExpress)──
|
||||
// ── 更新快递与运单号(storage.stockout.updateExpress)──
|
||||
const updateExpressDialogVisible = ref(false)
|
||||
const updateExpressLoading = ref(false)
|
||||
const updateExpressTargetRow = ref<any>(null)
|
||||
const updateExpressForm = reactive({
|
||||
/** 快递公司编码(如 SF/STO/ZT),非运单号 */
|
||||
express_code: '',
|
||||
express_codes: ''
|
||||
/** 运单号(单个) */
|
||||
waybill_code: '',
|
||||
/** 运单号列表(多包裹,文本按逗号/换行分隔) */
|
||||
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
|
||||
@ -796,29 +837,44 @@ function openUpdateExpressDialog() {
|
||||
const row = rows[0]
|
||||
updateExpressTargetRow.value = row
|
||||
updateExpressForm.express_code = String(row?.express_code ?? '')
|
||||
updateExpressForm.express_codes = Array.isArray(row?.express_codes)
|
||||
? row.express_codes.join('\n')
|
||||
: String(row?.express_codes ?? '')
|
||||
updateExpressOriginalExpressCode = updateExpressForm.express_code
|
||||
updateExpressForm.waybill_code = String(row?.waybill_code ?? '')
|
||||
updateExpressForm.waybill_codes = normalizeWaybillCodes(row?.waybill_codes).join('\n')
|
||||
// 快递公司下拉复用「修改出库单信息」的 index.getExpressList 选项,首次打开时加载
|
||||
if (!updateInfoExpressOptions.value.length) void loadUpdateInfoSelectOptions()
|
||||
updateExpressDialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleUpdateExpressSubmit() {
|
||||
const row = updateExpressTargetRow.value
|
||||
if (!row) return
|
||||
const payload: any = { id: row.id }
|
||||
const code = updateExpressForm.express_code.trim()
|
||||
if (code) payload.express_code = code
|
||||
const codes = updateExpressForm.express_codes
|
||||
.split(/[,;\n]+/)
|
||||
.map((s: string) => s.trim())
|
||||
.filter(Boolean)
|
||||
if (codes.length) payload.express_codes = codes
|
||||
|
||||
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) {
|
||||
ElMessage.warning('没有需要更新的字段')
|
||||
return
|
||||
}
|
||||
|
||||
updateExpressLoading.value = true
|
||||
try {
|
||||
const res: any = await stockoutApi.stockoutUpdateExpress(payload)
|
||||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
|
||||
ElMessage.success('运单号更新成功')
|
||||
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('快递与运单号更新成功')
|
||||
updateExpressDialogVisible.value = false
|
||||
loadData()
|
||||
} else {
|
||||
@ -1071,6 +1127,9 @@ async function fetchPrintData(row: any, _index: number) {
|
||||
// 其余单据信息
|
||||
stockout_order_code: row.stockout_order_code || '',
|
||||
express_code: row.express_code || '',
|
||||
waybill_code: row.waybill_code || '',
|
||||
waybill_codes: row.waybill_codes || '',
|
||||
// 旧字段(已废弃),保留以兼容历史模板
|
||||
express_codes: row.express_codes || '',
|
||||
order_type: row.order_type || '',
|
||||
source_type: row.source_type || '',
|
||||
@ -1116,6 +1175,8 @@ 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,
|
||||
waybill_code: order.waybill_code ?? formData.waybill_code,
|
||||
waybill_codes: order.waybill_codes ?? formData.waybill_codes,
|
||||
express_codes: order.express_codes ?? formData.express_codes,
|
||||
order_type: order.order_type ?? formData.order_type,
|
||||
source_type: order.source_type ?? formData.source_type,
|
||||
@ -1242,6 +1303,12 @@ async function handleSingleRowStockout(row: any) {
|
||||
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('出库成功')
|
||||
loadData()
|
||||
} else {
|
||||
|
||||
@ -159,7 +159,7 @@ export function formatDateTime(dateStr: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
// 运单号列:express_codes 为空时回退 waybill_code / waybill_codes(数组或分隔字符串),去重后展示
|
||||
// 运单号列:优先 waybill_code / waybill_codes(当前接口字段),兼容旧字段 express_codes(数组或分隔字符串),去重后展示
|
||||
export function formatExpressCodes(row: any): string {
|
||||
const flatten = (v: any): string[] => {
|
||||
if (v === null || v === undefined || v === '') return []
|
||||
@ -171,7 +171,7 @@ export function formatExpressCodes(row: any): string {
|
||||
.map(s => s.trim())
|
||||
.filter(Boolean)
|
||||
}
|
||||
const codes = [...flatten(row?.express_codes), ...flatten(row?.waybill_code), ...flatten(row?.waybill_codes)]
|
||||
const codes = [...flatten(row?.waybill_code), ...flatten(row?.waybill_codes), ...flatten(row?.express_codes)]
|
||||
const unique = [...new Set(codes)]
|
||||
if (!unique.length) return '--'
|
||||
const escapeHtml = (s: string) =>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user