approval-fields.ts
3.48 KB
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
import type { FieldSchema } from '@/components';
import type { DictOption } from '@/api';
import { compactParams, expandDateRanges } from '@/features/shared/format';
import { APPROVAL_STATUS, statusOptions, withAll } from '@/features/shared/dictionaries';
/**
* 积分提现审批的筛选区(字段名与顺序对齐老系统 approve.vue 的 showFormData)。
*
* 老系统「付款渠道」是一个三层级联(渠道 → 付款主体 → 代征主体),
* 提交的是级联第 2、3 层的 id:paymentSubjectId 与 paymentChannelId(后者存的是代征主体,字段名沿用接口)。
* 现系统的 SearchForm 还不支持级联懒加载,因此拆成三个下拉,选了上一层才拉下一层,提交值与老系统逐字相同。
*/
const DATE_RANGES = [
{ from: 'approvalTime', start: 'approvalTimeStart', end: 'approvalTimeEnd' },
{ from: 'oaApprovalTime', start: 'oaApprovalTimeStart', end: 'oaApprovalTimeEnd' },
{ from: 'userSettleTime', start: 'userSettleTimeStart', end: 'userSettleTimeEnd' },
];
/** `channel` 只是第一个下拉的联动用字段,接口没有这个入参,提交前去掉。 */
export function toApprovalParams(values: Record<string, unknown>): Record<string, unknown> {
const params = expandDateRanges({ ...values }, DATE_RANGES);
delete params.channel;
return compactParams(params);
}
export interface ApprovalFieldDeps {
channels: DictOption[];
entities: DictOption[];
levies: DictOption[];
/** 已选中的上层,用于禁用还没到手的下层(老级联框也是选完上一层才展开下一层)。 */
channel?: string;
entity?: string;
/** 换上层要清掉下层的选择,否则提交的是「老主体 + 新渠道」这种组合。 */
onChannelChange: (channel?: string) => void;
onEntityChange: (entity?: string) => void;
}
export function buildApprovalFields(
deps: ApprovalFieldDeps,
): FieldSchema<Record<string, unknown>>[] {
return [
{
name: 'batchNo',
label: '批次号',
type: 'input',
placeholder: '请输入批次号',
inputProps: { maxLength: 20 },
essential: true,
},
{
name: 'oaSpNo',
label: 'OA审批编号',
type: 'input',
placeholder: '请输入OA审批编号',
inputProps: { maxLength: 20 },
essential: true,
},
{
name: 'channel',
label: '付款渠道',
type: 'select',
options: withAll(deps.channels),
selectProps: {
onChange: (value) => {
deps.onChannelChange(value === undefined || value === '' ? undefined : String(value));
deps.onEntityChange(undefined);
},
},
},
{
name: 'paymentSubjectId',
label: '付款主体',
type: 'select',
options: withAll(deps.entities),
disabled: !deps.channel,
selectProps: {
onChange: (value) =>
deps.onEntityChange(value === undefined || value === '' ? undefined : String(value)),
},
},
{
name: 'paymentChannelId',
label: '代征主体',
type: 'select',
options: withAll(deps.levies),
disabled: !deps.entity,
},
{
name: 'status',
label: '状态',
type: 'select',
options: withAll(statusOptions(APPROVAL_STATUS)),
essential: true,
},
{ name: 'approvalTime', label: '审批时间', type: 'dateRange', essential: true },
{ name: 'oaApprovalTime', label: 'OA审批时间', type: 'dateRange' },
{ name: 'userSettleTime', label: '付款时间', type: 'dateRange' },
];
}