Commit a831cc6d authored by Bill's avatar Bill

fix: 修改考评权重问题

parent 2832c0cb
import React, { useEffect, useMemo, useState } from 'react';
import { Card, Button } from 'antd';
import { Card, Button, message } from 'antd';
import { history } from 'umi';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { LinkOutlined, PlusOutlined, SaveOutlined } from '@ant-design/icons';
......@@ -98,8 +98,11 @@ const EvaluateAdd = (props) => {
const onSubmit = async (values: SubmitDataType) => {
const { items, appraisalDayStart, appraisalDayEnd, attachments, selectedProject, verifySteps, history: anyHistory, currentStep, ...rest } = values
// 计算权重
let totalScoreWeight = 0
const projectList = items.map((_item) => {
const { sendAppraisal, memberName, score, templates, reports, type, ...otherProps } = _item;
totalScoreWeight += +_item.scoreWeight;
return {
userId: _item.memberName.userId,
userName: _item.memberName.name,
......@@ -116,6 +119,10 @@ const EvaluateAdd = (props) => {
...otherProps
}
})
if (totalScoreWeight > 100) {
message.error(`添加的评估项目的权重和为${totalScoreWeight}, 大于100, 请修改`);
return
}
const tempPostData = {
...rest,
......@@ -186,7 +193,6 @@ const EvaluateAdd = (props) => {
})) || []
// const withProjectId = new Set(tempData.map((_item) => _item.id));
const dataSource = formActions.getFieldValue('tabs.tab-2.items') || [];
console.log("dataSource", dataSource);
// 对比两个数据, 如果dataSource 中 有 tempData 的值, 那么保留,如果没有择去除(没有id项)
const dataSourceKey = new Set(Array.from(dataSource?.map((_item) => _item.type)).filter(Boolean));
// 获取新增组
......@@ -215,9 +221,10 @@ const EvaluateAdd = (props) => {
const numberIndex = FormPath.transform(name, /\d/, $1 => {
return `${$1}`
});
const scoreWeight = formActions.getFieldValue(`items.${numberIndex}.grade`) || 0
const grade = formActions.getFieldValue(`items.${numberIndex}.scoreWeight`) || 0;
formActions.setFieldValue(`items.${numberIndex}.score`, scoreWeight * grade / 100);
const scoreWeight = formActions.getFieldValue(`items.${numberIndex}.scoreWeight`) || 0
const grade = formActions.getFieldValue(`items.${numberIndex}.grade`) || 0;
console.log(scoreWeight)
formActions.setFieldValue(`items.${numberIndex}.score`, +scoreWeight !== 0 ? scoreWeight * grade / 100 : grade);
})
}
......@@ -261,7 +268,6 @@ const EvaluateAdd = (props) => {
type: _row.type,
}
})
console.log(itmesList)
return {
appraisalDayStart: moment(appraisalDayEnd, 'YYYY-MM-DD'),
appraisalDayEnd: moment(appraisalDayEnd, 'YYYY-MM-DD'),
......
......@@ -92,9 +92,8 @@ export const evaluateAddSchema: ISchema = {
},
attachments: {
title: '附件',
type: 'object',
type: 'array',
'x-component': 'FormilyUploadFiles',
required: true,
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment