兰宝车间质量管理系统-前端
疯狂的狮子Li
2024-06-06 2c9c837c1b999748e3ec7e0526f5673111d108bd
src/views/workflow/leave/leaveEdit.vue
@@ -6,12 +6,7 @@
          <el-button
            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'))
              (routeParams.type === 'update' && form.status && (form.status === 'draft' || form.status === 'cancel' || form.status === 'back'))
            "
            :loading="buttonLoading"
            type="info"
@@ -21,11 +16,7 @@
          <el-button
            v-if="
              routeParams.type === 'add' ||
              (routeParams.type === 'update' &&
                form.processInstanceVo &&
                (form.processInstanceVo.businessStatus === 'draft' ||
                  form.processInstanceVo.businessStatus === 'cancel' ||
                  form.processInstanceVo.businessStatus === 'back'))
              (routeParams.type === 'update' && form.status && (form.status === 'draft' || form.status === 'cancel' || form.status === 'back'))
            "
            :loading="buttonLoading"
            type="primary"
@@ -33,13 +24,13 @@
            >提 交</el-button
          >
          <el-button
            v-if="routeParams.type === 'approval' && form.processInstanceVo && form.processInstanceVo.businessStatus === 'waiting'"
            v-if="routeParams.type === 'approval' && form.status && form.status === 'waiting'"
            :loading="buttonLoading"
            type="primary"
            @click="approvalVerifyOpen"
            >审批</el-button
          >
          <el-button v-if="processInstanceId" type="primary" @click="handleApprovalRecord">流程进度</el-button>
          <el-button v-if="form.status !== 'draft'" type="primary" @click="handleApprovalRecord">流程进度</el-button>
        </div>
        <div>
          <el-button style="float: right" @click="goBack()">返回</el-button>
@@ -85,14 +76,12 @@
import SubmitVerify from '@/components/Process/submitVerify.vue';
import ApprovalRecord from '@/components/Process/approvalRecord.vue';
import { AxiosResponse } from 'axios';
import { StartProcessBo } from '@/api/workflow/workflowCommon/types';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const buttonLoading = ref(false);
const loading = ref(true);
const leaveTime = ref<Array<string>>([]);
//流程实例id
const processInstanceId = ref('');
//路由参数
const routeParams = ref<Record<string, any>>({});
const options = [
@@ -120,9 +109,9 @@
const leaveFormRef = ref<ElFormInstance>();
const submitFormData = ref<Record<string, any>>({
const submitFormData = ref<StartProcessBo>({
  businessKey: '',
  processKey: '',
  tableName: '',
  variables: {}
});
const taskVariables = ref<Record<string, any>>({});
@@ -134,7 +123,7 @@
  endDate: undefined,
  leaveDays: undefined,
  remark: undefined,
  processInstanceVo: {}
  status: undefined
};
const data = reactive<PageData<LeaveForm, LeaveQuery>>({
  form: { ...initFormData },
@@ -165,7 +154,7 @@
  const startDate = new Date(leaveTime.value[0]).getTime();
  const endDate = new Date(leaveTime.value[1]).getTime();
  const diffInMilliseconds = endDate - startDate;
  form.value.leaveDays = Math.floor(diffInMilliseconds / (1000 * 60 * 60 * 24));
  form.value.leaveDays = Math.floor(diffInMilliseconds / (1000 * 60 * 60 * 24)) + 1;
};
/** 获取详情 */
const getInfo = () => {
@@ -177,9 +166,6 @@
    leaveTime.value = [];
    leaveTime.value.push(form.value.startDate);
    leaveTime.value.push(form.value.endDate);
    if (form.value.processInstanceVo) {
      processInstanceId.value = form.value.processInstanceVo.id;
    }
    loading.value = false;
    buttonLoading.value = false;
  });
@@ -191,51 +177,59 @@
    proxy?.$modal.msgError('请假时间不能为空');
    return;
  }
  leaveFormRef.value?.validate(async (valid: boolean) => {
    form.value.startDate = leaveTime.value[0];
    form.value.endDate = leaveTime.value[1];
    if (valid) {
      buttonLoading.value = true;
      let res: AxiosResponse<LeaveVO>;
      if (form.value.id) {
        res = await updateLeave(form.value);
      } else {
        res = await addLeave(form.value);
  try {
    leaveFormRef.value?.validate(async (valid: boolean) => {
      form.value.startDate = leaveTime.value[0];
      form.value.endDate = leaveTime.value[1];
      if (valid) {
        buttonLoading.value = true;
        let res: AxiosResponse<LeaveVO>;
        if (form.value.id) {
          res = await updateLeave(form.value);
        } else {
          res = await addLeave(form.value);
        }
        form.value = res.data;
        if (status === 'draft') {
          buttonLoading.value = false;
          proxy?.$modal.msgSuccess('暂存成功');
          proxy.$tab.closePage(proxy.$route);
          proxy.$router.go(-1);
        } else {
          await handleStartWorkFlow(res.data);
        }
      }
      form.value = res.data;
      if (status === 'draft') {
        buttonLoading.value = false;
        proxy?.$modal.msgSuccess('暂存成功');
        proxy.$tab.closePage(proxy.$route);
        proxy.$router.go(-1);
      } else {
        await handleStartWorkFlow(res.data);
      }
    }
  });
    });
  } finally {
    buttonLoading.value = false;
  }
};
//提交申请
const handleStartWorkFlow = async (data: LeaveVO) => {
  submitFormData.value.processKey = 'leave1';
  submitFormData.value.businessKey = data.id;
  //流程变量
  taskVariables.value = {
    entity: data,
    leaveDays: data.leaveDays,
    userList: [1, 2],
    userList2: [1, 2]
  };
  submitFormData.value.variables = taskVariables.value;
  const resp = await startWorkFlow(submitFormData.value);
  if (submitVerifyRef.value) {
  try {
    submitFormData.value.tableName = 'test_leave';
    submitFormData.value.businessKey = data.id;
    //流程变量
    taskVariables.value = {
      entity: data,
      leaveDays: data.leaveDays,
      userList: [1, 3],
      userList2: [1, 3]
    };
    submitFormData.value.variables = taskVariables.value;
    const resp = await startWorkFlow(submitFormData.value);
    if (submitVerifyRef.value) {
      buttonLoading.value = false;
      submitVerifyRef.value.openDialog(resp.data.taskId);
    }
  } finally {
    buttonLoading.value = false;
    submitVerifyRef.value.openDialog(resp.data.taskId);
  }
};
//审批记录
const handleApprovalRecord = () => {
  approvalRecordRef.value.init(processInstanceId.value);
  approvalRecordRef.value.init(form.value.id);
};
//提交回调
const submitCallback = async () => {