/*
 * Creator:     ML
 * CreatDate:   2020-04-30
 * descripts：  居民健康管理体检满意度
 * */
import React from 'react';
import moment from 'moment';
import { dayFormat } from 'tools/index';
import { Form, Col, Select, Icon, Tooltip, Button, Row, Cascader } from 'antd';
import RangeDatePicker from 'components/rangePicker/index';
import { $http } from 'containers/config/https';
import AnalysisChartsConful from './AnalysisChartsConful.jsx';//图表
//组件const
const Option = Select.Option;
const FormItem = Form.Item;
const padding = {
    padding: "0px"
}
const formItemLayout = { // label 和input宽度
    labelCol: { span: 3 },
    wrapperCol: { span: 20 }
}
let formItem815 = {
    labelCol: { span: 8 },
    wrapperCol: { span: 16 }
};
const formItem614 = {
    labelCol: { span: 6 },
    wrapperCol: { span: 14 }
};
const AnalysisPhysical = Form.create()(
    class AnalysisPhysical 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
            };
        }

        componentWillReceiveProps(nextProps) {
        }
        componentDidMount = () => {
            this.props.onAnalysisPhysical(this)
            this.loadInit()
        }
        loadInit = () => {
            this.loadDiseaseArr()
            this.loadDiseaseType()
            this.findData()
        }
        loadDiseaseArr = () => {
            let datas = {}
            datas = {
                params: [{
                    hospID: sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")).hospID : " "
                }],
            }
            $http.post('urlS', this, {
                code: '03070033',
                data: datas,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({
                            diseaseArr: res.result.data
                        })
                    }
                }
            })
        }
        loadDiseaseType() {
            var params = {
                params: [{}]
            }
            $http.post('urlDeault', this, {
                code: "03070018",
                data: params,
                success: function (res) {
                    if (res.errorCode == '0') {
                        this.setState({
                            diseaseType: res.result.fatherArr,
                        })
                    }
                }
            });
        }
        //级联选择
        onChangeDisease(e, selectedOptions) {
            if (selectedOptions.length > 1) {
                this.setState({
                    diseaseID: selectedOptions[1].code
                });
            } else if (selectedOptions.length === 1) {
                this.setState({
                    diseaseID: selectedOptions[0].code
                });
            }
            else {
                this.setState({
                    diseaseID: ''
                });
            }
        }

        //开始日期
        startChange(date) {
            this.setState({
                StartDate: date,
            })
        }
        //结束日期
        endChange(date) {
            this.setState({
                EndDate: date,
            })
        }
        onRefConful = (ref) => {
            this.childPeople = (ref)
        }
        getData(code, data) {
            return new Promise((resolve, reject) => {
                $http.post('urlS', this, {
                    code: code,
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            resolve(res.result);
                        }
                    },
                })
            })
        }
        //查询图表
        findData = () => {
            let data = {}
            data = {
                params: [{
                    hospID: sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")).hospID : " ",

                    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") : "",
                }],
            }
            Promise.all([this.getData("03070113", data), this.getData("03070112", data)]).then(res => {
                // console.log("===", res);
                this.childPeople.getData(
                    res[0] && res[0] || [],
                    res[1] && res[1] || [],
                )
            }).catch(res => {
                // console.log("res", res)
            })

        }

        render() {
            const { getFieldDecorator } = this.props.form;
            const { collArr, diseaseArr, diseaseSubArr, diseaseType, doctorData, statusArr, columns, widthTotal } = this.state;
            var date = new Date();
            let searchColConfig = {
                xs: { span: 24 },
                sm: { span: 12 },
                md: { span: 10 },
                lg: { span: this.props && this.props.modal ? 8 : 7 }
            }


            return (
                <div className="viewSelectDom">
                    <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>
                        <AnalysisChartsConful doctorData={this.state.doctorData} onRefConful={this.onRefConful}></AnalysisChartsConful>
                    </Row>
                </div>
            );
        }
    })
export default AnalysisPhysical
