import React, { Component } from 'react';
import { Timeline, message, Row, Col, Card } from 'antd';
import { $http } from '../../../containers/config/https';
import '../BedChart/CSS/bedchart.less'

const TimeItem = Timeline.Item;

class PatientProcess extends Component {
	constructor(props) {
		super(props);
		this.state = {
			processData: [],
			title: "病区信息",
			admID: "",
			skinTestData: []
		}
	}

	componentWillReceiveProps(nextProps) {
		if ((this.props.admID !== nextProps.admID) || (nextProps.reloading)) {
			this.setState({ admID: nextProps.admID })
			if (nextProps.admID !== "" && nextProps.admID !== this.state.admID) {
				this.getPatientProcess(nextProps.admID);
			}
			else {
				//未点击患者
				this.setState({ title: "病区信息" });
			}
		}
	}

	componentWillUnmount() {
		this.setState = (state, callback) => {
			return
		}
	}

	componentDidMount() {
		this.getSkinTestData()
	}

	getPatientProcess = (admID) => {
		let data = {
			params: [{
				admID: admID,
				type: "2"
			}]
		}
		$http.post('urlDeault', this, {
			code: "03030001",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					this.setState({ processData: res.result, title: "患者就诊流程信息" });
				} else {
					message.error('未获取到患者流程信息' + e.errorMessage);
				}
			}
		})
	}

	getSkinTestData = (record) => {
		let data = {
			"params": [{
				wardID: this.props.locID
			}]
		};

		$http.post('urlDeault', this, {
			code: "04020013",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					this.setState({
						skinTestData: res.result
					})
				}
			},
			error: function (error) {
				message.error('获取患者皮试信息失败：' + error);
			}
		});
	}

	render() {
		let content = (this.state.admID ?
			<Timeline mode="left" className="process">
				{
					this.state.processData.map(
						(item) => {
							return (
								<TimeItem key={item.id} >
									<div>
										<span className="eventFont">

											{item.processDescripts}
										</span><br />
										<span className="dateFont">
											{item.eventDate + " " + item.eventTime}
										</span>
									</div>
								</TimeItem>
							);
						}
					)
				}
			</Timeline> :
			<Card size="small" title="皮试患者">
				{this.state.skinTestData.map(item => {
					return <p key={item.id}>{item.bedDesc + ' ' + item.patName + ' ' + item.display}</p>
				})}
			</Card>
		);

		return (
			<Row className="process">
				<Col
					className="process title"
				>
					<div className="processimg" >
					</div>

					{
						this.state.title
					}
				</Col>
				<Col className="process content">
					{content}
				</Col>
			</Row>
		);
	}
};

export default PatientProcess;