提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<Dialog v-model="dialogVisible" title="委派任务" width="500"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
v-loading="formLoading" |
|
6 |
:model="formData" |
|
7 |
:rules="formRules" |
|
8 |
label-width="110px" |
|
9 |
> |
|
10 |
<el-form-item label="接收人" prop="delegateUserId"> |
|
11 |
<el-select v-model="formData.delegateUserId" clearable style="width: 100%"> |
|
12 |
<el-option |
|
13 |
v-for="item in userList" |
|
14 |
:key="item.id" |
|
15 |
:label="item.nickname" |
|
16 |
:value="item.id" |
|
17 |
/> |
|
18 |
</el-select> |
|
19 |
</el-form-item> |
|
20 |
<el-form-item label="委派理由" prop="reason"> |
|
21 |
<el-input v-model="formData.reason" clearable placeholder="请输入委派理由" /> |
|
22 |
</el-form-item> |
|
23 |
</el-form> |
|
24 |
<template #footer> |
|
25 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
26 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
27 |
</template> |
|
28 |
</Dialog> |
|
29 |
</template> |
|
30 |
<script lang="ts" setup> |
|
31 |
import * as TaskApi from '@/api/bpm/task' |
|
32 |
import * as UserApi from '@/api/system/user' |
|
33 |
|
|
34 |
defineOptions({ name: 'BpmTaskDelegateForm' }) |
|
35 |
|
|
36 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
37 |
const formLoading = ref(false) // 表单的加载中 |
|
38 |
const formData = ref({ |
|
39 |
id: '', |
|
40 |
delegateUserId: undefined, |
|
41 |
reason: '' |
|
42 |
}) |
|
43 |
const formRules = ref({ |
|
44 |
delegateUserId: [{ required: true, message: '接收人不能为空', trigger: 'change' }], |
|
45 |
reason: [{ required: true, message: '委派理由不能为空', trigger: 'blur' }] |
|
46 |
}) |
|
47 |
|
|
48 |
const formRef = ref() // 表单 Ref |
|
49 |
const userList = ref<any[]>([]) // 用户列表 |
|
50 |
|
|
51 |
/** 打开弹窗 */ |
|
52 |
const open = async (id: string) => { |
|
53 |
dialogVisible.value = true |
|
54 |
resetForm() |
|
55 |
formData.value.id = id |
|
56 |
// 获得用户列表 |
|
57 |
userList.value = await UserApi.getSimpleUserList() |
|
58 |
} |
|
59 |
defineExpose({ open }) // 提供 openModal 方法,用于打开弹窗 |
|
60 |
|
|
61 |
/** 提交表单 */ |
|
62 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
63 |
const submitForm = async () => { |
|
64 |
// 校验表单 |
|
65 |
if (!formRef) return |
|
66 |
const valid = await formRef.value.validate() |
|
67 |
if (!valid) return |
|
68 |
// 提交请求 |
|
69 |
formLoading.value = true |
|
70 |
try { |
|
71 |
await TaskApi.delegateTask(formData.value) |
|
72 |
dialogVisible.value = false |
|
73 |
// 发送操作成功的事件 |
|
74 |
emit('success') |
|
75 |
} finally { |
|
76 |
formLoading.value = false |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
/** 重置表单 */ |
|
81 |
const resetForm = () => { |
|
82 |
formData.value = { |
|
83 |
id: '', |
|
84 |
delegateUserId: undefined, |
|
85 |
reason: '' |
|
86 |
} |
|
87 |
formRef.value?.resetFields() |
|
88 |
} |
|
89 |
</script> |