From 0df80041a1ad9fa879ec81edc69c2ad9209d4b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=99=AF=E5=AD=A6?= <5412262+sun_jing_xue@user.noreply.gitee.com> Date: Thu, 24 Jul 2025 14:36:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=9B=E5=BA=94=E5=95=86=E5=BC=B9=E5=87=BA?= =?UTF-8?q?=20=E5=9C=B0=E5=B8=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/SupplierRegisterInfo.tsx | 98 +++++++++++++++---- 1 file changed, 77 insertions(+), 21 deletions(-) diff --git a/src/components/GlobalModal/components/SupplierRegisterInfo.tsx b/src/components/GlobalModal/components/SupplierRegisterInfo.tsx index c69aae6..062bb79 100644 --- a/src/components/GlobalModal/components/SupplierRegisterInfo.tsx +++ b/src/components/GlobalModal/components/SupplierRegisterInfo.tsx @@ -1,7 +1,9 @@ -import React from 'react'; -import { Descriptions, Table } from 'antd'; +import React, { useEffect, useState } from 'react'; +import { Descriptions, Table, Spin } from 'antd'; import type { ColumnsType } from 'antd/es/table'; import { useIntl } from 'umi'; +import { getDictList } from '@/servers/api/dicts'; +import { dictRegion } from '@/servers/api/user' interface qualifications { id: string; // 主键ID(如后续用于 rowKey) certificateType: string; // 资质证书类型 @@ -23,8 +25,62 @@ interface BankInfo { province: string; city: string; } -const SupplierRegisterInfo = ({ registerInfo }: { registerInfo: any }) => { +const codeNameCache = new Map(); +const fetchRegionNames = async (codes: string[]) => { + const waitCodes = codes.filter(code => code && !codeNameCache.has(code)); + if (waitCodes.length === 0) return; + // 批量接口推荐你后端支持,单个请求也兼容如下 + await Promise.all(waitCodes.map(async (code) => { + try { + const { code: status, data } = await dictRegion(code); + if (status === 200 && data && data.name) { + codeNameCache.set(code, data.name); + } + } catch { /* ignore */ } + })); +}; +const SupplierRegisterInfo = ({ registerInfo }: { registerInfo: any }) => { + //币种 + const [currencyMap, setCurrencyMap] = useState<{ [code: string]: string }>({}); + const [regionLoading, setRegionLoading] = useState(false); + const [, forceUpdate] = useState({}); // 用于触发重新渲染 + + useEffect(() => { + getDictList('currency').then((res) => { + if (res.code === 200) { + const map: { [code: string]: string } = {}; + res.data.forEach((item: { code: string, dicName: string }) => { + map[item.code] = item.dicName; + }); + setCurrencyMap(map); + } + }); + + }, []); + useEffect(() => { + if (!Array.isArray(registerInfo?.coscoSupplierBank)) return; + // 收集所有 code + const codes: string[] = []; + registerInfo.coscoSupplierBank.forEach((item: BankInfo) => { + if (item.nation) codes.push(item.nation); + if (item.province) codes.push(item.province); + if (item.city) codes.push(item.city); + }); + setRegionLoading(true); + fetchRegionNames(codes).then(() => { + setRegionLoading(false); + forceUpdate({}); + }); + }, [registerInfo?.coscoSupplierBank]); + // 通用渲染 + const renderRegionName = (code: string) => { + if (!code) return ''; + if (codeNameCache.has(code)) { + return codeNameCache.get(code); + } + return ; + }; const intl = useIntl(); const qualificationsColumns: ColumnsType = [ @@ -44,10 +100,10 @@ const SupplierRegisterInfo = ({ registerInfo }: { registerInfo: any }) => { { title: intl.formatMessage({ id: 'component.globalModal.openingBank' }), dataIndex: 'bank', key: 'bank' }, { title: intl.formatMessage({ id: 'component.globalModal.accountName' }), dataIndex: 'accountName', key: 'accountName' }, { title: intl.formatMessage({ id: 'component.globalModal.accountNumber' }), dataIndex: 'account', key: 'account' }, - { title: intl.formatMessage({ id: 'component.globalModal.currency' }), dataIndex: 'currencyName', key: 'currency' }, - { title: intl.formatMessage({ id: 'component.globalModal.country' }), dataIndex: 'nationName', key: 'nation' }, - { title: intl.formatMessage({ id: 'component.globalModal.province' }), dataIndex: 'provinceName', key: 'province' }, - { title: intl.formatMessage({ id: 'component.globalModal.city' }), dataIndex: 'cityName', key: 'city' }, + { title: intl.formatMessage({ id: 'component.globalModal.currency' }), dataIndex: 'currency', key: 'currency', render: (code: string) => currencyMap[code] || code }, + { title: intl.formatMessage({ id: 'component.globalModal.country' }), dataIndex: 'nation', key: 'nation', render: renderRegionName }, + { title: intl.formatMessage({ id: 'component.globalModal.province' }), dataIndex: 'province', key: 'province', render: renderRegionName }, + { title: intl.formatMessage({ id: 'component.globalModal.city' }), dataIndex: 'city', key: 'city', render: renderRegionName}, ]; if (!registerInfo) return
{intl.formatMessage({ id: 'component.globalModal.loading' })}...
; @@ -241,12 +297,12 @@ const SupplierRegisterInfo = ({ registerInfo }: { registerInfo: any }) => { index + 1 }, - { title: intl.formatMessage({id: 'component.globalModal.question'}), dataIndex: 'questionName', key: 'questionName' }, - { title: intl.formatMessage({id: 'component.globalModal.answer'}), dataIndex: 'replyValue', key: 'replyValue', width: 120 }, + { title: intl.formatMessage({ id: 'component.globalModal.index' }), dataIndex: 'index', key: 'index', width: 60, align: 'center', render: (_: any, __: any, index: number) => index + 1 }, + { title: intl.formatMessage({ id: 'component.globalModal.question' }), dataIndex: 'questionName', key: 'questionName' }, + { title: intl.formatMessage({ id: 'component.globalModal.answer' }), dataIndex: 'replyValue', key: 'replyValue', width: 120 }, ]} pagination={false} - title={() =>
{intl.formatMessage({id: 'component.globalModal.questionnaire'})}
} + title={() =>
{intl.formatMessage({ id: 'component.globalModal.questionnaire' })}
} /> @@ -261,11 +317,11 @@ const SupplierRegisterInfo = ({ registerInfo }: { registerInfo: any }) => { label={intl.formatMessage({ id: 'component.globalModal.antiBriberyLabel' })} labelStyle={{ width: '200px' }} > - { registerInfo.coscoSupplierSurveyAttachments.map((item:any) => { - const { attachmentsType, fileUrl , fileName } = item; - return attachmentsType === 'commitment'? ( - {fileName} - ) :null + {registerInfo.coscoSupplierSurveyAttachments.map((item: any) => { + const { attachmentsType, fileUrl, fileName } = item; + return attachmentsType === 'commitment' ? ( + {fileName} + ) : null })} @@ -281,11 +337,11 @@ const SupplierRegisterInfo = ({ registerInfo }: { registerInfo: any }) => { label={intl.formatMessage({ id: 'component.globalModal.otherAttachmentLabel' })} labelStyle={{ width: '200px' }} > - { registerInfo.coscoSupplierSurveyAttachments.map((item:any) => { - const { attachmentsType, fileUrl , fileName } = item; - return attachmentsType === 'accessory'? ( - {fileName} - ) :null + {registerInfo.coscoSupplierSurveyAttachments.map((item: any) => { + const { attachmentsType, fileUrl, fileName } = item; + return attachmentsType === 'accessory' ? ( + {fileName} + ) : null })}