import React,{Component} from 'react';
import {
    Table,Button, Col, Row, Input, Select, message,Pagination,Card,Tabs,DatePicker
} from 'antd';
import { $http } from '../../containers/config/https';
import store from '../../store';
const Option=Select.Option
const TabPane = Tabs.TabPane;
class MedRecordExport extends Component {
    constructor(props) {
        super(props);
        this.state = {
            data:[],
            startDate:"",
            endDate:"",
            total: 0,
            page: 1,
            pageSize: 10,
        };
        this.classColumns=[
            {
                key: 1,
                title: '开始日期',
                dataIndex: 'startDate',
                width: 80,
                align: "center"
              },
              {
                key: 2,
                title: '结束日期',
                dataIndex: 'endDate',
                width: 80,
                align: "center"
              },
              {
                key: 3,
                title: '记录数量',
                dataIndex: 'recordNum',
                width: 80,
                align: "center"
              },
              {
                key: 4,
                title: '执行日期',
                dataIndex: 'createDate',
                width: 80,
                align: "center"
              },
              {
                key: 5,
                title: '执行时间',
                dataIndex: 'createTime',
                width: 80,
                align: "center"
              },
              {
                key: 6,
                title: '下载',
                dataIndex: 'fileURL',
                width: 80,
                align: "center",
                render: (text, record,index) => {
                    if(text!==""){
                        return (
                            <a href={text}>下载文件</a>
                         )
                    }else{
                        return ""
                    }
                }
              }
        ]
    }
    ExportData=()=>{
        var startDate=this.state.startDate.format('YYYY-MM-DD')
        var endDate=this.state.endDate.format('YYYY-MM-DD')
        //var className=this.props.className
        // debugger
        const hide = message.loading('正在导出数据..', 0);
        let data = {
            params: [{
                    startDate:startDate,
                    endDate:endDate
                }]
        }
        $http.post("urlS",this, {
            code: "01010001",
            data: data,
            success: function (res) { 
                if (+res.errorCode === 0) {
                    setTimeout(hide, 100); 
                    this.FindLogData()
                } else {
                    setTimeout(hide, 100); 
                    message.error('失败：' + res.errorMessage);
                }
            },
            error:function (error) {
                setTimeout(hide, 100); 
                message.error('失败：' + error);
            }
        })  
    }
    FindLogData=()=>{
        let {page, pageSize} = this.state;
        let data = {
            params: [{
                    
            }],
            pagination:[{
              pageSize: pageSize,
              currentPage: page
            }]
        }
        $http.post("urlS",this, {
            code: "01010003",
            data: data,
            success: function (res) { 
                if (+res.errorCode === 0) {
                    this.setState({
                        data:res.result.Data,
                        total: res.result.TotalCount
                    })
                } else {
                    message.error('失败：' + res.errorMessage);
                }
            },
            error:function (error) {
                message.error('失败：' + error);
            }
        }) 
    }
    setRowClassName=(record)=>{
        return record.Code === this.state.ClassName ? 'clickRowStyle' : '';
    }
    ShowMessage=()=>{
        const hide = message.loading('正在载入数据..', 0);
        return hide
    }
    componentWillMount() {
        this.FindLogData()
    }
    startDateChange=(date, dateString)=>{
        this.setState({
            startDate:date
        })
    }
    endDateChange=(date, dateString)=>{
        this.setState({
            endDate:date
        })
    }
    // 页码改变的回调，参数是改变后的页码及每页条数
    PageChange = (page, pageSize)=> {
        this.setState({page: page, pageSize: pageSize}, () => {
            this.FindLogData()
        });
    }
    // 条数改变的回调
    onShowSizeChange = (current, size) => {
        this.setState({page: current, pageSize: size}, () => {
            this.FindLogData()
        });
    }
    FindExportLog=()=>{
        this.FindLogData()
    }
    render() {
        return (
            <div>
                <Card >
                    <br />
                <Row type="flex" justify="space-between">
                    <Col span={6}>
                        开始日期:<DatePicker  value={this.state.startDate} onChange={this.startDateChange} format="YYYY-MM-DD" />   
                    </Col>
                    <Col span={6}>
                        结束日期:<DatePicker  value={this.state.endDate} onChange={this.endDateChange} format="YYYY-MM-DD" />   
                    </Col>
                    <Col span={6}>
                        <Button type="primary" onClick={this.ExportData}>导出</Button>   
                    </Col>
                    <Col span={6}>
                        <Button type="primary" onClick={this.FindExportLog}>查询</Button>   
                    </Col>
                </Row>
                <br />
                        <Table
                            dataSource={this.state.data}
                            columns={this.classColumns}
                            rowClassName={this.setRowClassName}
                            pagination={false}
                            bordered
                            rowKey="ID"
                            onRow={this.onClickRow}
                            style={{height: store.getState().tableHeight.y + 45 + 'px'}}
                            scroll={{y: store.getState().tableHeight.y,x:300 }}
                            //rowSelection={{onChange:this.tableOnChange,type:"radio"}}
                        />
                        <Pagination
                            size="small"
                            showQuickJumper
                            showSizeChanger
                            defaultCurrent={1}
                            current={this.state.page}
                            total={this.state.total}
                            onChange={this.PageChange}
                            onShowSizeChange={this.onShowSizeChange}
                            style={{textAlign: "right", marginTop: '10px'}}
                            />,
                </Card>
            </div>
        );
    }
}

export default MedRecordExport;