import React, { useState, useEffect } from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Form, Input, Button, Icon, Select, message, Table, Divider, Tag, Steps, Pagination, Modal, Breadcrumb } from 'antd';
import router from 'umi/router';
import moment from 'moment';
import styles from '../style.less';
import { fetch, apis } from '../../../../utils/request';
import request from '../../../../utils/request';
import AuthButton from '@/components/AuthButton';




function header(props) {

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

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

    const getList = params => {
        request({ ...apis.relatedOrganization.listOrg, params: { ...params } }).then(data => {
            setData(data)
        })
    }
    function handleReset() {
        props.form.resetFields();
        getList({ pageNum: 1, pageSize: 10 });
    }

    const changePageNum = pageNumber => {
        getList({ pageNum: pageNumber, pageSize: 10, ...props.form.getFieldsValue() })
    }

    const handleSubmit = (e, props) => {
        e.preventDefault();
        getList({ pageNum: 1, pageSize: 10, ...props.form.getFieldsValue() });
    }

    const choiceorg = value =>{
        props.onChoiceOrg(value)
    }

    const columns = [
        {
            title: '组织名称',
            dataIndex: 'name',
            key: 'name',
            align: 'center',

        },
        {
            title: '组织编号',
            dataIndex: 'orgId',
            key: 'orgId',
            align: 'center',
           
        },
        {
            title: '小程序名称',
            dataIndex: 'miniAppName',
            key: 'miniAppName',
            align: 'center',
           
        },
        {
            title: '代理商名称',
            dataIndex: 'channelProxyName',
            key: 'channelProxyName',
            align: 'center',
           
        },
        {
            title: '操作',
            dataIndex: 'handle',
            key: 'handle',
            align: 'center',
            render: (x, row) => (
                <>


                    <span style={{ color: '#FF925C', cursor: 'pointer' }} onClick={e=>choiceorg(row)}>
                    选择<Icon type="form" className={styles.edit} />
                    </span>

                </>
            ),
        }
    ]
   
    const { getFieldDecorator } = props.form
    return (<>
        <div>
        <Form layout="inline" style={{ marginTop: '30px' }} onSubmit={e => handleSubmit(e, props) }>
                <Form.Item>
                    {getFieldDecorator('orgName')(
                        <Input
                            prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
                            placeholder="组织名称 "
                        />,
                    )}
                </Form.Item>
                <Form.Item>
                    {getFieldDecorator('miniAppName')(
                        <Input
                            prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
                            placeholder="小程序名称 "
                        />,
                    )}
                    </Form.Item>
                    <Form.Item>
                    <Button type="primary" htmlType="submit" className={styles.searchBtn}>搜索</Button>
                    <Button style={{ marginLeft: 8 }} onClick={handleReset}>重置</Button>
                </Form.Item>
            </Form>
            <Table id='noticeTable' style={{ marginTop: '30px' }}  dataSource={data.records} columns={columns} pagination={false} />
                <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
                    <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={e => changePageNum(e)} current={data.current} />
                </div>
        </div>
    </>)
}

const WrappedHeader = Form.create({ name: 'header' })(header);

export default WrappedHeader