zhongshujie
2025-08-01 07d1135a1913a919679dc23f0a38b9b61987171f
src/components/ApplyIndex/components/staff.tsx
@@ -1,6 +1,7 @@
import { postOaStaffGetStaffList } from '@/services/WebApi/oaStaff';
import { Modal, Table } from 'antd';
import React, { useEffect, useState } from 'react';
import { postOaStaffGetStaffList } from "@/services/WebApi/oaStaff";
import type { TableProps } from "antd";
import { Modal, Table } from "antd";
import React, { useEffect, useState } from "react";
interface StaffProps {
  open: boolean;
@@ -8,37 +9,71 @@
  onCancel: () => void;
}
interface DataType {
  id: number | string;
  label: string;
  value: number | string;
  department?: string;
  post?: string;
}
const Staff: React.FC<StaffProps> = (props) => {
  const { open, setData, onCancel } = props;
  const [staffOptions, setStaffOptions] = useState([]);
  const [staffOptions, setStaffOptions] = useState([]); // 员工数据
  const [currentRow, setRow] = useState<DataType>(); // 选中行
  const [loading, setLoading] = useState(false);
  const staffColums: any[] = [
    {
      title: '员工姓名',
      dataIndex: 'label',
      title: "员工姓名",
      dataIndex: "label",
    },
    {
      title: '部门',
      dataIndex: 'tsetwe',
      title: "部门",
      dataIndex: "department",
    },
    {
      title: '职位',
      dataIndex: 'post',
      title: "职位",
      dataIndex: "post",
    },
  ];
  // 获取员工列表
  const getStaffList = async () => {
    const res = await postOaStaffGetStaffList({ start: 0, size: 10, orgId: 4 });
    if (res && res.datas.length > 0) {
      const data = res.datas.map((item: any) => ({
        label: item.name,
        value: item.id,
      }));
      setStaffOptions(data);
  // 关闭员工弹框
  const onCloseStaff = () => {
    if (onCancel) {
      onCancel();
    }
    return [];
    setData(null);
  };
  // 设置选中行
  const onSelectRow = () => {
    setData(currentRow);
    onCloseStaff();
  };
  // 获取员工列表
  const getStaffList = () => {
    setLoading(true);
    postOaStaffGetStaffList({ start: 0, size: 10, orgId: 4 })
      .then((res) => {
        if (res && res.datas.length > 0) {
          const data = res.datas.map((item: any) => ({
            label: item.name,
            value: item.id,
            ...item,
          }));
          setStaffOptions(data);
        }
      })
      .catch((err) => {
        setLoading(false);
        setStaffOptions([]);
      })
      .finally(() => {
        setLoading(false);
      });
  };
  useEffect(() => {
@@ -47,9 +82,29 @@
    }
  }, [open]);
  const rowSelection: TableProps<DataType>["rowSelection"] = {
    onChange: (selectedRowKeys: React.Key[], selectedRows: DataType[]) => {
      setRow(selectedRows[0]);
    },
  };
  return (
    <Modal title={'员工列表'} width={600} open={open} onCancel={onCancel}>
      <Table dataSource={staffOptions} columns={staffColums} pagination={false} />
    <Modal
      title={"员工列表"}
      width={600}
      open={open}
      onCancel={onCloseStaff}
      onOk={onSelectRow}
    >
      <Table
        dataSource={staffOptions}
        columns={staffColums}
        pagination={false}
        loading={loading}
        rowKey={(record) => record?.id}
        rowSelection={{ type: "radio", ...rowSelection }}
        scroll={{ y: 400 }}
      />
    </Modal>
  );
};