From d7df286214c658e3b444697f9613874194280ce7 Mon Sep 17 00:00:00 2001 From: linxd <544554903@qq.com> Date: Tue, 24 Jun 2025 18:58:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98=E8=AF=84=E4=BB=B7=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EvaluateTaskPersonnelSelector.less | 42 ++ .../EvaluateTaskPersonnelSelector.tsx | 411 +++------- .../SupplierSelector/SupplierSelector.less | 40 +- .../SupplierSelector/SupplierSelector.tsx | 155 ++-- .../components/BasicInfoStep.tsx | 53 +- .../components/DivisionStep.tsx | 370 +++++++++ .../BatchEvaluatorModal.tsx | 36 + .../SupplierEvaluatorModal.tsx | 107 +++ .../EvaluatorComponents/SupplierTable.tsx | 110 +++ .../WeightSettingModal.tsx | 50 ++ .../components/EvaluatorComponents/index.ts | 15 + .../components/EvaluatorSelectStep.tsx | 702 ++++++++---------- .../components/SupplierSelectStep.tsx | 25 +- .../supplierTaskManageAdd.less | 4 +- .../supplierTaskManageAdd.tsx | 102 ++- .../supplierTemplateManage.tsx | 44 +- .../supplierTemplateManageAdd.tsx | 2 +- .../supplierTemplateManageDetail.tsx | 3 +- src/servers/api/typings.d.ts | 43 +- src/servers/api/user.ts | 13 + src/servers/types/evaluator.ts | 78 ++ src/servers/types/index.ts | 5 + 22 files changed, 1502 insertions(+), 908 deletions(-) create mode 100644 src/pages/supplierEvaluateManage/supplierTaskManage/components/DivisionStep.tsx create mode 100644 src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/BatchEvaluatorModal.tsx create mode 100644 src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/SupplierEvaluatorModal.tsx create mode 100644 src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/SupplierTable.tsx create mode 100644 src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/WeightSettingModal.tsx create mode 100644 src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/index.ts create mode 100644 src/servers/api/user.ts create mode 100644 src/servers/types/evaluator.ts create mode 100644 src/servers/types/index.ts diff --git a/src/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector.less b/src/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector.less index c91455c..e44c776 100644 --- a/src/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector.less +++ b/src/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector.less @@ -102,3 +102,45 @@ border-top: 1px solid #f0f0f0; } } + +.evaluate-task-personnel-selector-simple { + display: flex; + flex-direction: column; + height: 100%; + + .selector-header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 16px; + + .search-input { + width: 320px; + } + + .selected-count { + font-size: 14px; + + .count-number { + font-weight: bold; + color: #1890ff; + } + } + } + + .personnel-table { + margin-bottom: 16px; + + .ant-table-tbody > tr.ant-table-row-selected > td { + background-color: #e6f7ff; + } + } + + .selector-footer { + display: flex; + justify-content: center; + margin-top: 16px; + padding-top: 16px; + border-top: 1px solid #f0f0f0; + } +} diff --git a/src/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector.tsx b/src/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector.tsx index f033fac..d866f41 100644 --- a/src/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector.tsx +++ b/src/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector.tsx @@ -1,53 +1,25 @@ import React, { useState, useEffect, useCallback, useMemo } from 'react'; -import { Input, Button, Badge, Avatar, Space, Tabs, Checkbox, Row, Col, Card, Empty, Divider, Alert } from 'antd'; -import { SearchOutlined, UserOutlined, TeamOutlined, CheckCircleOutlined } from '@ant-design/icons'; +import { Table, Input, Button, Space, message } from 'antd'; +import { SearchOutlined } from '@ant-design/icons'; +import { getUserList } from '@/servers/api/user'; import './EvaluateTaskPersonnelSelector.less'; -const { TabPane } = Tabs; const { Search } = Input; /** * 评价任务人员选择组件属性接口 * @interface EvaluateTaskPersonnelSelectorProps * @property {Function} onSelect - 选择确认后的回调函数,返回所选人员数组 - * @property {PersonnelItem[]} selectedPersonnel - 已选择的人员列表 + * @property {API.PersonnelItem[]} selectedPersonnel - 已选择的人员列表 */ interface EvaluateTaskPersonnelSelectorProps { - onSelect: (personnel: PersonnelItem[]) => void; - selectedPersonnel?: PersonnelItem[]; -} - -/** - * 人员信息接口 - * @interface PersonnelItem - * @property {string} id - 人员唯一标识 - * @property {string} name - 人员姓名 - * @property {string} department - 所属部门 - * @property {string} position - 职位信息 - * @property {boolean} selected - 是否被选中 - */ -export interface PersonnelItem { - id: string; - name: string; - department: string; - position?: string; - selected?: boolean; -} - -/** - * 部门信息接口 - * @interface Department - * @property {string} id - 部门ID - * @property {string} name - 部门名称 - */ -interface Department { - id: string; - name: string; + onSelect: (personnel: API.PersonnelItem[]) => void; // 选择确认后的回调函数 + selectedPersonnel?: API.PersonnelItem[]; // 已选择的人员列表(用于回显) } /** * 评价任务人员选择组件 - * 用于在评价任务管理中选择评价人员,按部门分类展示 + * 用于在评价任务管理中选择评价人员,显示为简单表格 * * @component * @example @@ -64,302 +36,147 @@ const EvaluateTaskPersonnelSelector: React.FC { // 搜索关键词 const [keyword, setKeyword] = useState(''); + // 所有可选人员列表 - const [personnel, setPersonnel] = useState([]); + const [personnel, setPersonnel] = useState([]); + // 已选择人员ID列表 const [selectedKeys, setSelectedKeys] = useState([]); - // 当前选中的部门Tab - const [activeTab, setActiveTab] = useState('1'); + + // 加载状态 + const [loading, setLoading] = useState(false); + + // 初始化时根据传入的selectedPersonnel设置选中状态 + useEffect(() => { + // 直接使用传入的selectedPersonnel更新选中状态 + // 如果为空数组,则清空选择 + const newSelectedIds = selectedPersonnel?.map(item => item.id) || []; + setSelectedKeys(newSelectedIds); + }, [selectedPersonnel]); // 依赖selectedPersonnel而不是selectedPersonnelIds /** - * 部门数据列表 - * 实际项目中可通过API获取 + * 从API获取用户列表数据 */ - const departments: Department[] = useMemo(() => [ - { id: '1', name: '采购部' }, - { id: '2', name: '技术部' }, - { id: '3', name: '质量部' }, - { id: '4', name: '生产部' }, - { id: '5', name: '财务部' }, - ], []); + const fetchPersonnelData = useCallback(async () => { + setLoading(true); + try { + const params: API.UserListRequest = { + basePageRequest: { + pageNo: 1, + pageSize: 100, // 获取足够多的数据 + }, + keyword: keyword || undefined, + }; + + const response = await getUserList(params); + + if (response && response.code === 200 && response.data) { + const users = response.data as API.UserItem[]; + + // 转换API返回的用户数据为组件所需格式 + const personnelData: API.PersonnelItem[] = users.map((user) => ({ + id: user.userId, // 用户ID + name: user.userName, // 用户名称 + department: user.userDept, // 用户部门 + position: '', // API中没有提供职位信息 + })); + + setPersonnel(personnelData); + } else { + message.error(response?.message || '获取用户列表失败'); + } + } catch (error) { + console.error('获取人员数据失败:', error); + message.error('获取人员数据失败,请稍后重试'); + } finally { + setLoading(false); + } + }, [keyword]); // 移除selectedPersonnelIds依赖 /** - * 模拟获取人员数据 - * 实际项目中替换为API调用 - */ - const fetchPersonnelData = useCallback(() => { - // 模拟API调用获取评价人员 - const mockPersonnel: PersonnelItem[] = [ - { id: '1', name: '张三', department: '采购部', position: '采购经理' }, - { id: '2', name: '李四', department: '技术部', position: '技术专家' }, - { id: '3', name: '王五', department: '质量部', position: '质量工程师' }, - { id: '4', name: '赵六', department: '采购部', position: '高级采购' }, - { id: '5', name: '钱七', department: '技术部', position: '部门经理' }, - { id: '6', name: '孙八', department: '质量部', position: '质量总监' }, - { id: '7', name: '周九', department: '生产部', position: '生产主管' }, - { id: '8', name: '吴十', department: '财务部', position: '财务经理' }, - { id: '9', name: '郑十一', department: '采购部', position: '采购专员' }, - { id: '10', name: '王十二', department: '技术部', position: '工程师' }, - { id: '11', name: '刘十三', department: '财务部', position: '财务专员' }, - { id: '12', name: '陈十四', department: '生产部', position: '技术员' }, - ]; - - setPersonnel(mockPersonnel); - }, []); - - /** - * 初始化人员数据和已选状态 + * 初始化人员数据 */ useEffect(() => { - // 加载人员数据(模拟API请求) + // 加载人员数据(API请求) fetchPersonnelData(); - - // 设置已选人员 - if (selectedPersonnel && selectedPersonnel.length > 0) { - const selectedIds = selectedPersonnel.map(item => item.id); - setSelectedKeys(selectedIds); - } - }, [fetchPersonnelData, selectedPersonnel]); + }, [fetchPersonnelData]); /** * 处理搜索 * @param {string} value - 搜索关键词 */ - const handleSearch = useCallback((value: string) => { + const handleSearch = (value: string) => { setKeyword(value); - }, []); + }; /** - * 处理Tab切换 - * @param {string} key - 选中的Tab键值 + * 处理行选择变化 + * @param {string[]} selectedRowKeys - 选中的行keys + * @param {API.PersonnelItem[]} selectedRows - 选中的行数据 */ - const handleTabChange = useCallback((key: string) => { - setActiveTab(key); - }, []); + const handleSelectChange = (selectedRowKeys: React.Key[], selectedRows: API.PersonnelItem[]) => { + setSelectedKeys(selectedRowKeys as string[]); + }; /** - * 处理单个人员选择 - * @param {string} personnelId - 人员ID - * @param {boolean} checked - 是否选中 + * 处理确认选择 */ - const handleSelect = useCallback((personnelId: string, checked: boolean) => { - setSelectedKeys(prevKeys => { - if (checked) { - return [...prevKeys, personnelId]; - } else { - return prevKeys.filter(id => id !== personnelId); - } - }); - }, []); + const handleConfirm = () => { + // 根据选中的ID筛选出完整的人员数据 + const selectedData = personnel.filter(item => selectedKeys.includes(item.id)); - /** - * 处理部门人员全选 - * @param {string} deptId - 部门ID - * @param {boolean} checked - 是否全选 - */ - const handleSelectAll = useCallback((deptId: string, checked: boolean) => { - const deptName = departments.find(d => d.id === deptId)?.name || ''; - const deptPersonnel = personnel.filter(p => - p.department === deptName && - (keyword ? p.name.includes(keyword) : true) - ); - const deptPersonnelIds = deptPersonnel.map(p => p.id); + // 回调传递给父组件 + onSelect(selectedData); + }; - setSelectedKeys(prevKeys => { - if (checked) { - // 添加该部门所有人员 - const newKeys = new Set([...prevKeys, ...deptPersonnelIds]); - return Array.from(newKeys); - } else { - // 移除该部门所有人员 - return prevKeys.filter(id => !deptPersonnelIds.includes(id)); - } - }); - }, [departments, keyword, personnel]); + // 表格列定义 + const columns = [ + { + title: '姓名', // 列标题 + dataIndex: 'name', // 数据字段名 + key: 'name', // 列唯一标识 + }, + { + title: '部门', + dataIndex: 'department', + key: 'department', + }, + ]; - /** - * 确认选择 - * 将选中的人员ID列表转换为人员对象列表 - */ - const handleConfirm = useCallback(() => { - const selectedItems = personnel.filter(item => selectedKeys.includes(item.id)); - onSelect(selectedItems); - }, [onSelect, personnel, selectedKeys]); - - /** - * 计算各部门已选人数 - * @param {string} deptId - 部门ID - * @returns {number} - 已选人数 - */ - const getSelectedCountByDept = useCallback((deptId: string) => { - const deptName = departments.find(d => d.id === deptId)?.name || ''; - const deptPersonnel = personnel.filter(p => p.department === deptName); - const selectedCount = deptPersonnel.filter(p => selectedKeys.includes(p.id)).length; - return selectedCount; - }, [departments, personnel, selectedKeys]); - - /** - * 渲染Tab标签 - * @param {Department} dept - 部门信息 - * @returns {React.ReactNode} - 渲染结果 - */ - const renderTabTitle = useCallback((dept: Department) => { - const selectedCount = getSelectedCountByDept(dept.id); - return ( - 0 ? selectedCount : 0} - size="small" - offset={[5, -3]} - style={{ backgroundColor: selectedCount > 0 ? '#1890ff' : '#d9d9d9' }} - > - {dept.name} - - ); - }, [getSelectedCountByDept]); - - /** - * 渲染部门下的人员列表 - * @param {string} deptId - 部门ID - * @returns {React.ReactNode} - 渲染结果 - */ - const renderDepartmentPersonnel = useCallback((deptId: string) => { - // 获取部门名称 - const deptName = departments.find(d => d.id === deptId)?.name || ''; - - // 过滤出当前部门且符合搜索条件的人员 - const deptPersonnel = personnel.filter(p => - p.department === deptName && - (keyword ? p.name.includes(keyword) : true) - ); - - // 检查该部门是否全部选中 - const deptPersonnelIds = deptPersonnel.map(p => p.id); - const isAllSelected = deptPersonnelIds.length > 0 && deptPersonnelIds.every(id => selectedKeys.includes(id)); - - // 如果没有符合条件的人员,显示空状态 - if (deptPersonnel.length === 0) { - return ; - } - - return ( -
- -
- - - {deptName} - - handleSelectAll(deptId, e.target.checked)} - > - 全选 - - - (共{deptPersonnel.length}人) - - -
- - - - - {deptPersonnel.map(person => ( - - - handleSelect(person.id, e.target.checked)} - > - - } - size="small" - className={selectedKeys.includes(person.id) ? 'selected-avatar' : ''} - /> -
-
- {person.name} - {selectedKeys.includes(person.id) && ( - - )} -
-
{person.position}
-
-
-
-
- - ))} -
-
-
- ); - }, [departments, handleSelect, handleSelectAll, keyword, personnel, selectedKeys]); - - // 使用useMemo优化部门Tab的渲染 - const departmentTabs = useMemo(() => { - return departments.map(dept => ( - - {renderDepartmentPersonnel(dept.id)} - - )); - }, [departments, renderDepartmentPersonnel, renderTabTitle]); return (
- {/* 顶部搜索和统计区域 */}
- 搜索} - onSearch={handleSearch} - onChange={(e) => setKeyword(e.target.value)} - className="search-input" - /> +
+ }>搜索} + /> +
- - 已选人员 - + 已选择: {selectedKeys.length}
- - {/* 显示已选人员数量的提示 */} - {selectedKeys.length > 0 && ( - - )} - - {/* 部门分类标签页 */} - - {departmentTabs} - - - {/* 底部确认按钮区域 */} +
- + + + +
); diff --git a/src/components/SupplierSelector/SupplierSelector.less b/src/components/SupplierSelector/SupplierSelector.less index e914f5a..2f08945 100644 --- a/src/components/SupplierSelector/SupplierSelector.less +++ b/src/components/SupplierSelector/SupplierSelector.less @@ -1,13 +1,26 @@ .supplier-selector { .supplier-lists { - margin-top: 12px; - } + margin-top: 16px; + min-height: 450px; - .list-title { - font-weight: 500; - margin-bottom: 8px; - padding-left: 8px; - border-left: 3px solid #1890ff; + .list-title { + font-weight: 500; + margin-bottom: 20px; + padding-left: 8px; + border-left: 3px solid #1890ff; + display: flex; + justify-content: space-between; + + .search-count { + margin-left: 8px; + font-weight: normal; + color: rgba(0, 0, 0, 0.45); + } + } + + .ant-table-wrapper { + height: 100%; + } } .transfer-buttons { @@ -15,17 +28,6 @@ flex-direction: column; justify-content: center; align-items: center; - height: 100%; - padding-top: 100px; - - .ant-btn { - margin: 8px 0; - } - } - - .search-count { - float: right; - color: rgba(0, 0, 0, 0.45); - font-size: 12px; + gap: 16px; } } diff --git a/src/components/SupplierSelector/SupplierSelector.tsx b/src/components/SupplierSelector/SupplierSelector.tsx index 246b0dd..3568c2f 100644 --- a/src/components/SupplierSelector/SupplierSelector.tsx +++ b/src/components/SupplierSelector/SupplierSelector.tsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'; import { Input, Select, Row, Col, Table, Button, Form, Tooltip, message } from 'antd'; import { RightOutlined, LeftOutlined } from '@ant-design/icons'; import { getSupplierPage } from '@/servers/api/supplier'; +import CategorySelector from '@/components/CategorySelector/CategorySelector'; import './SupplierSelector.less'; const { Option } = Select; @@ -11,16 +12,10 @@ const { Option } = Select; * @interface SupplierSelectorProps * @property {Function} [onSelect] - 当选择供应商发生变化时的回调函数 * @property {any[]} [selectedSuppliers] - 初始已选择的供应商列表 - * @property {string[]} [deptList] - 部门列表,用于筛选供应商 - * @property {boolean} [showDeptFilter] - 是否显示部门筛选,默认显示 - * @property {boolean} [showCompanyFilter] - 是否显示公司名称筛选,默认不显示 */ interface SupplierSelectorProps { onSelect?: (selected: any[]) => void; selectedSuppliers?: any[]; - deptList?: string[]; - showDeptFilter?: boolean; - showCompanyFilter?: boolean; } /** @@ -60,9 +55,6 @@ interface SupplierItem { const SupplierSelector: React.FC = ({ onSelect, selectedSuppliers: initialSelectedSuppliers = [], - deptList = [], - showDeptFilter = true, - showCompanyFilter = false }) => { // 表单实例,用于管理查询条件 const [form] = Form.useForm(); @@ -85,6 +77,12 @@ const SupplierSelector: React.FC = ({ // 最终已选择的供应商列表 const [chosenSuppliers, setChosenSuppliers] = useState(initialSelectedSuppliers); + // 查询参数 + const [queryParams, setQueryParams] = useState({ + pageNo: 1, + pageSize: 10 + }); + /** * 监听初始已选供应商变化,更新内部状态 */ @@ -139,79 +137,69 @@ const SupplierSelector: React.FC = ({ /** * 获取供应商列表数据 - * @param {any} values - 查询条件 - * @param {number} pageNo - 页码 - * @param {number} pageSize - 每页数量 */ - const getTableList = async (values: any = {}, pageNo: number = 1, pageSize: number = 10) => { + const fetchTableData = async () => { + if (loading) return; + setLoading(true); try { - // 整理查询参数 - const params = { - ...values, - pageNo, - pageSize, - deptList: deptList.length > 0 ? deptList : undefined - }; - // 调用API获取供应商列表 - const response = await getSupplierPage(params); + const response = await getSupplierPage(queryParams); if (response && response.code === 200) { // 请求成功,更新数据和分页信息 setTableListData(response.data.records || []); setPagination({ - current: pageNo, - pageSize, + current: queryParams.pageNo, + pageSize: queryParams.pageSize, total: response.data.total || 0 }); } else { // 请求失败,显示错误信息 message.error(response?.message || '获取供应商列表失败'); - - // 使用mock数据作为备用 - setTableListData([ - { id: '1', name: '供应商A', deptName: '采购部', companyName: '公司A', categoryName: '润滑油' }, - { id: '2', name: '供应商B', deptName: '技术部', companyName: '公司B', categoryName: '燃油' }, - { id: '3', name: '供应商C', deptName: '质量部', companyName: '公司C', categoryName: '备件' }, - { id: '4', name: '供应商D', deptName: '采购部', companyName: '公司D', categoryName: '计算机' }, - { id: '5', name: '供应商E', deptName: '技术部', companyName: '公司E', categoryName: '通信设备' }, - ]); - setPagination({ current: 1, pageSize: 10, total: 5 }); + setTableListData([]); + setPagination({ current: 1, pageSize: 10, total: 0 }); } } catch (error) { // 处理异常情况 console.error('获取供应商列表出错:', error); message.error('获取供应商列表失败,请稍后重试'); - - // 使用mock数据作为备用 - setTableListData([ - { id: '1', name: '供应商A', deptName: '采购部', companyName: '公司A', categoryName: '润滑油' }, - { id: '2', name: '供应商B', deptName: '技术部', companyName: '公司B', categoryName: '燃油' }, - { id: '3', name: '供应商C', deptName: '质量部', companyName: '公司C', categoryName: '备件' }, - { id: '4', name: '供应商D', deptName: '采购部', companyName: '公司D', categoryName: '计算机' }, - { id: '5', name: '供应商E', deptName: '技术部', companyName: '公司E', categoryName: '通信设备' }, - ]); - setPagination({ current: 1, pageSize: 10, total: 5 }); + setTableListData([]); + setPagination({ current: 1, pageSize: 10, total: 0 }); } finally { setLoading(false); } }; /** - * 组件初始化时加载数据 + * 当查询参数变化时,加载数据 + */ + useEffect(() => { + fetchTableData(); + }, [queryParams]); + + /** + * 组件初始挂载时,加载一次数据 */ useEffect(() => { const values = form.getFieldsValue(); - getTableList(values, 1, 10); - }, [deptList]); + setQueryParams(prev => ({ + ...prev, + ...values, + pageNo: 1 + })); + }, []); // 空依赖数组,只在组件挂载时执行一次 /** * 处理查询表单提交 * @param {any} values - 表单值 */ const handleSearch = (values: any) => { - getTableList(values, 1, pagination.pageSize); + setQueryParams(prev => ({ + ...prev, + ...values, + pageNo: 1 + })); }; /** @@ -220,7 +208,11 @@ const SupplierSelector: React.FC = ({ const handleReset = () => { form.resetFields(); const values = form.getFieldsValue(); - getTableList(values, 1, pagination.pageSize); + setQueryParams(prev => ({ + ...prev, + ...values, + pageNo: 1 + })); }; /** @@ -228,8 +220,11 @@ const SupplierSelector: React.FC = ({ * @param {any} paginationInfo - 分页信息 */ const handleTableChange = (paginationInfo: any) => { - const values = form.getFieldsValue(); - getTableList(values, paginationInfo.current, paginationInfo.pageSize); + setQueryParams(prev => ({ + ...prev, + pageNo: paginationInfo.current, + pageSize: paginationInfo.pageSize + })); }; // 表格列定义 @@ -253,12 +248,8 @@ const SupplierSelector: React.FC = ({ {categoryName || '-'} ), - } - ]; - - // 如果显示部门筛选,添加部门列 - if (showDeptFilter) { - columns.push({ + }, + { title: '部门', dataIndex: 'deptName', ellipsis: true, @@ -267,49 +258,27 @@ const SupplierSelector: React.FC = ({ {deptName || '-'} ) - }); - } - - // 如果显示公司名称筛选,添加公司名称列 - if (showCompanyFilter) { - columns.push({ - title: '公司名称', - dataIndex: 'companyName', - ellipsis: true, - render: (companyName: string) => ( - - {companyName || '-'} - - ), - }); - } + } + ]; return (
{/* 查询表单 */} -
+ - {showDeptFilter && ( - - - - )} + + + - {showCompanyFilter && ( - - - - )} - - - + + @@ -340,8 +309,6 @@ const SupplierSelector: React.FC = ({ loading={loading} pagination={pagination} onChange={handleTableChange} - scroll={{ y: 300 }} - size="middle" /> @@ -376,8 +343,6 @@ const SupplierSelector: React.FC = ({ dataSource={chosenSuppliers} rowKey="id" pagination={false} - scroll={{ y: 300 }} - size="middle" /> diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/components/BasicInfoStep.tsx b/src/pages/supplierEvaluateManage/supplierTaskManage/components/BasicInfoStep.tsx index 44642b3..8175b94 100644 --- a/src/pages/supplierEvaluateManage/supplierTaskManage/components/BasicInfoStep.tsx +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/components/BasicInfoStep.tsx @@ -38,19 +38,9 @@ const BasicInfoStep = forwardRef(({ formData, onFormDat const response = await getAllTemplates(); if (response.success && response.data) { setTemplates(response.data); - } else { - setTemplates([ - { id: '1', templateName: '不限品类模板', categoryLimitation: '0' }, - { id: '2', templateName: '限制品类模板', categoryLimitation: '1' }, - ]); } } catch (error) { console.error('获取模板列表失败:', error); - // 使用模拟数据 - setTemplates([ - { id: '1', templateName: '不限品类模板', categoryLimitation: '0' }, - { id: '2', templateName: '限制品类模板', categoryLimitation: '1' }, - ]); } finally { setLoading(false); } @@ -66,33 +56,22 @@ const BasicInfoStep = forwardRef(({ formData, onFormDat } }, []); + // 当formData变化时更新表单值 + useEffect(() => { + if (formData) { + // 处理日期字段,确保正确设置 + const formValues = { + ...formData, + startTime: formData.startTime ? moment(formData.startTime) : undefined, + endTime: formData.endTime ? moment(formData.endTime) : undefined, + }; + form.setFieldsValue(formValues); + } + }, [formData, form]); + // 表单值变化时触发 const handleValuesChange = (changedValues: any, allValues: any) => { - // 处理模板变更 - if (changedValues.templateId) { - const template = templates.find((t) => t.id === changedValues.templateId); - if (template) { - // 更新品类限制类型 - form.setFieldsValue({ - categoryLimitation: template.categoryLimitation || '0', - }); - - // 如果选择了不限品类的模板,清空品类选择 - if (template.categoryLimitation === '0') { - form.setFieldsValue({ - categoryId: undefined, - }); - } - } - } - - // 默认设置weightStatus为0 - const formattedValues = { - ...allValues, - weightStatus: 0, - }; - - onFormDataChange(formattedValues); + onFormDataChange(allValues); }; // 年度选项生成 @@ -107,9 +86,9 @@ const BasicInfoStep = forwardRef(({ formData, onFormDat // 判断是否显示品类选择器 const shouldShowCategorySelector = useCallback(() => { - const categoryLimitation = form.getFieldValue('categoryLimitation'); + const categoryLimitation = formData.categoryLimitation; return categoryLimitation === CategoryLimitationType.LIMITED; - }, [form]); + }, [formData]); return ( diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/components/DivisionStep.tsx b/src/pages/supplierEvaluateManage/supplierTaskManage/components/DivisionStep.tsx new file mode 100644 index 0000000..437a143 --- /dev/null +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/components/DivisionStep.tsx @@ -0,0 +1,370 @@ +import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react'; +import { Card, Table, Tag, Switch, Space, Button, message, Modal, Radio, Checkbox, Row, Col } from 'antd'; +import type { PersonnelItem } from '@/servers/types/evaluator'; +import type { ColumnsType } from 'antd/es/table'; +import type { CheckboxValueType } from 'antd/es/checkbox/Group'; +import styles from '../supplierTaskManageAdd.less'; + +// 评价指标类型定义 +interface IndicatorItem { + id: string; + name: string; + description: string; +} + +// 组件接收的Props定义 +interface DivisionStepProps { + formData: any; + onFormDataChange?: (values: any) => void; +} + +// 评价方式枚举 +enum EvaluateType { + ALL = 'ALL', // 按评价单评价(全部指标) + INDICATOR = 'INDICATOR', // 按指标评价(部分指标) +} + +// 模拟的评价指标数据 +const mockIndicators: IndicatorItem[] = [ + { id: 'I001', name: '产品质量', description: '评估供应商产品质量' }, + { id: 'I002', name: '交货及时性', description: '评估供应商交货的及时性' }, + { id: 'I003', name: '服务水平', description: '评估供应商提供的服务水平' }, + { id: 'I004', name: '价格竞争力', description: '评估供应商产品价格的竞争力' }, + { id: 'I005', name: '技术能力', description: '评估供应商的技术创新能力' }, +]; + +const DivisionStep = forwardRef(({ formData, onFormDataChange }, ref) => { + // 从上一步获取的评价人员列表 + const [evaluators, setEvaluators] = useState([]); + + // 评价人员指标分配数据 + const [indicatorAssignments, setIndicatorAssignments] = useState<{ + [userId: string]: { + type: EvaluateType; + indicatorIds: string[]; + }; + }>({}); + + // 选中的行keys + const [selectedRowKeys, setSelectedRowKeys] = useState([]); + + // 指标列表 + const [indicators] = useState(mockIndicators); + + // 指标分工弹窗可见性 + const [divisionModalVisible, setDivisionModalVisible] = useState(false); + + // 评价方式类型 + const [batchEvaluateType, setBatchEvaluateType] = useState(EvaluateType.ALL); + + // 批量选择的指标 + const [batchSelectedIndicators, setBatchSelectedIndicators] = useState([]); + + // 处理行选择变化 + const handleSelectChange = (newSelectedRowKeys: React.Key[]) => { + setSelectedRowKeys(newSelectedRowKeys); + }; + + // 打开指标分工弹窗 + const handleOpenDivisionModal = () => { + if (selectedRowKeys.length === 0) { + message.warning('请先选择评价人员'); + return; + } + setDivisionModalVisible(true); + }; + + // 处理评价方式变更 + const handleEvaluateTypeChange = (e: any) => { + setBatchEvaluateType(e.target.value); + }; + + // 处理指标选择变更 + const handleIndicatorChange = (checkedValues: CheckboxValueType[]) => { + setBatchSelectedIndicators(checkedValues.map(v => v.toString())); + }; + + // 批量设置指标分工 + const handleBatchSetDivision = () => { + // 获取选中的评价人员 + const selectedEvaluators = evaluators.filter( + evaluator => selectedRowKeys.includes(evaluator.id) + ); + + // 更新指标分配数据 + const newAssignments = { ...indicatorAssignments }; + + selectedEvaluators.forEach(evaluator => { + newAssignments[evaluator.id] = { + type: batchEvaluateType, + indicatorIds: batchEvaluateType === EvaluateType.INDICATOR ? batchSelectedIndicators : [], + }; + }); + + setIndicatorAssignments(newAssignments); + setDivisionModalVisible(false); + message.success(`已为${selectedRowKeys.length}名评价人员设置分工`); + }; + + // 处理单个评价人员的指标分工 + const handleAssignIndicators = (userId: string) => { + Modal.info({ + title: '评价指标分工', + content: '此功能将在后续完善', + okText: '确定', + }); + }; + + // 查看评价人员的指标分工 + const handleViewAssignment = (userId: string) => { + const assignment = indicatorAssignments[userId]; + if (!assignment) { + message.info('该评价人员尚未设置分工'); + return; + } + + const assignedIndicators = indicators.filter(ind => + assignment.type === EvaluateType.ALL || + assignment.indicatorIds.includes(ind.id) + ); + + Modal.info({ + title: '查看评价指标分工', + content: ( +
+

评价方式: {assignment.type === EvaluateType.ALL ? '按评价单评价' : '按指标评价'}

+

评价指标:

+
    + {assignedIndicators.map(ind => ( +
  • {ind.name}
  • + ))} +
+
+ ), + okText: '确定', + }); + }; + + // 删除评价人员 + const handleRemoveEvaluator = (userId: string) => { + Modal.confirm({ + title: '确认删除', + content: '确定要删除该评价人员吗?', + okText: '确定', + cancelText: '取消', + onOk: () => { + // 更新评价人员列表 + setEvaluators(prev => prev.filter(e => e.id !== userId)); + + // 更新指标分配数据 + const newAssignments = { ...indicatorAssignments }; + delete newAssignments[userId]; + setIndicatorAssignments(newAssignments); + + message.success('已删除评价人员'); + }, + }); + }; + + // 初始化:从formData中提取指标分配数据 + useEffect(() => { + if (formData.indicatorList) { + // 如果已有指标分配数据,直接使用 + const assignments: any = {}; + formData.indicatorList.forEach((item: any) => { + assignments[item.userId] = { + type: item.type, + indicatorIds: item.indicatorIds || [], + }; + }); + setIndicatorAssignments(assignments); + } + }, [formData.indicatorList]); + + // 从上一步获取评价人员列表 - 避免频繁更新 + useEffect(() => { + if (!formData.suppliersWithEvaluators) return; + + // 从所有供应商中提取评价人员列表 + const allEvaluators: PersonnelItem[] = []; + + formData.suppliersWithEvaluators.forEach((supplier: any) => { + if (supplier.evaluators && supplier.evaluators.length > 0) { + supplier.evaluators.forEach((evaluator: PersonnelItem) => { + // 检查是否已存在(避免重复) + if (!allEvaluators.some(e => e.id === evaluator.id)) { + allEvaluators.push({ + ...evaluator, + // 添加单位和员工编号,假设这些字段可能不存在 + company: evaluator.company || supplier.supplierName || '未知单位', + employeeNumber: evaluator.employeeNumber || `EMP${evaluator.id.slice(-4)}`, + department: evaluator.department || '未知部门', + }); + } + }); + } + }); + + setEvaluators(allEvaluators); + }, [formData.suppliersWithEvaluators]); + + // 为评价人员初始化指标分配数据 - 作为单独的效果处理 + useEffect(() => { + // 检查是否有新的评价人员需要初始化 + const newAssignments = { ...indicatorAssignments }; + let hasNewAssignments = false; + + evaluators.forEach(evaluator => { + if (!indicatorAssignments[evaluator.id]) { + newAssignments[evaluator.id] = { + type: EvaluateType.ALL, + indicatorIds: [], + }; + hasNewAssignments = true; + } + }); + + if (hasNewAssignments) { + setIndicatorAssignments(newAssignments); + } + }, [evaluators, indicatorAssignments]); + + // 同步数据回表单 - 使用防抖确保不会频繁触发 + const previousValueRef = React.useRef(""); + + useEffect(() => { + // 将评价人员列表和指标分配数据同步回表单 + const indicatorList = evaluators.map(evaluator => ({ + userId: evaluator.id, + userName: evaluator.name, + type: indicatorAssignments[evaluator.id]?.type || EvaluateType.ALL, + indicatorIds: indicatorAssignments[evaluator.id]?.indicatorIds || [], + })); + + // 使用JSON字符串比较确保只有在真正变化时才更新 + const currentValue = JSON.stringify(indicatorList); + if (currentValue !== previousValueRef.current) { + previousValueRef.current = currentValue; + onFormDataChange?.({ + ...formData, + indicatorList, + }); + } + }, [evaluators, indicatorAssignments, formData, onFormDataChange]); + + // 暴露给父组件的方法 + useImperativeHandle(ref, () => ({ + validate: () => { + if (evaluators.length === 0) { + return { + valid: false, + message: '请先分配评价人员', + }; + } + return { valid: true }; + }, + })); + + // 表格列定义 + const columns: ColumnsType = [ + { + title: '姓名', + dataIndex: 'name', + key: 'name', + }, + { + title: '所属单位', + dataIndex: 'company', + key: 'company', + }, + { + title: '所属部门', + dataIndex: 'department', + key: 'department', + }, + { + title: '员工编号', + dataIndex: 'employeeNumber', + key: 'employeeNumber', + }, + { + title: '是否设置分工', + key: 'hasDivision', + render: (_: any, record: PersonnelItem) => { + const assignment = indicatorAssignments[record.id]; + if (!assignment) return 未设置; + return 已设置; + }, + }, + { + title: '操作', + key: 'action', + render: (_: any, record: PersonnelItem) => ( + + + + + + ), + }, + ]; + + return ( +
+
+ +
+ +
+ + {/* 批量设置指标分工弹窗 */} + setDivisionModalVisible(false)} + okText="确定" + cancelText="取消" + width={700} + > +
+

您已选择 {selectedRowKeys.length} 名评价人员进行指标分工设置

+ + 按评价单评价 + 按指标评价 + + +
+

指标列表:

+ + + {indicators.map(indicator => ( +
+ {indicator.name} + + ))} + + + + + + + ); +}); + +export default DivisionStep; diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/BatchEvaluatorModal.tsx b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/BatchEvaluatorModal.tsx new file mode 100644 index 0000000..a56e63a --- /dev/null +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/BatchEvaluatorModal.tsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { Modal } from 'antd'; +import EvaluateTaskPersonnelSelector from '@/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector'; +import type { PersonnelItem } from '@/servers/types/evaluator'; + +interface BatchEvaluatorModalProps { + visible: boolean; + onCancel: () => void; + onSelect: (selectedEvaluators: PersonnelItem[]) => void; + selectedPersonnel?: PersonnelItem[]; +} + +const BatchEvaluatorModal: React.FC = ({ + visible, + onCancel, + onSelect, + selectedPersonnel = [], +}) => { + return ( + + + + ); +}; + +export default BatchEvaluatorModal; diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/SupplierEvaluatorModal.tsx b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/SupplierEvaluatorModal.tsx new file mode 100644 index 0000000..045a73b --- /dev/null +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/SupplierEvaluatorModal.tsx @@ -0,0 +1,107 @@ +import React, { useEffect, useState } from 'react'; +import { Modal, Button, List, message } from 'antd'; +import EvaluateTaskPersonnelSelector from '@/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector'; +import { ModalMode } from '@/servers/types/evaluator'; +import type { PersonnelItem, SupplierItem } from '@/servers/types/evaluator'; + +interface SupplierEvaluatorModalProps { + visible: boolean; // 控制弹窗显示/隐藏 + onCancel: () => void; // 取消按钮回调函数 + onSelect: (personnel: PersonnelItem[]) => void; // 选择人员后的回调函数 + currentSupplier: SupplierItem | null; // 当前操作的供应商对象 + mode: ModalMode; // 弹窗模式:SELECT(选择) 或 VIEW(查看) +} + +const SupplierEvaluatorModal: React.FC = ({ + visible, + onCancel, + onSelect, + currentSupplier, + mode, +}) => { + // 本地保存当前选中的人员,确保在弹窗打开/关闭时能正确处理数据 + const [localSelectedPersonnel, setLocalSelectedPersonnel] = useState([]); + + // 当currentSupplier变化时,更新本地的选中人员 + useEffect(() => { + if (currentSupplier && currentSupplier.evaluators) { + setLocalSelectedPersonnel(currentSupplier.evaluators); + } else { + setLocalSelectedPersonnel([]); + } + }, [currentSupplier]); + + // 处理选择人员的回调 + const handleSelect = (personnel: PersonnelItem[]) => { + if (personnel.length === 0) { + message.warning('请至少选择一名评价人员'); + return; + } + setLocalSelectedPersonnel(personnel); + onSelect(personnel); + }; + + // 渲染评价人员列表(用于查看模式) + const renderEvaluatorList = () => { + + if (!currentSupplier) { + return
无供应商数据
; + } + + if (!currentSupplier.evaluators || currentSupplier.evaluators.length === 0) { + return ( +
+ 当前供应商暂无评价人员,请点击"编辑人员"按钮添加 +
+ ); + } + + return ( + ( + + + + )} + /> + ); + }; + + return ( + + 关闭 + , + ] + : null + } + width={700} + destroyOnClose={false} + > + {mode === ModalMode.SELECT ? ( + + ) : ( + renderEvaluatorList() + )} + + ); +}; + +export default SupplierEvaluatorModal; diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/SupplierTable.tsx b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/SupplierTable.tsx new file mode 100644 index 0000000..6951909 --- /dev/null +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/SupplierTable.tsx @@ -0,0 +1,110 @@ +import React, { useEffect } from 'react'; +import { Table, Space, Button, Tag, Modal,Tooltip } from 'antd'; +import type { SupplierItem } from '@/servers/types/evaluator'; + +interface SupplierTableProps { + suppliers: SupplierItem[]; // 供应商数据列表 + selectedRowKeys: React.Key[]; // 选中的行keys + onSelectChange: (selectedRowKeys: React.Key[]) => void; // 选择行变化的回调 + onViewEvaluators: (supplier: SupplierItem) => void; // 查看评价人员的回调 + onSelectEvaluators: (supplier: SupplierItem) => void; // 选择评价人员的回调 + onDeleteSupplier: (key: string) => void; // 删除供应商的回调 +} + +const SupplierTable: React.FC = ({ + suppliers, + selectedRowKeys, + onSelectChange, + onViewEvaluators, + onSelectEvaluators, + onDeleteSupplier, +}) => { + // 表格行选择配置 + const rowSelection = { + selectedRowKeys, + onChange: onSelectChange, + }; + + // 删除确认对话框 + const showDeleteConfirm = (record: SupplierItem) => { + Modal.confirm({ + title: '确定要删除此供应商吗?', + content: `供应商: ${record.supplierName}${ + record.evaluatorCount > 0 ? `,将同时删除 ${record.evaluatorCount} 名关联的评价人员` : '' + }`, + okText: '确定', + okType: 'danger', + cancelText: '取消', + onOk: () => onDeleteSupplier(record.id), + }); + }; + + // 表格列定义 + const columns = [ + { + title: '供应商名称', // 列标题 + dataIndex: 'supplierName', // 数据字段名 + key: 'supplierName', // 列的唯一标识 + }, + { + title: '统一社会信用代码', + dataIndex: 'socialCreditCode', + key: 'socialCreditCode', + }, + { + title: '品类', + dataIndex: 'categoryName', + key: 'categoryName', + render: (categoryName: string) => ( + + {categoryName || '-'} + + ), + }, + { + title: '准入部门', + dataIndex: 'department', + key: 'department', + }, + { + title: '评价人员数', + align: 'center' as const, // 列对齐方式 + dataIndex: 'evaluatorCount', // 评价人员数量字段 + key: 'evaluatorCount', + }, + { + title: '操作', + key: 'action', + render: (_: any, record: SupplierItem) => ( + + + + + + ), + }, + ]; + + return ( +
+ ); +}; + +export default SupplierTable; diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/WeightSettingModal.tsx b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/WeightSettingModal.tsx new file mode 100644 index 0000000..66b1028 --- /dev/null +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/WeightSettingModal.tsx @@ -0,0 +1,50 @@ +import React from 'react'; +import { Modal, Form, Row, Col, InputNumber } from 'antd'; +import type { WeightUnit } from '@/servers/types/evaluator'; + +interface WeightSettingModalProps { + visible: boolean; + onCancel: () => void; + onOk: () => void; + weightUnits: WeightUnit[]; + form: any; +} + +const WeightSettingModal: React.FC = ({ + visible, + onCancel, + onOk, + weightUnits, + form, +}) => { + return ( + + + + {weightUnits.map((unit) => ( + + + + + + ))} + + + + ); +}; + +export default WeightSettingModal; diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/index.ts b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/index.ts new file mode 100644 index 0000000..4283746 --- /dev/null +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorComponents/index.ts @@ -0,0 +1,15 @@ +import SupplierTable from './SupplierTable'; +import BatchEvaluatorModal from './BatchEvaluatorModal'; +import SupplierEvaluatorModal from './SupplierEvaluatorModal'; +import WeightSettingModal from './WeightSettingModal'; + +// 日志组件版本 +console.log('EvaluatorComponents version: 1.0.1'); + +export { + SupplierTable, + BatchEvaluatorModal, + SupplierEvaluatorModal, + WeightSettingModal, + // 导出的所有组件 +}; diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorSelectStep.tsx b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorSelectStep.tsx index 5c8c5d0..acb24b5 100644 --- a/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorSelectStep.tsx +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/components/EvaluatorSelectStep.tsx @@ -1,421 +1,359 @@ import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react'; -import { Card, Button, Table, Space, Modal, Tag, Tooltip, Input, Form, InputNumber } from 'antd'; -import { UserOutlined, SettingOutlined } from '@ant-design/icons'; +import { Card, Button, Space, Form } from 'antd'; import styles from '../supplierTaskManageAdd.less'; -import EvaluateTaskPersonnelSelector, { PersonnelItem } from '@/components/EvaluateTaskPersonnelSelector/EvaluateTaskPersonnelSelector'; +import { + SupplierTable, + BatchEvaluatorModal, + SupplierEvaluatorModal, + WeightSettingModal, +} from './EvaluatorComponents'; +import { ModalMode } from '@/servers/types/evaluator'; +import type { PersonnelItem, SupplierItem, WeightUnit } from '@/servers/types/evaluator'; interface EvaluatorSelectStepProps { - formData: any; - onFormDataChange: (data: any) => void; + formData: any; // 从上层组件传递过来的表单数据 + onFormDataChange: (data: any) => void; // 表单数据变更回调函数 } -interface SupplierItem { - key: string; - supplierName: string; - socialCreditCode: string; - category: string; - department: string; - evaluatorCount: number; - evaluators?: PersonnelItem[]; -} +const EvaluatorSelectStep = forwardRef( + ({ formData, onFormDataChange }, ref) => { + // 选中的供应商行的key列表,用于批量操作 + const [selectedRowKeys, setSelectedRowKeys] = useState([]); -interface WeightUnit { - id: string; - name: string; - weight: number; -} + // 供应商列表数据,包含评价人员信息 + const [suppliers, setSuppliers] = useState([]); -const EvaluatorSelectStep = forwardRef(({ formData, onFormDataChange }, ref) => { - const [selectedRowKeys, setSelectedRowKeys] = useState([]); - const [suppliers, setSuppliers] = useState([]); - const [batchSelectModalVisible, setBatchSelectModalVisible] = useState(false); - const [weightSettingModalVisible, setWeightSettingModalVisible] = useState(false); - const [evaluatorModalVisible, setEvaluatorModalVisible] = useState(false); - const [currentSupplier, setCurrentSupplier] = useState(null); - const [weightUnits, setWeightUnits] = useState([ - { id: '1', name: '集运', weight: 0 }, - { id: '2', name: '散运', weight: 0 }, - { id: '3', name: '能源', weight: 0 }, - { id: '4', name: '特运', weight: 0 }, - { id: '5', name: '化运', weight: 0 }, - ]); - const [form] = Form.useForm(); + // 批量选择模态框的可见性控制 + const [batchSelectModalVisible, setBatchSelectModalVisible] = useState(false); - // 暴露表单方法给父组件 - useImperativeHandle(ref, () => ({ - validateFields: () => { - // 自定义验证逻辑 - if (suppliers.length === 0) { - return Promise.reject('请至少添加一个供应商'); + // 权重设置模态框的可见性控制 + const [weightSettingModalVisible, setWeightSettingModalVisible] = useState(false); + + // 评价人员选择/查看模态框的可见性控制 + const [evaluatorModalVisible, setEvaluatorModalVisible] = useState(false); + + // 当前操作的供应商对象,用于评价人员的选择和查看 + const [currentSupplier, setCurrentSupplier] = useState(null); + + // 模态框模式:SELECT(选择模式) 或 VIEW(查看模式) + const [modalMode, setModalMode] = useState(ModalMode.SELECT); + + // 权重单位列表,根据评价人员部门动态生成 + const [weightUnits, setWeightUnits] = useState([]); + + // 表单实例,用于权重设置 + const [form] = Form.useForm(); + + // 暴露表单方法给父组件 + useImperativeHandle(ref, () => ({ + validateFields: () => { + // 自定义验证逻辑 + if (suppliers.length === 0) { + return Promise.reject('请至少添加一个供应商'); + } + + // 检查是否每个供应商都有评价人员 + const hasNoEvaluator = suppliers.some( + (supplier) => !supplier.evaluators || supplier.evaluators.length === 0, + ); + + if (hasNoEvaluator) { + return Promise.reject('存在未分配评价人员的供应商'); + } + + return Promise.resolve(); + }, + getFieldsValue: () => { + // 构建评价人员列表 + const indicatorList = suppliers.flatMap( + (supplier) => + supplier.evaluators?.map((evaluator: PersonnelItem) => ({ + userId: evaluator.id, + type: 0, // type 评价类型(默认0 按评价单 ,当用户关联了指标则为 :1 按指标) + indicatorIds: [], + })) || [], + ); + + // 构建供应商ID列表 + const supplierIds = suppliers.map((supplier) => ({ + id: supplier.id, + userIds: supplier.evaluators?.map((e: PersonnelItem) => e.id) || [], + })); + + return { + indicatorList, + supplierIds, + suppliersWithEvaluators: suppliers, + weightUnits, + }; + }, + setFieldsValue: (values: any) => { + if (values.suppliersWithEvaluators) { + debugger; + setSuppliers(values.suppliersWithEvaluators); + } + if (values.weightUnits) { + setWeightUnits(values.weightUnits); + } + }, + })); + + // 从上一步获取供应商数据 + useEffect(() => { + if (formData.selectedSuppliers && formData.selectedSuppliers.length > 0) { + // 转换上一步的供应商数据,添加评价人员数量字段 + const suppliersWithEvaluators = formData.selectedSuppliers.map((supplier: any) => { + // 确保evaluators字段存在且为数组 + const evaluators = supplier.evaluators || []; + return { + ...supplier, + department: supplier.userDept || '采购部', // 假设部门数据,实际应该从上一步获取 + evaluatorCount: evaluators.length, + evaluators: evaluators, + }; + }); + setSuppliers(suppliersWithEvaluators); + } else { + // 没有选择供应商,清空供应商列表 + setSuppliers([]); } - // 检查是否每个供应商都有评价人员 - const hasNoEvaluator = suppliers.some(supplier => - !supplier.evaluators || supplier.evaluators.length === 0 - ); - - if (hasNoEvaluator) { - return Promise.reject('存在未分配评价人员的供应商'); + // 初始化权重数据(如果有) + if (formData.WeightUnit && formData.WeightUnit.length > 0) { + setWeightUnits(formData.WeightUnit); + } else { + // 没有权重数据,将在下面的useEffect中根据人员部门计算 + setWeightUnits([]); } + }, [formData]); - return Promise.resolve(); - }, - getFieldsValue: () => { - // 构建评价人员列表 - const indicatorList = suppliers.flatMap(supplier => - supplier.evaluators?.map(evaluator => ({ - userId: evaluator.id, - type: 0, // 假设按评价单评价 - indicatorIds: [] - })) || [] + // 当选择的人员变化时,更新权重单位列表 + useEffect(() => { + // 抽取所有评价人员的部门 + const allDepartments: string[] = []; + + suppliers.forEach((supplier) => { + if (supplier.evaluators && supplier.evaluators.length > 0) { + supplier.evaluators.forEach((evaluator) => { + if (evaluator.department) { + allDepartments.push(evaluator.department); + } + }); + } + }); + + // 去重部门列表 + const uniqueDepartments = [...new Set(allDepartments)]; + + // 如果有部门数据,生成权重单位列表 + if (uniqueDepartments.length > 0) { + const newWeightUnits: WeightUnit[] = uniqueDepartments.map((dept, index) => ({ + id: (index + 1).toString(), + name: dept, + weight: 0, // 默认权重为0 + })); + + // 更新权重单位列表,保留原有权重值 + setWeightUnits((prevUnits) => { + const prevUnitsMap = new Map(prevUnits.map((unit) => [unit.name, unit.weight])); + + return newWeightUnits.map((unit) => ({ + ...unit, + weight: prevUnitsMap.get(unit.name) || 0, // 如果有原来的权重值则保留 + })); + }); + } + }, [suppliers]); + + // 更新表单数据 + const updateFormData = (updatedData: any) => { + // // 构建评价人员列表 + const indicatorList = suppliers.flatMap( + (supplier) => + supplier.evaluators?.map((evaluator: PersonnelItem) => ({ + userId: evaluator.id, + type: 0, // 默认按评价单评价 (没有指派分工),如果指派了 (就 1 按指标) + indicatorIds: [], // 指标id集合 + })) || [], ); // 构建供应商ID列表 - const supplierIds = suppliers.map(supplier => ({ - id: supplier.key, - userIds: supplier.evaluators?.map(e => e.id) || [] + const supplierIds = suppliers.map((supplier) => ({ + id: supplier.id, + userIds: supplier.evaluators?.map((e: PersonnelItem) => e.id) || [], })); - - return { + onFormDataChange({ + ...updatedData, indicatorList, supplierIds, - suppliersWithEvaluators: suppliers - }; - }, - setFieldsValue: (values: any) => { - if (values.suppliersWithEvaluators) { - setSuppliers(values.suppliersWithEvaluators); + weightUnits, + }); + }; + + // 处理批量选择 + const handleBatchSelect = () => { + if (selectedRowKeys.length === 0) return; + setBatchSelectModalVisible(true); + }; + + // 处理设置评分单位权重 + const handleWeightSetting = () => { + // 设置初始表单值 + form.setFieldsValue({ + weightUnits: weightUnits.reduce((acc, unit) => { + acc[unit.id] = unit.weight; + return acc; + }, {} as Record), + }); + + setWeightSettingModalVisible(true); + }; + + // 保存权重设置 + const handleSaveWeights = () => { + form.validateFields().then((values) => { + const updatedWeightUnits = weightUnits.map((unit) => ({ + ...unit, + weight: values.weightUnits[unit.id], + })); + + setWeightUnits(updatedWeightUnits); + updateFormData({ weightUnits: updatedWeightUnits }); + setWeightSettingModalVisible(false); + }); + }; + + // 处理选择评价人员 + const handleSelectEvaluators = (supplier: SupplierItem) => { + setCurrentSupplier(supplier); + setModalMode(ModalMode.SELECT); + setEvaluatorModalVisible(true); + }; + + // 处理查看评价人员 + const handleViewEvaluators = (supplier: SupplierItem) => { + + // 查找完整的供应商数据(包括evaluators) + const fullSupplier = suppliers.find((s) => s.id === supplier.id); + if (fullSupplier) { + setCurrentSupplier(fullSupplier); + } else { + setCurrentSupplier(supplier); } - if (values.weightUnits) { - setWeightUnits(values.weightUnits); - } - }, - })); - // 从上一步获取供应商数据 - useEffect(() => { - if (formData.selectedSuppliers) { - // 转换上一步的供应商数据,添加评价人员数量字段 - const suppliersWithEvaluators = formData.selectedSuppliers.map((supplier: any) => ({ - ...supplier, - department: supplier.department || '采购部', // 假设部门数据,实际应该从上一步获取 - evaluatorCount: supplier.evaluators?.length || 0, - })); - setSuppliers(suppliersWithEvaluators); - } else { - // 如果没有从上一步获取到数据,使用模拟数据 - const mockSuppliers: SupplierItem[] = [ - { key: '1', supplierName: '供应商A', socialCreditCode: '123456789012345678', category: '润滑油', department: '采购部', evaluatorCount: 2, evaluators: [ - { id: '1', name: '张三', department: '采购部' }, - { id: '2', name: '李四', department: '技术部' } - ] }, - { key: '2', supplierName: '供应商B', socialCreditCode: '123456789012345679', category: '燃油', department: '技术部', evaluatorCount: 0 }, - { key: '3', supplierName: '供应商C', socialCreditCode: '123456789012345680', category: '备件', department: '质量部', evaluatorCount: 1, evaluators: [ - { id: '3', name: '王五', department: '质量部' } - ] }, - { key: '4', supplierName: '供应商D', socialCreditCode: '123456789012345681', category: '计算机', department: '生产部', evaluatorCount: 0 }, - ]; - setSuppliers(mockSuppliers); - } + setModalMode(ModalMode.VIEW); + setEvaluatorModalVisible(true); + }; - // 初始化权重数据(如果有) - if (formData.weightUnits) { - setWeightUnits(formData.weightUnits); - } - }, [formData]); + // 处理评价人员选择确认 + const handleEvaluatorSelect = (selectedEvaluators: PersonnelItem[]) => { + if (!currentSupplier) return; - // 更新表单数据 - const updateFormData = (updatedData: any) => { - // 构建评价人员列表 - const indicatorList = suppliers.flatMap(supplier => - supplier.evaluators?.map(evaluator => ({ - userId: evaluator.id, - type: 0, // 假设按评价单评价 - indicatorIds: [] - })) || [] - ); + const updatedSuppliers = suppliers.map((supplier) => { + if (supplier.id === currentSupplier.id) { + const updated = { + ...supplier, + evaluators: selectedEvaluators, + evaluatorCount: selectedEvaluators.length, + }; + return updated; + } + return supplier; + }); - // 构建供应商ID列表 - const supplierIds = suppliers.map(supplier => ({ - id: supplier.key, - userIds: supplier.evaluators?.map(e => e.id) || [] - })); + setSuppliers(updatedSuppliers); + updateFormData({ suppliersWithEvaluators: updatedSuppliers }); + setEvaluatorModalVisible(false); + }; - onFormDataChange({ - ...updatedData, - indicatorList, - supplierIds - }); - }; + // 处理批量选择评价人员确认 + const handleBatchEvaluatorSelect = (selectedEvaluators: PersonnelItem[]) => { + if (selectedRowKeys.length === 0) return; + const updatedSuppliers = suppliers.map((supplier) => { + if (selectedRowKeys.includes(supplier.id)) { + return { + ...supplier, + evaluators: selectedEvaluators, + evaluatorCount: selectedEvaluators.length, + }; + } + return supplier; + }); + setSuppliers(updatedSuppliers); + updateFormData({ suppliersWithEvaluators: updatedSuppliers }); + setBatchSelectModalVisible(false); + }; - // 处理批量选择 - const handleBatchSelect = () => { - if (selectedRowKeys.length === 0) return; - setBatchSelectModalVisible(true); - }; + // 处理删除供应商 + const handleDeleteSupplier = (key: string) => { + const updatedSuppliers = suppliers.filter((item) => item.id !== key); + setSuppliers(updatedSuppliers); + updateFormData({ suppliersWithEvaluators: updatedSuppliers }); + // 更新选中行,移除已删除的供应商 + setSelectedRowKeys((prevKeys) => prevKeys.filter((k) => k !== key)); + }; - // 处理设置评分单位权重 - const handleWeightSetting = () => { - // 设置初始表单值 - form.setFieldsValue({ - weightUnits: weightUnits.reduce((acc, unit) => { - acc[unit.id] = unit.weight; - return acc; - }, {} as Record) - }); + return ( +
+ +
+ + + + +
- setWeightSettingModalVisible(true); - }; - - // 保存权重设置 - const handleSaveWeights = () => { - form.validateFields().then(values => { - const updatedWeightUnits = weightUnits.map(unit => ({ - ...unit, - weight: values.weightUnits[unit.id] - })); - - setWeightUnits(updatedWeightUnits); - updateFormData({ weightUnits: updatedWeightUnits }); - setWeightSettingModalVisible(false); - }); - }; - - // 处理选择评价人员 - const handleSelectEvaluators = (supplier: SupplierItem) => { - setCurrentSupplier(supplier); - setEvaluatorModalVisible(true); - }; - - // 处理评价人员选择确认 - const handleEvaluatorSelect = (selectedEvaluators: PersonnelItem[]) => { - if (!currentSupplier) return; - - const updatedSuppliers = suppliers.map(supplier => { - if (supplier.key === currentSupplier.key) { - return { - ...supplier, - evaluators: selectedEvaluators, - evaluatorCount: selectedEvaluators.length - }; - } - return supplier; - }); - - setSuppliers(updatedSuppliers); - updateFormData({ suppliersWithEvaluators: updatedSuppliers }); - setEvaluatorModalVisible(false); - }; - - // 处理批量选择评价人员确认 - const handleBatchEvaluatorSelect = (selectedEvaluators: PersonnelItem[]) => { - if (selectedRowKeys.length === 0) return; - - const updatedSuppliers = suppliers.map(supplier => { - if (selectedRowKeys.includes(supplier.key)) { - return { - ...supplier, - evaluators: selectedEvaluators, - evaluatorCount: selectedEvaluators.length - }; - } - return supplier; - }); - - setSuppliers(updatedSuppliers); - updateFormData({ suppliersWithEvaluators: updatedSuppliers }); - setBatchSelectModalVisible(false); - }; - - // 处理删除供应商 - const handleDeleteSupplier = (key: string) => { - const updatedSuppliers = suppliers.filter(item => item.key !== key); - setSuppliers(updatedSuppliers); - updateFormData({ suppliersWithEvaluators: updatedSuppliers }); - }; - - // 删除确认对话框 - const showDeleteConfirm = (record: SupplierItem) => { - Modal.confirm({ - title: '确定要删除此供应商吗?', - content: `供应商: ${record.supplierName}`, - okText: '确定', - okType: 'danger', - cancelText: '取消', - onOk: () => handleDeleteSupplier(record.key), - }); - }; - - // 表格行选择配置 - const rowSelection = { - selectedRowKeys, - onChange: (keys: React.Key[]) => { - setSelectedRowKeys(keys); - } - }; - - // 表格列定义 - const columns = [ - { - title: '供应商名称', - dataIndex: 'supplierName', - key: 'supplierName', - }, - { - title: '统一社会信用代码', - dataIndex: 'socialCreditCode', - key: 'socialCreditCode', - }, - { - title: '品类', - dataIndex: 'category', - key: 'category', - render: (text: string) => {text}, - }, - { - title: '准入部门', - dataIndex: 'department', - key: 'department', - }, - { - title: '评价人员数', - dataIndex: 'evaluatorCount', - key: 'evaluatorCount', - render: (count: number) => ( - - {count} - - ), - }, - { - title: '操作', - key: 'action', - render: (_: any, record: SupplierItem) => ( - <> - - - {record.evaluatorCount > 0 && ( - + {suppliers.length === 0 ? ( +
+ 请先在上一步选择供应商 +
+ ) : ( + )} - - - ), - }, - ]; - - return ( -
- -
- - - - -
- -
- - {/* 批量选择评价人员弹窗 */} - setBatchSelectModalVisible(false)} - footer={null} - width={700} - > - setBatchSelectModalVisible(false)} onSelect={handleBatchEvaluatorSelect} - selectedPersonnel={[]} /> - - {/* 单个供应商选择评价人员弹窗 */} - setEvaluatorModalVisible(false)} - footer={null} - width={700} - > - setEvaluatorModalVisible(false)} onSelect={handleEvaluatorSelect} - selectedPersonnel={currentSupplier?.evaluators || []} + currentSupplier={currentSupplier} + mode={modalMode} /> - - {/* 权重设置弹窗 */} - setWeightSettingModalVisible(false)} - > -
setWeightSettingModalVisible(false)} + onOk={handleSaveWeights} + weightUnits={weightUnits} form={form} - layout="vertical" - > - -

