/*
 * Creator:     ML
 * CreatDate:   2020-04-07
 * descripts：  居民健康管理工作量统计
 * */
import React from 'react';
import moment from 'moment';
import { dayFormat } from 'tools/index';
import { Form, Col, Select, Icon, Tooltip, Button, Row } from 'antd';
import RangeDatePicker from 'components/rangePicker/index';
import { $http } from 'containers/config/https';
import AnalysisChartsWork from './AnalysisChartsWork.jsx';//图表
//组件const
const Option = Select.Option;
const FormItem = Form.Item;
const padding = {
    padding: "0px"
}
const formItemLayout = { // label 和input宽度
    labelCol: { span: 3 },
    wrapperCol: { span: 20 }
}
const formItemLayouts = {
    labelCol: { span: 3 },
    wrapperCol: { span: 24 }
}
const AnalysisWorkloadStatistics = Form.create()(
    class AnalysisWorkloadStatistics extends React.Component {
        constructor(props) {
            super(props);
            var date = new Date();
            this.state = {
                diseaseArr: [],
                diseaseSubArr: [],
                typeArr: [],
                StartDate: moment().startOf('month').format("YYYY-MM-DD"),  // //开始日期
                EndDate: moment(date).format(dayFormat),  // //结束日期
                advicelogMessage: "",
                advicelogVisible: false,
                requid: this.props.requireds,
                requireds: true,
                newNum: "",
                newNumOne: "",
                newNumTwo: "",
                newNumA: "",
                newNumB: ""
            };
        }

        componentWillReceiveProps(nextProps) {
        }
        componentDidMount = () => {
            this.props.onAnalysisWorkloadStatistics(this)
            this.handleGet()
        }
        onRefWork = (ref) => {
            this.childWork = (ref)
        }
        handleGet = () => {
            this.findData()
            // this.findNum()
            // this.getToHos()
            // this.getToHosOne()
        }
        // getNum(code,data){
        //     return new Promise((resolve,reject)=>{
        //         $http.post('urlS', this, {
        //             code: "03070107",
        //             data: data,
        //             success: function (res) {
        //                 if (+res.errorCode === 0) {
        //                     resolve(res.result);
        //                 }
        //             },
        //         })
        //     })
        // }
        //查询咨询全科医生/护士/社工次数 就诊次数
        findNum() {
            let data = {}
            data = {
                params: [{
                    dateFrom: this.state.StartDate || "",
                    dateTo: this.state.EndDate || "",
                    hospID: sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")).hospID : " ",
                    docTypeCode: "01"
                }],
            }
            $http.post('urlS', this, {
                code: "03070107",
                data: data,
                success: function (res) {
                    if (res.errorCode == '0') {
                        this.setState({
                            newNum: res.result
                        })
                    }
                },
            })
            let dataa = {}
            dataa = {
                params: [{
                    dateFrom: this.state.StartDate || "",
                    dateTo: this.state.EndDate || "",
                    hospID: sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")).hospID : " ",
                    docTypeCode: "02"
                }],
            }
            $http.post('urlS', this, {
                code: "03070107",
                data: dataa,
                success: function (res) {
                    if (res.errorCode == '0') {
                        this.setState({
                            newNumA: res.result
                        })
                    }
                },
            })
            let datab = {}
            datab = {
                params: [{
                    dateFrom: this.state.StartDate || "",
                    dateTo: this.state.EndDate || "",
                    hospID: sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")).hospID : " ",
                    docTypeCode: "04"
                }],
            }
            $http.post('urlS', this, {
                code: "03070107",
                data: datab,
                success: function (res) {
                    if (res.errorCode == '0') {
                        this.setState({
                            newNumB: res.result
                        })
                    }
                },
            })

            // "01" 全科 
            // "02" 专科
          
                let dataOne = {}
                dataOne = {
                    params: [{
                        dateFrom: this.state.StartDate || "",
                        dateTo: this.state.EndDate || "",
                        hospID: sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")).hospID : " ",
                        docTypeCode: "01"
                    }],
                }
                $http.post('urlS', this, {
                    code: "03070108",
                    data: dataOne,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            this.setState({
                                newNumOne: res
                            }, () => {
                                console.log("newNumOne",this.state.newNumOne)
                            })
                        }
                    },
                })
                
                let dataTwo = {}
                dataTwo = {
                    params: [{
                        dateFrom: this.state.StartDate || "",
                        dateTo: this.state.EndDate || "",
                        hospID: sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")).hospID : " ",
                        docTypeCode: "02"
                    }],
                }
                $http.post('urlS', this, {
                    code: "03070108",
                    data: dataTwo,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            this.setState({
                                newNumTwo: res
                            }, () => {
                                console.log("newNumTwo",this.state.newNumTwo)
                            })
                        }
                    },
                })
        }
        //查询图表
        getData(code, ) {
            return new Promise((resolve, reject) => {
                let data = {}
                data = {
                    params: [{
                        hospID: sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")).hospID : " ",
                        docTypeCode: code,
                        dateFrom: this.state.StartDate && this.state.StartDate ? moment(this.state.StartDate).format("YYYY-MM-DD") : "",
                        dateTo: this.state.StartDate && this.state.EndDate ? moment(this.state.EndDate).format("YYYY-MM-DD") : "",
                    }],
                }
                $http.post('urlS', this, {
                    code: "03070109",
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            resolve(res.result);
                        }
                    },
                })

            })
        }
        //查询图表 咨询 全科医生 社工 护士
        findData = () => {
            this.findNum()
            this.getToHos()
            this.getToHosOne()
            Promise.all([this.getData("01"), this.getData("03"), this.getData("04")]).then(res => {
                // console.log("===promise", res);
                this.childWork.getData(

                    res[0] && res[0] || [],
                    //  res[0]&&res[0].docCount||0,
                    //  res[0]&&res[0].undisposedCount||0,
                    //  res[0]&&res[0].disposeCount||0,

                    res[1] && res[1] || [],
                    //   res[1]&&res[1].docCount||0,
                    //   res[1]&&res[1].undisposedCount||0,
                    //   res[1]&&res[1].disposeCount||0,


                    res[2] && res[2] || [],
                    //  res[2]&&res[2].docCount||0,
                    //  res[2]&&res[2].undisposedCount||0,
                    //  res[2]&&res[2].disposeCount||0,



                )
                //     res[1].data, res[1].patCount,
                //     res[1].data, res[1].patCount,
                // )
            }).catch(res => {
                // console.log("catch", res)
            })

        }
        //获取医生工作量 专科医生量 就诊数据
        getToHos = () => {

            let dataOne = {}
            dataOne = {
                params: [{
                    hospID: sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")).hospID : " ",
                    docTypeCode: "01",

                    dateFrom: this.state.StartDate && this.state.StartDate ? moment(this.state.StartDate).format("YYYY-MM-DD") : "",
                    dateTo: this.state.StartDate && this.state.EndDate ? moment(this.state.EndDate).format("YYYY-MM-DD") : "",
                }],
            }
            $http.post('urlS', this, {
                code: "03070110",
                data: dataOne,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.childWork.getToHosData(
                            res && res.result || [],
                        )
                    }
                },
            })
        }
        getToHosOne = () => {
            let dataOne = {}
            dataOne = {
                params: [{
                    hospID: sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")).hospID : " ",
                    docTypeCode: "02",
                    dateFrom: this.state.StartDate || "",
                    dateTo: this.state.EndDate || "",
                }],
            }
            $http.post('urlS', this, {
                code: "03070110",
                data: dataOne,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.childWork.getToHosdataOne(
                            res && res.result || [],
                        )
                    }
                },
            })
        }
        //开始日期
        startChange(date) {
            this.setState({
                StartDate: date,
            })
        }
        //结束日期
        endChange(date) {
            this.setState({
                EndDate: date,
            })
        }

        render() {
            const { getFieldDecorator } = this.props.form;
            const { newNum, newNumOne, newNumA, newNumB ,newNumTwo} = this.state;
            let searchColConfig = {
                xs: { span: 24 },
                sm: { span: 12 },
                md: { span: 10 },
                lg: { span: this.props && this.props.modal ? 8 : 7 }
            }

            return (
                <div className="viewDom">
                    <Row>
                        <Form>
                            <Col {...searchColConfig} style={{ padding: "4px 0" }}>
                                <RangeDatePicker isChange={true} label={this.props.locale && this.props.locale == 'EN' ? 'Date' : '日期：'} format='YYYY-MM-DD' width={378}
                                    startDate={this.state.StartDate} endDate={this.state.EndDate}
                                    startChange={this.startChange.bind(this)} endChange={this.endChange.bind(this)} />
                            </Col>
                            <Col span={2} style={{ paddingLeft: "0" }}>
                                <FormItem  {...formItemLayout}>
                                    {getFieldDecorator('findData', {
                                        initialValue: undefined,
                                        rules: [{ required: false, message: '' }],
                                    })(
                                        <div style={{ display: "flex", marginTop: "4px" }}>
                                            <Button style={{ margin: "0 18px 0 18px" }} onClick={this.findData} type="primary">查询</Button>
                                        </div>
                                    )}
                                </FormItem>
                            </Col>
                        </Form>
                    </Row>
                    <Row className="workNum-dom">
                        <div className="garyLine"></div>
                        <p>
                            <span style={{ margin: "0" }}>总计：</span>
                            <span>咨询全科医生<i>{newNum && newNum}</i>次</span>
                            <span>就诊次数(全科医生)<i>{newNumOne && newNumOne.result}</i>次<b><span>({newNumOne && newNumOne.effectCount}/</span><span>{newNumOne && newNumOne.ineffectCount})</span></b></span>
                            <span>咨询护士<i>{newNumA}</i>次</span>
                            <span>就诊次数(专科医生)<i>{newNumTwo && newNumTwo.result}</i>次<b><span>({newNumTwo && newNumTwo.effectCount}/</span><span>{newNumTwo && newNumTwo.ineffectCount})</span></b></span>
                            <span>咨询社工<i>{newNumB && newNumB}</i>次</span>
                            <span>电话呼叫社工<i>{0}</i>次</span>
                        </p>
                        <div className="garyLine"></div>
                    </Row>
                    <Row>
                        <AnalysisChartsWork onRefWork={this.onRefWork}></AnalysisChartsWork>
                    </Row>
                </div>
            );
        }
    })
export default AnalysisWorkloadStatistics
