feat: enhance CompanyAddModal with industry and scale enums, and update company list fetching
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { Modal, message } from 'antd';
|
import { Modal, Tag, message } from 'antd';
|
||||||
import { ActionType, ProTable, ProColumns } from '@ant-design/pro-components';
|
import { ActionType, ProTable, ProColumns } from '@ant-design/pro-components';
|
||||||
import { addParticipatingCompany } from '@/services/jobportal/outdoorFairDetail';
|
import { addParticipatingCompany } from '@/services/jobportal/outdoorFairDetail';
|
||||||
|
import { getCmsCompanyList } from '@/services/company/list';
|
||||||
|
import { getDictValueEnum } from '@/services/system/dict';
|
||||||
|
import { getCmsIndustryTreeList } from '@/services/classify/industry';
|
||||||
|
import DictTag, { DictValueEnumObj } from '@/components/DictTag';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@@ -10,28 +14,74 @@ interface Props {
|
|||||||
onSuccess: () => void;
|
onSuccess: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 可添加的企业列表 */
|
const flattenIndustryTree = (
|
||||||
const MOCK_AVAILABLE_COMPANIES = [
|
tree: { id: number; label: string; children?: any[] }[],
|
||||||
{ companyId: 1013, companyName: '石河子市天富集团', industry: '能源', scale: '1000人以上', contactPerson: '黄经理', contactPhone: '13309930001' },
|
): DictValueEnumObj => {
|
||||||
{ companyId: 1014, companyName: '新疆兵团勘察设计院', industry: '建筑/工程', scale: '200-500人', contactPerson: '曹院长', contactPhone: '13309930002' },
|
const map: DictValueEnumObj = {};
|
||||||
{ companyId: 1015, companyName: '石河子市商业银行', industry: '金融', scale: '500-1000人', contactPerson: '钱行长', contactPhone: '13309930003' },
|
const walk = (nodes: { id: number; label: string; children?: any[] }[]) => {
|
||||||
{ companyId: 1016, companyName: '兵团广播电视大学', industry: '教育/科研', scale: '200-500人', contactPerson: '杨校长', contactPhone: '13309930004' },
|
nodes?.forEach((node) => {
|
||||||
{ companyId: 1017, companyName: '新疆如意纺织服装有限公司', industry: '纺织/服装', scale: '1000人以上', contactPerson: '林经理', contactPhone: '13309930005' },
|
map[node.id] = {
|
||||||
{ companyId: 1018, companyName: '石河子市人民医院', industry: '医疗/卫生', scale: '1000人以上', contactPerson: '郝主任', contactPhone: '13309930006' },
|
text: node.label,
|
||||||
{ companyId: 1019, companyName: '兵团信息技术服务中心', industry: 'IT/互联网', scale: '100-200人', contactPerson: '孙主管', contactPhone: '13309930007' },
|
label: node.label,
|
||||||
{ companyId: 1020, companyName: '新疆燕京啤酒有限公司', industry: '快消/食品', scale: '500-1000人', contactPerson: '吕厂长', contactPhone: '13309930008' },
|
value: node.id,
|
||||||
];
|
};
|
||||||
|
if (node.children?.length) {
|
||||||
|
walk(node.children);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
walk(tree);
|
||||||
|
return map;
|
||||||
|
};
|
||||||
|
|
||||||
const CompanyAddModal: React.FC<Props> = ({ open, fairId, onCancel, onSuccess }) => {
|
const CompanyAddModal: React.FC<Props> = ({ open, fairId, onCancel, onSuccess }) => {
|
||||||
const actionRef = useRef<ActionType>();
|
const actionRef = useRef<ActionType>();
|
||||||
const [selectedRows, setSelectedRows] = useState<any[]>([]);
|
const [selectedRows, setSelectedRows] = useState<API.CompanyList.Company[]>([]);
|
||||||
|
const [scaleEnum, setScaleEnum] = useState<Record<string, any>>({});
|
||||||
|
const [industryEnum, setIndustryEnum] = useState<DictValueEnumObj>({});
|
||||||
|
|
||||||
const columns: ProColumns<any>[] = [
|
useEffect(() => {
|
||||||
{ title: '企业名称', dataIndex: 'companyName', ellipsis: true },
|
if (open) {
|
||||||
{ title: '行业', dataIndex: 'industry', width: 80 },
|
getDictValueEnum('scale', true, true).then(setScaleEnum);
|
||||||
{ title: '规模', dataIndex: 'scale', width: 100 },
|
getCmsIndustryTreeList().then((res) => {
|
||||||
{ title: '联系人', dataIndex: 'contactPerson', width: 80 },
|
if (res?.data) {
|
||||||
{ title: '联系电话', dataIndex: 'contactPhone', width: 130 },
|
setIndustryEnum(flattenIndustryTree(res.data));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
actionRef.current?.reload();
|
||||||
|
}
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
const getEnumLabel = (enums: Record<string | number, any>, value?: string | number) => {
|
||||||
|
if (value === undefined || value === null || value === '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return enums[value]?.label || enums[value]?.text || String(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns: ProColumns<API.CompanyList.Company>[] = [
|
||||||
|
{ title: '企业名称', dataIndex: 'name', ellipsis: true },
|
||||||
|
{
|
||||||
|
title: '行业',
|
||||||
|
dataIndex: 'industry',
|
||||||
|
width: 120,
|
||||||
|
render: (_, record) => <DictTag enums={industryEnum} value={record.industry} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '规模',
|
||||||
|
dataIndex: 'scale',
|
||||||
|
width: 120,
|
||||||
|
render: (_, record) => <DictTag enums={scaleEnum} value={record.scale} />,
|
||||||
|
},
|
||||||
|
{ title: '联系人', dataIndex: 'contactPerson', width: 100, hideInSearch: true },
|
||||||
|
{ title: '联系电话', dataIndex: 'contactPersonPhone', width: 140, hideInSearch: true },
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 90,
|
||||||
|
hideInSearch: true,
|
||||||
|
render: () => <Tag color="success">通过</Tag>,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const handleOk = async () => {
|
const handleOk = async () => {
|
||||||
@@ -41,7 +91,16 @@ const CompanyAddModal: React.FC<Props> = ({ open, fairId, onCancel, onSuccess })
|
|||||||
}
|
}
|
||||||
let success = 0;
|
let success = 0;
|
||||||
for (const row of selectedRows) {
|
for (const row of selectedRows) {
|
||||||
const res = await addParticipatingCompany({ fairId, ...row });
|
const res = await addParticipatingCompany({
|
||||||
|
fairId,
|
||||||
|
companyId: row.companyId,
|
||||||
|
companyName: row.name,
|
||||||
|
industry: getEnumLabel(industryEnum, row.industry),
|
||||||
|
scale: getEnumLabel(scaleEnum, row.scale),
|
||||||
|
contactPerson: row.contactPerson || row.companyContactList?.[0]?.contactPerson || '',
|
||||||
|
contactPhone:
|
||||||
|
row.contactPersonPhone || row.companyContactList?.[0]?.contactPersonPhone || '',
|
||||||
|
});
|
||||||
if (res.code === 200) success++;
|
if (res.code === 200) success++;
|
||||||
}
|
}
|
||||||
message.success(`成功添加 ${success} 家企业`);
|
message.success(`成功添加 ${success} 家企业`);
|
||||||
@@ -55,7 +114,10 @@ const CompanyAddModal: React.FC<Props> = ({ open, fairId, onCancel, onSuccess })
|
|||||||
open={open}
|
open={open}
|
||||||
width={800}
|
width={800}
|
||||||
destroyOnClose
|
destroyOnClose
|
||||||
onCancel={() => { setSelectedRows([]); onCancel(); }}
|
onCancel={() => {
|
||||||
|
setSelectedRows([]);
|
||||||
|
onCancel();
|
||||||
|
}}
|
||||||
onOk={handleOk}
|
onOk={handleOk}
|
||||||
okText="确认添加"
|
okText="确认添加"
|
||||||
>
|
>
|
||||||
@@ -66,9 +128,23 @@ const CompanyAddModal: React.FC<Props> = ({ open, fairId, onCancel, onSuccess })
|
|||||||
options={false}
|
options={false}
|
||||||
pagination={{ pageSize: 6 }}
|
pagination={{ pageSize: 6 }}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={MOCK_AVAILABLE_COMPANIES}
|
request={async (params) => {
|
||||||
|
const res = await getCmsCompanyList({
|
||||||
|
current: params.current,
|
||||||
|
pageSize: params.pageSize,
|
||||||
|
name: params.name,
|
||||||
|
industry: params.industry,
|
||||||
|
scale: params.scale,
|
||||||
|
status: 1,
|
||||||
|
} as API.CompanyList.Params);
|
||||||
|
return {
|
||||||
|
data: res.rows as any,
|
||||||
|
total: res.total,
|
||||||
|
success: res.code === 200,
|
||||||
|
};
|
||||||
|
}}
|
||||||
rowSelection={{
|
rowSelection={{
|
||||||
selectedRowKeys: selectedRows.map(r => r.companyId),
|
selectedRowKeys: selectedRows.map((r) => r.companyId),
|
||||||
onChange: (_, rows) => setSelectedRows(rows),
|
onChange: (_, rows) => setSelectedRows(rows),
|
||||||
}}
|
}}
|
||||||
tableAlertRender={false}
|
tableAlertRender={false}
|
||||||
|
|||||||
5
src/types/company/list.d.ts
vendored
5
src/types/company/list.d.ts
vendored
@@ -22,9 +22,11 @@ declare namespace API.CompanyList {
|
|||||||
code: string;
|
code: string;
|
||||||
description: string;
|
description: string;
|
||||||
companyContactList?: CompanyContact[];
|
companyContactList?: CompanyContact[];
|
||||||
|
contactPerson?: string;
|
||||||
|
contactPersonPhone?: string;
|
||||||
notPassReason?: string;
|
notPassReason?: string;
|
||||||
updateTime?: string;
|
updateTime?: string;
|
||||||
status?: 1 | 2; // 1 通过, 2 驳回
|
status?: 0 | 1 | 2; // 0 待审核, 1 通过, 2 驳回
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Params {
|
export interface Params {
|
||||||
@@ -35,6 +37,7 @@ declare namespace API.CompanyList {
|
|||||||
industry?: string;
|
industry?: string;
|
||||||
scale?: string;
|
scale?: string;
|
||||||
code?: string;
|
code?: string;
|
||||||
|
status?: 0 | 1 | 2;
|
||||||
startDate?: string;
|
startDate?: string;
|
||||||
endDate?: string;
|
endDate?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user