import { useState, useEffect, useMemo } from 'react';
import { Button, Col, Form, Input, Row, Select, Space, Card, Table, InputNumber, Badge, Modal, Radio, Flex, message, Drawer, Steps, DatePicker, Popconfirm, Tag } from 'antd';
import UploadScore from '@/components/UploadScore';
import { logger } from '@/apis/auth';
import { getSubjectList } from '@/apis/subject';
import { getExamList, deleteExam, startComputeExam, afreshComputeExam, getExamDescription, updateExam, getExam, addExamList, getScoreLineList, saveScoreLine, deleteScoreLine } from '@/apis/data';
import { getSemesterEnum, getGradeEnum, getExamEnum } from '@/apis/common';
import dayjs from 'dayjs';
import styles from './index.less';

const { TextArea } = Input;

const ExportDataPage = () => {
    const [searchForm] = Form.useForm();
    const [form] = Form.useForm();
    const [tableLoading, setTableLoading] = useState(false);
    const [dataSource, setDataSource] = useState([]);
    const [open, setOpen] = useState(false);

    const [termOptions, setTermOptions] = useState([]);
    const [examOptions, setExamOptions] = useState([]);
    const [semesterOptions, setSemesterOptions] = useState([]);


    const [descriptionOpen, setDescriptionOpen] = useState(false);
    const [descriptionForm] = Form.useForm();
    const [examId, setExamId] = useState('');
    const [descriptionConfirmLoading, setDescriptionConfirmLoading] = useState(false);

    const [current, setCurrent] = useState(0);

    const [fileForm] = Form.useForm();

    const [handleType, setHandleType] = useState('');

    const stageOption = [
        {
            value: 1,
            label: '小学',
        },
        {
            value: 2,
            label: '初中',
        },
        {

            value: 3,
            label: '高中'
        }
    ];


    const [scoreOpen, setScoreOpen] = useState(false);
    const [scoreConfirmLoading, setScoreConfirmLoading] = useState(false);
    const [scoreLoading, setScoreLoading] = useState(false);
    const [subjectOptions, setSubjectOptions] = useState([]);
    const [scoreLineData, setSoreLineData] = useState([]);

    const [visible, setVisible] = useState(false);

    const [scoreLineForm] = Form.useForm();


    const [scoreLineId, setScoreLineId] = useState('');


    const [compositeOpen, setCompositeOpen] = useState(false);
    const [compositeConfirmLoading, setCompositeConfirmLoading] = useState(false);
    const [compositeForm] = Form.useForm();


    const [patternOpen,setPatternOpen] = useState(false);
    const [patternForm] = Form.useForm(); 
    const [patternConfirmLoading, setPatternConfirmLoading] = useState(false);
    const [record, setRecord] = useState({});

    const computedDrawerTitle = useMemo(() => {
        if (!handleType) {
            return;
        }
        if (handleType === 'ADD') {
            return '创建考试';
        } else if (handleType === 'EDIT') {
            return '编辑考试';
        }
    }, [handleType])

    useEffect(() => {
        init(searchForm.getFieldsValue()?.stage);
        getTermOptions();
        getExamOptions();
        getSemesterOptions();

    }, []);

    useEffect(() => {
        if (scoreOpen) {
            getSubjectSelectOptions();
            getScoreLineListData(searchForm.getFieldsValue()?.stage);
        }
    }, [scoreOpen]);


    const compositeSelectOptions = useMemo(() => {
        if (!scoreLineData?.length) {
            return;
        }
        return scoreLineData?.filter(item => item?.type === 1)?.map(item => ({ label: item?.name, value: item?.id }));

    }, [scoreLineData])



    console.log(compositeSelectOptions, 'compositeSelectOptions');



    const getTermOptions = async () => {
        try {

            const res = await getGradeEnum();
            if (res.code === 200) {
                setTermOptions(() => {
                    return res.data.map(item => {
                        return {
                            value: item,
                            label: item
                        }
                    });
                })
            }
        } catch (error) {
            console.log(error, 'getTermOptions-error');

        }
    };

    const getExamOptions = async () => {
        try {

            const res = await getExamEnum();
            if (res.code === 200) {
                setExamOptions(() => {
                    return res.data.map(item => {
                        return {
                            value: item,
                            label: item
                        }
                    });
                })
            }
        } catch (error) {
            console.log(error, 'getExamOptions-error');

        }
    };


    const getSemesterOptions = async () => {
        try {

            const res = await getSemesterEnum();
            if (res.code === 200) {
                setSemesterOptions(() => {
                    return res.data.map(item => {
                        return {
                            value: item,
                            label: item
                        }
                    });
                })
            }
        } catch (error) {
            console.log(error, 'getExamOptions-error');

        }
    };

    const init = async (stage) => {
        try {
            setTableLoading(true);
            const res = await getExamList({ stage, });
            if (res?.code === 200) {
                setTableLoading(false);
                setDataSource(res?.data || []);
                return;
            }
            setTableLoading(false);
        } catch (error) {
            setTableLoading(false);
            console.log(error, 'init-error');

        }
    };

    const getSubjectSelectOptions = async () => {
        try {
            const res = await getSubjectList({ stages: searchForm.getFieldsValue()?.stages, contain256: false, level: 1, single: true, showFlag: true });
            if (res?.code === 200) {

                setSubjectOptions(() => {
                    return res?.data?.map(item => {
                        return {
                            label: item?.cname,
                            value: item?.id
                        }
                    })
                })
            }
        } catch (error) {
            console.log(error, 'getSubjectSelectOptions-error');

        }
    };

    const getScoreLineListData = async (stage) => {
        try {
            setScoreLoading(true);
            const res = await getScoreLineList({ examId, stage, });
            if (res?.code === 200) {
                setScoreLoading(false);
                setSoreLineData(res?.data || []);
                return;
            }
            setScoreLoading(false);
        } catch (error) {
            setScoreLoading(false);
            console.log(error, 'getScoreLineListData-error');

        }

    };

    const onFormValuesChange = async (values) => {
        try {
            setTableLoading(true);
            const res = await getExamList(values);
            if (res?.code === 200) {
                setTableLoading(false);
                setDataSource(res?.data || []);
                return;
            }
            setTableLoading(false);
        } catch (error) {
            setTableLoading(false);
            console.log(error, 'onFormValuesChange-error');

        }
    };


    const handleCreateExam = () => {
        setExamId('');
        form.resetFields();
        setOpen(true);
        setCurrent(0);
        setHandleType("ADD");

    };

    // const handleFinish = async () => {
    //     setConfirmLoading(true);
    //     form.validateFields().then(async () => {

    //         const data = disabled ? {
    //             id: schoolId,
    //             ...form.getFieldsValue(),
    //             stage: searchForm.getFieldsValue()?.stages,
    //         } : {
    //             ...form.getFieldsValue(),
    //             stage: searchForm.getFieldsValue()?.stages,
    //         };
    //         const res = await saveSchool(data);
    //         if (res.code === 200) {
    //             setConfirmLoading(false);
    //             setOpen(false);
    //             init(searchForm.getFieldsValue()?.stage);
    //             setSchoolId('');
    //             message.success('操作成功');
    //             return;
    //         }
    //         setConfirmLoading(false);
    //     }).catch(error => {
    //         setConfirmLoading(false);
    //         console.log(error, 'handleFinish-error');
    //     });
    // };


    const handleDeleteExam = (record) => {
        Modal.confirm({
            title: "温馨提示",
            content: "确定删除该考试吗？",
            centered: true,
            onOk: () => {
                return new Promise((resolve, reject) => {
                    deleteExam({ examId: record.id }).then(async (res) => {
                        if (res?.code === 200) {
                            resolve(true);
                            message.success('删除成功');
                            await logger({ description: "删除考试" });
                            init(searchForm.getFieldsValue()?.stage);
                        } else {
                            resolve(false);
                            message.error(res?.msg);
                        }
                    }).catch(reject);
                });
            }
        })

    };

    const handleAfreshExam = (record) => {
        afreshComputeExam({ examId: record.id }).then(async (res) => {
            if (res?.code === 200) {
                message.success('操作成功');
                await logger({ description: "重新计算考试" });
                init(searchForm.getFieldsValue()?.stage);
            } else {
                message.error(res?.msg);

            }
        }).catch(error => {
            console.log(error, 'handleAfreshExam-error');

        });

    };

    const handleStartExam = (record) => {
        setRecord(record);
        setPatternOpen(true);

    };

    const handleOpenEditDescription = async (record) => {
        try {
            setDescriptionOpen(true);
            setExamId(record.id);

            const res = await getExamDescription({ id: record.id });
            if (res?.code === 200) {
                descriptionForm.setFieldValue('description', res?.data);
            }

        } catch (error) {
            console.log(error, 'handleOpenEditDescription-error');

        }
    };


    const handleFinishDescription = async () => {
        try {
            setDescriptionConfirmLoading(true);
            const res = await updateExam({
                examId,
                description: descriptionForm.getFieldValue('description'),
            });
            if (res?.code === 200) {
                await logger({ description: "修改考试描述" });
                setDescriptionConfirmLoading(false);
                descriptionForm.resetFields();
                setExamId('');
                message.success('操作成功');
                setDescriptionOpen(false);
                return;
            }
            setDescriptionConfirmLoading(false);
            message.error(res?.msg);

        } catch (error) {
            setDescriptionConfirmLoading(false);
            console.log(error, 'handleFinishDescription-error');

        }

    };


    const handleEditExam = async (record) => {
        try {
            setExamId(record.id);
            setHandleType('EDIT')
            const res = await getExam({ examId: record.id });
            if (res?.code === 200) {
                setOpen(true);
                form.setFieldsValue({
                    term: res?.data?.term,
                    examName: res?.data?.examName,
                    calElective: res?.data?.calElective,
                    semester: res?.data?.semester,
                    examDate: dayjs(res?.data?.examDate, 'YYYY-MM-DD'),
                });
                return;
            }
            setOpen(false);
            message.error(res?.msg);

        } catch (error) {
            setOpen(false);
            console.log(error);

        }
    };


    const handleClose = () => {
        setOpen(false);
        setExamId('');
        form.resetFields();
        setCurrent(0);
    };


    const onStepsChange = (current) => {
        setCurrent(current);
    }


    const handleSetupScoreLine = (record) => {
        setScoreOpen(true);
        setExamId(record?.id);
    };


    const handleAddScoreLine = () => {
        setVisible(true);
        setScoreLineId('');
    };

    const handleAddCompositeScoreLine = () => {
        setScoreLineId('');
        setCompositeOpen(true);
    }

    const handleEditScoreLine = (record) => {
        if (record?.type === 1) {
            setVisible(true);
            setScoreLineId(record?.id);
            const data = {
                ...record,
                combIds: record?.combIds ? record.combIds.split(',').map(Number) : []
            };
            scoreLineForm.setFieldsValue(data);
            return;
        }
        if (record?.type === 2) {
            setCompositeOpen(true);
            setScoreLineId(record?.id);
            const data = {
                ...record,
                lineIds: record?.lineIds ? record.lineIds.split(',').map(Number) : []
            };
            compositeForm.setFieldsValue(data);
            return;
        }

    };

    const onScoreLineFinish = () => {
        setScoreConfirmLoading(true);
        scoreLineForm.validateFields().then(async () => {

            const selectedOptions = subjectOptions?.filter(opt =>
                scoreLineForm.getFieldsValue().combIds?.includes(opt.value)
            );
            const formData = {
                ...scoreLineForm.getFieldsValue(),
                combIds: scoreLineForm.getFieldsValue()?.combIds?.join(','),
                combNames: selectedOptions?.map(opt => opt.label)?.join(','),
                type: 1,
                nsId: examId,
            };
            const res = await saveScoreLine(scoreLineId ? {
                id: scoreLineId,
                ...formData,

            } : formData);
            if (res.code === 200) {
                setScoreConfirmLoading(false);
                setVisible(false);
                getScoreLineListData(searchForm.getFieldsValue()?.stage);
                setScoreLineId('');
                message.success('操作成功');
                scoreLineForm.resetFields();
                if (scoreLineId) {
                    await logger({ description: "修改分数线" });
                } else {
                    await logger({ description: "新增分数线" });
                }
                return;
            }
            setScoreConfirmLoading(false);

        }).catch(error => {
            setScoreConfirmLoading(false);
            console.log(error, 'onScoreLineFinish-error');
        });
    };


    const onCompositeScoreLineFinish = () => {
        setCompositeConfirmLoading(true);
        compositeForm.validateFields().then(async () => {

            // const selectedOptions = subjectOptions?.filter(opt =>
            //     compositeForm.getFieldsValue().lineIds?.includes(opt.value)
            // );
            const formData = {
                ...compositeForm.getFieldsValue(),
                lineIds: compositeForm.getFieldsValue()?.lineIds?.join(','),
                nsId: examId,
                type: 2,
                sort: 99
            };
            const res = await saveScoreLine(scoreLineId ? {
                id: scoreLineId,
                ...formData,

            } : formData);
            if (res.code === 200) {
                setCompositeConfirmLoading(false);
                setCompositeOpen(false);
                getScoreLineListData(searchForm.getFieldsValue()?.stage);
                setScoreLineId('');
                message.success('操作成功');
                compositeForm.resetFields();
                if (scoreLineId) {
                    await logger({ description: "修改复合分数线" });
                } else {
                    await logger({ description: "新增复合分数线" });
                }
                return;
            }
            setCompositeConfirmLoading(false);

        }).catch(error => {
            setCompositeConfirmLoading(false);
            console.log(error, 'onScoreLineFinish-error');
        });
    };

    const handleDeleteScoreLine = async (record) => {
        try {
            const res = await deleteScoreLine({ id: record.id });
            if (res?.code === 200) {
                await logger({ description: "删除分数线" });
                getScoreLineListData(searchForm.getFieldsValue()?.stage);
                message.success('操作成功');
                return;
            }
        } catch (error) {
            console.log(error, 'handleDeleteScoreLine-error');

        }
    }


    const handleSelectPatternFinish = async() => {
        setPatternConfirmLoading(true);
        try {
            const res =  await startComputeExam({ examId: record.id,...patternForm?.getFieldsValue() });
            setPatternConfirmLoading(false);
            if(res?.code === 200){
                message.success('操作成功');
                setPatternOpen(false);
                await logger({ description: "开始计算考试" });
                init(searchForm.getFieldsValue()?.stage);
            }else{
                message.error(res?.msg);
            }
        } catch (error) {
            console.log(error,'handleSelectPatternFinish-error');
            
        }
    }

    const columns = [
        {
            title: '考试名称',
            dataIndex: 'examName',
            key: 'examName',
            width: 200,
            align: 'center',
        },
        {
            title: '考试时间',
            dataIndex: 'examDate',
            key: 'examDate',
            width: 140,
            align: 'center',
        },
        {
            title: '届别',
            dataIndex: 'term',
            key: 'term',
            width: 80,
            align: 'center',
        },
        {
            title: '学期',
            dataIndex: 'semester',
            key: 'semester',
            width: 80,
            align: 'center',
        },
        {
            title: '状态',
            dataIndex: 'state',
            key: 'state',
            width: 80,
            align: 'center',
            render(value) {
                if (value === 0) {
                    return <Badge status="default" text="未计算" />
                }
                if (value === 1) {
                    return <Badge status="success" text="计算成功" />
                }
                if (value === 2) {
                    return <Badge status="processing" text="计算中" />
                }
                if (value === 3) {
                    return <Badge status="error" text="计算失败" />
                }

            }
        },
        {
            title: '备注',
            dataIndex: 'calMsg',
            key: 'calMsg',
            width: 180,
            align: 'center',

        },
        {
            title: '操作',
            key: 'action',
            align: 'center',
            width: 100,
            render(_, record) {

                if (record?.state === 2) {
                    return null;
                }
                return (
                    <Flex>
                        <Space size="middle">
                            <Button onClick={() => handleEditExam(record)} >编辑考试</Button>
                            {record?.state !== 0 ? <Button onClick={() => handleOpenEditDescription(record)} >编辑描述</Button> : null}
                            {(record?.state === 0) ? <Button onClick={() => handleStartExam(record)}>开始计算</Button> : null}
                            {[1, 3].includes(record?.state) ? <Button onClick={() => { handleAfreshExam(record) }}>重新计算</Button> : null}
                            <Button onClick={() => handleSetupScoreLine(record)}>设置分数线</Button>
                            <Button type='primary' danger onClick={() => handleDeleteExam(record)}>删除考试</Button>
                        </Space>
                    </Flex>

                );
            }
        },
    ];

    const scoreLineColumns = [
        {
            title: '名称',
            dataIndex: 'name',
            key: 'name',
            align: 'center',
        },
        {
            title: '分数线',
            dataIndex: 'score',
            key: 'score',
            align: 'center',
        },
        {
            title: '学科',
            dataIndex: 'combNames',
            key: 'combNames',
            align: 'center',
        },
        {
            title: '类型',
            dataIndex: 'type',
            key: 'type',
            width: 120,
            align: 'center',
            render(value) {
                if (value === 1) {
                    return <Tag color="geekblue">单一分数线</Tag>
                }
                if (value === 2) {
                    return <Tag color="purple">复合分数线</Tag>
                }
            }
        },
        {
            title: '排序',
            dataIndex: 'sort',
            key: 'sort',
            width: 80,
            align: 'center',
        },
        {
            title: '操作',
            align: 'center',
            render(_, record) {
                return (<Space>
                    <Button
                        type='link'
                        onClick={() => handleEditScoreLine(record)}
                    >编辑</Button>
                    <Popconfirm
                        title="温馨提示"
                        description="是否删除分数线?"
                        onConfirm={() => handleDeleteScoreLine(record)}
                        okText="确定"
                        cancelText="取消"
                    >
                        <Button type='link' danger>删除</Button>
                    </Popconfirm>

                </Space>)
            }
        },
    ];

    return (
        <div className={styles.data}>
            <header className={styles.data_header}>
                <Card>
                    <Form form={searchForm} initialValues={{ stage: 3 }} name="advanced_search" onValuesChange={onFormValuesChange} >
                        <Row gutter={24}>
                            <Col span={8}>
                                <Form.Item
                                    name='stage'
                                    label='学段'
                                >
                                    <Select placeholder="请选择学段" options={stageOption} style={{ maxWidth: 120 }} />
                                </Form.Item>

                            </Col>
                            <Col span={2} offset={14}>
                                <Button type="primary" onClick={handleCreateExam}>创建考试</Button>
                            </Col>
                        </Row>
                        {/* <div style={{ textAlign: 'right' }}>
                            <Space size="small">
                                <Button type="primary" htmlType="submit">
                                    查询
                                </Button>
                                <Button
                                    onClick={() => {
                                        searchForm.resetFields();
                                    }}
                                >
                                    重置
                                </Button>
                            </Space>
                        </div> */}

                    </Form>
                </Card>
            </header>
            <main className={styles.data_main}>
                <Card>
                    <Table bordered columns={columns} loading={tableLoading} dataSource={dataSource} pagination={false} style={{ height: '100%' }} />
                </Card>
            </main>
            {/* <footer className={styles.subject_footer}></footer> */}

            <Modal
                title='编辑描述'
                open={descriptionOpen}
                maskClosable={false}
                centered
                destroyOnClose
                width={800}
                onOk={handleFinishDescription}
                confirmLoading={descriptionConfirmLoading}
                onCancel={() => {
                    setExamId('');
                    setDescriptionOpen(false);
                    descriptionForm.resetFields();
                }}
            >

                <Form
                    form={descriptionForm}
                    layout="vertical"
                >
                    <Form.Item label="描述" name="description" rules={[
                        {
                            required: true,
                            message: '请填写描述',
                        },
                    ]}>
                        <TextArea
                            placeholder="请输入描述"
                            autoSize={{ minRows: 6, maxRows: 8 }}
                        />
                    </Form.Item>
                </Form>

            </Modal>

            <Drawer
                title={computedDrawerTitle}
                placement="right"
                size="large"
                maskClosable={false}
                destroyOnClose
                width={620}
                onClose={handleClose}
                open={open}
            >
                <div className={styles.drawer}>
                    <header className={styles.drawer_header}>
                        <Steps
                            current={current}
                            // onChange={onStepsChange}
                            items={[
                                {
                                    title: '编辑考试信息',
                                },
                                {
                                    title: '编辑考试资料',
                                },
                            ]}
                        />
                    </header>
                    <main className={styles.drawer_main}>
                        {current === 0 ? (
                            <Form
                                form={form}
                                layout="vertical"
                            >

                                <Form.Item label="届别" name="term" rules={[
                                    {
                                        required: true,
                                        message: '请选择届别',
                                    },
                                ]}>
                                    <Select placeholder="请选择届别" options={termOptions} style={{ width: '100%' }} />
                                </Form.Item>
                                <Form.Item label="考试" name="examName" rules={[
                                    {
                                        required: true,
                                        message: '请选择考试',
                                    },
                                ]}>
                                    <Select placeholder="请选择考试" options={examOptions} style={{ width: '100%' }} />
                                </Form.Item>
                                <Form.Item label="时间" name="examDate" rules={[
                                    {
                                        required: true,
                                        message: '请选择考试',
                                    },
                                ]}>
                                    <DatePicker style={{ width: '100%' }} />
                                </Form.Item>
                                <Form.Item label="学期" name="semester" rules={[
                                    {
                                        required: true,
                                        message: '请选择学期',
                                    },
                                ]}>
                                    <Select placeholder="请选择学期" options={semesterOptions} style={{ width: '100%' }} />
                                </Form.Item>
                                <Form.Item label="赋分" name='calElective' rules={[
                                    {
                                        required: true,
                                        message: "请选择是否使用赋分"
                                    },
                                ]}>
                                    <Radio.Group
                                        options={[
                                            { value: true, label: '使用' },
                                            { value: false, label: '不使用' },
                                        ]}
                                    />
                                </Form.Item>

                                <Form.Item>
                                    <Flex justify='center'>
                                        <Button type="primary" onClick={() => {
                                            form.validateFields().then(async (values) => {

                                                const data = { ...values, examDate: dayjs(values.examDate).format('YYYY-MM-DD'), stage: searchForm.getFieldsValue().stage };
                                                if (handleType === "ADD") {
                                                    const res = await addExamList(data);
                                                    if (res.code === 200) {
                                                        message.success("新增成功");
                                                        setExamId(res?.data?.id);
                                                        setCurrent(1);
                                                        await logger({ description: "创建考试" });
                                                        init(searchForm.getFieldValue().stage);
                                                        return;

                                                    }
                                                    message.error(res?.meg);
                                                    return;
                                                }

                                                if (handleType === "EDIT") {
                                                    const res = await updateExam({
                                                        examId,
                                                        ...data
                                                    });
                                                    if (res.code === 200) {
                                                        message.success("修改成功");
                                                        setExamId(res?.data?.id);
                                                        setCurrent(1);
                                                        await logger({ description: "编辑考试" });
                                                        init(searchForm.getFieldValue().stage);
                                                        return;

                                                    }
                                                    message.error(res?.meg);
                                                    return;
                                                }
                                            });
                                        }}>下一步</Button>
                                    </Flex>
                                </Form.Item>
                            </Form>
                        ) : null}

                        {current === 1 ? (
                            <Form
                                form={fileForm}
                                layout="vertical"
                            >
                                <Form.Item label="原始成绩" name="file" rules={[
                                    {
                                        required: true,
                                        message: '注意：请勿上传个人敏感信息！',
                                    },
                                ]}>
                                    <UploadScore examId={examId} onChange={(value) => fileForm.setFieldValue('file', value)} />
                                </Form.Item>
                                <Form.Item>
                                    <Flex justify='center'>
                                        <Button type="primary" onClick={() => {


                                            fileForm.validateFields().then((values) => {
                                                message.success('操作成功');
                                                fileForm.resetFields();
                                                setOpen(false);
                                                setCurrent(0);
                                            });
                                        }}>完成</Button>
                                    </Flex>
                                </Form.Item>
                            </Form>
                        ) : null}
                    </main>
                </div>
            </Drawer>
            <Drawer
                title='设置分数线'
                open={scoreOpen}
                maskClosable={false}
                placement="right"
                size="large"
                destroyOnClose
                width={1000}
                onClose={() => {
                    setScoreOpen(false);
                    setExamId("");
                }}
            >
                <Flex align='center' justify='flex-end' style={{ boxSizing: 'border-box', padding: '16px' }}>
                    <Space>
                        <Button onClick={handleAddCompositeScoreLine}>新增复合分数线</Button>
                        <Button type='primary' onClick={handleAddScoreLine}>新增分数线</Button>
                    </Space>
                </Flex>
                <Table dataSource={scoreLineData} pagination={false} loading={scoreLoading} columns={scoreLineColumns} />
            </Drawer>

            <Modal
                title={scoreLineId ? '编辑分数线' : '新增分数线'}
                open={visible}
                maskClosable={false}
                centered
                destroyOnClose
                width={600}
                confirmLoading={scoreConfirmLoading}
                onOk={onScoreLineFinish}
                onCancel={() => {
                    setVisible(false);
                    setScoreLineId("");
                    scoreLineForm.resetFields();
                }}
            >

                <Form
                    form={scoreLineForm}
                    layout="vertical"
                >
                    <Form.Item label="分数线名称" name="name" rules={[
                        {
                            required: true,
                            message: '分数线名称',
                        },
                    ]}>
                        <Input placeholder="请输入分数线名称" />
                    </Form.Item>

                    <Form.Item label="分数线" name="score" rules={[
                        {
                            required: true,
                            message: '请输入分数线',
                        },
                    ]}>
                        <InputNumber placeholder="请输入分数线" style={{ width: '100%' }} />
                    </Form.Item>
                    <Form.Item label="学科" name='combIds'>
                        <Select mode="multiple" maxTagCount={3} placeholder="请选择学科" options={subjectOptions} />
                    </Form.Item>
                    <Form.Item label="排序" name="sort">
                        <InputNumber placeholder="请输入排序" style={{ width: '100%' }} />
                    </Form.Item>
                </Form>

            </Modal>

            <Modal
                title={scoreLineId ? '编辑复合分数线' : '新增复合分数线'}
                open={compositeOpen}
                maskClosable={false}
                centered
                destroyOnClose
                width={600}
                confirmLoading={compositeConfirmLoading}
                onOk={onCompositeScoreLineFinish}
                onCancel={() => {
                    setScoreLineId("");
                    setCompositeOpen(false);
                    compositeForm.resetFields();
                }}
            >

                <Form
                    form={compositeForm}
                    layout="vertical"
                >
                    <Form.Item label="复合分数线名称" name="name" rules={[
                        {
                            required: true,
                            message: '请输入复合分数线名称',
                        },
                    ]}>
                        <Input placeholder="请输入复合分数线名称" />
                    </Form.Item>
                    <Form.Item label="单一分数线" name='lineIds'>
                        <Select mode="multiple" maxTagCount={3} placeholder="请选择单一分数线" options={compositeSelectOptions} />
                    </Form.Item>
                    {/* <Form.Item label="排序" name="sort">
                        <InputNumber placeholder="请输入排序" style={{ width: '100%' }} />
                    </Form.Item> */}
                </Form>

            </Modal>
            <Modal
                title='选择计算模式'
                open={patternOpen}
                maskClosable={false}
                centered
                destroyOnClose
                width={600}
                confirmLoading={patternConfirmLoading}
                onOk={handleSelectPatternFinish}
                onCancel={() => {
                    setPatternOpen(false);
                    patternForm.resetFields();
                    setRecord({});
                }}
            >

                <Form
                    form={patternForm}
                    initialValues={{
                        prepareType:0
                    }}
                >
                    <Form.Item label="模式" name="prepareType" rules={[
                        {
                            required: true,
                            message: '请选择导入计算模式',
                        },
                    ]}>
                        <Radio.Group
                                        options={[
                                            { value: 0, label: '通用导入计算' },
                                            { value: 1, label: '云阅卷导入计算' },
                                        ]}
                                    />
                    </Form.Item>
                </Form>

            </Modal>
        </div>
    );
};

export default ExportDataPage;