zhou zhou
1 天以前 0a1d91e42e6c5af96e1108e9ebcc37e99eb3b22c
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 SERIAL_RULE_RESET_OPTIONS = [
  { label: '年重置', value: 'year' },
  { label: '月重置', value: 'month' },
  { label: '日重置', value: 'day' }
]
 
export function createSerialRuleSearchState() {
  return {
    condition: '',
    code: '',
    name: '',
    reset: '',
    status: ''
  }
}
 
export function createSerialRuleFormState() {
  return {
    id: null,
    code: '',
    name: '',
    delimit: '',
    reset: '',
    resetDep: '',
    currValue: 0,
    lastCode: '',
    status: 1,
    memo: ''
  }
}
 
export function getSerialRulePaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getSerialRuleResetOptions() {
  return SERIAL_RULE_RESET_OPTIONS
}
 
export function getSerialRuleResetLabel(value) {
  return SERIAL_RULE_RESET_OPTIONS.find((item) => item.value === value)?.label || value || '-'
}
 
export function getSerialRuleStatusMeta(status) {
  return Number(status) === 1
    ? { text: '正常', type: 'success', bool: true }
    : { text: '冻结', type: 'danger', bool: false }
}
 
export function buildSerialRuleSearchParams(params = {}) {
  return {
    condition: String(params.condition || '').trim(),
    code: String(params.code || '').trim(),
    name: String(params.name || '').trim(),
    ...(params.reset ? { reset: String(params.reset) } : {}),
    ...(params.status !== '' && params.status !== null && params.status !== undefined
      ? { status: Number(params.status) }
      : {})
  }
}
 
export function buildSerialRulePageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildSerialRuleSearchParams(params)
  }
}
 
export function buildSerialRuleDialogModel(record = {}) {
  return {
    ...createSerialRuleFormState(),
    ...(record.id ? { id: Number(record.id) } : {}),
    code: record.code || '',
    name: record.name || '',
    delimit: record.delimit || '',
    reset: record.reset || '',
    resetDep: record.resetDep || '',
    currValue: record.currValue !== undefined && record.currValue !== null ? Number(record.currValue) : 0,
    lastCode: record.lastCode || '',
    status: record.status !== undefined && record.status !== null ? Number(record.status) : 1,
    memo: record.memo || ''
  }
}
 
export function buildSerialRuleSavePayload(formData = {}) {
  return {
    ...(formData.id ? { id: Number(formData.id) } : {}),
    code: String(formData.code || '').trim(),
    name: String(formData.name || '').trim(),
    delimit: String(formData.delimit || '').trim(),
    reset: String(formData.reset || '').trim(),
    resetDep: String(formData.resetDep || '').trim(),
    currValue: Number(formData.currValue || 0),
    lastCode: String(formData.lastCode || '').trim(),
    status: Number(formData.status ?? 1),
    memo: String(formData.memo || '').trim()
  }
}
 
export function normalizeSerialRuleListRow(record = {}) {
  const statusMeta = getSerialRuleStatusMeta(record.status)
  return {
    ...record,
    code: record.code || '',
    name: record.name || '',
    delimit: record.delimit || '-',
    resetText: record['reset$'] || getSerialRuleResetLabel(record.reset),
    resetDep: record.resetDep || '-',
    currValue: record.currValue ?? 0,
    lastCode: record.lastCode || '-',
    memo: record.memo || '',
    statusText: record['status$'] || statusMeta.text,
    statusType: statusMeta.type,
    statusBool: record.statusBool ?? statusMeta.bool,
    updateByLabel: record['updateBy$'] || '',
    createByLabel: record['createBy$'] || '',
    updateTimeText: record['updateTime$'] || record.updateTime || '',
    createTimeText: record['createTime$'] || record.createTime || ''
  }
}