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