// 病案上传入口
import React from 'react';
import { Row, Col, Button, Card, message, DatePicker } from 'antd';
import { INSUYBUtil } from 'tools/index';
import { $http } from '../../containers/config/https';
import moment from 'moment';

const { RangePicker } = DatePicker;
export default class EMRUploadEntrance extends React.Component {

    constructor(props) {
        super(props)
        this.state = {
            btnArr: [],
            stDate: moment(),
            endDate: moment()
        }
    }
    componentDidMount() {
        this.getConfigInfo();
    }

    /// 获取入口配置
    getConfigInfo = () => {
        let params = {
            params: [{
            }]
        }
        $http.post('urlDeault', this, {
            code: "99140005",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        btnArr: res.result
                    })
                } else {
                    message.error('获取配置信息报错！')
                }
            }
        });
    }
    /// 入口程序
    onBtnClick = async (item) => {
        let params = {
            params: [{
                stDate: moment(this.state.stDate).format("YYYY-MM-DD"),
                endDate: moment(this.state.endDate).format("YYYY-MM-DD")
            }]
        }
        // console.log(params)
        $http.post('urlDeault', this, {
            code: item.interfaceNo,
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    message.success('数据上传成功！')
                } else {
                    message.error(res.errorMessage)
                }
            }
        });
    }

    //挂号时间选择
    changeRegistrTime = (date, dateStr) => {
        this.setState({
            stDate: dateStr[0],
            endDate: dateStr[1]
        })
    }
    render() {
        let { btnArr } = this.state
        return (
            <div className='hospital-zation-express'>
                <Card>
                    <Row style={{ margin: '20px' }}>
                        上传日期区间：<RangePicker
                            format="YYYY-MM-DD"
                            placeholder={['开始时间', '结束时间']}
                            value={[moment(this.state.stDate, 'YYYY-MM-DD'), moment(this.state.endDate, 'YYYY-MM-DD')]}
                            onChange={this.changeRegistrTime} />
                    </Row>
                    <Row style={{ margin: '20px' }}>
                        {
                            btnArr.map((item) => {
                                return (<Col span={5} key={item.code} style={{ margin: '20px' }}>
                                    <Button type='primary' onClick={this.onBtnClick.bind(this, item)}>{item.descripts}</Button>
                                </Col>)
                            })
                        }
                    </Row>
                </Card>

            </div >
        )
    }
}