登录与品类

This commit is contained in:
孙景学
2025-08-04 16:06:23 +08:00
parent ad4efd8e46
commit b5cb08deb5
29 changed files with 665 additions and 270 deletions

View File

@ -22,6 +22,7 @@ interface viewDataData {
interface coscoSupplierUserCategory {
categoryName: string;
categoryId: string;
categoryPathName?: string;
supplierUserId: string;
}
interface SupplierUserCategory {
@ -32,19 +33,27 @@ interface SupplierUserCategory {
interface CategoryNode {
key: string;
title: string;
pathName: string;
path: string;
children?: CategoryNode[];
}
function flattenTree(
function getKeyTitlePathMap(
tree: CategoryNode[],
map: Record<string, string> = {}
): Record<string, string> {
keyTitleMap: Record<string, string> = {},
keyPathMap: Record<string, string> = {},
keyIdMap: Record<string, string> = {}
) {
tree.forEach((node) => {
map[node.key] = node.title;
if (node.children) flattenTree(node.children, map);
keyTitleMap[node.key] = node.title;
keyPathMap[node.key] = node.pathName;
keyIdMap[node.key] = node.path;
if (node.children && node.children.length > 0) {
getKeyTitlePathMap(node.children, keyTitleMap, keyPathMap, keyIdMap);
}
});
return map;
}
return { keyTitleMap, keyPathMap, keyIdMap };
}
const InvoiceFormModal: React.FC<props> = ({
@ -141,12 +150,15 @@ const InvoiceFormModal: React.FC<props> = ({
const leafKeys = findLeafKeys(convertTreeData(categoriesTreeData));
const onlyLeafChecked = keys.filter(key => leafKeys.includes(String(key)));
// 平铺tree获取id=>title映射
const keyTitleMap = flattenTree(convertTreeData(categoriesTreeData));
// 获取映射
const { keyTitleMap, keyPathMap, keyIdMap } = getKeyTitlePathMap(convertTreeData(categoriesTreeData));
// 拼 categoryItem 数组
const coscoSupplierUserCategoryList = onlyLeafChecked.map((id) => ({
categoryId: id,
categoryName: keyTitleMap[id] || '',
categoryPathName: keyPathMap[id] || '',
categoryPathId: keyIdMap[id] || '',
}));
setCheckedKeys(keys); // UI 显示用,还是全量
@ -208,7 +220,7 @@ const InvoiceFormModal: React.FC<props> = ({
<Descriptions.Item label="联系人邮箱">{viewData?.contactsEmail}</Descriptions.Item>
<Descriptions.Item label="负责品类">
{viewData?.coscoSupplierUserCategoryList && viewData.coscoSupplierUserCategoryList.map((item) => {
return <div>{item.categoryName}</div>
return <div>{item.categoryPathName}</div>
})}
</Descriptions.Item>
</Descriptions>

View File

@ -137,18 +137,18 @@ const OtherAttachmentsTab: React.FC<Props> = (props) => {
key: 'coscoSupplierUserCategoryList',
ellipsis: true,
width: 160,
render: (value: { categoryName: string }[] = []) => {
render: (value: { categoryName: string; categoryPathName: string }[] = []) => {
if (!value || value.length === 0) return '-';
if (value.length === 1) {
return <span>{value[0].categoryName}</span>;
}
// 多于1条
const allNames = value.map(item => item.categoryName).join('');
const allNames = value.map(item => item.categoryPathName).join('\n');
return (
<Tooltip title={allNames} overlayStyle={{ zIndex: 1200 }}>
<Tooltip title={<pre style={{ margin: 0, fontSize: 12, fontFamily: '微软雅黑', whiteSpace: 'pre-wrap' }}>{allNames}</pre>} overlayStyle={{ zIndex: 1200 }}>
<span>
{value[0].categoryName}
<span></span>
{value.length !== 1 && (
<span></span>
)}
</span>
</Tooltip>
);