leaveEdit.vue 8.0 KB

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