提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<el-form |
|
3 |
ref="formRef" |
|
4 |
v-loading="formLoading" |
|
5 |
:model="formData" |
|
6 |
:rules="formRules" |
|
7 |
label-width="80px" |
|
8 |
> |
|
9 |
<el-form-item label="请假类型" prop="type"> |
|
10 |
<el-select v-model="formData.type" clearable placeholder="请选择请假类型"> |
|
11 |
<el-option |
|
12 |
v-for="dict in getIntDictOptions(DICT_TYPE.BPM_OA_LEAVE_TYPE)" |
|
13 |
:key="dict.value" |
|
14 |
:label="dict.label" |
|
15 |
:value="dict.value" |
|
16 |
/> |
|
17 |
</el-select> |
|
18 |
</el-form-item> |
|
19 |
<el-form-item label="开始时间" prop="startTime"> |
|
20 |
<el-date-picker |
|
21 |
v-model="formData.startTime" |
|
22 |
clearable |
|
23 |
placeholder="请选择开始时间" |
|
24 |
type="datetime" |
|
25 |
value-format="x" |
|
26 |
/> |
|
27 |
</el-form-item> |
|
28 |
<el-form-item label="结束时间" prop="endTime"> |
|
29 |
<el-date-picker |
|
30 |
v-model="formData.endTime" |
|
31 |
clearable |
|
32 |
placeholder="请选择结束时间" |
|
33 |
type="datetime" |
|
34 |
value-format="x" |
|
35 |
/> |
|
36 |
</el-form-item> |
|
37 |
<el-form-item label="原因" prop="reason"> |
|
38 |
<el-input v-model="formData.reason" placeholder="请输请假原因" type="textarea" /> |
|
39 |
</el-form-item> |
|
40 |
<el-col v-if="startUserSelectTasks.length > 0"> |
|
41 |
<el-card class="mb-10px"> |
|
42 |
<template #header>指定审批人</template> |
|
43 |
<el-form |
|
44 |
:model="startUserSelectAssignees" |
|
45 |
:rules="startUserSelectAssigneesFormRules" |
|
46 |
ref="startUserSelectAssigneesFormRef" |
|
47 |
> |
|
48 |
<el-form-item |
|
49 |
v-for="userTask in startUserSelectTasks" |
|
50 |
:key="userTask.id" |
|
51 |
:label="`任务【${userTask.name}】`" |
|
52 |
:prop="userTask.id" |
|
53 |
> |
|
54 |
<el-select |
|
55 |
v-model="startUserSelectAssignees[userTask.id]" |
|
56 |
multiple |
|
57 |
placeholder="请选择审批人" |
|
58 |
> |
|
59 |
<el-option |
|
60 |
v-for="user in userList" |
|
61 |
:key="user.id" |
|
62 |
:label="user.nickname" |
|
63 |
:value="user.id" |
|
64 |
/> |
|
65 |
</el-select> |
|
66 |
</el-form-item> |
|
67 |
</el-form> |
|
68 |
</el-card> |
|
69 |
</el-col> |
|
70 |
<el-form-item> |
|
71 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
72 |
</el-form-item> |
|
73 |
</el-form> |
|
74 |
</template> |
|
75 |
<script lang="ts" setup> |
|
76 |
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
|
77 |
import * as LeaveApi from '@/api/bpm/leave' |
|
78 |
import { useTagsViewStore } from '@/store/modules/tagsView' |
|
79 |
import * as DefinitionApi from '@/api/bpm/definition' |
|
80 |
import * as UserApi from '@/api/system/user' |
|
81 |
|
|
82 |
defineOptions({ name: 'BpmOALeaveCreate' }) |
|
83 |
|
|
84 |
const message = useMessage() // 消息弹窗 |
|
85 |
const { delView } = useTagsViewStore() // 视图操作 |
|
86 |
const { push, currentRoute } = useRouter() // 路由 |
|
87 |
|
|
88 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
89 |
const formData = ref({ |
|
90 |
type: undefined, |
|
91 |
reason: undefined, |
|
92 |
startTime: undefined, |
|
93 |
endTime: undefined |
|
94 |
}) |
|
95 |
const formRules = reactive({ |
|
96 |
type: [{ required: true, message: '请假类型不能为空', trigger: 'blur' }], |
|
97 |
reason: [{ required: true, message: '请假原因不能为空', trigger: 'change' }], |
|
98 |
startTime: [{ required: true, message: '请假开始时间不能为空', trigger: 'change' }], |
|
99 |
endTime: [{ required: true, message: '请假结束时间不能为空', trigger: 'change' }] |
|
100 |
}) |
|
101 |
const formRef = ref() // 表单 Ref |
|
102 |
|
|
103 |
// 指定审批人 |
|
104 |
const processDefineKey = 'oa_leave' // 流程定义 Key |
|
105 |
const startUserSelectTasks = ref([]) // 发起人需要选择审批人的用户任务列表 |
|
106 |
const startUserSelectAssignees = ref({}) // 发起人选择审批人的数据 |
|
107 |
const startUserSelectAssigneesFormRef = ref() // 发起人选择审批人的表单 Ref |
|
108 |
const startUserSelectAssigneesFormRules = ref({}) // 发起人选择审批人的表单 Rules |
|
109 |
const userList = ref<any[]>([]) // 用户列表 |
|
110 |
|
|
111 |
/** 提交表单 */ |
|
112 |
const submitForm = async () => { |
|
113 |
// 校验表单 |
|
114 |
if (!formRef) return |
|
115 |
const valid = await formRef.value.validate() |
|
116 |
if (!valid) return |
|
117 |
// 校验指定审批人 |
|
118 |
if (startUserSelectTasks.value?.length > 0) { |
|
119 |
await startUserSelectAssigneesFormRef.value.validate() |
|
120 |
} |
|
121 |
|
|
122 |
// 提交请求 |
|
123 |
formLoading.value = true |
|
124 |
try { |
|
125 |
const data = { ...formData.value } as unknown as LeaveApi.LeaveVO |
|
126 |
// 设置指定审批人 |
|
127 |
if (startUserSelectTasks.value?.length > 0) { |
|
128 |
data.startUserSelectAssignees = startUserSelectAssignees.value |
|
129 |
} |
|
130 |
await LeaveApi.createLeave(data) |
|
131 |
message.success('发起成功') |
|
132 |
// 关闭当前 Tab |
|
133 |
delView(unref(currentRoute)) |
|
134 |
await push({ name: 'BpmOALeave' }) |
|
135 |
} finally { |
|
136 |
formLoading.value = false |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
/** 初始化 */ |
|
141 |
onMounted(async () => { |
|
142 |
const processDefinitionDetail = await DefinitionApi.getProcessDefinition( |
|
143 |
undefined, |
|
144 |
processDefineKey |
|
145 |
) |
|
146 |
if (!processDefinitionDetail) { |
|
147 |
message.error('OA 请假的流程模型未配置,请检查!') |
|
148 |
return |
|
149 |
} |
|
150 |
startUserSelectTasks.value = processDefinitionDetail.startUserSelectTasks |
|
151 |
// 设置指定审批人 |
|
152 |
if (startUserSelectTasks.value?.length > 0) { |
|
153 |
// 设置校验规则 |
|
154 |
for (const userTask of startUserSelectTasks.value) { |
|
155 |
startUserSelectAssignees.value[userTask.id] = [] |
|
156 |
startUserSelectAssigneesFormRules.value[userTask.id] = [ |
|
157 |
{ required: true, message: '请选择审批人', trigger: 'blur' } |
|
158 |
] |
|
159 |
} |
|
160 |
// 加载用户列表 |
|
161 |
userList.value = await UserApi.getSimpleUserList() |
|
162 |
} |
|
163 |
}) |
|
164 |
</script> |