This commit is contained in:
linxd
2025-07-17 08:46:01 +08:00
10 changed files with 170 additions and 116 deletions

View File

@ -111,8 +111,8 @@ const DomesticForm: React.FC<ForeignFormProps> = ({ form, countdown, handleGetCa
{/* <Col span={12}>
<Form.Item
name={['coscoSupplierBase', 'supplierType']}
label="供应商分类"
rules={[{ required: true, message: '请选择供应商分类' }]}
label="企业类型"
rules={[{ required: true, message: '请选择企业类型' }]}
>
<Select placeholder="请选择">
<Option value="dvs">境内企业/机构</Option>

View File

@ -1,20 +1,21 @@
import React, { useState, useEffect } from 'react';
import { Modal, Form, Select, Button, Tree, message, Input } from 'antd';
import { Modal, Form, Button, Tree, message, Input } from 'antd';
//组件
import SupplierSelector from './SupplierSelector';
import AccessDepartmentSelect from '@/components/AccessDepartmentSelect';
// 请求
import { categoryTree, add } from '../services';
const { Option } = Select;
// 主体
const CreateModal: React.FC<{ visible: boolean; onCancel: () => void; }> = ({ visible, onCancel }) => {
const [form] = Form.useForm();
//名称输入
const [accessWorkNameEdited, setAccessWorkNameEdited] = useState(false);
//品类选择
const [checkedKeys, setCheckedKeys] = useState<React.Key[]>([]);
//供应商
const [selectedSuppliers, setSelectedSuppliers] = useState<any[]>([]);
const [disabledCategories, setDisabledCategories] = useState<string[]>([]);
//供应商弹出
const [supplierModalVisible, setSupplierModalVisible] = useState(false);
//品类选择渲染数据
@ -26,7 +27,7 @@ const CreateModal: React.FC<{ visible: boolean; onCancel: () => void; }> = ({ vi
title: item.categoryName,
key: item.id,
children: item.children ? convertTreeData(item.children) : undefined,
disabled: disabledCategories.includes(item.id),
}));
}
function findLeafKeys(treeData: any[]): string[] {
@ -56,8 +57,55 @@ const CreateModal: React.FC<{ visible: boolean; onCancel: () => void; }> = ({ vi
// 只取叶子节点 key
const leafKeys = findLeafKeys(convertTreeData(categoriesTreeData));
const onlyLeafChecked = keys.filter(key => leafKeys.includes(String(key)));
console.log(onlyLeafChecked,'onlyLeafChecked', leafKeys ,keys);
setCheckedKeys(keys); // UI 显示用,还是全量
form.setFieldsValue({ categoryIds: onlyLeafChecked }); // 只存叶子到表单
// ==============================
// 增加自动拼标题的逻辑
// ==============================
if (!accessWorkNameEdited) {
// 1. 获取供应商名
const supplier = (form.getFieldValue('supplier') || [])[0];
let supplierName = '';
if (supplier) {
supplierName = supplier.supplierType === 'ovs' ? supplier.nameEn : supplier.name;
}
// 2. 获取已选品类名称
const findNamesByIds = (treeData: any[], ids: any[]) => {
let names: string[] = [];
const dfs = (list: any[]) => {
list.forEach(item => {
if (ids.includes(item.id)) {
names.push(item.categoryName);
}
if (item.children) dfs(item.children);
});
}
dfs(treeData);
return names;
};
const categoryNames = findNamesByIds(categoriesTreeData, onlyLeafChecked);
let autoTitle = supplierName;
if (supplierName && categoryNames.length) {
if (categoryNames.length === 1) {
autoTitle = `${supplierName}-${categoryNames[0]}-品类准入工作`;
} else {
autoTitle = `${supplierName}-${categoryNames[0]}等-品类准入工作`;
}
} else if (!supplierName && categoryNames.length) {
if (categoryNames.length === 1) {
autoTitle = categoryNames[0];
} else {
autoTitle = `${categoryNames[0]}等-品类准入工作`;
}
}
form.setFieldsValue({ accessWorkName: autoTitle });
}
};
// 提交
@ -95,7 +143,6 @@ const CreateModal: React.FC<{ visible: boolean; onCancel: () => void; }> = ({ vi
message.success('创建成功');
form.resetFields();
setCheckedKeys([]);
setSelectedSuppliers([]);
onCancel();
} else {
message.error('创建失败');
@ -120,7 +167,6 @@ const CreateModal: React.FC<{ visible: boolean; onCancel: () => void; }> = ({ vi
onCancel={() => {
form.resetFields();
setCheckedKeys([]);
setSelectedSuppliers([]);
onCancel();
}}
width="700px"
@ -137,7 +183,14 @@ const CreateModal: React.FC<{ visible: boolean; onCancel: () => void; }> = ({ vi
name="accessWorkName"
rules={[{ required: true, message: '请输入标题名称' }]}
>
<Input placeholder="请输入标题名称" allowClear />
<Input placeholder="请输入标题名称" allowClear
onChange={e => {
if (e.target.value) {
setAccessWorkNameEdited(true);
} else {
setAccessWorkNameEdited(false);
}
}}/>
</Form.Item>
<Form.Item
label="准入部门"
@ -148,6 +201,17 @@ const CreateModal: React.FC<{ visible: boolean; onCancel: () => void; }> = ({ vi
</Form.Item>
<Form.Item
label="选择供应商"
name="supplier"
rules={[{ required: true, message: '请选择供应商' }]}
>
<Button onClick={() => setSupplierModalVisible(true)}>
</Button>
<span style={{marginLeft: 10}}>{`${form.getFieldValue('supplier')? form.getFieldValue('supplier')[0].supplierType === 'ovs' ? form.getFieldValue('supplier')[0].nameEn : form.getFieldValue('supplier')[0].name : ''}`}</span>
</Form.Item>
<Form.Item
label="品类选择"
name="categoryIds"
@ -170,15 +234,6 @@ const CreateModal: React.FC<{ visible: boolean; onCancel: () => void; }> = ({ vi
/>
</Form.Item>
<Form.Item
label="选择供应商"
name="supplier"
rules={[{ required: true, message: '请选择供应商' }]}
>
<Button onClick={() => setSupplierModalVisible(true)}>
</Button>
</Form.Item>
<Form.Item wrapperCol={{ offset: 6 }}>
<Button type="primary" htmlType="submit" style={{ marginRight: 8 }}>
@ -187,7 +242,6 @@ const CreateModal: React.FC<{ visible: boolean; onCancel: () => void; }> = ({ vi
onClick={() => {
form.resetFields();
setCheckedKeys([]);
setSelectedSuppliers([]);
}}
>
@ -197,11 +251,31 @@ const CreateModal: React.FC<{ visible: boolean; onCancel: () => void; }> = ({ vi
<SupplierSelector
visible={supplierModalVisible}
selectedKeys={(form.getFieldValue('supplier') || []).map((i: any) => i.id)}
onCancel={() => setSupplierModalVisible(false)}
onSelect={(selected) => {
setSelectedSuppliers(selected);
form.setFieldsValue({ supplier: selected });
setCheckedKeys([]);
setSupplierModalVisible(false);
// 取所有已选供应商的 categoryName 并分割
const allCategories = selected
.map(item => item.categoryIds) // 取出字符串
.filter(Boolean) // 防止空
.flatMap(str => str.split(',')) // 逗号切分
.map(c => c.trim()) // 去空格
.filter(Boolean);
setDisabledCategories(Array.from(new Set(allCategories))); // 去重
//名称
if (!accessWorkNameEdited) {
if (selected.length > 0) {
console.log(selected, 'accessWorkName');
const suppliersName = `${selected[0].supplierType === 'ovs' ? selected[0].nameEn : selected[0].name}-品类准入工作`
form.setFieldsValue({ 'accessWorkName': suppliersName });
} else {
form.setFieldsValue({ 'accessWorkName': '' });
}
}
}}
/>
</Modal>

View File

@ -1,46 +1,28 @@
import React, { useState, useEffect } from 'react';
import { Modal, Input, Select, Row, Col, Table, Button, Form, Tooltip } from 'antd';
import { RightOutlined, LeftOutlined } from '@ant-design/icons';
import { Modal, Input, Button, Form, Table, Tooltip } from 'antd';
import { coscoSupplierBase } from '../services';
import RegionTypeSelect from '@/components/CommonSelect/RegionTypeSelect'
const SupplierSelector: React.FC<{ visible: boolean; onCancel: () => void; onSelect?: (selected: any[]) => void; }> = ({ visible, onCancel, onSelect }) => {
// 查询
const SupplierSelector: React.FC<{
visible: boolean;
onCancel: () => void;
onSelect?: (selected: any[]) => void;
selectedKeys?: React.Key[];
}> = ({ visible, onCancel, onSelect, selectedKeys = [] }) => {
// 查询表单
const [form] = Form.useForm();
//列表渲染数据
const [tableListData, setTableListData] = useState([]);
//列表分页
// 列表数据
const [tableListData, setTableListData] = useState<any[]>([]);
// 单选key
const [selectedRowKey, setSelectedRowKey] = useState<string | null>(null);
// 当前选中对象
const [selectedSupplier, setSelectedSupplier] = useState<any | null>(null);
// 分页
const [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: 0 });
//列表加载
// 加载
const [loading, setLoading] = useState(false);
//已选供应商
const [leftSelected, setLeftSelected] = useState<React.Key[]>([]);
//选择供应商
const [rightSelected, setRightSelected] = useState<React.Key[]>([]);
//确认 已选供应商
const [chosenSuppliers, setChosenSuppliers] = useState<any[]>([]);
//已选供应商 去重
const filteredData = (chosenSuppliers: any, selected: any) => {
const ids = new Set(chosenSuppliers.map((item: any) => item.id));
// 只把 selected 里没出现过的加进去
const newSelected = selected.filter((item: any) => !ids.has(item.id));
return [...chosenSuppliers, ...newSelected];
};
//获取已选供应商
const moveToRight = () => {
const selected = tableListData.filter((item: any) => leftSelected.includes(item.id));
const chosenSuppliersNew = filteredData(chosenSuppliers, selected);
setChosenSuppliers(chosenSuppliersNew);
setLeftSelected([]);
};
// 删除已选供应商
const moveToLeft = () => {
const remaining = chosenSuppliers.filter((item: any) => !rightSelected.includes(item.id));
setChosenSuppliers(remaining);
setRightSelected([]);
};
// 列表方法
// 查询
const getTableList = async (values: any = {}, pageNo: number = 1, pageSize: number = 10) => {
setLoading(true);
try {
@ -53,29 +35,46 @@ const SupplierSelector: React.FC<{ visible: boolean; onCancel: () => void; onSel
setLoading(false);
}
};
// 初始化
useEffect(() => {
if (visible) {
setSelectedRowKey(selectedKeys[0] ? selectedKeys[0].toString() : null);
form.resetFields();
setSelectedSupplier(null);
const values = form.getFieldsValue();
getTableList(values, 1, 10)
getTableList(values, 1, 10);
}
}, [visible])
//供应商名称
// eslint-disable-next-line
}, [visible, selectedKeys]);
// 列
const columns = [
{
title: '供应商名称', dataIndex: 'name', ellipsis: true, width: 160, render: (_: any, record: any) => {
title: '供应商名称',
dataIndex: 'name',
ellipsis: true,
width: 160,
render: (_: any, record: any) => {
const name = record.supplierType === "ovs" ? record.nameEn : record.name;
return (
<Tooltip placement="topLeft" title={name}>
{name}
</Tooltip>)
</Tooltip>
);
}
},
{ title: '统一社会信用代码/税号', ellipsis: true, dataIndex: 'unifiedCode' },
];
return (
<Modal title="选择供应商" visible={visible} onCancel={onCancel} footer={null} width="80%">
return (
<Modal
title="选择供应商"
visible={visible}
onCancel={onCancel}
footer={null}
width="50%"
>
<Form layout="inline" form={form} onFinish={getTableList} style={{ marginBottom: 16 }}>
<Form.Item name="name" label="供应商名称">
<Input placeholder="请输入供应商名称关键字" style={{ width: 220 }} allowClear maxLength={20} />
@ -88,55 +87,35 @@ const SupplierSelector: React.FC<{ visible: boolean; onCancel: () => void; onSel
</Form.Item>
<Form.Item>
<Button onClick={() => {
form.resetFields()
form.resetFields();
setSelectedRowKey(null);
setSelectedSupplier(null);
const values = form.getFieldsValue();
getTableList(values, 1, 10)
getTableList(values, 1, 10);
}}></Button>
</Form.Item>
</Form>
<Row gutter={16}>
<Col span={10}>
<div></div>
<Table
rowSelection={{ type: 'checkbox', onChange: setLeftSelected, selectedRowKeys: leftSelected }}
rowKey="id"
dataSource={tableListData}
columns={columns}
loading={loading}
pagination={pagination}
onChange={(pagination) => {
const values = form.getFieldsValue();
getTableList(values, pagination.current!, pagination.pageSize!)
}}
scroll={{ y: 300 }}
/>
</Col>
<Col span={4} style={{ textAlign: 'center', paddingTop: 100 }}>
<Button onClick={moveToRight} disabled={leftSelected.length === 0}>
<RightOutlined />
</Button>
<br />
<br />
<Button onClick={moveToLeft} disabled={rightSelected.length === 0}>
<LeftOutlined />
</Button>
</Col>
<Col span={10}>
<div></div>
<Table
rowSelection={{ type: 'checkbox', onChange: setRightSelected, selectedRowKeys: rightSelected }}
columns={columns}
dataSource={chosenSuppliers}
rowKey="id"
pagination={false}
scroll={{ y: 300 }}
/>
</Col>
</Row>
<Table
rowSelection={{
type: 'radio',
selectedRowKeys: selectedRowKey ? [selectedRowKey] : [],
onChange: (selectedKeys, selectedRows) => {
setSelectedRowKey(selectedKeys[0] ? selectedKeys[0].toString() : null);
setSelectedSupplier(selectedRows[0] || null);
}
}}
rowKey="id"
dataSource={tableListData}
columns={columns}
loading={loading}
pagination={pagination}
onChange={pagination => {
const values = form.getFieldsValue();
getTableList(values, pagination.current!, pagination.pageSize!);
}}
scroll={{ y: 300 }}
/>
<div style={{ textAlign: 'right', marginTop: 16 }}>
<Button style={{ marginRight: 8 }} onClick={onCancel}>
@ -144,8 +123,9 @@ const SupplierSelector: React.FC<{ visible: boolean; onCancel: () => void; onSel
</Button>
<Button
type="primary"
disabled={!selectedSupplier}
onClick={() => {
onSelect?.(chosenSuppliers);
onSelect?.(selectedSupplier ? [selectedSupplier] : []);
onCancel();
}}
>

View File

@ -111,7 +111,7 @@ const SupplierAddModal: React.FC<{
{ title: '供应商名称', dataIndex: 'name', align: 'center' },
{ title: '境内/境外', dataIndex: 'region', align: 'center' },
{ title: '统一社会信用代码', dataIndex: 'creditCode', align: 'center' },
{ title: '供应商分类', dataIndex: 'type', align: 'center' },
{ title: '企业类型', dataIndex: 'type', align: 'center' },
{
title: '操作',
align: 'center',

View File

@ -83,7 +83,7 @@ const SupplierListModal: React.FC<{
{ title: '供应商名称', dataIndex: 'name', align: 'center' },
{ title: '境内/境外', dataIndex: 'region', align: 'center' },
{ title: '统一社会信用代码', dataIndex: 'creditCode', align: 'center' },
{ title: '供应商分类', dataIndex: 'type', align: 'center' },
{ title: '企业类型', dataIndex: 'type', align: 'center' },
];
return (

View File

@ -124,7 +124,7 @@ const SupplierAddModal: React.FC<{
{ title: '境内/境外', dataIndex: 'supplierType', align: 'center',
render: (ext: any, record: any) => (<span>{`${record.supplierCategory === 'dvs'? '境内企业':'境外企业'}`}</span>) },
{ title: '统一社会信用代码', dataIndex: 'socialCreditCode', align: 'center', ellipsis: true },
{ title: '供应商分类', dataIndex: 'categoryName', align: 'center' , ellipsis: true },
{ title: '企业类型', dataIndex: 'categoryName', align: 'center' , ellipsis: true },
{
title: '操作',

View File

@ -83,7 +83,7 @@ const SupplierListModal: React.FC<{
{ title: '供应商名称', dataIndex: 'name', align: 'center' },
{ title: '境内/境外', dataIndex: 'region', align: 'center' },
{ title: '统一社会信用代码', dataIndex: 'creditCode', align: 'center' },
{ title: '供应商分类', dataIndex: 'enterpriseTypeCn', align: 'center' },
{ title: '企业类型', dataIndex: 'enterpriseTypeCn', align: 'center' },
];
return (

View File

@ -83,7 +83,7 @@ const SupplierListModal: React.FC<{
{ title: '供应商名称', dataIndex: 'name', align: 'center' },
{ title: '境内/境外', dataIndex: 'region', align: 'center' },
{ title: '统一社会信用代码', dataIndex: 'creditCode', align: 'center' },
{ title: '供应商分类', dataIndex: 'type', align: 'center' },
{ title: '企业类型', dataIndex: 'type', align: 'center' },
];
return (

View File

@ -145,7 +145,7 @@ const SupplierChangeReviewManage: React.FC<Props> = ({ dispatch }) => {
width: 160,
},
{
title: '供应商分类',
title: '企业类型',
dataIndex: 'enterpriseTypeCn',
align: 'center',
width: 160,

View File

@ -126,7 +126,7 @@ const RegistrationQuery: React.FC<RegistrationQueryProps> = ({ dispatch }) => {
width: 160,
},
{
title: '供应商分类',
title: '企业类型',
dataIndex: 'enterpriseTypeCn',
key: 'enterpriseTypeCn',
align: 'center',