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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
| <script lang="ts" setup>
| import type { ResearchFundRecordApi } from '#/api/research/fund';
|
| import { computed, ref } from 'vue';
|
| import { DICT_TYPE } from '@vben/constants';
| import { getDictOptions } from '@vben/hooks';
|
| import { useVbenModal } from '@vben/common-ui';
|
| import { Alert, message } from 'ant-design-vue';
|
| import { useVbenForm } from '#/adapter/form';
| import { createFundRecord, updateFundRecord } from '#/api/research/fund';
|
| import { FundStatus } from '../data';
|
| defineOptions({ name: 'ResearchFundRecordForm' });
|
| const emit = defineEmits(['success']);
|
| const isEdit = ref(false);
| /** 申请经费减去已登记拨付金额后的可用余额 */
| const remainder = ref<number>();
|
| const alertMessage = computed(() => {
| if (remainder.value === undefined) {
| return '';
| }
| return `本课题申请经费可用余额:${remainder.value.toFixed(2)} 元,拨款金额累计不得超过申请经费`;
| });
|
| const [Form, formApi] = useVbenForm({
| commonConfig: {
| componentProps: {
| class: 'w-full',
| },
| labelWidth: 130,
| },
| wrapperClass: 'grid-cols-2',
| layout: 'vertical',
| schema: [
| {
| fieldName: 'id',
| component: 'Input',
| dependencies: {
| triggerFields: [''],
| show: () => false,
| },
| },
| {
| fieldName: 'applicationId',
| component: 'Input',
| dependencies: {
| triggerFields: [''],
| show: () => false,
| },
| },
| {
| fieldName: 'batchName',
| label: '拨付批次',
| component: 'Input',
| componentProps: {
| placeholder: '如:第一期',
| maxlength: 64,
| },
| },
| {
| fieldName: 'amount',
| label: '拨付金额(元)',
| component: 'InputNumber',
| componentProps: {
| class: '!w-full',
| placeholder: '请输入本次拨付金额',
| precision: 2,
| min: 0,
| },
| rules: 'required',
| },
| {
| fieldName: 'payDate',
| label: '拨付日期',
| component: 'DatePicker',
| componentProps: {
| placeholder: '请选择拨付日期',
| // 后端为 LocalDate,只能传 yyyy-MM-dd
| valueFormat: 'YYYY-MM-DD',
| style: { width: '100%' },
| },
| },
| {
| fieldName: 'payee',
| label: '收款单位/账户名',
| component: 'Input',
| componentProps: {
| placeholder: '请输入收款单位或账户名',
| maxlength: 128,
| },
| },
| {
| fieldName: 'status',
| label: '拨付状态',
| component: 'Select',
| componentProps: {
| options: getDictOptions(DICT_TYPE.RESEARCH_FUND_STATUS, 'number'),
| placeholder: '请选择拨付状态',
| },
| rules: 'selectRequired',
| help: '选择「已拨付」时必须上传拨付凭证附件',
| },
| {
| fieldName: 'remark',
| label: '备注',
| component: 'Textarea',
| componentProps: {
| placeholder: '请输入备注',
| autoSize: { minRows: 2, maxRows: 3 },
| },
| formItemClass: 'col-span-2',
| },
| {
| fieldName: 'blobIds',
| label: '拨付凭证',
| component: 'FileUpload',
| componentProps: {
| valueKey: 'id',
| maxNumber: 10,
| multiple: true,
| showDescription: true,
| },
| formItemClass: 'col-span-2',
| },
| ],
| showDefaultActions: false,
| });
|
| const [Modal, modalApi] = useVbenModal({
| async onConfirm() {
| const { valid } = await formApi.validate();
| if (!valid) {
| return;
| }
| const values =
| (await formApi.getValues()) as ResearchFundRecordApi.FundRecord;
| // 「已拨付」必须有凭证,先在前端拦一道,避免用户白等一次请求
| if (
| values.status === FundStatus.PAID &&
| (!values.blobIds || values.blobIds.length === 0)
| ) {
| message.warning('拨付状态为「已拨付」时,请先上传拨付凭证附件');
| return;
| }
| modalApi.lock();
| // 附件为全量替换语义:清空全部凭证时必须显式传空数组
| const data = {
| id: values.id,
| applicationId: values.applicationId,
| batchName: values.batchName,
| amount: values.amount,
| payDate: values.payDate,
| payee: values.payee,
| status: values.status,
| remark: values.remark,
| blobIds: values.blobIds ?? [],
| } as ResearchFundRecordApi.FundRecord;
| try {
| await (data.id ? updateFundRecord(data) : createFundRecord(data));
| await modalApi.close();
| emit('success');
| message.success('保存成功');
| } finally {
| modalApi.unlock();
| }
| },
| async onOpenChange(isOpen: boolean) {
| if (!isOpen) {
| isEdit.value = false;
| remainder.value = undefined;
| return;
| }
| const data = modalApi.getData<{
| applicationId: number;
| remainder?: number;
| record?: ResearchFundRecordApi.FundRecord;
| }>();
| isEdit.value = !!data.record;
| remainder.value = data.remainder;
| await formApi.resetForm();
| if (data.record) {
| const blobIds = (data.record.attachmentList ?? []).map((item) => ({
| uid: String(item.id),
| name: item.name || '',
| url: item.url || '',
| status: 'done',
| id: item.id,
| }));
| await formApi.setValues(
| {
| ...data.record,
| applicationId: data.applicationId,
| blobIds,
| },
| false,
| );
| } else {
| await formApi.setValues(
| {
| applicationId: data.applicationId,
| status: FundStatus.PENDING,
| },
| false,
| );
| }
| },
| });
| </script>
|
| <template>
| <Modal
| :title="isEdit ? '编辑拨款记录' : '登记拨款记录'"
| class="w-1/2"
| :close-on-click-modal="false"
| >
| <Alert
| v-if="alertMessage"
| class="mx-3 mb-3"
| type="info"
| show-icon
| :message="alertMessage"
| />
| <Form class="mx-3" />
| </Modal>
| </template>
|
|