|
|
|
|
@ -30,17 +30,7 @@
|
|
|
|
|
<el-row :gutter="20">
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
<el-form-item label="工时单号" prop="timesheetCode">
|
|
|
|
|
<el-input v-model="form.timesheetCode" placeholder="自动生成工时单号" disabled>
|
|
|
|
|
<template #append>
|
|
|
|
|
<el-button
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="generateCode"
|
|
|
|
|
:disabled="isCodeGenerated || routeParams.type === 'view' || routeParams.type === 'approval'"
|
|
|
|
|
>
|
|
|
|
|
生成编号
|
|
|
|
|
</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</el-input>
|
|
|
|
|
<el-input v-model="form.timesheetCode" placeholder="自动生成" disabled />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
|
|
|
|
|
@ -271,7 +261,6 @@ const userStore = useUserStore();
|
|
|
|
|
const routeParams = ref<any>({});
|
|
|
|
|
const buttonLoading = ref(false);
|
|
|
|
|
const timesheetFormRef = ref<ElFormInstance>();
|
|
|
|
|
const isCodeGenerated = ref(false);
|
|
|
|
|
|
|
|
|
|
const submitVerifyRef = ref<InstanceType<typeof SubmitVerify>>();
|
|
|
|
|
const approvalRecordRef = ref<InstanceType<typeof ApprovalRecord>>();
|
|
|
|
|
@ -304,7 +293,7 @@ const data = reactive({
|
|
|
|
|
timesheetProjectList: [] as any[]
|
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
timesheetCode: [{ required: true, message: '编号不能为空', trigger: 'blur' }],
|
|
|
|
|
// timesheetCode: [{ required: true, message: '编号不能为空', trigger: 'blur' }],
|
|
|
|
|
startTime: [{ required: true, message: '请选择起始日期', trigger: 'change' }],
|
|
|
|
|
endTime: [{ required: true, message: '请选择结束日期', trigger: 'change' }]
|
|
|
|
|
}
|
|
|
|
|
@ -328,7 +317,6 @@ onMounted(async () => {
|
|
|
|
|
form.value = res.data;
|
|
|
|
|
if (!form.value.timesheetDeptList) form.value.timesheetDeptList = [];
|
|
|
|
|
if (!form.value.timesheetProjectList) form.value.timesheetProjectList = [];
|
|
|
|
|
if (form.value.timesheetCode) isCodeGenerated.value = true;
|
|
|
|
|
} else {
|
|
|
|
|
setWeekDates();
|
|
|
|
|
form.value.timesheetDeptList = [];
|
|
|
|
|
@ -449,20 +437,6 @@ const getDeptName = (deptId: any) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** 生成编号 */
|
|
|
|
|
const generateCode = async () => {
|
|
|
|
|
if (isCodeGenerated.value) return;
|
|
|
|
|
try {
|
|
|
|
|
const res = await getRuleGenerateCode({ codeRuleCode: CodeRuleEnum.TIMESHEET } as any);
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
form.value.timesheetCode = res.msg;
|
|
|
|
|
isCodeGenerated.value = true;
|
|
|
|
|
proxy?.$modal.msgSuccess('生成成功');
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** 自动计算工时 */
|
|
|
|
|
const calculateHours = () => {
|
|
|
|
|
const deptList = form.value.timesheetDeptList || [];
|
|
|
|
|
@ -525,103 +499,111 @@ const getSummary = (param: any) => {
|
|
|
|
|
|
|
|
|
|
/** 提交按钮 */
|
|
|
|
|
const submitForm = (status: string) => {
|
|
|
|
|
if (status === 'draft') {
|
|
|
|
|
executeSubmit(status);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
timesheetFormRef.value?.validate(async (valid: boolean) => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
buttonLoading.value = true;
|
|
|
|
|
try {
|
|
|
|
|
const submitData: any = { ...form.value };
|
|
|
|
|
|
|
|
|
|
if (status !== 'draft') {
|
|
|
|
|
// 提交前校验
|
|
|
|
|
if (submitData.timesheetDeptList && submitData.timesheetDeptList.length > 0) {
|
|
|
|
|
for (let i = 0; i < submitData.timesheetDeptList.length; i++) {
|
|
|
|
|
const row = submitData.timesheetDeptList[i];
|
|
|
|
|
// 检查每一行是否选了审批人
|
|
|
|
|
if (!row.approverId) {
|
|
|
|
|
proxy.$modal.msgError(`部门工作:第 ${i + 1} 行未选择审批人`);
|
|
|
|
|
buttonLoading.value = false;
|
|
|
|
|
return; // 阻止提交
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (submitData.timesheetProjectList && submitData.timesheetProjectList.length > 0) {
|
|
|
|
|
for (let i = 0; i < submitData.timesheetProjectList.length; i++) {
|
|
|
|
|
const row = submitData.timesheetProjectList[i];
|
|
|
|
|
if (!row.approverId) {
|
|
|
|
|
proxy.$modal.msgError(`项目工作:第 ${i + 1} 行未选择审批人`);
|
|
|
|
|
buttonLoading.value = false;
|
|
|
|
|
return; // 阻止提交
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (submitData.timesheetDeptList.length === 0 && submitData.timesheetProjectList.length === 0) {
|
|
|
|
|
proxy.$modal.msgError('请至少填写一项部门工时或项目工时');
|
|
|
|
|
buttonLoading.value = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 提交审批
|
|
|
|
|
submitData.flowCode = FlowCodeEnum.TIMESHEET_KEY;
|
|
|
|
|
|
|
|
|
|
// 提取部门工时审批人 (取 approverId)
|
|
|
|
|
const deptApproverSet = new Set();
|
|
|
|
|
submitData.timesheetDeptList.forEach((item: any) => {
|
|
|
|
|
if (item.approverId) deptApproverSet.add(item.approverId);
|
|
|
|
|
});
|
|
|
|
|
const deptApprovers = Array.from(deptApproverSet);
|
|
|
|
|
|
|
|
|
|
// 提取项目工时审批人 (取 approverId)
|
|
|
|
|
const projectApproverSet = new Set();
|
|
|
|
|
submitData.timesheetProjectList.forEach((item: any) => {
|
|
|
|
|
if (item.approverId) projectApproverSet.add(item.approverId);
|
|
|
|
|
});
|
|
|
|
|
const projectApprovers = Array.from(projectApproverSet);
|
|
|
|
|
|
|
|
|
|
// 必须选择审批人
|
|
|
|
|
if (deptApprovers.length === 0 && projectApprovers.length === 0) {
|
|
|
|
|
proxy.$modal.msgError('请至少填写一项工时并指定审批人');
|
|
|
|
|
buttonLoading.value = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 放入流程变量
|
|
|
|
|
submitData.variables = {
|
|
|
|
|
startUserId: userStore.userId,
|
|
|
|
|
totalHours: submitData.totalHours,
|
|
|
|
|
deptApprovers: deptApprovers, // 对应后端 variables.put("deptApprovers", ...)
|
|
|
|
|
projectApprovers: projectApprovers, // 对应后端 variables.put("projectApprovers", ...)
|
|
|
|
|
hasDeptWork: deptApprovers.length > 0, // 前端也可以传这个标记,双重保险
|
|
|
|
|
hasProjectWork: projectApprovers.length > 0 // 前端也可以传这个标记
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
submitData.bizExt = {
|
|
|
|
|
businessTitle: `工时填报:${userStore.nickname}`,
|
|
|
|
|
businessCode: submitData.timesheetCode
|
|
|
|
|
};
|
|
|
|
|
submitData.timesheetStatus = '2'; // 已提交
|
|
|
|
|
submitData.flowStatus = 'waiting';
|
|
|
|
|
|
|
|
|
|
const res = await submitTimesheetAndFlowStart(submitData);
|
|
|
|
|
if (res?.data) form.value = res.data;
|
|
|
|
|
proxy.$modal.msgSuccess('提交成功');
|
|
|
|
|
} else {
|
|
|
|
|
// 暂存
|
|
|
|
|
submitData.timesheetStatus = '1'; // 草稿
|
|
|
|
|
submitData.flowStatus = 'draft';
|
|
|
|
|
if (submitData.timesheetId) await updateTimesheetInfo(submitData);
|
|
|
|
|
else await addTimesheetInfo(submitData);
|
|
|
|
|
proxy.$modal.msgSuccess('暂存成功');
|
|
|
|
|
}
|
|
|
|
|
proxy.$tab.closePage(route);
|
|
|
|
|
router.go(-1);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
} finally {
|
|
|
|
|
buttonLoading.value = false;
|
|
|
|
|
}
|
|
|
|
|
executeSubmit(status);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const executeSubmit = async (status: string) => {
|
|
|
|
|
buttonLoading.value = true;
|
|
|
|
|
try {
|
|
|
|
|
const submitData: any = { ...form.value };
|
|
|
|
|
|
|
|
|
|
if (status !== 'draft') {
|
|
|
|
|
// 提交前校验
|
|
|
|
|
if (submitData.timesheetDeptList && submitData.timesheetDeptList.length > 0) {
|
|
|
|
|
for (let i = 0; i < submitData.timesheetDeptList.length; i++) {
|
|
|
|
|
const row = submitData.timesheetDeptList[i];
|
|
|
|
|
// 检查每一行是否选了审批人
|
|
|
|
|
if (!row.approverId) {
|
|
|
|
|
proxy.$modal.msgError(`部门工作:第 ${i + 1} 行未选择审批人`);
|
|
|
|
|
buttonLoading.value = false;
|
|
|
|
|
return; // 阻止提交
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (submitData.timesheetProjectList && submitData.timesheetProjectList.length > 0) {
|
|
|
|
|
for (let i = 0; i < submitData.timesheetProjectList.length; i++) {
|
|
|
|
|
const row = submitData.timesheetProjectList[i];
|
|
|
|
|
if (!row.approverId) {
|
|
|
|
|
proxy.$modal.msgError(`项目工作:第 ${i + 1} 行未选择审批人`);
|
|
|
|
|
buttonLoading.value = false;
|
|
|
|
|
return; // 阻止提交
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (submitData.timesheetDeptList.length === 0 && submitData.timesheetProjectList.length === 0) {
|
|
|
|
|
proxy.$modal.msgError('请至少填写一项部门工时或项目工时');
|
|
|
|
|
buttonLoading.value = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 提交审批
|
|
|
|
|
submitData.flowCode = FlowCodeEnum.TIMESHEET_KEY;
|
|
|
|
|
|
|
|
|
|
// 提取部门工时审批人 (取 approverId)
|
|
|
|
|
const deptApproverSet = new Set();
|
|
|
|
|
submitData.timesheetDeptList.forEach((item: any) => {
|
|
|
|
|
if (item.approverId) deptApproverSet.add(item.approverId);
|
|
|
|
|
});
|
|
|
|
|
const deptApprovers = Array.from(deptApproverSet);
|
|
|
|
|
|
|
|
|
|
// 提取项目工时审批人 (取 approverId)
|
|
|
|
|
const projectApproverSet = new Set();
|
|
|
|
|
submitData.timesheetProjectList.forEach((item: any) => {
|
|
|
|
|
if (item.approverId) projectApproverSet.add(item.approverId);
|
|
|
|
|
});
|
|
|
|
|
const projectApprovers = Array.from(projectApproverSet);
|
|
|
|
|
|
|
|
|
|
// 必须选择审批人
|
|
|
|
|
if (deptApprovers.length === 0 && projectApprovers.length === 0) {
|
|
|
|
|
proxy.$modal.msgError('请至少填写一项工时并指定审批人');
|
|
|
|
|
buttonLoading.value = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 放入流程变量
|
|
|
|
|
submitData.variables = {
|
|
|
|
|
startUserId: userStore.userId,
|
|
|
|
|
totalHours: submitData.totalHours,
|
|
|
|
|
deptApprovers: deptApprovers, // 对应后端 variables.put("deptApprovers", ...)
|
|
|
|
|
projectApprovers: projectApprovers, // 对应后端 variables.put("projectApprovers", ...)
|
|
|
|
|
hasDeptWork: deptApprovers.length > 0, // 前端也可以传这个标记,双重保险
|
|
|
|
|
hasProjectWork: projectApprovers.length > 0 // 前端也可以传这个标记
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
submitData.bizExt = {
|
|
|
|
|
businessTitle: `工时填报:${userStore.nickname}`,
|
|
|
|
|
businessCode: submitData.timesheetCode
|
|
|
|
|
};
|
|
|
|
|
submitData.timesheetStatus = '2'; // 已提交
|
|
|
|
|
submitData.flowStatus = 'waiting';
|
|
|
|
|
|
|
|
|
|
const res = await submitTimesheetAndFlowStart(submitData);
|
|
|
|
|
if (res?.data) form.value = res.data;
|
|
|
|
|
proxy.$modal.msgSuccess('提交成功');
|
|
|
|
|
} else {
|
|
|
|
|
// 暂存
|
|
|
|
|
submitData.timesheetStatus = '1'; // 草稿
|
|
|
|
|
submitData.flowStatus = 'draft';
|
|
|
|
|
if (submitData.timesheetId) await updateTimesheetInfo(submitData);
|
|
|
|
|
else await addTimesheetInfo(submitData);
|
|
|
|
|
proxy.$modal.msgSuccess('暂存成功');
|
|
|
|
|
}
|
|
|
|
|
proxy.$tab.closePage(route);
|
|
|
|
|
router.go(-1);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
} finally {
|
|
|
|
|
buttonLoading.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleApprovalRecord = () => {
|
|
|
|
|
if (form.value.timesheetId) approvalRecordRef.value?.init(form.value.timesheetId);
|
|
|
|
|
};
|
|
|
|
|
|