请设置各评分单位的权重比例,总和需为100%

- {weightUnits.map(unit => ( - - `${value}%`} - parser={(value: string | undefined) => { - if (!value) return 0; - const num = Number(value.replace('%', '')); - return num; - }} - style={{ width: '100%' }} - /> - - ))} -
- -
- - - ); -}); + /> + + + ); + }, +); export default EvaluatorSelectStep; diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/components/SupplierSelectStep.tsx b/src/pages/supplierEvaluateManage/supplierTaskManage/components/SupplierSelectStep.tsx index f2004e9..8f8ea24 100644 --- a/src/pages/supplierEvaluateManage/supplierTaskManage/components/SupplierSelectStep.tsx +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/components/SupplierSelectStep.tsx @@ -4,15 +4,15 @@ import styles from '../supplierTaskManageAdd.less'; import SupplierSelector from '@/components/SupplierSelector'; interface SupplierSelectStepProps { - formData: any; - onFormDataChange: (data: any) => void; + formData: any; // 从父组件传递的表单数据 + onFormDataChange: (data: any) => void; // 表单数据变更的回调函数 } interface SupplierItem { - id: string; - name: string; - supplierType: string; - [key: string]: any; + id: string; // 供应商ID + name: string; // 供应商名称 + supplierType: string; // 供应商类型 + [key: string]: any; // 其他可能的字段 } const SupplierSelectStep = forwardRef(({ formData, onFormDataChange }, ref) => { @@ -40,10 +40,19 @@ const SupplierSelectStep = forwardRef(({ formData, // 处理供应商选择 const handleSupplierSelect = (suppliers: SupplierItem[]) => { + + // 确保每个供应商都有evaluators字段 + const suppliersWithEvaluators = suppliers.map(supplier => ({ + ...supplier, + evaluators: supplier.evaluators || [], // 确保evaluators字段存在,即使是空数组 + evaluatorCount: supplier.evaluators?.length || 0 // 计算评价人员数量 + })); + + onFormDataChange({ ...formData, - selectedSuppliers: suppliers, - supplierIds: suppliers.map(supplier => ({ id: supplier.id })) + selectedSuppliers: suppliersWithEvaluators, + supplierIds: suppliersWithEvaluators.map(supplier => ({ id: supplier.id })) }); }; diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/supplierTaskManageAdd.less b/src/pages/supplierEvaluateManage/supplierTaskManage/supplierTaskManageAdd.less index d8e1fdf..124c070 100644 --- a/src/pages/supplierEvaluateManage/supplierTaskManage/supplierTaskManageAdd.less +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/supplierTaskManageAdd.less @@ -41,7 +41,9 @@ min-height: 300px; flex: 1; } - +.toolbar { + margin-bottom: 16px; +} .stepsAction { margin-top: 24px; text-align: center; diff --git a/src/pages/supplierEvaluateManage/supplierTaskManage/supplierTaskManageAdd.tsx b/src/pages/supplierEvaluateManage/supplierTaskManage/supplierTaskManageAdd.tsx index 11f24f4..11111c7 100644 --- a/src/pages/supplierEvaluateManage/supplierTaskManage/supplierTaskManageAdd.tsx +++ b/src/pages/supplierEvaluateManage/supplierTaskManage/supplierTaskManageAdd.tsx @@ -6,26 +6,69 @@ import { addTask } from '@/servers/api/supplierEvaluate'; import BasicInfoStep from './components/BasicInfoStep'; import SupplierSelectStep from './components/SupplierSelectStep'; import EvaluatorSelectStep from './components/EvaluatorSelectStep'; +import DivisionStep from './components/DivisionStep'; import styles from './supplierTaskManageAdd.less'; const { Step } = Steps; const SupplierTaskManageAdd: React.FC = () => { - const [currentStep, setCurrentStep] = useState(1); + // 当前步骤索引,从0开始 + const [currentStep, setCurrentStep] = useState(0); + + // 提交加载状态 const [loading, setLoading] = useState(false); + + // 整个表单的数据,包含所有步骤的数据 const [formData, setFormData] = useState>({}); - // 创建表单引用 - const basicFormRef = useRef(null); - const supplierFormRef = useRef(null); - const evaluatorFormRef = useRef(null); + // 处理表单数据变更 + const handleFormDataChange = (data: any) => { + console.log(data) + // 第一步:基本信息 + if (data) { + setFormData((prev) => ({ ...prev, ...data })); + } + + // 第二步:供应商选择 + if (data.selectedSuppliers) { + // 确保供应商数据包含evaluators字段 + const suppliersWithEvaluators = data.selectedSuppliers.map((supplier: any) => ({ + ...supplier, + evaluators: supplier.evaluators || [], // 确保evaluators字段存在 + })); + + setFormData((prev) => ({ ...prev, selectedSuppliers: suppliersWithEvaluators })); + } + + // 第三步:评价人员 + if (data.suppliersWithEvaluators) { + // 确保suppliersWithEvaluators和selectedSuppliers保持一致 + const evaluatedSuppliers = data.suppliersWithEvaluators; + setFormData((prev) => ({ + ...prev, + suppliersWithEvaluators: evaluatedSuppliers, + selectedSuppliers: evaluatedSuppliers // 同步更新selectedSuppliers + })); + } + + // 更新权重单位 + if (data.weightUnits) { + setFormData((prev) => ({ ...prev, WeightUnit: data.weightUnits })); + } + }; + + // 创建表单引用,用于访问子组件的表单方法 + const basicFormRef = useRef(null); // 基本信息表单引用 + const supplierFormRef = useRef(null); // 供应商选择表单引用 + const evaluatorFormRef = useRef(null); // 评价人员表单引用 + const divisionFormRef = useRef(null); // 评价分工表单引用 // 步骤配置 const steps = [ { - title: '基本信息', - description: '请填写基本信息', - content: , + title: '基本信息', // 步骤标题 + description: '请填写基本信息', // 步骤描述 + content: , // 步骤内容组件 }, { title: '选择供应商', @@ -40,7 +83,7 @@ const SupplierTaskManageAdd: React.FC = () => { { title: '设置评价分工', description: '不设置按默认全部指标评价', - content:
设置评价分工步骤(待实现)
, + content: , }, { title: '创建成功', @@ -49,11 +92,6 @@ const SupplierTaskManageAdd: React.FC = () => { }, ]; - // 处理表单数据变更 - function handleFormDataChange(data: any) { - setFormData({ ...formData, ...data }); - } - // 处理返回 const handleBack = () => { history.goBack(); @@ -72,6 +110,13 @@ const SupplierTaskManageAdd: React.FC = () => { } else if (currentStep === 2 && evaluatorFormRef.current) { // 验证评价人员选择 await evaluatorFormRef.current.validateFields(); + } else if (currentStep === 3 && divisionFormRef.current) { + // 验证评价分工 + const result = divisionFormRef.current.validate(); + if (!result.valid) { + message.error(result.message); + return; + } } // 验证通过,进入下一步 @@ -96,18 +141,27 @@ const SupplierTaskManageAdd: React.FC = () => { const handleSubmit = async () => { setLoading(true); try { + // 验证评价分工 + if (divisionFormRef.current) { + const result = divisionFormRef.current.validate(); + if (!result.valid) { + message.error(result.message); + return; + } + } + // 构建提交数据 const submitData: SupplierEvaluate.TaskAddRequest = { - evaluateTheme: formData.evaluateTheme || '', - startTime: formData.startTime || '', - endTime: formData.endTime || '', - templateId: formData.templateId || '', - categoryLimitation: formData.categoryLimitation || '0', - evaluateYear: formData.evaluateYear || '', - supplierIds: formData.supplierIds || [], - indicatorList: formData.indicatorList || [], - taskDeptWeightList: formData.taskDeptWeightList || [], - weightStatus: formData.weightStatus || 0 + evaluateTheme: formData.evaluateTheme || '', // 评价主题 + startTime: formData.startTime || '', // 开始时间 + endTime: formData.endTime || '', // 结束时间 + templateId: formData.templateId || '', // 模板ID + categoryLimitation: formData.categoryLimitation || '0', // 品类限制 + evaluateYear: formData.evaluateYear || '', // 评价年份 + supplierIds: formData.selectedSuppliers?.map((supplier: any) => supplier.id) || [], // 供应商ID列表 + indicatorList: formData.indicatorList || [], // 指标分配列表 + taskDeptWeightList: formData.taskDeptWeightList || [], // 部门权重列表 + weightStatus: formData.weightStatus || 0 // 权重状态 }; // 调用API提交数据 diff --git a/src/pages/supplierEvaluateManage/supplierTemplateManage/supplierTemplateManage.tsx b/src/pages/supplierEvaluateManage/supplierTemplateManage/supplierTemplateManage.tsx index 964f949..9d7c6d8 100644 --- a/src/pages/supplierEvaluateManage/supplierTemplateManage/supplierTemplateManage.tsx +++ b/src/pages/supplierEvaluateManage/supplierTemplateManage/supplierTemplateManage.tsx @@ -10,7 +10,6 @@ import { Form, Tooltip, Tag, - TreeSelect, } from 'antd'; import type { TablePaginationConfig } from 'antd'; import { @@ -25,22 +24,11 @@ import { } from '@/dicts/supplierTemplateDict'; import { getTemplateList, - getCategoryTree, } from '@/servers/api/supplierEvaluate'; +import CategorySelector from '@/components/CategorySelector/CategorySelector'; const { Option } = Select; -// 处理品类树数据 -const processCategoryTree = (data: any[]): any[] => { - return data.map(item => ({ - title: item.categoryName, - value: item.id, - key: item.id, - selectable: item.type === '1', // 只有类型为品类的节点可选 - children: item.children ? processCategoryTree(item.children) : undefined - })); -}; - const SupplierTemplateManage: React.FC = () => { const [loading, setLoading] = useState(false); const [form] = Form.useForm(); @@ -56,8 +44,7 @@ const SupplierTemplateManage: React.FC = () => { }); const [searchParams, setSearchParams] = useState({}); - // 品类和部门下拉选项 - const [categoryTreeData, setCategoryTreeData] = useState([]); + // 部门下拉选项 const [companyOptions, setCompanyOptions] = useState<{ label: string, value: string }[]>([ { label: '中山市合创展包装材料有限公司', value: '中山市合创展包装材料有限公司' }, { label: '广州市科技发展有限公司', value: '广州市科技发展有限公司' }, @@ -65,21 +52,6 @@ const SupplierTemplateManage: React.FC = () => { { label: '东莞市制造业有限公司', value: '东莞市制造业有限公司' }, ]); - // 获取品类树 - const fetchCategoryTree = async () => { - try { - const res = await getCategoryTree(); - if (res.success && res.data) { - // 使用组件外的函数处理数据 - const treeData = processCategoryTree(res.data); - setCategoryTreeData(treeData); - } - } catch (error) { - console.error('获取品类树失败:', error); - message.error('获取品类树失败'); - } - }; - // 获取模板列表 const fetchTemplateList = async ( current = 1, @@ -128,7 +100,6 @@ const SupplierTemplateManage: React.FC = () => { // 首次加载获取数据 useEffect(() => { fetchTemplateList(pagination.current, pagination.pageSize, {}); - fetchCategoryTree(); }, []); // 处理查看 @@ -284,16 +255,7 @@ const SupplierTemplateManage: React.FC = () => { - +