/*
* 待办任务
* */

import React, { Component } from 'react';
import {
    Input, Form, Select, Modal, Button, Progress, Upload, message, Icon, Table,
    Card, Row, Col, DatePicker, Result, Checkbox, Radio, Calendar, Tabs
} from 'antd';
import { Util, dayFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import RangeDatePicker from 'components/rangePicker/index';
import ShowCommonInformationPage from './ShowCommonInformationPage';
import HypertensionPageTabPane from './HypertensionPageTabPane';
import DiabetesPageTabPane from './DiabetesPageTabPane';
import '../style/index.less';
import moment from 'moment';

const Option = Select.Option;
const Search = Input.Search;
const FormItem = Form.Item;
const TabPane = Tabs.TabPane;
const { TextArea } = Input;

class ShowToDealWithTodayModal extends Component {

    constructor(props) {
        super(props);
        var date = new Date();
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        this.state = {
            leftData: [],
            rightData: [],
            userData: userData,
            activeKey: "1",
            startDate: moment(date).format(dayFormat)
        }
    }
    componentWillReceiveProps(nextProp) {
        if (nextProp.isShow === true) {
            this.loadData()
        } else if (this.props.isShow === false) {
            this.cleanInput();
        }
    }

    componentDidMount() {
    }

    loadData() {
        var date = new Date()
        var params = {
            params: [{
                docID: this.state.userData.userID,
                date: this.state.startDate ? moment(this.state.startDate).format(dayFormat) : '',

            }]
        }
        $http.post('urlDeault', this, {
            code: "03070036",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        visitList: res.result,
                        assRecordID: !Util.isEmpty(res.result) ? res.result[0].assRecordID : '',
                        assignmentTypeValue: !Util.isEmpty(res.result) ? res.result[0].assignmentTypeValue : '',
                        patID: !Util.isEmpty(res.result) ? res.result[0].patID : '',
                        hypertension: !Util.isEmpty(res.result) ? res.result[0].hypertension : '',
                        diabetes: !Util.isEmpty(res.result) ? res.result[0].diabetes : '',
                    }, () => {
                        if (!Util.isEmpty(this.state.assignmentTypeValue)) {
                            this.loadRightData()
                        }
                    })
                }
            }
        });
    }



    closeModal(name) {
        let { onHide } = this.props;
        onHide && onHide();
        this.cleanInput();
    }

    //清空输入框
    cleanInput() {
        this.props.form.resetFields();
        this.setState({
            detailData: {}
        })
    }

    startChange(date) {
        this.setState({
            regDateFrom: date,
        })
    }

    endChange(date) {
        this.setState({
            regDateTo: date,
        })
    }


    //提交
    onSubmit() {
        let { onSubmit } = this.props;
        onSubmit && onSubmit(this.state.data, this.state.newCode);
    }

    onPanelChange(e) {
        console.dir(e)
    }

    changeDate(e) {
        this.setState({
            startDate: e
        }, () => {
            this.loadData()
        })
    }

    onSelectDate(e) {
        console.dir(e)
    }

    changeActiveKey(e) {
        this.setState({
            activeKey: e
        })
    }

    handleOnSelectList(data) {
        this.setState({
            assRecordID: data.assRecordID,
            assignmentTypeValue: data.assignmentTypeValue,
            patID: data.patID,
            hypertension: data.hypertension,
            diabetes: data.diabetes
        }, () => {
            this.loadRightData()
        })
    }

    loadRightData() {
        var params = {
            params: [{
                visitRecordID: this.state.assignmentTypeValue,
            }]
        }
        $http.post('urlDeault', this, {
            code: "03070068",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        dataSource: res.result
                    })
                }
            }
        });
    }

    onRefs = ref => {
        this.onRefresh = ref
    }

    render() {
        var dataSourceOption = []
        this.state.visitList && this.state.visitList.map((item, index) => {
            dataSourceOption.push(<div key={index} style={{
                borderBottom: '3px solid #e8e8e8',
                background: item.assRecordID == this.state.assRecordID ? '#bfe6f8' : ''
            }}
                onClick={this.handleOnSelectList.bind(this, item)}>
                <div style={{ color: 'black' }}>{item.startDate}</div>
                <div className='exception-text-ellipisis'>{item.patInfoPC}</div>
            </div>)
        })

        return <div>
            <Modal className='show-information-modal'
                title={'待办任务'}
                maskClosable={false}
                visible={this.props.isShow}
                onCancel={this.closeModal.bind(this)}
                okText='随访完成'
                footer={<div style={{ height: '40px' }}></div>}
                onOk={this.onSubmit.bind(this)}>
                <Card style={{ float: 'left', width: '25%', height: '70vh', overflow: 'auto', background: '#F0F2F5' }}>
                    <Card>
                        <div className="site-calendar-demo-card">
                            <Calendar fullscreen={false} onPanelChange={this.onPanelChange.bind(this)}
                                onChange={this.changeDate.bind(this)}
                                onSelect={this.onSelectDate.bind(this)} />
                        </div>
                    </Card>
                    <Card style={{ marginTop: 2, height: '34vh', overflow: 'auto' }}>
                        {dataSourceOption}
                    </Card>
                </Card>
                <Card style={{ float: 'right', width: '74.8%', height: '70vh', overflow: 'auto', background: '#F0F2F5' }}>
                    <Card style={{ height: '9vh' }}>
                        {this.state.patID ? <ShowCommonInformationPage patID={this.state.patID} onRef={this.onRefs}/> :
                            <div style={{ textAlign: 'center', marginTop: 20 }}>{'暂无病人信息~'}</div>}
                    </Card>

                    <Card style={{ marginTop: 5, height: '59vh', overflow: 'auto' }}>
                        <Tabs type='card' activeKey={this.state.activeKey} onChange={this.changeActiveKey.bind(this)}>
                            {!Util.isEmpty(this.state.hypertension) ? <TabPane tab='高血压随访' key='1'>
                                <HypertensionPageTabPane today={true} assignmentTypeValue={this.state.assignmentTypeValue}
                                    dataSource={this.state.dataSource} patID={this.state.patID}
                                    loadData={this.loadData.bind(this)} />
                            </TabPane> : <Result title={'暂无数据信息~'} status="500" />}
                            {!Util.isEmpty(this.state.diabetes) ? <TabPane tab='糖尿病随访' key='2'>
                                <DiabetesPageTabPane today={true} assignmentTypeValue={this.state.assignmentTypeValue}
                                    dataSource={this.state.dataSource} patID={this.state.patID}
                                    loadData={this.loadData.bind(this)} />
                            </TabPane> : null}
                        </Tabs>
                    </Card>
                </Card>
            </Modal></div>
    }
}

export default Form.create()(ShowToDealWithTodayModal);