修复ts警告,增加供应商评价模板管理一级指标二级指标的禁用逻辑
This commit is contained in:
@ -25,7 +25,6 @@ import {
|
||||
CategoryLimitationTypeText,
|
||||
TemplateStatus,
|
||||
TemplateStatusText,
|
||||
StarLevel,
|
||||
IndicatorAddOption
|
||||
} from '@/dicts/supplierTemplateDict';
|
||||
import {
|
||||
@ -71,6 +70,7 @@ const SupplierTemplateManageAdd: React.FC = () => {
|
||||
const [indicatorStMore, setIndicatorStMore] = useState<string>(IndicatorAddOption.CAN_ADD);
|
||||
const [indicatorNdMore, setIndicatorNdMore] = useState<string>(IndicatorAddOption.CAN_ADD);
|
||||
|
||||
|
||||
// 获取路由传递的数据
|
||||
const location = useLocation<LocationState>();
|
||||
|
||||
@ -122,12 +122,10 @@ const SupplierTemplateManageAdd: React.FC = () => {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化编辑数据
|
||||
useEffect(() => {
|
||||
// 获取所有模板列表
|
||||
fetchTemplateList();
|
||||
|
||||
// 如果是编辑模式,加载编辑数据
|
||||
if (location.state?.isEdit && location.state?.editData) {
|
||||
setIsEdit(true);
|
||||
@ -242,19 +240,30 @@ const SupplierTemplateManageAdd: React.FC = () => {
|
||||
// 处理模板选择
|
||||
const handleTemplateSelect = async (templateId: string) => {
|
||||
// 如果是新建模式,并且选择了模板,获取模板详情作为基础数据
|
||||
// 要求,如果选择模板时,需读取模板中的 indicatorStMore(一级指标是否可编辑) 和 indicatorNdMore(二级指标是否可编辑) 的值
|
||||
// 来动态设置 EvaluateTemplateTable 组件的value(templateData) 中的disable属性
|
||||
// 注意 当一级指标禁用时,需要判断指标类型是通用类型的才禁用,其他类型的指标不进行禁用
|
||||
if (!isEdit && templateId) {
|
||||
try {
|
||||
setLoading(true);
|
||||
const res = await getTemplateDetail(templateId);
|
||||
if (res.success && res.data) {
|
||||
// 一级指标是否可编辑
|
||||
const indicatorStMoreStatus = res.data.indicatorStMore === IndicatorAddOption.CANNOT_ADD;
|
||||
// 二级指标是否可编辑
|
||||
const indicatorNdMoreStatus = res.data.indicatorNdMore === IndicatorAddOption.CANNOT_ADD;
|
||||
|
||||
// 只复制指标数据,不复制基础信息
|
||||
if (res.data.indicatorStList && res.data.indicatorStList.length > 0) {
|
||||
// 复制模板数据,但清除ID以创建新记录
|
||||
const copiedIndicatorStList = JSON.parse(JSON.stringify(res.data.indicatorStList)).map((stItem: SupplierTemplateManage.IndicatorSt) => {
|
||||
// 通用类型指标禁用,其他类型指标不禁用 (如果当前是true 表示已禁用, 需要同时满足当前指标类型是通用类型)
|
||||
stItem.disabled = indicatorStMoreStatus && stItem.indicatorType === "generalType";
|
||||
// 删除ID而不是设为undefined
|
||||
delete stItem.id;
|
||||
// delete stItem.id;
|
||||
stItem.indicatorNdList = stItem.indicatorNdList.map((ndItem: SupplierTemplateManage.IndicatorNd) => {
|
||||
delete ndItem.id;
|
||||
ndItem.disabled = indicatorNdMoreStatus
|
||||
// delete ndItem.id;
|
||||
return ndItem;
|
||||
});
|
||||
return stItem;
|
||||
@ -372,7 +381,7 @@ const SupplierTemplateManageAdd: React.FC = () => {
|
||||
<Form.Item
|
||||
label={intl.formatMessage({ id: 'supplierTemplateManage.form.status' })}
|
||||
name="status"
|
||||
rules={[{ required: true, message: intl.formatMessage({ id: 'supplierTemplateManage.rule.status' }, { defaultMessage: '请选择是否启用' }) }]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Radio.Group>
|
||||
<Radio value={TemplateStatus.DRAFT}>{TemplateStatusText[TemplateStatus.DRAFT]}</Radio>
|
||||
|
Reference in New Issue
Block a user