Files
fe_supplier_frontend/src/components/CompanyInfo/component/ContactsInfoTab.tsx

232 lines
6.4 KiB
TypeScript
Raw Normal View History

2025-06-24 10:52:30 +08:00
import React, { useEffect, useState } from 'react';
2025-07-18 10:37:13 +08:00
import { Table, Button, message, Switch, Popconfirm, Tooltip } from 'antd';
2025-06-24 10:52:30 +08:00
import type { ColumnsType, TablePaginationConfig } from 'antd/es/table';
2025-07-17 15:17:49 +08:00
import { getCoscoSupplierUserPage, editType, coscoSupplierUserDel } from '../services';
2025-06-24 10:52:30 +08:00
import { useIntl } from 'umi';
2025-07-17 15:17:49 +08:00
import ContactsInfoFormModal from './ContactsInfoFormModal';
2025-06-24 10:52:30 +08:00
2025-07-17 15:17:49 +08:00
interface getCoscoSupplierUser {
2025-06-24 10:52:30 +08:00
id: string;
2025-07-17 15:17:49 +08:00
attachmentsType?: string;
fileName?: string;
filePath?: string;
fileSize?: string;
fileType?: string;
fileUrl?: string;
supplierId?: string;
certificateUrl?: string;
delFlag: string;
type: string;
2025-07-18 10:37:13 +08:00
coscoSupplierUserCategoryList?: CoscoSupplierUserCategory[];
}
interface CoscoSupplierUserCategory {
categoryId:string;
categoryName:string;
supplierUserId:string;
2025-06-24 10:52:30 +08:00
}
2025-07-17 15:17:49 +08:00
2025-07-03 10:24:33 +08:00
interface Props {
viewType?: boolean;
record?: string;
}
2025-07-17 15:17:49 +08:00
const OtherAttachmentsTab: React.FC<Props> = (props) => {
const userId = sessionStorage.getItem('userId') || '';
const { viewType = false, record = userId } = props;
2025-07-17 15:17:49 +08:00
//语言切换
2025-06-24 10:52:30 +08:00
const intl = useIntl();
2025-07-17 15:17:49 +08:00
//列表渲染数据
const [data, setData] = useState<getCoscoSupplierUser[]>([]);
//列表加载
2025-06-24 10:52:30 +08:00
const [loading, setLoading] = useState(false);
2025-07-17 15:17:49 +08:00
//列表分页
const [pagination, setPagination] = useState<TablePaginationConfig>({ current: 1, pageSize: 10, total: 0 });
2025-06-24 10:52:30 +08:00
2025-07-17 15:17:49 +08:00
//列表方法
const getList = async (pageNo = 1, pageSize = 10) => {
setLoading(true);
try {
const { code, data } = await getCoscoSupplierUserPage({ pageNo, pageSize, supplierId: record });
if (code === 200) {
setData(data.records);
setPagination({ current: pageNo, pageSize, total: data.total });
}
} finally {
setLoading(false);
}
};
2025-07-02 16:18:03 +08:00
2025-07-17 15:17:49 +08:00
//增改查
const [formVisible, setFormVisible] = useState(false);
const [editingRecord, setEditingRecord] = useState<getCoscoSupplierUser | null>(null);
const [isViewMode, setIsViewMode] = useState(false);
const handleFormSubmit = () => {
setFormVisible(false);
getList();
};
//新增
const handleAdd = () => {
setEditingRecord(null);
setIsViewMode(false);
setFormVisible(true);
};
// 修改
const handleEdit = (record: getCoscoSupplierUser) => {
setEditingRecord(record);
setIsViewMode(false);
setFormVisible(true);
};
// 查看
const handleView = (record: getCoscoSupplierUser) => {
setEditingRecord(record);
setIsViewMode(true);
setFormVisible(true);
};
//删除
const handleDel = (record: getCoscoSupplierUser) => {
coscoSupplierUserDel(record.id).then((res) => {
if (res.code == 200) {
message.success('删除成功');
getList();
2025-06-24 10:52:30 +08:00
}
2025-07-02 16:18:03 +08:00
})
2025-06-24 10:52:30 +08:00
};
2025-07-17 15:17:49 +08:00
//是否为主联系人
const handleObsoleteChange = async (checked: boolean, id: string) => {
2025-07-18 10:37:13 +08:00
if(!checked) return
2025-07-17 15:17:49 +08:00
// 调用你的作废接口
const res = await editType({ id, supplierId: record });
if (res.code === 200) {
message.success('操作成功');
getList(pagination.current, pagination.pageSize); // 刷新列表
} else {
message.error('操作失败');
}
}
//初始化
2025-06-24 10:52:30 +08:00
useEffect(() => {
2025-07-17 15:17:49 +08:00
if (record) {
getList();
}
}, [record]);
2025-06-24 10:52:30 +08:00
2025-07-17 15:17:49 +08:00
const columns: ColumnsType<getCoscoSupplierUser> = [
2025-06-24 10:52:30 +08:00
{
2025-07-17 15:17:49 +08:00
title: intl.formatMessage({ id: 'page.workbench.attachments.index' }),
render: (_: any, __: any, index: number) => index + 1,
width: 60,
2025-06-24 10:52:30 +08:00
},
{
2025-07-02 16:18:03 +08:00
title: '联系人',
dataIndex: 'contactsName',
key: 'contactsName',
2025-06-24 10:52:30 +08:00
},
{
2025-07-02 16:18:03 +08:00
title: '手机号',
dataIndex: 'contactsPhone',
key: 'contactsPhone',
2025-06-24 10:52:30 +08:00
},
{
2025-07-02 16:18:03 +08:00
title: '邮箱',
dataIndex: 'contactsEmail',
key: 'contactsEmail',
2025-06-24 10:52:30 +08:00
},
2025-07-18 10:37:13 +08:00
{
title: '负责品类',
dataIndex: 'coscoSupplierUserCategoryList',
key: 'coscoSupplierUserCategoryList',
ellipsis: true,
width: 160,
render: (value: { categoryName: 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('、');
return (
<Tooltip title={allNames} overlayStyle={{ zIndex: 1200 }}>
<span>
{value[0].categoryName}
<span></span>
</span>
</Tooltip>
);
},
},
2025-06-24 10:52:30 +08:00
2025-07-17 15:17:49 +08:00
{
title: '是否为主联系人',
dataIndex: 'type',
align: 'center',
width: 180,
render: (value, record: getCoscoSupplierUser) => {
let checkedType = value === '1' ? true : false;
return (
<Switch
checked={checkedType}
disabled={viewType}
onChange={(checked) => handleObsoleteChange(checked, record.id)}
/>
)
},
},
...(viewType ? [] : [
{
title: 'page.workbench.attachments.action',
dataIndex: 'option',
width: 140,
render: (_: any, record: getCoscoSupplierUser) => {
return (
<>
<a style={{ marginRight: 8 }} onClick={() => handleView(record)}></a>
<a style={{ marginRight: 8 }} onClick={() => handleEdit(record)}></a>
{record.type === '0' && (
<Popconfirm
title="确定要删除该联系人吗?"
onConfirm={() => handleDel(record)}
>
<a ></a>
</Popconfirm>
)}
</>
)
}
}
])
];
2025-06-24 10:52:30 +08:00
return (
<div style={{ padding: '0 30px 0 0' }}>
2025-07-17 15:17:49 +08:00
<div style={{ marginBottom: 16 }}>
{!viewType && (
<Button type="primary" onClick={handleAdd}></Button>
)}
</div>
2025-06-24 10:52:30 +08:00
<Table
className="custom-table"
rowKey="id"
2025-07-17 15:17:49 +08:00
columns={columns.map(column => ({
...column,
2025-07-18 10:37:13 +08:00
title: column.title
2025-07-17 15:17:49 +08:00
}))}
dataSource={data}
2025-06-24 10:52:30 +08:00
pagination={pagination}
2025-07-17 15:17:49 +08:00
loading={loading}
onChange={(pagination) => getList(pagination.current!, pagination.pageSize!)}
/>
<ContactsInfoFormModal
visible={formVisible}
onOk={handleFormSubmit}
onCancel={() => setFormVisible(false)}
initialValues={editingRecord || undefined}
readOnly={isViewMode}
2025-06-24 10:52:30 +08:00
/>
</div>
);
};
2025-07-17 15:17:49 +08:00
export default OtherAttachmentsTab;