评价模板禁用逻辑
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
// 供应商评价 模板管理新增中的table
|
// 供应商评价 模板管理新增中的table
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useIntl } from 'umi';
|
import { useIntl } from 'umi';
|
||||||
import { Table, Input, Button, Select, InputNumber, message, Popconfirm } from 'antd';
|
import { Table, Input, Button, Select, InputNumber, message, Popconfirm, Switch } from 'antd';
|
||||||
import {
|
import {
|
||||||
PlusOutlined,
|
PlusOutlined,
|
||||||
MinusCircleOutlined,
|
MinusCircleOutlined,
|
||||||
@ -13,6 +13,7 @@ import type { DictItem } from '@/servers/api/dicts';
|
|||||||
import { StarLevel, StarLevelText } from '@/dicts/supplierTemplateDict';
|
import { StarLevel, StarLevelText } from '@/dicts/supplierTemplateDict';
|
||||||
import { generateUUID } from '@/utils/utils';
|
import { generateUUID } from '@/utils/utils';
|
||||||
import './EvaluateTemplateTable.less';
|
import './EvaluateTemplateTable.less';
|
||||||
|
import { useUser } from '@/hooks/useUser';
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
const { TextArea } = Input;
|
const { TextArea } = Input;
|
||||||
@ -24,6 +25,8 @@ interface EvaluateTemplateTableProps {
|
|||||||
isCheck?: boolean; // 是否显示勾选操作,如果为true则在表格最后一列增加勾选操作项
|
isCheck?: boolean; // 是否显示勾选操作,如果为true则在表格最后一列增加勾选操作项
|
||||||
onSelect?: (selectedItems: any[]) => void; // 勾选回调函数
|
onSelect?: (selectedItems: any[]) => void; // 勾选回调函数
|
||||||
defaultSelectedIds?: string[]; // 默认选中的二级指标ID数组
|
defaultSelectedIds?: string[]; // 默认选中的二级指标ID数组
|
||||||
|
firstIsAdd?: boolean; // 是否可追加一级指标 默认是
|
||||||
|
disableType?: string; // 禁用指标类型
|
||||||
}
|
}
|
||||||
|
|
||||||
// 内部使用的数据结构,扁平化后的行数据
|
// 内部使用的数据结构,扁平化后的行数据
|
||||||
@ -50,6 +53,18 @@ interface TableRowItem {
|
|||||||
selected?: boolean; // 是否选中
|
selected?: boolean; // 是否选中
|
||||||
disabledSt?: boolean; // 是否禁用一级
|
disabledSt?: boolean; // 是否禁用一级
|
||||||
disabledNd?: boolean; // 是否禁用二级
|
disabledNd?: boolean; // 是否禁用二级
|
||||||
|
|
||||||
|
// 因为table是需要扁平化数据,所以需要添加以下字段
|
||||||
|
baseIndicatorEdit?: string; // 基本指标是否可编辑 0.是、1.否
|
||||||
|
descIndicatorEdit?: string; // 指标说明是否可编辑(0.是、1.否)
|
||||||
|
scoreEdit?: string; // 分值是否可编辑(0.是、1.否)
|
||||||
|
indicatorStEdit?: string; // 该一级指标是否可编辑(0.是、1.否)
|
||||||
|
|
||||||
|
|
||||||
|
indicatorStEditST?: string; // 该一级指标是否可编辑(0.是、1.否)
|
||||||
|
baseIndicatorEditST?: string; // 基本指标是否可编辑 0.是、1.否
|
||||||
|
descIndicatorEditST?: string; // 指标说明是否可编辑(0.是、1.否)
|
||||||
|
scoreEditST?: string; // 分值是否可编辑(0.是、1.否)
|
||||||
}
|
}
|
||||||
|
|
||||||
const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||||
@ -59,11 +74,23 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
isCheck = false,
|
isCheck = false,
|
||||||
onSelect,
|
onSelect,
|
||||||
defaultSelectedIds = [],
|
defaultSelectedIds = [],
|
||||||
|
firstIsAdd = true,
|
||||||
|
disableType = '',
|
||||||
}) => {
|
}) => {
|
||||||
|
const { getUserRole } = useUser();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [dataSource, setDataSource] = useState<TableRowItem[]>([]);
|
const [dataSource, setDataSource] = useState<TableRowItem[]>([]);
|
||||||
const [indicatorTypes, setIndicatorTypes] = useState<DictItem[]>([]);
|
const [indicatorTypes, setIndicatorTypes] = useState<DictItem[]>([]);
|
||||||
const [loadingTypes, setLoadingTypes] = useState<boolean>(false);
|
const [loadingTypes, setLoadingTypes] = useState<boolean>(false);
|
||||||
|
const [isFirstDisabled, setIsFirstDisabled] = useState<boolean>(!firstIsAdd);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsFirstDisabled(!firstIsAdd);
|
||||||
|
if (disableType) {
|
||||||
|
const newIndicatorTypes = indicatorTypes.filter((item) => item.code !== disableType);
|
||||||
|
setIndicatorTypes(newIndicatorTypes);
|
||||||
|
}
|
||||||
|
}, [firstIsAdd, disableType]);
|
||||||
|
|
||||||
// 获取指标类型字典
|
// 获取指标类型字典
|
||||||
const fetchIndicatorTypes = async () => {
|
const fetchIndicatorTypes = async () => {
|
||||||
@ -106,8 +133,6 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
orderBy: typeof item.stOrderBy === 'string' ? parseInt(item.stOrderBy) : item.stOrderBy,
|
orderBy: typeof item.stOrderBy === 'string' ? parseInt(item.stOrderBy) : item.stOrderBy,
|
||||||
ndOrderBy: typeof item.orderBy === 'string' ? parseInt(item.orderBy) : item.orderBy,
|
ndOrderBy: typeof item.orderBy === 'string' ? parseInt(item.orderBy) : item.orderBy,
|
||||||
selected: defaultSelectedIds.includes(item.id), // 根据defaultSelectedIds设置选中状态
|
selected: defaultSelectedIds.includes(item.id), // 根据defaultSelectedIds设置选中状态
|
||||||
disabledSt: item.disabledSt ?? false,
|
|
||||||
disabledNd: item.disabledNd,
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,10 +157,10 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
ndOrderBy:
|
ndOrderBy:
|
||||||
typeof ndItem.orderBy === 'string' ? parseInt(ndItem.orderBy) : ndItem.orderBy,
|
typeof ndItem.orderBy === 'string' ? parseInt(ndItem.orderBy) : ndItem.orderBy,
|
||||||
selected: defaultSelectedIds.includes(ndItem.id), // 根据defaultSelectedIds设置选中状态
|
selected: defaultSelectedIds.includes(ndItem.id), // 根据defaultSelectedIds设置选中状态
|
||||||
// 关键点1:将API数据中的disabled属性映射到表格数据的disabledSt和disabledNd
|
indicatorStEditST: stItem.indicatorStEdit,
|
||||||
// 这确保了一级指标的禁用状态正确传递到所有相关行,二级指标保持自己的禁用状态
|
baseIndicatorEditST: stItem.baseIndicatorEdit,
|
||||||
disabledSt: stItem.disabled, // 根据disabled设置一级禁用状态
|
descIndicatorEditST: stItem.descIndicatorEdit,
|
||||||
disabledNd: ndItem.disabled, // 根据disabled设置二级禁用状态
|
scoreEditST: stItem.scoreEdit,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -174,6 +199,10 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
id: firstItem.stId || tempStId,
|
id: firstItem.stId || tempStId,
|
||||||
baseIndicator: firstItem.baseIndicator || '',
|
baseIndicator: firstItem.baseIndicator || '',
|
||||||
descIndicator: firstItem.descIndicator || '',
|
descIndicator: firstItem.descIndicator || '',
|
||||||
|
indicatorStEdit: firstItem.indicatorStEditST || 0,
|
||||||
|
baseIndicatorEdit: firstItem.baseIndicatorEditST || 0,
|
||||||
|
descIndicatorEdit: firstItem.descIndicatorEditST || 0,
|
||||||
|
scoreEdit: firstItem.scoreEditST || 0,
|
||||||
score: firstItem.stScore || '0',
|
score: firstItem.stScore || '0',
|
||||||
orderBy: firstItem.orderBy || stIndex + 1,
|
orderBy: firstItem.orderBy || stIndex + 1,
|
||||||
indicatorType: firstItem.indicatorType || '',
|
indicatorType: firstItem.indicatorType || '',
|
||||||
@ -229,7 +258,6 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
const currentValueStr = JSON.stringify(value);
|
const currentValueStr = JSON.stringify(value);
|
||||||
const currentDataSourceApiStr =
|
const currentDataSourceApiStr =
|
||||||
dataSource.length > 0 ? JSON.stringify(convertTableDataToApiData(dataSource)) : '';
|
dataSource.length > 0 ? JSON.stringify(convertTableDataToApiData(dataSource)) : '';
|
||||||
|
|
||||||
if (currentValueStr !== currentDataSourceApiStr) {
|
if (currentValueStr !== currentDataSourceApiStr) {
|
||||||
const tableData = convertApiDataToTableData(value);
|
const tableData = convertApiDataToTableData(value);
|
||||||
// 保留现有项的key,确保稳定性
|
// 保留现有项的key,确保稳定性
|
||||||
@ -256,7 +284,6 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
|
|
||||||
return newItem;
|
return newItem;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 确保所有key都是唯一的
|
// 确保所有key都是唯一的
|
||||||
setDataSource(ensureUniqueKeys(updatedTableData));
|
setDataSource(ensureUniqueKeys(updatedTableData));
|
||||||
} else {
|
} else {
|
||||||
@ -278,7 +305,6 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
selected: defaultSelectedIds.includes(item.ndId || ''),
|
selected: defaultSelectedIds.includes(item.ndId || ''),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
setDataSource(newData);
|
setDataSource(newData);
|
||||||
|
|
||||||
// 如果有onSelect回调,传递所有选中的项
|
// 如果有onSelect回调,传递所有选中的项
|
||||||
@ -293,10 +319,8 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
|
|
||||||
// 更新数据源
|
// 更新数据源
|
||||||
const updateDataSource = (newData: TableRowItem[]) => {
|
const updateDataSource = (newData: TableRowItem[]) => {
|
||||||
|
|
||||||
// 确保每行都有唯一稳定的key
|
// 确保每行都有唯一稳定的key
|
||||||
const finalData = ensureUniqueKeys(newData);
|
const finalData = ensureUniqueKeys(newData);
|
||||||
|
|
||||||
setDataSource(finalData);
|
setDataSource(finalData);
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
// 转换回API格式再传递给父组件
|
// 转换回API格式再传递给父组件
|
||||||
@ -325,6 +349,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
|
|
||||||
// 处理输入变化
|
// 处理输入变化
|
||||||
const handleInputChange = (val: any, record: TableRowItem, field: string) => {
|
const handleInputChange = (val: any, record: TableRowItem, field: string) => {
|
||||||
|
console.log('handleInputChange', val, record, field);
|
||||||
const newData = [...dataSource];
|
const newData = [...dataSource];
|
||||||
const index = newData.findIndex((item) => item.key === record.key);
|
const index = newData.findIndex((item) => item.key === record.key);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
@ -406,7 +431,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
disabledNd: false, // 默认不禁用二级指标
|
disabledNd: false, // 默认不禁用二级指标
|
||||||
};
|
};
|
||||||
// 制作数据源的副本,避免直接修改状态
|
// 制作数据源的副本,避免直接修改状态
|
||||||
const newData = dataSource.map(item => ({ ...item }));
|
const newData = dataSource.map((item) => ({ ...item }));
|
||||||
|
|
||||||
// 找到当前记录所在的一级指标组的最后一行
|
// 找到当前记录所在的一级指标组的最后一行
|
||||||
let insertIndex = -1;
|
let insertIndex = -1;
|
||||||
@ -429,7 +454,6 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
newData.push(newItem);
|
newData.push(newItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
updateDataSource(newData);
|
updateDataSource(newData);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -495,7 +519,6 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
newData.push(newItem);
|
newData.push(newItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
updateDataSource(newData);
|
updateDataSource(newData);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -542,13 +565,13 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
// 关键点5:检查同组内是否有任何行的disabledSt为true
|
// 关键点5:检查同组内是否有任何行的disabledSt为true
|
||||||
// 这是解决问题的核心,通过这个判断来决定是否禁用整个一级指标组的控件
|
// 这是解决问题的核心,通过这个判断来决定是否禁用整个一级指标组的控件
|
||||||
const anyDisabled = level1Items.some(item => !!item.disabledSt);
|
const anyDisabled = level1Items.some((item) => !!item.disabledSt);
|
||||||
|
|
||||||
// 关键点6:创建一个临时记录,使用组内任何行的禁用状态
|
// 关键点6:创建一个临时记录,使用组内任何行的禁用状态
|
||||||
// 这样确保只要组内有一行禁用,整个组的一级指标控件都会显示为禁用状态
|
// 这样确保只要组内有一行禁用,整个组的一级指标控件都会显示为禁用状态
|
||||||
const tempRecord = {
|
const tempRecord = {
|
||||||
...record,
|
...record,
|
||||||
disabledSt: anyDisabled
|
disabledSt: anyDisabled,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -566,6 +589,18 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filterColumns = (col: any) => {
|
||||||
|
if ((isDetail || getUserRole() != 'admin') && ['level1Action', 'indicator_st_edit', 'base_indicator_edit', 'desc_indicator_edit', 'score_edit'].includes(col.key)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
const filterColumnsSecond = (col: any) => {
|
||||||
|
if ((isDetail || getUserRole() != 'admin') && ['level2Action'].includes(col.key)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.levelOne' }),
|
title: intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.levelOne' }),
|
||||||
@ -603,7 +638,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
})}
|
})}
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
loading={loadingTypes}
|
loading={loadingTypes}
|
||||||
disabled={record.disabledSt}
|
disabled={record.indicatorStEditST === "1"}
|
||||||
>
|
>
|
||||||
{indicatorTypes.map((item) => (
|
{indicatorTypes.map((item) => (
|
||||||
<Option key={item.code} value={item.code}>
|
<Option key={item.code} value={item.code}>
|
||||||
@ -629,7 +664,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
return (
|
return (
|
||||||
<Input
|
<Input
|
||||||
value={cellContent}
|
value={cellContent}
|
||||||
disabled={record.disabledSt}
|
disabled={record.baseIndicatorEditST === "1" || record.indicatorStEditST === "1"}
|
||||||
onChange={(e) => handleInputChange(e.target.value, record, 'baseIndicator')}
|
onChange={(e) => handleInputChange(e.target.value, record, 'baseIndicator')}
|
||||||
placeholder={intl.formatMessage({
|
placeholder={intl.formatMessage({
|
||||||
id: 'supplierTemplateManage.evaluateTable.placeholder.baseIndicator',
|
id: 'supplierTemplateManage.evaluateTable.placeholder.baseIndicator',
|
||||||
@ -640,9 +675,31 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({
|
// (0.是、1.否 int类型)
|
||||||
id: 'supplierTemplateManage.evaluateTable.indicatorDescription',
|
title: '是否可编辑',
|
||||||
}),
|
align: 'center',
|
||||||
|
dataIndex: 'baseIndicatorEditST',
|
||||||
|
key: 'baseIndicatorEditST',
|
||||||
|
width: 50,
|
||||||
|
render: (text: string, record: TableRowItem) => {
|
||||||
|
return renderWithRowSpan(text, record, (cellContent) => {
|
||||||
|
if (isDetail) {
|
||||||
|
return cellContent === 1 ? '是' : '否';
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Switch
|
||||||
|
defaultChecked={true}
|
||||||
|
checked={cellContent === "0"}
|
||||||
|
onChange={(checked) =>
|
||||||
|
handleInputChange(checked ? "0" : "1", record, 'baseIndicatorEditST')
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "指标说明",
|
||||||
align: 'center',
|
align: 'center',
|
||||||
dataIndex: 'descIndicator',
|
dataIndex: 'descIndicator',
|
||||||
key: 'descIndicator',
|
key: 'descIndicator',
|
||||||
@ -655,7 +712,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
return (
|
return (
|
||||||
<Input
|
<Input
|
||||||
value={cellContent}
|
value={cellContent}
|
||||||
disabled={record.disabledSt}
|
disabled={record.descIndicatorEditST === "1" || record.indicatorStEditST === "1"}
|
||||||
onChange={(e) => handleInputChange(e.target.value, record, 'descIndicator')}
|
onChange={(e) => handleInputChange(e.target.value, record, 'descIndicator')}
|
||||||
placeholder={intl.formatMessage({
|
placeholder={intl.formatMessage({
|
||||||
id: 'supplierTemplateManage.evaluateTable.placeholder.indicatorDescription',
|
id: 'supplierTemplateManage.evaluateTable.placeholder.indicatorDescription',
|
||||||
@ -665,6 +722,32 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// (0.是、1.否 int类型)
|
||||||
|
title: '是否可编辑',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'descIndicatorEditST',
|
||||||
|
key: 'descIndicatorEditST',
|
||||||
|
width: 50,
|
||||||
|
render: (text: string, record: TableRowItem) => {
|
||||||
|
return renderWithRowSpan(text, record, (cellContent) => {
|
||||||
|
if (isDetail) {
|
||||||
|
return cellContent === 1 ? '是' : '否';
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Switch
|
||||||
|
defaultChecked={true}
|
||||||
|
checked={cellContent === "0"}
|
||||||
|
onChange={(checked) =>
|
||||||
|
handleInputChange(checked ? "0" : "1", record, 'descIndicatorEditST')
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.score' }),
|
title: intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.score' }),
|
||||||
align: 'center',
|
align: 'center',
|
||||||
@ -680,7 +763,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
<InputNumber
|
<InputNumber
|
||||||
min={0}
|
min={0}
|
||||||
max={100}
|
max={100}
|
||||||
disabled={record.disabledSt}
|
disabled={record.scoreEditST === "1" || record.indicatorStEditST === "1"}
|
||||||
value={parseFloat(cellContent) || 0}
|
value={parseFloat(cellContent) || 0}
|
||||||
onChange={(val) => handleInputChange(val?.toString() || '0', record, 'stScore')}
|
onChange={(val) => handleInputChange(val?.toString() || '0', record, 'stScore')}
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
@ -689,6 +772,30 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// (0.是、1.否 int类型)
|
||||||
|
title: '是否可编辑',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'scoreEditST',
|
||||||
|
key: 'scoreEditST',
|
||||||
|
width: 50,
|
||||||
|
render: (text: string, record: TableRowItem) => {
|
||||||
|
return renderWithRowSpan(text, record, (cellContent) => {
|
||||||
|
if (isDetail) {
|
||||||
|
return cellContent === 1 ? '是' : '否';
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Switch
|
||||||
|
defaultChecked={true}
|
||||||
|
checked={cellContent === "0"}
|
||||||
|
onChange={(checked) =>
|
||||||
|
handleInputChange(checked ? "0" : "1", record, 'scoreEditST')
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.action' }),
|
title: intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.action' }),
|
||||||
key: 'level1Action',
|
key: 'level1Action',
|
||||||
@ -701,6 +808,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
<div className="action-buttons">
|
<div className="action-buttons">
|
||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
|
disabled={isFirstDisabled || record.indicatorStEditST === "1"}
|
||||||
icon={<PlusCircleOutlined />}
|
icon={<PlusCircleOutlined />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
addLevel1Indicator(record);
|
addLevel1Indicator(record);
|
||||||
@ -724,7 +832,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
danger
|
danger
|
||||||
disabled={record.disabledSt}
|
disabled={isFirstDisabled || record.indicatorStEditST === "1"}
|
||||||
icon={<DeleteOutlined />}
|
icon={<DeleteOutlined />}
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
id: 'supplierTemplateManage.evaluateTable.button.deleteLevelOne',
|
id: 'supplierTemplateManage.evaluateTable.button.deleteLevelOne',
|
||||||
@ -735,7 +843,31 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
));
|
));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
].filter((col) => !(isDetail && col.key === 'level1Action')),
|
{
|
||||||
|
// (0.是、1.否 int类型)
|
||||||
|
title: '是否可编辑',
|
||||||
|
align: 'center',
|
||||||
|
dataIndex: 'indicatorStEditST',
|
||||||
|
key: 'indicatorStEditST',
|
||||||
|
width: 50,
|
||||||
|
render: (text: string, record: TableRowItem) => {
|
||||||
|
return renderWithRowSpan(text, record, (cellContent) => {
|
||||||
|
if (isDetail) {
|
||||||
|
return cellContent === 1 ? '是' : '否';
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Switch
|
||||||
|
defaultChecked={true}
|
||||||
|
checked={cellContent === "0"}
|
||||||
|
onChange={(checked) =>
|
||||||
|
handleInputChange(checked ? "0" : "1", record, 'indicatorStEditST')
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
].filter(filterColumns),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.levelTwo' }),
|
title: intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.levelTwo' }),
|
||||||
@ -896,7 +1028,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
].filter((col) => !(isDetail && col.key === 'level2Action')),
|
].filter(filterColumnsSecond),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -916,7 +1048,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
|||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{!isDetail && (
|
{!isDetail && !isFirstDisabled && (
|
||||||
<div className="add-button-row">
|
<div className="add-button-row">
|
||||||
<Button
|
<Button
|
||||||
type="dashed"
|
type="dashed"
|
||||||
|
@ -11,6 +11,17 @@ export const CategoryLimitationTypeText = {
|
|||||||
[CategoryLimitationType.UNIVERSAL]: '通用不限品类',
|
[CategoryLimitationType.UNIVERSAL]: '通用不限品类',
|
||||||
[CategoryLimitationType.LIMITED]: '限制品类',
|
[CategoryLimitationType.LIMITED]: '限制品类',
|
||||||
};
|
};
|
||||||
|
//指标类型 通用 技术
|
||||||
|
export const Types = [
|
||||||
|
{
|
||||||
|
label: '通用类型',
|
||||||
|
value: 'generalType',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '技术类型',
|
||||||
|
value: 'categoryType',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
// 模板状态
|
// 模板状态
|
||||||
export const TemplateStatus = {
|
export const TemplateStatus = {
|
||||||
@ -49,8 +60,8 @@ export enum IndicatorAddOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const IndicatorAddOptionText = {
|
export const IndicatorAddOptionText = {
|
||||||
[IndicatorAddOption.CAN_ADD]: '可修改',
|
[IndicatorAddOption.CAN_ADD]: '是',
|
||||||
[IndicatorAddOption.CANNOT_ADD]: '不可修改',
|
[IndicatorAddOption.CANNOT_ADD]: '否',
|
||||||
};
|
};
|
||||||
|
|
||||||
// 重新导出任务类型
|
// 重新导出任务类型
|
||||||
|
18
src/hooks/useUser.ts
Normal file
18
src/hooks/useUser.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
export const useUser = () => {
|
||||||
|
const [user, setUser] = useState<any>({
|
||||||
|
role: 'admin',
|
||||||
|
});
|
||||||
|
const getUserInfo = ()=>{
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
const setUserInfo = (user: any) => {
|
||||||
|
setUser(user);
|
||||||
|
}
|
||||||
|
const getUserRole = ()=>{
|
||||||
|
return user.role;
|
||||||
|
}
|
||||||
|
return { user, getUserInfo, setUserInfo, getUserRole };
|
||||||
|
};
|
@ -15,6 +15,7 @@ import {
|
|||||||
Typography,
|
Typography,
|
||||||
Spin,
|
Spin,
|
||||||
Modal,
|
Modal,
|
||||||
|
Checkbox,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import { history, useLocation, useIntl, connect } from 'umi';
|
import { history, useLocation, useIntl, connect } from 'umi';
|
||||||
import type { Dispatch, ConnectProps } from 'umi';
|
import type { Dispatch, ConnectProps } from 'umi';
|
||||||
@ -28,7 +29,11 @@ import {
|
|||||||
TemplateStatus,
|
TemplateStatus,
|
||||||
TemplateStatusText,
|
TemplateStatusText,
|
||||||
IndicatorAddOption,
|
IndicatorAddOption,
|
||||||
|
IndicatorAddOptionText,
|
||||||
|
Types,
|
||||||
} from '@/dicts/supplierTemplateDict';
|
} from '@/dicts/supplierTemplateDict';
|
||||||
|
|
||||||
|
import { useUser } from '@/hooks/useUser';
|
||||||
import {
|
import {
|
||||||
getTemplateDetail,
|
getTemplateDetail,
|
||||||
getAllTemplates,
|
getAllTemplates,
|
||||||
@ -36,6 +41,8 @@ import {
|
|||||||
addTemplate,
|
addTemplate,
|
||||||
} from '@/servers/api/supplierEvaluate';
|
} from '@/servers/api/supplierEvaluate';
|
||||||
import styles from './supplierTemplateManage.less';
|
import styles from './supplierTemplateManage.less';
|
||||||
|
import { getDictList } from '@/servers/api/dicts';
|
||||||
|
import type { DictItem } from '@/servers/api/dicts';
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
const { confirm } = Modal;
|
const { confirm } = Modal;
|
||||||
@ -65,6 +72,7 @@ interface LocationState {
|
|||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
|
|
||||||
const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }) => {
|
const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }) => {
|
||||||
|
const { getUserRole, setUserInfo } = useUser();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [form] = Form.useForm<FormValues>();
|
const [form] = Form.useForm<FormValues>();
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
@ -74,10 +82,11 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
useState<SupplierTemplateManage.TemplateDetailResponse['data']>();
|
useState<SupplierTemplateManage.TemplateDetailResponse['data']>();
|
||||||
const [templateList, setTemplateList] = useState<SupplierTemplateManage.TemplateItem[]>([]);
|
const [templateList, setTemplateList] = useState<SupplierTemplateManage.TemplateItem[]>([]);
|
||||||
|
|
||||||
// 添加控制开关的状态
|
// 添加控制开关的状态 一级指标是否可增加(0.可增加、1.不可增加)
|
||||||
const [indicatorStMore, setIndicatorStMore] = useState<string>(IndicatorAddOption.CAN_ADD);
|
const [indicatorStMore, setIndicatorStMore] = useState<string>(IndicatorAddOption.CAN_ADD);
|
||||||
|
//二级指标是否可增加(0.可增加、1.不可增加)
|
||||||
const [indicatorNdMore, setIndicatorNdMore] = useState<string>(IndicatorAddOption.CAN_ADD);
|
const [indicatorNdMore, setIndicatorNdMore] = useState<string>(IndicatorAddOption.CAN_ADD);
|
||||||
|
const [indicatorTypes, setIndicatorTypes] = useState<{ label: string; value: string }[]>([]);
|
||||||
// 获取路由传递的数据
|
// 获取路由传递的数据
|
||||||
const location = useLocation<LocationState>();
|
const location = useLocation<LocationState>();
|
||||||
|
|
||||||
@ -128,6 +137,7 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
copyTemplateId: res.data.copyTemplateId,
|
copyTemplateId: res.data.copyTemplateId,
|
||||||
indicatorStMore: res.data.indicatorStMore || IndicatorAddOption.CAN_ADD,
|
indicatorStMore: res.data.indicatorStMore || IndicatorAddOption.CAN_ADD,
|
||||||
indicatorNdMore: res.data.indicatorNdMore || IndicatorAddOption.CAN_ADD,
|
indicatorNdMore: res.data.indicatorNdMore || IndicatorAddOption.CAN_ADD,
|
||||||
|
indicatorTypeMore: res.data.indicatorTypeMore || '',
|
||||||
});
|
});
|
||||||
|
|
||||||
// 直接设置指标数据,无需转换
|
// 直接设置指标数据,无需转换
|
||||||
@ -147,6 +157,31 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 获取指标类型字典
|
||||||
|
const fetchIndicatorTypes = async () => {
|
||||||
|
try {
|
||||||
|
const res = await getDictList('Indicator_type');
|
||||||
|
if (res.success && res.data) {
|
||||||
|
setIndicatorTypes(
|
||||||
|
res.data.map((item: DictItem) => ({
|
||||||
|
label: item.dicName,
|
||||||
|
value: item.code,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
message.error(
|
||||||
|
intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.message.getTypeFailed' }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取指标类型失败:', error);
|
||||||
|
message.error(
|
||||||
|
intl.formatMessage({ id: 'supplierTemplateManage.evaluateTable.message.getTypeFailed' }),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (location.state?.editData?.id && dispatch) {
|
if (location.state?.editData?.id && dispatch) {
|
||||||
dispatch({
|
dispatch({
|
||||||
@ -164,6 +199,8 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 获取所有模板列表
|
// 获取所有模板列表
|
||||||
fetchTemplateList();
|
fetchTemplateList();
|
||||||
|
// 获取指标类型
|
||||||
|
fetchIndicatorTypes();
|
||||||
// 如果是编辑模式,加载编辑数据
|
// 如果是编辑模式,加载编辑数据
|
||||||
if (location.state?.isEdit && location.state?.editData) {
|
if (location.state?.isEdit && location.state?.editData) {
|
||||||
setIsEdit(true);
|
setIsEdit(true);
|
||||||
@ -188,7 +225,6 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
...values,
|
...values,
|
||||||
templateType: selectedTemplate?.templateType || '',
|
templateType: selectedTemplate?.templateType || '',
|
||||||
indicatorStList: templateData,
|
indicatorStList: templateData,
|
||||||
indicatorTypeMore: IndicatorAddOption.CAN_ADD,
|
|
||||||
status: parseInt(values.status, 10),
|
status: parseInt(values.status, 10),
|
||||||
} as unknown as SupplierTemplateManage.TemplateUpdateRequest;
|
} as unknown as SupplierTemplateManage.TemplateUpdateRequest;
|
||||||
|
|
||||||
@ -196,7 +232,6 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
if (isEdit && templateDetail) {
|
if (isEdit && templateDetail) {
|
||||||
dataToSubmit.id = templateDetail.id;
|
dataToSubmit.id = templateDetail.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
// 调用API接口
|
// 调用API接口
|
||||||
@ -260,6 +295,7 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
|
|
||||||
// 处理指标数据变更
|
// 处理指标数据变更
|
||||||
const handleTemplateDataChange = (data: SupplierTemplateManage.IndicatorSt[]) => {
|
const handleTemplateDataChange = (data: SupplierTemplateManage.IndicatorSt[]) => {
|
||||||
|
console.log('handleTemplateDataChange', data);
|
||||||
setTemplateData(data);
|
setTemplateData(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -371,7 +407,7 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Form<FormValues>
|
<Form
|
||||||
form={form}
|
form={form}
|
||||||
onFinish={handleSubmit}
|
onFinish={handleSubmit}
|
||||||
initialValues={{
|
initialValues={{
|
||||||
@ -511,22 +547,39 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
{getUserRole() === 'admin' && (
|
||||||
<Row gutter={24}>
|
<Row gutter={24}>
|
||||||
<Col span={8}>
|
<Col span={8}>
|
||||||
<Form.Item
|
<Form.Item label="是否可追加一级指标" name="indicatorStMore">
|
||||||
label={intl.formatMessage({ id: 'supplierTemplateManage.form.indicatorStMore' })}
|
<Radio.Group>
|
||||||
name="indicatorStMore"
|
<Radio value={IndicatorAddOption.CAN_ADD}>
|
||||||
valuePropName="checked"
|
{IndicatorAddOptionText[IndicatorAddOption.CAN_ADD]}
|
||||||
getValueProps={(value) => ({ checked: value === IndicatorAddOption.CAN_ADD })}
|
</Radio>
|
||||||
|
<Radio value={IndicatorAddOption.CANNOT_ADD}>
|
||||||
|
{IndicatorAddOptionText[IndicatorAddOption.CANNOT_ADD]}
|
||||||
|
</Radio>
|
||||||
|
</Radio.Group>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
<Form.Item // 这里必须放在Row下
|
||||||
|
shouldUpdate={(prev, curr) => prev.indicatorStMore !== curr.indicatorStMore}
|
||||||
|
noStyle
|
||||||
>
|
>
|
||||||
<Switch
|
{({ getFieldValue }) =>
|
||||||
checked={indicatorStMore === IndicatorAddOption.CAN_ADD}
|
getFieldValue('indicatorStMore') === IndicatorAddOption.CANNOT_ADD ? (
|
||||||
onChange={(checked) => handleSwitchChange('indicatorStMore', checked)}
|
<Col span={8}>
|
||||||
/>
|
<Form.Item label="禁用指标类型" name="indicatorTypeMore">
|
||||||
|
<Select
|
||||||
|
placeholder="请选择禁用指标类型"
|
||||||
|
options={indicatorTypes}
|
||||||
|
allowClear
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
{/* <Col span={8}>
|
||||||
<Col span={8}>
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={intl.formatMessage({ id: 'supplierTemplateManage.form.indicatorNdMore' })}
|
label={intl.formatMessage({ id: 'supplierTemplateManage.form.indicatorNdMore' })}
|
||||||
name="indicatorNdMore"
|
name="indicatorNdMore"
|
||||||
@ -538,8 +591,9 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
onChange={(checked) => handleSwitchChange('indicatorNdMore', checked)}
|
onChange={(checked) => handleSwitchChange('indicatorNdMore', checked)}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col> */}
|
||||||
</Row>
|
</Row>
|
||||||
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
@ -549,7 +603,22 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
|||||||
bordered={false}
|
bordered={false}
|
||||||
className={styles.innerCard}
|
className={styles.innerCard}
|
||||||
>
|
>
|
||||||
<EvaluateTemplateTable onChange={handleTemplateDataChange} value={templateData} />
|
<Form.Item
|
||||||
|
shouldUpdate={(prev, curr) =>
|
||||||
|
prev.indicatorStMore !== curr.indicatorStMore ||
|
||||||
|
prev.indicatorTypeMore !== curr.indicatorTypeMore
|
||||||
|
}
|
||||||
|
noStyle
|
||||||
|
>
|
||||||
|
{({ getFieldValue }) => (
|
||||||
|
<EvaluateTemplateTable
|
||||||
|
disableType={getFieldValue('indicatorTypeMore')}
|
||||||
|
firstIsAdd={getFieldValue('indicatorStMore') === IndicatorAddOption.CAN_ADD}
|
||||||
|
onChange={handleTemplateDataChange}
|
||||||
|
value={templateData}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Form.Item>
|
||||||
</Card>
|
</Card>
|
||||||
</Spin>
|
</Spin>
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ declare namespace SupplierTemplateManage {
|
|||||||
dimensions: TemplateDimension[];
|
dimensions: TemplateDimension[];
|
||||||
indicatorStMore: string;
|
indicatorStMore: string;
|
||||||
indicatorNdMore: string;
|
indicatorNdMore: string;
|
||||||
|
indicatorStList: IndicatorSt[];
|
||||||
|
indicatorNdList: IndicatorNd[];
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
message: string;
|
message: string;
|
||||||
|
Reference in New Issue
Block a user