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


const dataRecord = props => {
    const [data, setData] = useState({})
    const { targetId, targetType, channelId, targetName, buildingId, newCustomers, startDate, endDate } = props.location.query

    useEffect(() => {
        getList({ pageNum: 1, pageSize: 10 })

    }, [])

    const getList = params => {
        request({ ...apis.channelList.newuserList, params: { ...params, targetId: targetId,targetType: targetType,channelId: channelId,buildingId: buildingId,startDate: startDate, endDate: endDate } }).then(data => {
            console.log(data,"dddddddddddd")
          setData(data)
        }).catch(e => {
          console.log(e)
        })
    }

    const columns = [
        {
            title: '姓名',
            dataIndex: 'nickName',
            key: 'nickName',
            align: 'center',
        },
        {
            title: '电话',
            dataIndex: 'phone',
            key: 'phone',
            align: 'center',
        },
        {
            title: '性别',
            dataIndex: 'gender',
            key: 'gender',
            align: 'center',
        },
        {
            title: '归属地',
            dataIndex: 'province',
            key: 'province',
            align: 'center',
        },
        {
            title: '注册时间',
            dataIndex: 'createDate',
            key: 'createDate',
            align: 'center',
        },

    ]



    const changePageNum = pageNumber => {
        getList({ pageNum: pageNumber, pageSize: 10 })
    }


/**
     * 导出
     */
    const exportExcel = () => {
        // const fieldsValue = getFieldsValue()
        // console.log('fieldsValue', fieldsValue)
        request({ ...apis.channelList.newuserListExport, params: { targetId: targetId,targetType: targetType,channelId: channelId,buildingId: buildingId,startDate: startDate, endDate: endDate } })
          .then(data => {
            if (!data) {
              return
            }
            const url = window.URL.createObjectURL(new Blob([data]))
            const link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', '注册用户.xlsx')
            document.body.append(link)
            link.click()
          }).catch(() => {
    
          })
      }

    return <>
        <div>
            <div>
                <span>内容:{targetName}</span>
                <Button style={{ float: 'right', zIndex: 1 }} onClick={() => router.go(-1)}>
                    返回
               </Button>
            </div>
            <div style={{ marginTop: '20px'  }}>
                <span>注册用户:{newCustomers}</span>
                <Button type="primary" style={{ float: 'right', marginBottom: '20px', zIndex: 1 }} onClick={exportExcel}>导出</Button>
            </div>
            <Table style={{ marginTop: '30px' }} dataSource={data.records || []} columns={columns} pagination={false} rowKey="activityList" />
            {/* <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
        <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current} />
      </div> */}
        </div>
    </>
}

export default dataRecord