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
| <script lang="ts" setup>
| import type { ResearchFundRecordApi } from '#/api/research/fund';
|
| import { computed, ref } from 'vue';
|
| 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 rejectReason = ref('');
|
| 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: '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,
| },
| rules: 'required',
| help: '必填:凭证将随自动生成的财务报销单一起送交财务审批',
| 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.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,
| remark: values.remark,
| blobIds: values.blobIds,
| } as ResearchFundRecordApi.FundRecord;
| try {
| await (data.id ? updateFundRecord(data) : createFundRecord(data));
| await modalApi.close();
| emit('success');
| message.success(
| data.id ? '已重新发起财务报销审批' : '登记成功,已自动提交财务报销审批',
| );
| } finally {
| modalApi.unlock();
| }
| },
| async onOpenChange(isOpen: boolean) {
| if (!isOpen) {
| isEdit.value = false;
| remainder.value = undefined;
| rejectReason.value = '';
| return;
| }
| const data = modalApi.getData<{
| applicationId: number;
| remainder?: number;
| record?: ResearchFundRecordApi.FundRecord;
| }>();
| isEdit.value = !!data.record;
| remainder.value = data.remainder;
| rejectReason.value =
| data.record?.status === FundStatus.REJECTED
| ? data.record.rejectReason || '财务未填写驳回原因'
| : '';
| 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,
| },
| false,
| );
| }
| },
| });
| </script>
|
| <template>
| <Modal
| :title="isEdit ? '修改并重新发起报销' : '登记拨款(登记后自动提交财务报销审批)'"
| class="w-1/2"
| :close-on-click-modal="false"
| >
| <Alert
| v-if="rejectReason"
| class="mx-3 mb-3"
| type="error"
| show-icon
| :message="`财务报销已驳回:${rejectReason}`"
| />
| <Alert
| v-if="alertMessage"
| class="mx-3 mb-3"
| type="info"
| show-icon
| :message="alertMessage"
| />
| <Form class="mx-3" />
| </Modal>
| </template>
|
|