import { useRef, useState, useEffect } from 'react';
import { connect } from '@umijs/max';
import type { ActionType } from '@ant-design/pro-components';
import {
    ProTable
} from '@ant-design/pro-components';
import { Button, ConfigProvider, Image, message } from 'antd';
import { PostJobseekerList, PostJobseekerExport } from '@/apis/api';
import { Imageprefix } from '@/constants';

const selectfieldNames = { label: 'name', value: 'id' };


const PagesMainJobseekerListTable: React.FC = ({ dispatch, getId, dictModel, 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 setId = (id: number) => {
        getId(id)
    }

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

    useEffect(() => {
        dispatch({ type: 'dictModel/getList', payload: { code: 2004, type: 'setPositionList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2009, type: 'setAreaList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2005, type: 'setPayList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2016, type: 'setAccommodationRequirementList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2017, type: 'setHolidayRestList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2018, type: 'setLicenseList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2021, type: 'setWorkExperienceList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2006, type: 'setEducationList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2014, type: 'setTitleList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2015, type: 'setSkillCertificationeList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2007, type: 'setOtherLanguageList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2008, type: 'setDegreeList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2027, type: 'setIndustryPostList' } })
        dispatch({ type: 'dictModel/getList', payload: { code: 2010, type: 'setPoliticalList' } })
    }, [])
    return (
        <>
            <ConfigProvider
                theme={{
                    token: {
                        colorPrimary: '#4FBE70',
                        colorLink: '#4FBE70',
                    }
                }}
            >

                <ProTable
                    scroll={{ x: 1300 }}
                    actionRef={actionRef}
                    dataSource={list}
                    columns={[
                        {
                            title: '姓名',
                            dataIndex: 'seekername',
                            width: 200
                        }, {
                            title: '性别',
                            dataIndex: 'gender',
                            width: 80,
                            valueType: 'select',
                            valueEnum: {
                                '男': '男',
                                '女': '女'
                            }
                        }, {
                            title: '教育程度',
                            dataIndex: 'education_txt',
                            width: 120,
                            search: false
                        }, {
                            title: '教育程度',
                            dataIndex: 'education',
                            width: 120,
                            hidden: true,
                            valueType: 'select',
                            fieldProps: {
                                fieldNames: selectfieldNames,
                                options: dictModel.educationList
                            }
                        },
                        {
                            title: '英语',
                            dataIndex: 'english_txt',
                            width: 120,
                            search: false
                        }, {
                            title: '英语',
                            dataIndex: 'english',
                            width: 120,
                            hidden: true,
                            valueType: 'select',
                            fieldProps: {
                                fieldNames: selectfieldNames,
                                options: dictModel.degreeList
                            }
                        },
                        {
                            title: '国语',
                            dataIndex: 'mandarin_txt',
                            width: 120,
                            search: false

                        }, {
                            title: '国语',
                            dataIndex: 'mandarin',
                            width: 120,
                            hidden: true,
                            valueType: 'select',
                            fieldProps: {
                                fieldNames: selectfieldNames,
                                options: dictModel.degreeList
                            }
                        }, {
                            title: '粤语',
                            dataIndex: 'cantonese_txt',
                            width: 120,
                            search: false

                        }, {
                            title: '粤语',
                            dataIndex: 'cantonese',
                            width: 120,
                            hidden: true,
                            valueType: 'select',
                            fieldProps: {
                                fieldNames: selectfieldNames,
                                options: dictModel.degreeList
                            }
                        },
                        {
                            title: '职称',
                            dataIndex: 'title_txt',
                            width: 120,
                            search: false
                        }, {
                            title: '职称',
                            dataIndex: 'title',
                            width: 120,
                            hidden: true,
                            valueType: 'select',
                            fieldProps: {
                                fieldNames: selectfieldNames,
                                options: dictModel.titleList
                            }
                        },
                        {
                            title: '政治面貌',
                            dataIndex: 'political_status_txt',
                            width: 120,
                            search: false
                        }, {
                            title: '政治面貌',
                            dataIndex: 'political_status',
                            width: 120,
                            hidden: true,
                            valueType: 'select',
                            fieldProps: {
                                fieldNames: selectfieldNames,
                                options: dictModel.politicalList
                            }
                        }, {
                            title: '月薪要求范围',
                            dataIndex: 'salary_range_txt',
                            width: 120,
                            search: false
                        }, {
                            title: '月薪要求',
                            dataIndex: 'salary_range_desire',
                            width: 120,
                            hidden: true,
                            valueType: 'select',
                            fieldProps: {
                                fieldNames: selectfieldNames,
                                options: dictModel.payList
                            }
                        },
                        {
                            title: '审核状态',
                            dataIndex: 'status_txt',
                            width: 120,
                            search: false

                        },
                        // {
                        //     title: '审核状态',
                        //     dataIndex: 'status',
                        //     width: 120,
                        //     hidden: true,
                        //     valueType: 'select',
                        //     valueEnum: {
                        //         0: '全部',
                        //         1: '待审核',
                        //         2: '审核通过',
                        //         3: '审核不通过'
                        //     }
                        // },
                        {
                            title: '简历是否可见',
                            dataIndex: 'hide_resume',
                            width: 120,
                            search: false,
                            render: (_, record) => (<>
                                {
                                    <span>
                                        {record.hide_resume == 1 ? '可见' : '不可见'}
                                    </span>
                                }

                            </>),
                        },
                        {
                            title: '简历是否在家政模块可见',
                            dataIndex: 'house_keeping_status',
                            width: 120,
                            search: false,
                            render: (_, record) => (<>
                                {
                                    <span>
                                        {record.house_keeping_status == 1 ? '可见' : '不可见'}
                                    </span>
                                }

                            </>),
                        },
                        {
                            title: '操作',
                            width: 400,
                            key: 'option',
                            valueType: 'option',
                            fixed: 'right',
                            render: (_, record, action) => [
                                <Button key='1' type='link' onClick={() => {
                                    setId(record)

                                    dispatch({ type: 'openModel/getOpenModal', payload: true })
                                }}>编辑</Button>,
                                <Button key='2' type='link' onClick={() => {
                                    setId(record)
                                    dispatch({ type: 'openModel/getOpenResumeHelpModal', payload: true })
                                }}>工作帮扶情况</Button>,
                                <Button key='2' type='link' onClick={() => {
                                    setId(record)
                                    dispatch({ type: 'openModel/getOpenResumeDetailModal', payload: true })
                                }}>预览简历</Button>,
                                <Button key='4' type='link' onClick={() => {
                                    setId(record)
                                    dispatch({ type: 'openModel/getOpenExportModal', payload: true })
                                }}>导出登记表</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>) =>
                        PostJobseekerList({
                            page: page,
                            pagesize: pageSize,
                            sort: 'id',
                            sortby: 'desc',
                            keyword: params.name,
                            gender: params.gender,
                            education: params.education,
                            english: params.english,
                            mandarin: params.mandarin,
                            cantonese: params.cantonese,
                            title: params.title,
                            political_status: params.political_status,
                            salary_range_desire: params.salary_range_desire,
                            status: params.status
                        }).then(res => {
                            setList(res.data.seekers)
                            setTotal(res.data.total)
                        })
                    }
                    toolBarRender={() => [
                        <Button type="primary" onClick={() => {
                            message.info('数据导出需要时间，请耐心等待')
                            PostJobseekerExport().then(res => {
                                let url = Imageprefix + res.data.excel_url;
                                window.open(url);
                                message.info('数据导出完毕')
                            })
                        }}>
                            导出数据
                        </Button>
                    ]}
                    headerTitle="简历列表"
                />
            </ConfigProvider>

        </>



    );
};


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