



import { useRef, useState, useEffect } from 'react';
import { connect } from '@umijs/max';
import type { ActionType, ProFormInstance } from '@ant-design/pro-components';
import {
    ProTable,
    ProFormSelect
} from '@ant-design/pro-components';
import { Button,  ConfigProvider } from 'antd';
import { GetRecruitmentBookList, listRecruitment, GetRecruitmentDetail } from '@/apis/api';
const selectfieldNames = { label: 'title', value: 'id' };
const FairListPage: React.FC = ({ dispatch, getId, openModel }: any) => {
    const actionRef = useRef<ActionType>();
    const [list, setList] = useState<object[]>([])
    const [total, setTotal] = useState<number>(0)
    const [page, setPage] = useState<number>(1)
    const [pageSize, setPageSize] = useState<number>(10)
    const [recruitmentId, setRecruitmentId] = useState<number>(1);
    const setId = (id: number) => {
        getId(id)
    }

    useEffect(() => {
        if (!openModel.openModal) {
            actionRef.current.reload();
        }
    }, [openModel.openModal])

    return (
        <>
            <ConfigProvider
                theme={{
                    token: {
                        colorPrimary: '#4FBE70',
                        colorLink: '#4FBE70',

                    }
                }}
            >

                <ProTable
                    scroll={{ x: 1300 }}
                    actionRef={actionRef}
                    dataSource={list}
                    columns={[
                        {
                            title: '企业名称',
                            dataIndex: 'company_name',
                            width: 300,
                            fixed: 'left',
                            search: false

                        }, {
                            title: '招聘会ID',
                            dataIndex: 'recruitment_id',
                            width: 200,
                            valueType: 'select',
                            renderFormItem: () => {
                                return (
                                    <ProFormSelect
                                        fieldProps={{
                                            fieldNames: selectfieldNames,
                                            defaultValue: sessionStorage.getItem('recruitment_info') ? JSON.parse(sessionStorage.getItem('recruitment_info')).title : null,
                                        }}
                                        request={async (keyword) =>
                                            listRecruitment({ page: 1, pagesize: 100, keyword: keyword.keyWords }).then(res => {
                                                return res.data.recruitments;
                                            })
                                        }
                                        placeholder="请选择招聘会"
                                        onChange={(value) => {
                                            setRecruitmentId(value)
                                            GetRecruitmentDetail({ id: value }).then(res => {
                                                sessionStorage.setItem('recruitment_info', JSON.stringify(res.data))
                                            })
                                        }}
                                    />
                                )
                            }

                        },  {
                            title: '审核状态',
                            dataIndex: 'status',
                            width: 100,
                            search: false
                        },
                        {
                            title: '操作',
                            width: 300,
                            key: 'option',
                            valueType: 'option',
                            fixed: 'right',
                            render: (_, record, action) => [
                                <Button key='1' type='link' onClick={() => {
                                    
                                }}>审核</Button>,
                                <Button key='2' type='link' onClick={() => {
                                    
                                }}>移除企业</Button>,
                            ],
                        },
                    ]}
                    rowKey="id"
                    pagination={{
                        current: page,
                        pageSize: pageSize,
                        showSizeChanger: true,
                        total: total,
                        pageSizeOptions: [9, 18, 27, 99],
                        onChange(page, pageSize) {
                            setPage(page)
                            setPageSize(pageSize)
                        },
                        onShowSizeChange(current, size) {
                            setPage(current)
                            setPageSize(size)
                        }
                    }}
                    request={async (params = {} as Record<string, any>) =>
                        GetRecruitmentBookList({
                            page: page,
                            pagesize: pageSize,
                            sort: 'id',
                            sortby: 'desc',
                            recruitment_id: sessionStorage.getItem('recruitment_info') ? JSON.parse(sessionStorage.getItem('recruitment_info')).id : recruitmentId
                        }).then(res => {
                            setList(res.data.recruitmentbooks)
                            setTotal(res.data.total)
                        })
                    }
                    toolBarRender={() => [
                        <Button type="primary" onClick={() => {
                            dispatch({ type: 'openModel/getOpenModal', payload: true })
                        }}>
                            添加招聘会
                        </Button>
                    ]}
                    headerTitle="招聘会列表"
                    onReset={() => {
                        if (sessionStorage.getItem('recruitment_info')) {
                            sessionStorage.removeItem('recruitment_info')
                        }
                        setRecruitmentId(1)
                        actionRef.current.reload();
                    }}
                />
            </ConfigProvider>
        </>
    );
};




export default connect(({ dictModel, openModel }: any) => ({
    dictModel,
    openModel
}))(FairListPage);