/**
|
* 发货台账详情解包
|
*
|
* 后端 /shippingInfo/getDateil/{id} 的产品明细数组所在字段名在不同流程下不一致
|
* (审批详情走 shippingProductDetailDtoList,发货台账走 batchNoDetailList 等),
|
* 行内的批次号/数量也有多套命名。集中在这里探测,页面里不出现裸字段名。
|
*/
|
import { toFileList } from "@/utils/file";
|
|
const LIST_KEYS = [
|
"batchNoDetailList",
|
"batchNoList",
|
"shippingBatchList",
|
"shippingInfoDetailList",
|
"shippingProductDetailDtoList",
|
"detailList",
|
"batchDetailList",
|
"rows",
|
"records",
|
"list",
|
];
|
|
function pickList(source) {
|
if (!source) return [];
|
for (const key of LIST_KEYS) {
|
if (Array.isArray(source[key])) return source[key];
|
}
|
return [];
|
}
|
|
const pick = (row, keys) => {
|
for (const key of keys) {
|
const value = row?.[key];
|
if (value !== undefined && value !== null && value !== "") return value;
|
}
|
return "";
|
};
|
|
/**
|
* 归一化产品明细行
|
* @returns {Array<{batchNo, productName, specificationModel, deliveryQuantity, unit, remark}>}
|
*/
|
export function resolveDeliveryProducts(data) {
|
return pickList(data).map(row => ({
|
batchNo: pick(row, ["batchNo", "batchNumber"]),
|
productName: pick(row, ["productName", "product"]),
|
specificationModel: pick(row, ["specificationModel", "model", "specification"]),
|
deliveryQuantity: pick(row, ["deliveryQuantity", "quantity", "shippingQuantity"]),
|
unit: pick(row, ["unit", "measureUnit"]),
|
remark: pick(row, ["remark", "remarks"]),
|
}));
|
}
|
|
/**
|
* 发货图片回显:deliveryFileList / storageBlobVOs 两种命名
|
*/
|
export function resolveDeliveryFiles(data) {
|
return toFileList(
|
data?.deliveryFileList || data?.storageBlobVOs || data?.fileList
|
);
|
}
|
|
/**
|
* 退货单号列表:兼容字符串数组与 [{returnNo}] 两种结构
|
*/
|
export function resolveReturnNos(source) {
|
if (!Array.isArray(source)) return [];
|
return source
|
.map(item =>
|
typeof item === "string" || typeof item === "number"
|
? String(item)
|
: item?.returnNo || item?.returnOrderNo || ""
|
)
|
.filter(Boolean);
|
}
|