leaveEdit.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div class="p-2">
  3. <el-card shadow="never">
  4. <div style="display: flex; justify-content: space-between">
  5. <div>
  6. <el-button
  7. v-if="
  8. routeParams.type === 'add' ||
  9. (routeParams.type === 'update' &&
  10. form.processInstanceVo &&
  11. form.processInstanceVo.businessStatus &&
  12. (form.processInstanceVo.businessStatus === 'draft' ||
  13. form.processInstanceVo.businessStatus === 'cancel' ||
  14. form.processInstanceVo.businessStatus === 'back'))
  15. "
  16. :loading="buttonLoading"
  17. type="info"
  18. @click="submitForm('draft')"
  19. >暂存</el-button
  20. >
  21. <el-button
  22. v-if="
  23. routeParams.type === 'add' ||
  24. (routeParams.type === 'update' &&
  25. form.processInstanceVo &&
  26. (form.processInstanceVo.businessStatus === 'draft' ||
  27. form.processInstanceVo.businessStatus === 'cancel' ||
  28. form.processInstanceVo.businessStatus === 'back'))
  29. "
  30. :loading="buttonLoading"
  31. type="primary"
  32. @click="submitForm('submit')"
  33. >提 交</el-button
  34. >
  35. <el-button
  36. v-if="routeParams.type === 'approval' && form.processInstanceVo && form.processInstanceVo.businessStatus === 'waiting'"
  37. :loading="buttonLoading"
  38. type="primary"
  39. @click="approvalVerifyOpen"
  40. >审批</el-button
  41. >
  42. <el-button v-if="processInstanceId" type="primary" @click="handleApprovalRecord">流程进度</el-button>
  43. </div>
  44. <div>
  45. <el-button style="float: right" @click="goBack()">返回</el-button>
  46. </div>
  47. </div>
  48. </el-card>
  49. <el-card shadow="never" style="height: 78vh; overflow-y: auto">
  50. <el-form ref="leaveFormRef" v-loading="loading" :disabled="routeParams.type === 'view'" :model="form" :rules="rules" label-width="80px">
  51. <el-form-item label="请假类型" prop="leaveType">
  52. <el-select v-model="form.leaveType" placeholder="请选择请假类型" style="width: 100%">
  53. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
  54. </el-select>
  55. </el-form-item>
  56. <el-form-item label="请假时间">
  57. <el-date-picker
  58. v-model="leaveTime"
  59. type="daterange"
  60. range-separator="To"
  61. start-placeholder="开始时间"
  62. end-placeholder="结束时间"
  63. @change="changeLeaveTime()"
  64. />
  65. </el-form-item>
  66. <el-form-item label="请假天数" prop="leaveDays">
  67. <el-input v-model="form.leaveDays" disabled type="number" placeholder="请输入请假天数" />
  68. </el-form-item>
  69. <el-form-item label="请假原因" prop="remark">
  70. <el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入请假原因" />
  71. </el-form-item>
  72. </el-form>
  73. </el-card>
  74. <!-- 提交组件 -->
  75. <submitVerify ref="submitVerifyRef" :task-variables="taskVariables" @submit-callback="submitCallback" />
  76. <!-- 审批记录 -->
  77. <approvalRecord ref="approvalRecordRef" />
  78. </div>
  79. </template>
  80. <script setup name="Leave" lang="ts">
  81. import { addLeave, getLeave, updateLeave } from '@/api/workflow/leave';
  82. import { LeaveForm, LeaveQuery, LeaveVO } from '@/api/workflow/leave/types';
  83. import { startWorkFlow } from '@/api/workflow/task';
  84. import SubmitVerify from '@/components/Process/submitVerify.vue';
  85. import ApprovalRecord from '@/components/Process/approvalRecord.vue';
  86. import { AxiosResponse } from 'axios';
  87. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  88. const buttonLoading = ref(false);
  89. const loading = ref(true);
  90. const leaveTime = ref<Array<string>>([]);
  91. //流程实例id
  92. const processInstanceId = ref('');
  93. //路由参数
  94. const routeParams = ref<Record<string, any>>({});
  95. const options = [
  96. {
  97. value: '1',
  98. label: '事假'
  99. },
  100. {
  101. value: '2',
  102. label: '调休'
  103. },
  104. {
  105. value: '3',
  106. label: '病假'
  107. },
  108. {
  109. value: '4',
  110. label: '婚假'
  111. }
  112. ];
  113. //提交组件
  114. const submitVerifyRef = ref<InstanceType<typeof SubmitVerify>>();
  115. //审批记录组件
  116. const approvalRecordRef = ref<InstanceType<typeof ApprovalRecord>>();
  117. const leaveFormRef = ref<ElFormInstance>();
  118. const submitFormData = ref<Record<string, any>>({
  119. businessKey: '',
  120. processKey: '',
  121. variables: {}
  122. });
  123. const taskVariables = ref<Record<string, any>>({});
  124. const initFormData: LeaveForm = {
  125. id: undefined,
  126. leaveType: undefined,
  127. startDate: undefined,
  128. endDate: undefined,
  129. leaveDays: undefined,
  130. remark: undefined,
  131. processInstanceVo: {}
  132. };
  133. const data = reactive<PageData<LeaveForm, LeaveQuery>>({
  134. form: { ...initFormData },
  135. queryParams: {
  136. pageNum: 1,
  137. pageSize: 10,
  138. startLeaveDays: undefined,
  139. endLeaveDays: undefined
  140. },
  141. rules: {
  142. id: [{ required: true, message: '主键不能为空', trigger: 'blur' }],
  143. leaveType: [{ required: true, message: '请假类型不能为空', trigger: 'blur' }],
  144. leaveTime: [{ required: true, message: '请假时间不能为空', trigger: 'blur' }],
  145. leaveDays: [{ required: true, message: '请假天数不能为空', trigger: 'blur' }]
  146. }
  147. });
  148. const { form, rules } = toRefs(data);
  149. /** 表单重置 */
  150. const reset = () => {
  151. form.value = { ...initFormData };
  152. leaveTime.value = [];
  153. leaveFormRef.value?.resetFields();
  154. };
  155. const changeLeaveTime = () => {
  156. const startDate = new Date(leaveTime.value[0]).getTime();
  157. const endDate = new Date(leaveTime.value[1]).getTime();
  158. const diffInMilliseconds = endDate - startDate;
  159. form.value.leaveDays = Math.floor(diffInMilliseconds / (1000 * 60 * 60 * 24));
  160. };
  161. /** 获取详情 */
  162. const getInfo = () => {
  163. loading.value = true;
  164. buttonLoading.value = false;
  165. nextTick(async () => {
  166. const res = await getLeave(routeParams.value.id);
  167. Object.assign(form.value, res.data);
  168. leaveTime.value = [];
  169. leaveTime.value.push(form.value.startDate);
  170. leaveTime.value.push(form.value.endDate);
  171. if (form.value.processInstanceVo) {
  172. processInstanceId.value = form.value.processInstanceVo.id;
  173. }
  174. loading.value = false;
  175. buttonLoading.value = false;
  176. });
  177. };
  178. /** 提交按钮 */
  179. const submitForm = (status: string) => {
  180. if (leaveTime.value.length === 0) {
  181. proxy?.$modal.msgError('请假时间不能为空');
  182. return;
  183. }
  184. leaveFormRef.value?.validate(async (valid: boolean) => {
  185. form.value.startDate = leaveTime.value[0];
  186. form.value.endDate = leaveTime.value[1];
  187. if (valid) {
  188. buttonLoading.value = true;
  189. let res: AxiosResponse<LeaveVO>;
  190. if (form.value.id) {
  191. res = await updateLeave(form.value);
  192. } else {
  193. res = await addLeave(form.value);
  194. }
  195. form.value = res.data;
  196. if (status === 'draft') {
  197. buttonLoading.value = false;
  198. proxy?.$modal.msgSuccess('暂存成功');
  199. proxy.$tab.closePage(proxy.$route);
  200. proxy.$router.go(-1);
  201. } else {
  202. await handleStartWorkFlow(res.data);
  203. }
  204. }
  205. });
  206. };
  207. //提交申请
  208. const handleStartWorkFlow = async (data: LeaveVO) => {
  209. submitFormData.value.processKey = 'leave1';
  210. submitFormData.value.businessKey = data.id;
  211. //流程变量
  212. taskVariables.value = {
  213. entity: data,
  214. leaveDays: data.leaveDays,
  215. userList: [1, 2],
  216. userList2: [1, 2]
  217. };
  218. submitFormData.value.variables = taskVariables.value;
  219. const resp = await startWorkFlow(submitFormData.value);
  220. if (submitVerifyRef.value) {
  221. buttonLoading.value = false;
  222. submitVerifyRef.value.openDialog(resp.data.taskId);
  223. }
  224. };
  225. //审批记录
  226. const handleApprovalRecord = () => {
  227. approvalRecordRef.value.init(processInstanceId.value);
  228. };
  229. //提交回调
  230. const submitCallback = async () => {
  231. await proxy.$tab.closePage(proxy.$route);
  232. proxy.$router.go(-1);
  233. };
  234. //返回
  235. const goBack = () => {
  236. proxy.$tab.closePage(proxy.$route);
  237. proxy.$router.go(-1);
  238. };
  239. //审批
  240. const approvalVerifyOpen = async () => {
  241. submitVerifyRef.value.openDialog(routeParams.value.taskId);
  242. };
  243. onMounted(() => {
  244. nextTick(async () => {
  245. routeParams.value = proxy.$route.query;
  246. reset();
  247. loading.value = false;
  248. if (routeParams.value.type === 'update' || routeParams.value.type === 'view' || routeParams.value.type === 'approval') {
  249. getInfo();
  250. }
  251. });
  252. });
  253. </script>