/*
 * Creator:     ML
 * CreatDate:   2019-12-27
 * descripts：  治疗室----录入治疗信息
 * */
import React from 'react';
import { Form, Row, Col, Input, Select, Button, DatePicker, Modal, Table, Icon, Card, message, Divider, Tooltip, Checkbox } from 'antd';
import moment from 'moment';
import { $http } from 'containers/config/https';
import PatInfo from './PatInfo'
import '../style/index.less'
import TreatmentContent from './TreatmentContent'
const FormItem = Form.Item;
const paddRightCol = {
    paddingRight: "0px"
}
const formItemLayout = { // label 和input宽度
    labelCol: { span: 9 },
    wrapperCol: { span: 15 },
}
const TreatmentAddModal = Form.create()(
    class TreatmentAddModal extends React.Component {
        constructor(props) {
            super(props)
            this.state = {
                visible: false,
                baseParms: {},
                edit: -1,
                params: {},
                id: "",
            }
        }
        componentDidMount() {
            this.props.OnChildrefs(this);
        }
        onContent=(ref)=>{
            this.onHisContent=ref
        }
        onPat=(ref)=>{
            this.onChildPat=ref
        }
        showModal = (record, localeProvider) => {
            // this.onChildPat.getInfo()
            this.setState({
                visible: true,
                record,
                localeProvider,
            },()=>{
                setTimeout(()=>{
                    this.onChildPat.getInfo()
                    this.onHisContent.initialForm()
                },100)
            })
            //历次治疗展示
            if (record && record.cureRecordID) {
               //载入之前的完成治疗数据
               setTimeout(()=>{
                this.onHisContent.handleOnOpenChangeStop()
                this.onHisContent.handleOnOpenChangeStart()
                this.onHisContent.getHisContent(record.cureRecordID)
               },100)
             
            }else{
                //录入新的完成治疗记录
               setTimeout(()=>{
                this.onHisContent.handleOnOpenChangeStop()
                this.onHisContent.handleOnOpenChangeStart()
                this.onHisContent.getContent()
                this.onHisContent.autoTime(moment(record.bookDate).format('YYYY-MM-DD'),moment(record.bookDate).format('YYYY-MM-DD'),record.bookStartTime,moment(moment()).format('HH:MM'))
               },100)
            }
        }
        handleCancel = (judge) => {
            this.props.form.resetFields();
            this.setState({ visible: false, params: {}, edit: -1, id: "" });
        }
        handleSubmit(judge){
            var {onSubmit} = this.props;
            onSubmit && onSubmit(judge)
        }
        upData=()=>{
            this.handleCancel()
            this.props.getFindDate()
        }
         //国际化
         setMessage(name, message) {
            return this.state.localeProvider ? this.state.localeProvider[name][message] : ''
        }
        render() {
            const { getFieldDecorator, } = this.props.form;
            const { record } = this.state

            return (
                <div className="hisDom">
                    <Modal
                        className='addEditDom'
                        width='1000px'
                        visible={this.state.visible}
                        title={record && !record.cureRecordID?(this.state.localeProvider && this.state.localeProvider.BookRecordPleaseEnterTreatmentInformatio? this.setMessage('BookRecordPleaseEnterTreatmentInformatio', 'descripts') : "请录入治疗信息"):(this.state.localeProvider && this.state.localeProvider.BookRecordPleaseModifyTreatment? this.setMessage('BookRecordPleaseModifyTreatment', 'descripts') : "请编辑治疗信息")} 
                        onOk={this.handleOk}
                        onCancel={this.handleCancel}
                        footer={null}
                        >
                        <div className="department-header">
                            <Card><PatInfo onPat={this.onPat} localeProvider={this.state.localeProvider} record={this.state.record}></PatInfo></Card>
                            <Card><TreatmentContent localeProvider={this.state.localeProvider} handleCancel={this.upData}
                            onSubmit={this.handleSubmit.bind(this)}
                            records={this.state.record} rowIds={this.state.record&&this.state.record.cureRecordID?this.state.record.cureRecordID:""}  cureAppID={this.state.record&&this.state.record.cureAppID || ""} onContent={this.onContent}></TreatmentContent></Card>
                        </div>
                    </Modal>
                </div>
            )
        }
    })
export default TreatmentAddModal    