zhou zhou
3 小时以前 e12fb4e6e8e0a408e81ce05a269a15cc535d8c78
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const CHECK_DIFF_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 buildCheckDiffPageRequestParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...filterParams(params, ['current', 'pageSize', 'size'])
  }
}
 
export function buildCheckDiffItemPageRequestParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...filterParams(params, ['current', 'pageSize', 'size'])
  }
}
 
export function createCheckDiffSearchState() {
  return {
    condition: '',
    orderCode: '',
    checkType: '',
    exceStatus: '',
    areaId: '',
    areaName: '',
    memo: ''
  }
}
 
export function buildCheckDiffSearchParams(params = {}) {
  return filterParams(params, ['current', 'pageSize', 'size'])
}
 
export function buildCheckDiffPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...filterParams(params, ['current', 'pageSize', 'size'])
  }
}
 
export function buildCheckDiffDetailQueryParams(params = {}) {
  return {
    checkId: params.checkId,
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20
  }
}
 
function getCheckTypeLabel(checkType) {
  if (checkType === 0 || checkType === '0') return '明盘'
  if (checkType === 1 || checkType === '1') return '暗盘'
  if (checkType === null || checkType === undefined || checkType === '') return '-'
  return String(checkType)
}
 
function getCheckDiffStatusMeta(status) {
  const normalized = Number(status)
  if (normalized === 1) {
    return { text: '执行中', type: 'warning' }
  }
  if (normalized === 2) {
    return { text: '已完成', type: 'success' }
  }
  if (normalized === 8) {
    return { text: '已取消', type: 'danger' }
  }
  return { text: '未执行', type: 'info' }
}
 
export function normalizeCheckDiffRow(row = {}) {
  const statusMeta = getCheckDiffStatusMeta(row.exceStatus ?? row.exceStatus$)
  return {
    ...row,
    checkTypeLabel: row.checkTypeLabel || row.checkType$ || getCheckTypeLabel(row.checkType),
    exceStatusLabel: row.exceStatusLabel || row.exceStatus$ || statusMeta.text,
    exceStatusTagType: row.exceStatusTagType || statusMeta.type,
    createTimeText: row.createTimeText || row.createTime$ || row.createTime || '-',
    updateTimeText: row.updateTimeText || row.updateTime$ || row.updateTime || '-'
  }
}
 
export function getCheckDiffActionList(record = {}) {
  return [
    { key: 'view', label: '查看详情', icon: 'ri:file-list-3-line' },
    { key: 'print', label: '打印', icon: 'ri:printer-line' },
    {
      key: 'delete',
      label: '删除',
      icon: 'ri:delete-bin-4-line',
      color: '#f56c6c',
      auth: 'delete'
    }
  ].filter((item) => item.key !== 'delete' || Number(record.exceStatus) === 0 || Number(record.exceStatus) === 1)
}
 
export function buildCheckDiffPrintRows(records = []) {
  return Array.isArray(records) ? records.map((item) => normalizeCheckDiffRow(item)) : []
}
 
export function buildCheckDiffReportMeta(rows = []) {
  return {
    reportTitle: CHECK_DIFF_REPORT_TITLE,
    reportDate: new Date().toLocaleDateString('zh-CN'),
    printedAt: new Date().toLocaleString('zh-CN', { hour12: false }),
    count: rows.length
  }
}
 
export { CHECK_DIFF_REPORT_TITLE, getCheckDiffStatusMeta }