
import React from 'react';
import { DatePicker, Table, Button, Row, Col, message} from 'antd';
import moment from 'moment';
import { $http } from '../../containers/config/https';
import { Util } from 'tools/index';
export default class OPAccDataSummarization extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            data: [],
            total: 0,
            showLoading: true,
            stDateTime:undefined,
            endDateTime: undefined,
            accEarlyBalance:'',
            accCurrentBalance:'',
            accAddSum:'',
            accRefundSum:'',
            accPaySum:'',
            accPayRefundSum:'',
        },
        this.columns = [
            {
                title: '名称1',
                dataIndex: 'desc1',
                width: '100px',
                align: 'center'
            },
            {
                title: '金额1',
                dataIndex: 'amt1',
                width: '100px',
                align: 'center',
            },
            {
                title: '名称2',
                dataIndex: 'desc2',
                width: '100px',
                align: 'center'
            },
            {
                title: '金额2',
                dataIndex: 'amt2',
                width: '100px',
                align: 'center'
            }
        ]
    }
        
    
    //初始化数据
    componentDidMount() {
        this.getDate()
    }
    //获取时间
    getDate = () => {
        let data = {}
        data = {
            params: [{
                "hospID": JSON.parse(window.sessionStorage.userData).hospID,
            }],
        };
        $http.post("urlS", this, {
            code: '05100701',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                        this.setState({
                            stDateTime: res.stDateTime === ' ' ? undefined : res.stDateTime,
                            endDateTime: res.endDateTime === ' ' ? undefined : res.endDateTime 
                        }, () => {
                            this.handleQuery()
                        })   
                }
            },
            error: function (err) {
                this.setState({ errMsg: "数据加载失败，请重试!" });
            }
        });
    }
    //查询
   handleQuery = () => {
        let {stDateTime,endDateTime}=this.state
        let data = {}
        data = {
            params: [{
                "stDateTime":stDateTime,
                "endDateTime":endDateTime,
                "userID": JSON.parse(window.sessionStorage.userData).userID,
                "hospID": JSON.parse(window.sessionStorage.userData).hospID, 
            }],
        }
        $http.post('urlDeanlt', this, {
            code: '05100702',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    console.log("res",res);
                    this.setState({ 
                        data: res.data, 
                        total: res.total,
                        accEarlyBalance:res.accEarlyBalance,
                        accCurrentBalance:res.accCurrentBalance,
                        accAddSum:res.accAddSum,
                        accRefundSum:res.accRefundSum,
                        accPaySum:res.accPaySum,
                        accPayRefundSum:res.accPayRefundSum, 
                        loading: false 
                    })
                } else {
                    this.setState({ 
                        data:[], 
                        total:0,  
                        accEarlyBalance:'',
                        accCurrentBalance:'',
                        accAddSum:'',
                        accRefundSum:'',
                        accPaySum:'',
                        accPayRefundSum:'', 
                        loading: false 
                    })
                }
            }
        })
    }
     //查询
   print = () => {
    let {stDateTime,endDateTime}=this.state
    let hospID= JSON.parse(window.sessionStorage.userData).hospID
    let userName= JSON.parse(window.sessionStorage.userData).userName
    window.open("http://192.168.5.36:18080/demo/reportJsp/showReport.jsp?rpx=OPAccSummary.rpx&stDateTime="+stDateTime+"&endDateTime="+endDateTime+"&hospID="+hospID+"&userName="+userName)
    }
    

    //单击汇总
    handle = () => {
        var r=confirm("汇总后无法打印本次记录请汇总前打印，是否汇总")
        if (r==false){
          return false;
        }
        let {stDateTime,endDateTime,accEarlyBalance,accCurrentBalance,accAddSum,accRefundSum,accPaySum,accPayRefundSum}=this.state
        let data = {}
        data = {
            params: [{
                "stDateTime":stDateTime,
                "endDateTime":endDateTime,
                "userID": JSON.parse(window.sessionStorage.userData).userID,
                "hospID": JSON.parse(window.sessionStorage.userData).hospID,
                "accEarlyBalance":accEarlyBalance,
                "accCurrentBalance":accCurrentBalance,
                "accAddSum":accAddSum,
                "accRefundSum":accRefundSum,
                "accPaySum":accPaySum,
                "accPayRefundSum":accPayRefundSum, 
            }]
        }
        $http.post('urls', this, {
            code: '05100703',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    message("汇总成功！");
                    this.getDate()
                }
            }
        })
    }
    render() {
        return (
            <div style={{ width: '100%', height: '100%' }}>
                <div className="department-header">
                    <Row style={{ marginLeft:'20px' ,minHeight: '80px', padding: '0 24px' }}>
                        <Col span={12} style={{ marginTop: '24px' }}>
                            预交金时间：<DatePicker showTime format="YYYY-MM-DD HH:mm:ss" placeholder="stDateTime" value={this.state.stDateTime ? moment(this.state.stDateTime):undefined} disabled style={{ marginRight: '10px' }} />
                            <DatePicker showTime format="YYYY-MM-DD HH:mm:ss" placeholder="endDateTime"  value={this.state.endDateTime ? moment(this.state.endDateTime):undefined} disabled />
                            <Button style={{ marginLeft: '20px' }} onClick={this.getDate} >查询</Button>
                            <Button style={{ marginLeft: '20px' }} onClick={this.print}>打印汇总单</Button>
                            <Button style={{ marginLeft: '20px' }} type="primary" onClick={this.handle}>汇总</Button> 
                        </Col>
                    </Row>
                    <Row style={{ marginTop:'20px' , padding: '0 24px' }}>
                     <Col span={12} >
                     <Table showHeader={false} columns={this.columns} dataSource={this.state.data} pagination={false} style={{ minHeight: '220px' }} bordered></Table>
                     </Col> 
                    </Row>
                </div>
               
            </div>
        )
    }
}