liu
2026-09-29 7a6351a1fa5fc6e67b55c475bcd253d6d3e5d68f
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ResearchApplicationApi } from '#/api/research/application';
import type { ResearchFundRecordApi } from '#/api/research/fund';
 
import { computed, ref } from 'vue';
 
import { useVbenModal } from '@vben/common-ui';
 
import { Alert, message, Tag } from 'ant-design-vue';
 
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getApplication } from '#/api/research/application';
import { deleteFundRecord, getFundRecordList } from '#/api/research/fund';
 
import { ApplicationStatus, FundStatus, useFundColumns } from '../data';
import FundForm from './fund-form.vue';
 
defineOptions({ name: 'ResearchFundPanel' });
 
const emit = defineEmits(['success']);
 
const applicationId = ref<number>();
const application = ref<ResearchApplicationApi.Application>();
const records = ref<ResearchFundRecordApi.FundRecord[]>([]);
 
/** 仅「已立项」的申报单可登记拨款 */
const editable = computed(
  () => application.value?.status === ApplicationStatus.APPROVED,
);
 
/** 已登记拨付金额合计 */
const registeredAmount = computed(() =>
  records.value.reduce((sum, item) => sum + (Number(item.amount) || 0), 0),
);
 
/** 申请经费可用余额(负数表示已超额登记) */
const remainder = computed(
  () => (Number(application.value?.budgetAmount) || 0) - registeredAmount.value,
);
 
/** 各状态记录数量,用于顶部提示(0 条时不提示) */
const statusCount = (status: number) =>
  records.value.filter((item) => item.status === status).length;
 
const [FundFormModal, fundFormModalApi] = useVbenModal({
  connectedComponent: FundForm,
  destroyOnClose: true,
});
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    columns: useFundColumns(true),
    data: [],
    minHeight: 280,
    autoResize: true,
    border: true,
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    pagerConfig: {
      enabled: false,
    },
    toolbarConfig: {
      enabled: false,
    },
  } as VxeTableGridOptions<ResearchFundRecordApi.FundRecord>,
});
 
async function refresh() {
  if (!applicationId.value) {
    return;
  }
  const [recordList, applicationDetail] = await Promise.all([
    getFundRecordList(applicationId.value),
    getApplication(applicationId.value),
  ]);
  records.value = recordList;
  application.value = applicationDetail;
  gridApi.setGridOptions({ data: recordList });
}
 
/** 拨款记录增删改后:本面板重载,同时通知列表页刷新 */
async function handleChanged() {
  await refresh();
  emit('success');
}
 
function handleCreate() {
  fundFormModalApi
    .setData({ applicationId: applicationId.value!, remainder: remainder.value })
    .open();
}
 
function handleEdit(row: ResearchFundRecordApi.FundRecord) {
  fundFormModalApi
    .setData({
      applicationId: applicationId.value!,
      // 编辑时把当前记录自身金额加回,避免用户看到「余额」偏小产生误解
      remainder: remainder.value + (Number(row.amount) || 0),
      record: row,
    })
    .open();
}
 
async function handleDelete(row: ResearchFundRecordApi.FundRecord) {
  const hideLoading = message.loading({ content: '删除中...', duration: 0 });
  try {
    await deleteFundRecord(row.id!);
    message.success('删除成功');
    await handleChanged();
  } finally {
    hideLoading();
  }
}
 
const [Modal, modalApi] = useVbenModal({
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      applicationId.value = undefined;
      application.value = undefined;
      records.value = [];
      return;
    }
    const data = modalApi.getData<{ id: number }>();
    applicationId.value = data.id;
    modalApi.lock();
    try {
      const [recordList, applicationDetail] = await Promise.all([
        getFundRecordList(data.id),
        getApplication(data.id),
      ]);
      records.value = recordList;
      application.value = applicationDetail;
      gridApi.setGridOptions({ data: recordList });
    } finally {
      modalApi.unlock();
    }
  },
});
</script>
 
<template>
  <Modal title="经费拨付" class="w-4/5" :show-confirm-button="false">
    <div class="space-y-3">
      <Alert
        v-if="!editable"
        type="info"
        show-icon
        message="仅「已立项」的课题申报书可以登记经费拨付记录"
      />
      <div class="flex flex-wrap items-center gap-6 rounded border border-border p-3">
        <div>
          <span class="text-gray-500">课题名称:</span>
          <span class="font-medium">{{ application?.title || '-' }}</span>
        </div>
        <div>
          <span class="text-gray-500">立项编号:</span>
          <span class="font-medium">{{ application?.researchNo || '未立项' }}</span>
        </div>
        <div>
          <span class="text-gray-500">申请经费:</span>
          <span class="font-medium">
            {{ Number(application?.budgetAmount || 0).toFixed(2) }} 元
          </span>
        </div>
        <div>
          <span class="text-gray-500">已登记拨付:</span>
          <span class="font-medium">{{ registeredAmount.toFixed(2) }} 元</span>
        </div>
        <div>
          <span class="text-gray-500">可用余额:</span>
          <span
            class="font-medium"
            :class="remainder < 0 ? 'text-red-500' : ''"
          >
            {{ remainder.toFixed(2) }} 元
          </span>
        </div>
      </div>
 
      <Alert
        v-if="statusCount(FundStatus.APPROVING) > 0"
        type="info"
        show-icon
        :message="`有 ${statusCount(FundStatus.APPROVING)} 条拨付记录正在报销审批中,暂不可修改;财务审批结果将自动回写本记录`"
      />
      <Alert
        v-if="statusCount(FundStatus.PAID) > 0"
        type="success"
        show-icon
        :message="`有 ${statusCount(FundStatus.PAID)} 条拨付记录财务已通过,拨款完成`"
      />
      <Alert
        v-if="statusCount(FundStatus.REJECTED) > 0"
        type="error"
        show-icon
        :message="`有 ${statusCount(FundStatus.REJECTED)} 条拨付记录财务已驳回,请修改金额或凭证后点「重新发起报销」`"
      />
 
      <div v-if="editable">
        <TableAction
          :actions="[
            {
              label: '登记拨款记录',
              type: 'primary',
              icon: ACTION_ICON.ADD,
              auth: ['research:fund:create'],
              onClick: handleCreate,
            },
          ]"
        />
      </div>
 
      <Grid>
        <template #hasAttachment="{ row }">
          <Tag :color="row.hasAttachment ? 'success' : 'warning'">
            {{ row.hasAttachment ? '已上传' : '缺失' }}
          </Tag>
        </template>
        <template #actions="{ row }">
          <TableAction
            v-if="editable"
            :actions="[
              {
                label: '编辑',
                type: 'link',
                icon: ACTION_ICON.EDIT,
                auth: ['research:fund:update'],
                ifShow: () => row.status === FundStatus.PENDING,
                onClick: handleEdit.bind(null, row),
              },
              {
                label: '重新发起报销',
                type: 'link',
                icon: ACTION_ICON.REFRESH,
                auth: ['research:fund:update'],
                ifShow: () => row.status === FundStatus.REJECTED,
                onClick: handleEdit.bind(null, row),
              },
              {
                label: '删除',
                type: 'link',
                danger: true,
                icon: ACTION_ICON.DELETE,
                auth: ['research:fund:delete'],
                ifShow: () => row.status === FundStatus.PENDING,
                popConfirm: {
                  title: `确认删除「${row.batchName || '本条'}」拨款记录吗?`,
                  confirm: handleDelete.bind(null, row),
                },
              },
            ]"
          />
        </template>
      </Grid>
    </div>
  </Modal>
  <FundFormModal @success="handleChanged" />
</template>