/**
 * 新建治疗申请
 */
import React from 'react';
import {
    Modal, Row, Col, Select, Card, Radio, Input, Button, Tree, Icon, Tag, Table,
    Divider, message, DatePicker
} from 'antd';
import { Util, dayFormat, timeFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import ReadCard from 'components/readcard/ReadCard';
import '../style/index.less';
import moment from 'moment';

const Option = Select.Option;
const confirm = Modal.confirm;
const Search = Input.Search;
const RadioGroup = Radio.Group;
const { TextArea } = Input;

class ShowApplicationDetailModal extends React.Component {

    constructor(props) {
        super(props);
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        var date = new Date()
        this.state = {
            userData: userData,
            radioValue: '1',
            ids: [],
            dataSource: [],
            dateTime: moment(date).format(dayFormat),
            bookScheduleID: []
        }
    }
    componentWillReceiveProps(nextProp) {
        if (nextProp.isShow === true) {
            this.setState({
                cureAppID: nextProp.cureAppID
            }, () => {
                this.loadApplicationDetail()
                this.initData()
            })
        } else if (this.props.isShow === false) {
            this.clearInput()
        }
    }

    initData() {
        let data = {
            params: [{
                type: "C",
                reactCode: ['isShowApplicationDetailModal']
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040073",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        localeProvider: this.state.userData.language == 'EN' ? res.result.language.EN : res.result.language.CN
                    })
                }
            }
        })
    }

    //国际化
    setMessage(name, message) {
        return this.state.localeProvider && this.state.localeProvider[name] ? this.state.localeProvider[name][message] : ''
    }

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

    clearInput() {
        this.setState({
        })
    }

    loadApplicationDetail() {
        var params = {
            params: [{
                userID: this.state.userData.userID,
                cureAppID: this.state.cureAppID
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040196",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        appDetail: res.result.data[0]
                    })
                }
            }
        });
    }

    onSubmit() {
        var { onSubmit } = this.props;
        onSubmit && onSubmit()
    }

    render() {
        var { appDetail } = this.state;
        //卡类型
        let cardTypeOption = []
        this.state.cardTypeData && this.state.cardTypeData.map((item, index) => {
            cardTypeOption.push(<Option key={index} value={item.id} code={item.descripts}>{item.descripts}</Option>)
        })

        //坐诊医生
        let doctorOption = []
        this.state.doctorData && this.state.doctorData.map((item, index) => {
            doctorOption.push(<Option key={index} value={item.id} code={item.descriptsSPCode} name={item.descripts}>
                {item.descripts}</Option>)
        })

        let timeRangeOption = []
        this.state.timeRange && this.state.timeRange.map((item, index) => {
            timeRangeOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
        })
        //申请单项目
        let appProgramOption = []
        this.state.appProgram && this.state.appProgram.map((item, index) => {
            appProgramOption.push(<Option key={index} value={item.medItemID}>{item.medItemDesc}</Option>)
        })

        return <div className='show-application-modal'>
            <ReadCard ref={ref => this.readCard = ref}></ReadCard>
            <Modal className='confirm-detail-modal'
                title={this.setMessage('isShowApplicationDetailModalform','descripts')}
                maskClosable={false}
                footer={null}
                visible={this.props.isShow}
                onOk={this.onSubmit.bind(this)}
                okText='保存'
                onCancel={this.closeModal.bind(this)}>
                <div style={{ width: '100%' }}>
                    <Card title={<div style={{ display: 'flex' }}>
                        <Icon className={this.state.appDetail && this.state.appDetail.sexCode == '1' ? 'application-detail-boy' :
                            (this.state.appDetail && this.state.appDetail.sexCode == '2' ? 'application-detail-girl' : 'application-detail-none')} />
                        <div style={{ marginLeft: 10, marginTop: '20px', color: '#666666' }}>
                            <Icon className='patNo-splice' />{this.state.appDetail && this.state.appDetail.patName}</div>
                        <div style={{ marginLeft: 10, marginTop: '20px', color: '#666666' }}>
                            <Icon className='patNo-splice' />{this.state.appDetail && this.state.appDetail.patSex}</div>
                        <div style={{ marginLeft: 10, marginTop: '20px', color: '#666666' }}>
                            <Icon className='patNo-splice' />{this.state.appDetail && this.state.appDetail.age}</div>
                        <div style={{ marginLeft: 10, marginTop: '20px', color: '#666666' }}>
                            <Icon className='patNo-splice' />{this.state.appDetail && this.state.appDetail.birthDate + this.state.appDetail && this.state.appDetail.birthTime}</div>
                        <div style={{ marginLeft: 10, marginTop: '20px', color: '#666666' }}>
                            <Icon className='patNo-splice' />{this.state.appDetail && this.state.appDetail.diagnosis}</div>
                    </div>}>
                        <div>
                        {this.setMessage('isShowApplicationDetailModalApplication','descripts')}<span>{this.state.appDetail && this.state.appDetail.appOrder}</span>
                        </div>
                        <div>
                            <span>{this.setMessage('isShowApplicationDetailModalTime','descripts')}<span>{this.state.appDetail && this.state.appDetail.applyTime}</span></span>
                            <span style={{ marginLeft: 10 }}>{this.setMessage('isShowApplicationDetailModalDepartment','descripts')}<span>{this.state.appDetail && this.state.appDetail.appLoc}</span></span>
                            <span style={{ marginLeft: 10 }}>{this.setMessage('isShowApplicationDetailModalDoctor','descripts')}<span>{this.state.appDetail && this.state.appDetail.appDoctor}</span></span>
                        </div>
                        <div style={{ marginTop: 10 }}>{this.setMessage('isShowApplicationDetailModalplan','descripts')}<TextArea rows={4} disabled={true} value={this.state.appDetail && this.state.appDetail.appPlan} /></div>
                        <div style={{ marginTop: 10 }}>{this.setMessage('isShowApplicationDetailModalobjectives','descripts')}<TextArea rows={4} disabled={true} value={this.state.appDetail && this.state.appDetail.note} /></div>
                    </Card>
                </div>
            </Modal>
        </div>
    }
}

export default ShowApplicationDetailModal;