zhou zhou
昨天 aaf8a50511d77dbc209ca93bbba308c21179a8bc
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const CHECK_DIFF_ITEM_REPORT_TITLE = '盘点差异明细报表'
 
function filterParams(params = {}, ignoredKeys = []) {
  return Object.fromEntries(
    Object.entries(params)
      .filter(([key, value]) => {
        if (ignoredKeys.includes(key)) return false
        if (value === undefined || value === null) return false
        if (typeof value === 'string' && value.trim() === '') return false
        return true
      })
      .map(([key, value]) => [key, typeof value === 'string' ? value.trim() : value])
  )
}
 
export function createCheckDiffItemSearchState() {
  return {
    condition: '',
    checkId: '',
    orderCode: '',
    matnrCode: '',
    barcode: '',
    reason: '',
    exceStatus: ''
  }
}
 
export function buildCheckDiffItemSearchParams(params = {}) {
  return filterParams(params, ['current', 'pageSize', 'size'])
}
 
export function buildCheckDiffItemPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...filterParams(params, ['current', 'pageSize', 'size'])
  }
}
 
function getCheckDiffItemStatusMeta(status) {
  const normalized = Number(status)
  if (normalized === 2) {
    return { text: '已完成', type: 'success' }
  }
  if (normalized === 1) {
    return { text: '处理中', type: 'warning' }
  }
  return { text: '待处理', type: 'info' }
}
 
export function normalizeCheckDiffItemRow(row = {}) {
  const statusMeta = getCheckDiffItemStatusMeta(row.exceStatus ?? row.exceStatus$)
  const checkQty = Number(row.checkQty ?? 0)
  const anfme = Number(row.anfme ?? 0)
  return {
    ...row,
    exceStatusLabel: row.exceStatusLabel || row.exceStatus$ || statusMeta.text,
    exceStatusTagType: row.exceStatusTagType || statusMeta.type,
    diffQty: row.diffQty ?? Number((checkQty - anfme).toFixed(3)),
    updateTimeText: row.updateTimeText || row.updateTime$ || row.updateTime || '-',
    createTimeText: row.createTimeText || row.createTime$ || row.createTime || '-'
  }
}
 
export function getCheckDiffItemActionList(record = {}) {
  return [
    { key: 'view', label: '查看详情', icon: 'ri:file-list-3-line' },
    {
      key: 'approve',
      label: '审批通过',
      icon: 'ri:checkbox-circle-line',
      auth: 'edit',
      disabled: Number(record.exceStatus) === 2
    }
  ]
}
 
export function buildCheckDiffItemPrintRows(records = []) {
  return Array.isArray(records) ? records.map((item) => normalizeCheckDiffItemRow(item)) : []
}
 
export function buildCheckDiffItemReportMeta(rows = []) {
  return {
    reportTitle: CHECK_DIFF_ITEM_REPORT_TITLE,
    reportDate: new Date().toLocaleDateString('zh-CN'),
    printedAt: new Date().toLocaleString('zh-CN', { hour12: false }),
    count: rows.length
  }
}
 
export { CHECK_DIFF_ITEM_REPORT_TITLE, getCheckDiffItemStatusMeta }