import React, { useState, useEffect } from 'react';
import { Form, Input, Button, Icon, Select, message, Table, Divider, Tag, Pagination, Modal, Breadcrumb } from 'antd';
import router from 'umi/router';
import moment from 'moment';
import apis from '../../../services/apis';
import request from '../../../utils/request';

function financialContact(props) {

    // const [taNoticeList, setTaNoticeList] = useState([])
    const [data, setData] = useState({})

    useEffect(() => {
        getList({ pageNum: 1, pageSize: 10 });
    }, [])
    // 查询列表

    const getList = params => {
        request({ ...apis.funds.list, params: { ...params } }).then(data => {
            setData(data)
        })
    }

    function handleSubmit(e) {
        e.preventDefault();
        props.form.validateFields((err, values) => {
            if (!err) {
                // eslint-disable-next-line no-console
                console.log('提交数据: ', values)
                getList({ ...values })
            }
        });
    }

    function handleReset() {
        props.form.resetFields();

        getList({ pageNum: 1, pageSize: 10 })
    }

    const columns = [
        {
            title: '姓名',
            dataIndex: 'contactName',
            key: 'contactName',
            align: 'center',
        },
        {
            title: '性别',
            dataIndex: 'sex',
            key: 'sex',
            align: 'center',
            render: x => <span>{x == 1 ? '男' : x === 2 ? '女' : '未知'}</span >,
        },
        {
            title: '头像',
            dataIndex: 'avatar',
            key: 'avatar',
            align: 'center',
            render: (x, row) => <img src={row.avatar} alt="" width="93px" height="93px"></img >,
        },
        {
            title: '固话',
            dataIndex: 'telephone',
            key: 'telephone',
            align: 'center',
        },
        {
            title: '手机号',
            dataIndex: 'phone',
            key: 'phone',
            align: 'center',
        },
        {
            title: '头衔',
            dataIndex: 'appellation',
            key: 'appellation',
            align: 'center',
        },
    ]

    const changePageNum = pageNumber => {
        props.form.validateFields((err, values) => {
            if (!err) {
                getList({ pageNum: pageNumber, pageSize: 10, ...values })
            }
        });
    }


    const { getFieldDecorator } = props.form

    return (

        <>
            <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
                <Form.Item>
                    {getFieldDecorator('contactName')(
                        <Input
                            placeholder="姓名"
                        />,
                    )}
                </Form.Item>
                <Form.Item>
                    {getFieldDecorator('telephone')(
                        <Input
                            placeholder="固话"
                        />,
                    )}
                </Form.Item>
                <Form.Item>
                    {getFieldDecorator('phone')(
                        <Input
                            placeholder="手机号"
                        />,
                    )}
                </Form.Item>
                <Form.Item>
                    <Button type="primary" htmlType="submit"> 搜索</Button>
                    <Button style={{ marginLeft: 8 }} onClick={handleReset}>重置</Button>
                </Form.Item>
            </Form>
            {/* <div style={{ marginTop: '20px' }}>
                <Button type="primary" style={{ float: 'right', marginBottom: '20px', zIndex: 1 }} >导出</Button>
            </div> */}
            <Table dataSource={data.records} columns={columns} pagination={false} style={{ marginTop: '20px' }} />
            <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
                <Pagination
                    showQuickJumper
                    defaultCurrent={1}
                    total={data.total} onChange={e => changePageNum(e)} current={data.current} />
            </div>
        </>

    )
}


const WrappedFinancialContact = Form.create({ name: 'financialContact' })(financialContact);

export default WrappedFinancialContact

