/**
 * JYW
 * 消息列表
 */
import React, { Component } from 'react';
import { MessageSocket } from 'tools/MessageSocket.js';
import { Modal, message, Input, Button, Select, Radio, Icon, Table, Col ,Carousel} from 'antd';
import fetchJsonp from 'fetch-jsonp';
import { $http } from '../../containers/config/https';
import './CSS/message.less';
import CommonPagination from 'components/pagination/index';
import RangeDatePicker from 'components/rangePicker/index';
import ColumnAuthoritysModel from '../columnAuthority/ColumnAuthoritysModel';
import moment from 'moment';
import { Util, dayFormat } from 'tools/index';
import ExecuteMessage from './ExecuteMessage.jsx';

let user;
const { Search } = Input;
const { Option } = Select;
const confirm = Modal.confirm;
const { TextArea } = Input;
let messageServer;

class MessageDialog extends Component {
	constructor(props) {
		messageServer = window.sessionStorage.messageServer ? JSON.parse(window.sessionStorage.messageServer) : {};
		user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
		super(props);
		var date = new Date();
		this.state = {
			admDateFrom: moment(date).subtract(1, 'months').format('YYYY-MM-DD'),
			admDateTo: moment(date).format('YYYY-MM-DD'),
			keywords: '',
			visible: true,
			size: 'small',
			messageList: [],
			messageDetail: {},
			newMsg: [],
			readFinish: true,
			readMessageIndex: -1,
			RecordColums: [],
			dataSource: [],
			columns: [],
			search: 'search',
			page: 1,
			pageSize: 20,
			total: 0,
			patientInfo: {},
			messageImportanceArr: [],
			messageEventArr: [],
			messageStatusArr: [],
			messageEventCode: 'ALL',
			eventImportCode: 'ALL',
			messageStatusCode: 'U',
			clickRow: {},
			activeKey: '',
			ENObj: {},
			CNObj: {},
			languageObj: {},
			totalWidth: '',
		};
	}

	componentDidMount() {
		this.props.onRef(this);
		//MessageSocket.init(this.handleMessage);
	}
	componentWillUnmount() {
		this.setState = (state, callback) => {
			return;
		};
	}
	/**
   * 处理消息
   */
	handleMessage = () => {};

	//关闭消息框
	hide = (event) => {
		event.stopPropagation(); 
		this.props.handlerThis.setState({
			visible: false
		});
	};
	onClick = (e) => {
		e.stopPropagation();
	};
	afterChange=(total,current)=>{ 
		if(current==(total-1)){
			setTimeout(()=>{
				this.props.handlerThis.setState({
					visible: false
				});
			},1500) 
		}
	}
	beforeChange=(total,from,to)=>{
		// if(to==0){
		// 	this.setState({
		// 		visible:false,
		// 	})
		// }else{
		// 	this.setState({
		// 		visible:true,
		// 	})
		// }
	}
	render() {
		const contentStyle = {
			height: '40px',
			color: '#000',
			lineHeight: '40px', 
            textAlign: "left",
            paddingLeft: "20px",
			whiteSpace: "nowrap",
            overflow: "hidden",
            textOverflow: "ellipsis",
		};
		var arr = [], len = 0,carouselArr=[],total=0; 
		this.props.dataSource.map((item, index) => { 
			if (item.showDialog == 'Y') {
				len = len + 1;
				arr.push(
					<div style={contentStyle}>
						{item.message}
					</div>
				);
				if (len == 3) {
					len = 0;
					total=total+1;
                    carouselArr.push( <div onClick={this.onClick}>{arr}</div>);
                    arr=[];
				}
			}
        }); 
		if(arr.length!=0){
			total=total+1;
            carouselArr.push( <div onClick={this.onClick}>{arr}</div>);
        }
		return (
			<Modal
				mask={false}
				className="messagedialog"
				title={
					<div
						onClick={this.onClick}
						style={{
							padding: '20px',
							height: '100%',
                            width: '100%',
                            borderTop:'5px solid #F6A724',
						}}
					>
						您有新的消息:
					</div>
				}
				visible={this.props.visible}
				destroyOnClose
				maskClosable={false}
				onCancel={this.hide}
				footer={null}
				wrapClassName="messagewrapdialog"
			>
				<Carousel dotPosition="left" dots={false} autoplay={true} beforeChange={this.beforeChange.bind(this,total)} afterChange={this.afterChange.bind(this,total)}>
                    {carouselArr}
                </Carousel>
			</Modal>
		);
	}
}

export default MessageDialog;
