
import { useRef, useState, useEffect } from 'react';
import { connect } from '@umijs/max';
import type { ActionType, ProFormInstance } from '@ant-design/pro-components';
import {
    ProFormText,
    ProForm,
} from '@ant-design/pro-components';
import { ConfigProvider, Flex, Space, Modal, message, Image, Row, Col, Switch, Form, Typography } from 'antd';
import { PostJobapplicantAddcontact, PostJobapplicantUpdatecontact, GetJobapplicantContactdetail } from '@/apis/api';


const PagesMainJobseekerListResumeContact: React.FC = ({ dispatch, dictModel, openModel, id }: any) => {
    const formRef = useRef<ProFormInstance>();
    const [detail, setDetail] = useState<ResumeType.contact | null>(null)

    return (
        <>
            <ConfigProvider
                theme={{
                    token: {
                        colorPrimary: '#4FBE70',
                    }
                }}
            >
                <ProForm<ResumeType.contact>
                    formRef={formRef}
                    request={async () => {
                        if (id) {
                            let res = await GetJobapplicantContactdetail({ customer_id: id.customer_id })
                            setDetail(res.data)
                            return res.data;
                        }
                    }}
                    submitter={{
                        searchConfig: {
                            resetText: '取消',
                            submitText: '保存',
                        },
                        render: (_, dom) => { return <Flex justify='flex-end'> <Space>{dom}</Space></Flex> },
                        onReset: () => {

                        }
                    }}
                    onFinish={async (values) => {
                        console.log(values)
                        if (detail) {
                            values.id = detail.id;
                            values.customer_id = detail.customer_id;
                            let res = await PostJobapplicantUpdatecontact(values)
                            message.success('提交成功')
                        } else {
                            let res = await PostJobapplicantAddcontact(values)
                            message.success('提交成功')
                        }
                    }}
                >
                    <Row gutter={[16, 16]}>
                        <Col span={12}>
                            <ProFormText
                                label="固话"
                                name="landline"
                                placeholder="请输入固话"
                            />
                        </Col>
                        <Col span={12}>
                            <ProFormText
                                label="手机号"
                                name="mobile"
                                placeholder="请输入手机号"
                                rules={[{ required: true, message: '请输入手机号' }]}
                            />
                        </Col>
                        <Col span={12}>
                            <ProFormText
                                label="QQ"
                                name="qq"
                                placeholder="请输入QQ"
                            />
                        </Col>
                        <Col span={12}>
                            <ProFormText
                                label="个人网站"
                                name="personal_website"
                                placeholder="请输入个人网站"
                            />
                        </Col>
                        <Col span={12}>
                            <ProFormText
                                label="通信地址"
                                name="mailing_address"
                                placeholder="请输入通信地址"
                            />
                        </Col>
                        <Col span={12}>
                            <ProFormText
                                label="邮编"
                                name="postal_code"
                                placeholder="请输入邮编"
                            />
                        </Col>
                    </Row>
                </ProForm>
            </ConfigProvider>
        </>
    );
};



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