//填写麻醉信息
import React from 'react';
import { Form, message, Modal, Row, Col, Tabs } from 'antd';
import { $http } from 'containers/config/https';
import { Util } from 'tools/index';
// import FormItem from 'antd/lib/form/FormItem';
// import TextArea from 'antd/lib/input/TextArea';
// import Moment from 'moment';
// import PatientInfo from '../Patient/PatientInfo';
import RegAfterOperation from './RegAfterOperation';
// import OperationSearchModel from './OperationSearchModel';
import OperationApply from './OperationApply';
import './style/OperationSearchModel.less';
// const FormItem = Form.Item;
const { TabPane } = Tabs;
// const { Option } = Select;
// 用户数据
let userData;
// 点击编辑时记录当前行数据
// let tableRecord = {};
// 创建表单
const AnesthesiaModel = Form.create()(
	class extends React.Component {
		constructor(props) {
			super(props);
			let patientData = JSON.parse(sessionStorage.getItem('patientData'));
			userData = sessionStorage.userData ? JSON.parse(sessionStorage.userData) : {};
			this.state = {
				visible: false,//弹框显示状态
				patientData: patientData,
				activeKey: ''
			}
		}

		componentDidMount() {
			this.props.onRef(this);
		}

		componentWillReceiveProps(nextProps) {
			if (!Util.isEmpty(nextProps.activeKey)) {
				this.setState({ activeKey: nextProps.activeKey })
			}
		}

		// 关闭
		close = (e) => {
			this.setState({
				visible: false,
			});
			this.props.handleQuery();
		};

		// 打开弹框
		showModal = () => {
			this.loadPatientMsg()//获取接诊病人信息
			let patientData = JSON.parse(sessionStorage.getItem('patientData'))
			if ((!patientData) || (patientData.admID == '')) {
				message.warning('请选择患者');
			}
			this.setState({
				visible: true,
			});
		};

		changeActiveKey(e) {
			var isShow = false
			if (e == '3') {
				isShow = true
			}
			this.setState({
				activeKey: e,
				isShow: isShow
			})
		}

		loadPatientMsg() {
			let patientData = JSON.parse(sessionStorage.getItem('patientData'))
			if (!patientData || patientData.admID == '') {
				return;
			}
			var params = {
				params: [{
					admID: patientData.admID ? patientData.admID : '',
					userID: userData.userID
				}]
			}
			$http.post('urlDeault', this, {
				code: "04020007",
				data: params,
				success: function (res) {
					//	console.log(res)
					if (res.errorCode == '0') {
						sessionStorage.setItem('titleData', JSON.stringify(res.result))
						this.setState({
							titleData: res.result,
						})
					}
				}
			});
		};

		// 保存成功后回调
		handleSaveCollBack = () => {
			this.close();
			this.props?.getCallMsg();
		}

		render() {
			// const { getFieldDecorator } = this.props.form;
			// const formItemLayout = {    // label 和input宽度
			// 	labelCol: { span: 5 },
			// 	wrapperCol: { span: 19 },
			// };
			// const formItemLayoutAdd = {    // label 和input宽度
			// 	labelCol: { span: 8 },
			// 	wrapperCol: { span: 16 },
			// };
			// const formItemLayoutLong1 = {
			// 	labelCol: { span: 1 },
			// 	wrapperCol: { span: 23 },
			// }
			return (
				<Modal
					width={'96%'}
					// height="882px"
					title="术后登记"
					visible={this.state.visible}
					onCancel={this.close}
					footer={null}
					bodyStyle={{
						height: '82vh',
						padding: 0
					}}
					className="anesthesia-model"
					style={{ top: '76px' }}
				>
					<div className="outpatient-station-body">
						<Row style={{ background: 'rgba(248,248,248)', height: '45px', textAlign: 'left', lineHeight: '45px' }}>
							<Col span={24} style={{ display: 'flex' }}>
								<div style={{ width: '100%', height: 45, display: 'flex' }}>
									<div className="ther" style={{ display: 'flex', flexShrink: '1', flex: '0 0 auto', width: 100 }}>
										<div className={this.state.titleData && this.state.titleData.basicInfo.patSexCode == '1' ?
											'splice-Boy' : (this.state.titleData && this.state.titleData.basicInfo.patSexCode == '2' ? 'splice-Girl' : 'splice-ther')}></div>
										{/* <span className="bed">{this.state.titleData ? this.state.titleData.admInfo.admBedCode : ''}</span> */}
										{/* <span>床号</span> */}
									</div>
									<div style={{ display: 'flex', flex: '1 1 auto' }}>
										<div style={{ padding: '10px 0 0 20px' }} className="item">
											<div>
												<span className="bed">{this.state.titleData ? this.state.titleData.admInfo.admBedCode : ''}</span>
												<i className="icon"></i>
												<span>{this.state.titleData ? this.state.titleData.basicInfo.patName : ''}</span>
											</div>
											<div>
												<i className="icon"></i>
												<span>{this.state.titleData ? this.state.titleData.basicInfo.patSexDesc : ''}</span>
											</div>
											<div>
												<i className="icon"></i>
												<span>{this.state.titleData ? this.state.titleData.basicInfo.patAge : ''}</span>
											</div>
											<div>
												<i className="icon"></i>
												<span>{this.state.titleData ? this.state.titleData.admInfo.admLocDesc : ''}</span>
											</div>
											<div>
												<i className="icon"></i>
												<span>{this.state.titleData ? this.state.titleData.admInfo.admWardDesc : ''}</span>
											</div>
											{/* <div>
												<i className="icon"></i>
												<span>{this.state.titleData ? this.state.titleData.basicInfo.patBirthDate : ''}</span>
												<span>{this.state.titleData ? this.state.titleData.basicInfo.patBirthTime : ''}</span>
											</div> */}
										</div>
									</div>
								</div>
							</Col>
						</Row>
						<div className="tabs" style={{ marginTop: '12px' }}>
							<Tabs type="card" activeKey={this.state.activeKey} onChange={this.changeActiveKey.bind(this)}>
								<TabPane tab={<span>申请单</span>} key="1">
									<div style={{ height: '84vh' }}>
										<OperationApply
											operationID={this.props.operationID}
											close={this.close}
											parentVisible={this.state.visible}
										/>
									</div>

								</TabPane>
								{/* <TabPane tab={<span>麻醉信息</span>} key="2">
									<Form style={{ minHeight: '400px',padding: '21px 7px' }}>
										<Row>
											<Col span={6} style={{ paddingRight: '15px' }}>
												<FormItem {...formItemLayout} label='麻醉医生'>
													{getFieldDecorator('opera', {
														initialValue: '',
														// rules: [{ required: true, message: '请选择...', }]
													})(
														<Select showSearch allowClear optionFilterProp="role" >
														</Select>
													)}
												</FormItem>
											</Col>
											<Col span={6} style={{ paddingRight: '15px' }}>
												<FormItem {...formItemLayout} label='指导医师'>
													{getFieldDecorator('RoomID', {
														initialValue: '',
														// rules: [{ required: true, message: '请选择...', }]
													})(
														<Select showSearch allowClear optionFilterProp="role" >
														</Select>
													)}
												</FormItem>
											</Col>
											<Col span={6} style={{ paddingRight: '15px' }}>
												<FormItem {...formItemLayout} label='麻醉护士'>
													{getFieldDecorator('ID', {
														initialValue: '',
														// rules: [{ required: true, message: '请选择...', }]
													})(
														<Select showSearch allowClear optionFilterProp="role" >
														</Select>
													)}
												</FormItem>
											</Col>
											<Col span={6} style={{ paddingRight: '15px' }}>
												<FormItem {...formItemLayout} label='麻醉助手'>
													{getFieldDecorator('messa', {
														initialValue: '',
														// rules: [{ required: true, message: '请选择...', }]
													})(
														<Select showSearch allowClear optionFilterProp="role" >
														</Select>
													)}
												</FormItem>
											</Col>
										</Row>
										<Row>
											<Col span={6} style={{ paddingRight: '15px' }}>
												<FormItem {...formItemLayout} label='交麻醉师'>
													{getFieldDecorator('tionRoomID', {
														initialValue: '',
														// rules: [{ required: true, message: '请选择...', }]
													})(
														<Select showSearch allowClear optionFilterProp="role" >
														</Select>
													)}
												</FormItem>
											</Col>
											<Col span={6} style={{ paddingRight: '15px' }}>
												<FormItem {...formItemLayout} label='麻醉规模'>
													{getFieldDecorator('DocID', {
														initialValue: '',
														// rules: [{ required: true, message: '请选择...', }]
													})(
														<Select showSearch allowClear optionFilterProp="role" >
														</Select>
													)}
												</FormItem>
											</Col>
											<Col span={6} style={{ paddingRight: '15px' }}>
												<FormItem {...formItemLayout} label='麻醉方法'>
													{getFieldDecorator('assistan', {
														initialValue: '',
														// rules: [{ required: true, message: '请选择...', }]
													})(
														<Select showSearch allowClear optionFilterProp="role" >

														</Select>
													)}
												</FormItem>
											</Col>
										</Row>
										<Row>
											<Col span={24} style={{ padding: '0 10px 10px' }}>
												<FormItem {...formItemLayoutLong1} label="备注">
													{getFieldDecorator('Evaluate', {
														initialValue: '',
														rules: [{ required: '', message: '请填写备注' }]
													})(
														<TextArea style={{ marginTop: '10px' }} autosize={{ minRows: 2, maxRows: 6 }} />
													)}
												</FormItem>
											</Col>
										</Row>
									</Form>
									<Row>
										<Col span={1} offset={11}>
											<FormItem>
												<Button
													type='primary'
													htmlType="submit"
													// onClick={this.save.bind(this, 'SA')}
													disabled={this.state.clickFlag ? true : this.state.disabledAll}
												>保存
                                    				</Button>
											</FormItem>
										</Col>
										<Col span={1}>
											<FormItem>
												<Button
												    style={{marginLeft:'20px'}}
													type='primary'
													htmlType="submit"
													// onClick={this.save.bind(this, 'CAL')}
													disabled={this.state.clickFlag ? true : this.state.disabledAll}
												>取消
                                    				</Button>
											</FormItem>
										</Col>
									</Row>
								</TabPane> */}
								<TabPane key='3'
									tab={<span>术后登记</span>}
								>
									<RegAfterOperation
										operationID={this.props.operationID}
										isShow={this.state.isShow}
										close={this.close}
										status={this.props.status}
										handleSaveCollBack={this.handleSaveCollBack}
									/>
								</TabPane>
							</Tabs>
						</div>
					</div>
				</Modal>
			)
		}
	}
);

export default AnesthesiaModel;
