云
2026-09-28 d7538a8fb830c3de582b25e70566211987c4151f
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
<script lang="ts" setup>
import type { FinanceReimbursementApi } from '#/api/finance/reimbursement';
 
import { computed, ref } from 'vue';
 
import { useVbenModal } from '@vben/common-ui';
 
import { message, Select } from 'ant-design-vue';
 
import { submitReimbursement } from '#/api/finance/reimbursement';
 
const emit = defineEmits(['success']);
 
const reimbursementId = ref<number>();
const processList = ref<FinanceReimbursementApi.ProcessDefinition[]>([]);
const selectedProcessKey = ref<string>('');
 
/** 流程 key 只能来自后端实时列表,禁止前端写死 */
const processOptions = computed(() =>
  processList.value.map((item) => ({ label: item.name, value: item.key })),
);
 
const [Modal, modalApi] = useVbenModal({
  async onConfirm() {
    if (!selectedProcessKey.value) {
      message.warning('请选择审批流程');
      return;
    }
    modalApi.lock();
    try {
      await submitReimbursement(
        reimbursementId.value!,
        selectedProcessKey.value,
      );
      await modalApi.close();
      emit('success');
      message.success('提交成功');
    } finally {
      modalApi.unlock();
    }
  },
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      reimbursementId.value = undefined;
      selectedProcessKey.value = '';
      processList.value = [];
      return;
    }
    const data =
      modalApi.getData<{
        id: number;
        processList: FinanceReimbursementApi.ProcessDefinition[];
      }>();
    reimbursementId.value = data.id;
    processList.value = data.processList || [];
    // 默认选择第一个流程
    if (processList.value.length > 0) {
      selectedProcessKey.value = processList.value[0]!.key;
    }
  },
});
</script>
 
<template>
  <Modal title="选择审批流程" class="w-1/3">
    <div class="mb-4">
      <span class="mr-2">审批流程:</span>
      <Select
        v-model:value="selectedProcessKey"
        :options="processOptions"
        style="width: 200px"
        placeholder="请选择审批流程"
      />
    </div>
  </Modal>
</template>