/*
 * Creator:     ML
 * CreatDate:   2020-04-08
 * descripts：  问卷调查
 * */
import React from 'react';
import {
    Card, Table, Input, Form, Select, Row, Col, Checkbox, Tabs,
    DatePicker, Button, Popconfirm, Icon, Divider, message, Modal,
} from 'antd';
// import { Util, dayFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import store from 'store';
import './style/StatisticalAnalysis.less';
import './style/assessment.less';
import AssessmentLeftList from './component/AssessmentLeftList'
import AssessmentSelfCareAbility from './component/AssessmentSelfCareAbility.jsx';//自理能力评估
import AssessmentPsychological from './component/AssessmentPsychological.jsx';//心理评估
import AssessmentFRAX from './component/AssessmentFRAX.jsx';//骨质疏松(原) FRAX评分
import AssessmentOsteoporosis from './component/AssessmentOsteoporosis.jsx';//骨质疏松一分钟问卷

// import AssessmentMMSE from './component/AssessmentMMSE.jsx';//MMSE
// import AssessmentIADL from './component/AssessmentIADL.jsx';//IADL
// import AssessmentHADS from './component/AssessmentHADS.jsx';//HADS
// import AssessmentADCTab from './component/AssessmentADCTab.jsx';//HADS
import AssessmentConsTab from './component/AssessmentConsTab.jsx';//中医体质辨识
import AssessmentHeartSieve from './component/AssessmentHeartSieve.jsx';//老年人心筛能力评分
const TabPane = Tabs.TabPane;
const confirm = Modal.confirm;
class QuestionnairePage extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'))
        this.state = {
            dataSource: [],
            total: 0,
            page: 1,
            pageSize: 10,
            userData: userData,
            activeKeys: '1',
            pressObj: {}
        }
    }

    componentDidMount() {
        this.props.ques(this)
        this.getPress()
        window.sessionStorage.setItem("noSave", false);
    }
    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }
  
    getPress = () => {
        let data = {}
        data = {
            params: [{
                patID: JSON.parse(sessionStorage.getItem('patID')) || "",
            }],
        }
        $http.post('urlS', this, {
            code: '03070028',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    var params = {
                        params: [{
                            userID: this.state.userData.userID,
                            hospID: this.state.userData.hospID,
                            healthRecordID: JSON.parse(sessionStorage.getItem('healthRecordID')) || "",
                            sexCode:res.result[0].patSexCode || "",
                            age:res.result[0].patAge&&parseInt(res.result[0].patAge) || "",
                        }]
                    }
                    $http.post('urlS', this, {
                        code: "03070116",
                        data: params,
                        success: function (res) {
                            let obj = res.result
                            obj.a19 = parseInt(Number(obj.a19) * 100)
                            obj.a20 = parseInt(Number(obj.a20) * 100)
                            obj.a21 = parseInt(Number(obj.a21) * 100)
                            obj.a22 = parseInt(Number(obj.a22) * 100)
                            obj.a23 = parseInt(Number(obj.a23) * 100)
                            obj.a33 = parseInt(Number(obj.a33) * 100)
                            this.setState({
                                pressObj: obj
                            })
                            // console.log("0-0-0-",obj)
                        }
                    })
                }
            }
        })
      
    }
    // 导航栏切换
    callback = (key) => {
        var that = this;
        if (sessionStorage.getItem("noSave") && JSON.parse(sessionStorage.getItem("noSave")) === true) {
            confirm({
                title: '提示',
                content: '当前页面数据还没保存，确定要切换页面吗？',
                okText:  '确定',
                cancelText: '取消',
                onOk() {
                    window.sessionStorage.setItem("noSave",false);
                    that.setState({ activeKeys: key },()=>{
                        window.sessionStorage.setItem("noSave",false);
                        that.clearAll()
                        that.getDocID()
                    })
                },
                onCancel() {
                    return
                }
            })
        } else {
            that.setState({ activeKeys: key },()=>{
                that.clearAll()
                that.getDocID()
            })
        }
    }
    handleTo = (key) => {
        // console.log(key)
        let obj = {
            "1": () => this.childSelf.setValue(this.childrecord.state.detailsId),
            "2": () => this.childConsTab.handleSetValue(this.childrecord.state.detailsId),
            "3": () => this.childConsPsy.setValue(this.childrecord.state.detailsId),
            "4": () => this.childonFRAX.setValue(this.childrecord.state.detailsId),
            "5": () => this.childheart.setValue(this.childrecord.state.detailsId),
            "6": () => this.childOso.setValue(this.childrecord.state.detailsId),
            // "7": () => this.childIADL.setValue(this.childrecord.state.detailsId),
            // "8": () => this.childHADS.setValue(this.childrecord.state.detailsId),
            // "9": () => this.childAdcTab.handleSetValue(this.childrecord.state.detailsId),
        }
        if (obj[key]) {
            obj[key]()
        }
        // debugger
    }
    //获取体检责任医师
    getDocID = (f) => {
        // console.log("getDocID",this.childrecord.state.detailsId )
        // console.log("this.state.activeKeys22222",this.state.activeKeys)
        if (this.childrecord.state.detailsId && this.childrecord.state.detailsId) {
            // console.log(this.childrecord.state.detailsId,"---------",id)
            this.setState({
                doctorID: this.childrecord.state.detailsId
            }, () => {
                // console.log("this.state.activeKeys",this.state.activeKeys)
                this.handleTo(this.state.activeKeys)
                if(this.state.activeKeys=="2"){
                    //中医体质辨识回到第一步骤
                    if(f){
                        this.childConsTab.handleHome()
                    }
                }

            })
        }
    }
    handleClear = (key, d) => {
        // console.log(key)
        let obj = {
            "1": () => this.childSelf.clear(d),
            "2": () => this.childConsTab.handleClear(d),
            "3": () => this.childConsPsy.clear(d),
            "4": () => this.childonFRAX.clear(d),
            "5": () => this.childheart.clear(d),
            "6": () => this.childOso.clear(d),
            // "7": () => this.childIADL.clear(d),
            // "8": () => this.childHADS.clear(d),
            // "9": () => this.childAdcTab.handleClear(d),
        }
        if (obj[key]) {
            obj[key]()
        }
        // debugger
    }
    //清除调查问卷
    clearAll = () => {
        this.handleClear(this.state.activeKeys, "d")
    }
    //添加问卷调查 新增一条体检记录
    updateList = () => {
        this.childrecord.initialData()
    }
    onRef = (ref) => {
        this.childrecord = ref
    }
    onSelf = (ref) => {
        this.childSelf = ref
    }
    onConsTab = (ref) => {
        this.childConsTab = ref
    }
    onAdcTab = (ref) => {
        this.childAdcTab = ref
    }
    onConsPsy = (ref) => {
        this.childConsPsy = ref
    }
    onFRAX = (ref) => {
        this.childonFRAX = ref
    }
    onheart = (ref) => {
        this.childheart = ref
    }
    MMSE = (ref) => {
        this.childMMSE = ref
    }
    IADL = (ref) => {
        this.childIADL = ref
    }
    HADS = (ref) => {
        this.childHADS = ref
    }
    onOso = (ref) => {
        this.childOso = ref
    }
    render() {
        let tabsHeight = store.getState().tableHeight.y + 352 + 'px';
        const { pressObj } = this.state
        return <div className='out-patient-service-body tabs-dom'>
            <Row style={{ display: "flex" }}>
                <Col className='recordingLeft' stryle={{ height: store.getState().tableHeight.y + 82 + 'px' }} >
                    <AssessmentLeftList onRef={this.onRef} tabThis={this} />
                </Col>
                <Col className='recordingRight' style={{ height: store.getState().tableHeight.y + 82 + 'px' }}>
                    <Tabs
                        activeKey={this.state.activeKeys}
                        onChange={this.callback}
                        tabPosition="left"
                        type="card"
                        //    className="new_department_tabs"
                        style={{ width: '100%', height:  store.getState().tableHeight.y + 82 + 'px' }}
                    >
                        <TabPane tab={<span>自理能力评估<span className={pressObj.a19 && pressObj.a19 == 100 ? "successNumber" : pressObj.a19 && pressObj.a19 > 0 ? "pressNumber" : "warningNumber"}>{pressObj.a19 && pressObj.a19 ? "(" + pressObj.a19 + "%" + ")" : "(0%)"}</span></span>} key="1">
                            <AssessmentSelfCareAbility onSelf={this.onSelf} updateList={this.updateList} getPress={this.getPress} doctorID={this.state.doctorID} />
                        </TabPane>
                        <TabPane tab={<span>中医体质辨识<span className={pressObj.a20 && pressObj.a20 == 100 ? "successNumber" : pressObj.a20 && pressObj.a20 > 0 ? "pressNumber" : "warningNumber"}>{pressObj.a20 && pressObj.a20 ? "(" + pressObj.a20 + "%" + ")" : "(0%)"}</span></span>} key="2">
                            <AssessmentConsTab onConsTab={this.onConsTab} updateList={this.updateList} getPress={this.getPress} doctorID={this.state.doctorID} />
                        </TabPane>
                        <TabPane tab={<span>心理评估<span className={pressObj.a21 && pressObj.a21 == 100 ? "successNumber" : pressObj.a21 && pressObj.a21 > 0 ? "pressNumber" : "warningNumber"}>{pressObj.a21 && pressObj.a21 ? "(" + pressObj.a21 + "%" + ")" : "(0%)"}</span></span>} key="3">
                            <AssessmentPsychological onConsPsy={this.onConsPsy} updateList={this.updateList} getPress={this.getPress} doctorID={this.state.doctorID} />
                        </TabPane>
                        <TabPane tab={<span>FRAX评分<span className={pressObj.a22 && pressObj.a22 == 100 ? "successNumber" : pressObj.a22 && pressObj.a22 > 0 ? "pressNumber" : "warningNumber"}>{pressObj.a22 && pressObj.a22 ? "(" + pressObj.a22 + "%" + ")" : "(0%)"}</span></span>} key="4">
                            <AssessmentFRAX onFRAX={this.onFRAX} updateList={this.updateList} getPress={this.getPress} doctorID={this.state.doctorID} />
                        </TabPane>
                        <TabPane tab={<span>心血管疾病早期筛查<span className={pressObj.a23 && pressObj.a23 == 100 ? "successNumber" : pressObj.a23 && pressObj.a23 > 0 ? "pressNumber" : "warningNumber"}>{pressObj.a23 && pressObj.a23 ? "(" + pressObj.a23 + "%" + ")" : "(0%)"}</span></span>} key="5">
                            <AssessmentHeartSieve onheart={this.onheart} updateList={this.updateList} getPress={this.getPress} doctorID={this.state.doctorID} />
                        </TabPane>
                        <TabPane tab={<span>骨质疏松一分钟问卷<span className={pressObj.a33 && pressObj.a33 == 100 ? "successNumber" : pressObj.a33 && pressObj.a33 > 0 ? "pressNumber" : "warningNumber"}>{pressObj.a33 && pressObj.a33 ? "(" + pressObj.a33 + "%" + ")" : "(0%)"}</span></span>} key="6">
                            <AssessmentOsteoporosis onOso={this.onOso} updateList={this.updateList} getPress={this.getPress} doctorID={this.state.doctorID} />
                        </TabPane>
                     
                        
                        {/* <TabPane tab="ADC评分" key="9">
                            <AssessmentADCTab onAdcTab={this.onAdcTab} updateList={this.updateList} doctorID={this.state.doctorID} />
                        </TabPane> */}
                    </Tabs>
                </Col>
            </Row>

        </div>
    }

}

export default QuestionnairePage;