123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import React, { useEffect, useState } from 'react';
- import { Select } from 'antd';
- import { queryApproval } from '@/services/approval';
- function DDProjectField(props) {
- const { value, disabled = false, onChange } = props;
- const [projectList, setProjectList] = useState([]);
- const [loading, setLoading] = useState(false);
- const getProjectList = async () => {
- setLoading(true);
- const res = await queryApproval({ pageSize: 9999 }).catch(err => {
- console.log(err);
- setLoading(false);
- });
- if (res.code === 200) {
- console.log(res.data.list);
- setProjectList(res.data.list);
- setLoading(false);
- }
- };
- useEffect(() => {
- getProjectList();
- }, []);
- return (
- <Select
- showSearch
- loading={loading}
- style={{ width: '100%' }}
- disabled={disabled}
- defaultValue={value ? Number(value) : undefined}
- onChange={val => {
- console.log(val);
- const project = projectList.find(item => item.id === val);
- onChange(`${val}`);
- }}
- filterOption={(input, option) =>
- (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
- }
- options={projectList.map(item => {
- return {
- label: `${item.project_name}(${item.project_full_code})`,
- value: item.id,
- };
- })}
- />
- );
- }
- export default DDProjectField;
|