gaoluyang
6 小时以前 e449a5408265e4bd1f6c66f5be28a42efac444ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 * 发货台账详情解包
 *
 * 后端 /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);
}