import React, {Component} from "react";
import '../css/signincdi.css';
import {Progress} from 'antd';
import axios from 'axios';
import Createsignmodel from '../model/Createsignmodel';
//条目
class Teacherentry extends Component {
	//条目组件
	constructor(props) {
		super(props);

		this.state = {
				editvisible:false,
			  attendancesid:null
		}
	}

	componentDidMount() {

	}

	componentDidUpdate = (prevProps) => {


	}

  getdatalist=(id)=>{
		let urls = `/attendances/${id}/edit.json`;
		axios.get(urls).then((response) => {
			//console.log(response);
			if(response){
				if(response.data){
					this.setState({
						editvisible:true,
						attendancesdata:response.data,
						attendancesid:id
					})
				}
			}

		}).catch((error) => {
			console.log(error);
		})
	}

	hideCreatesign=()=>{
		this.setState({
			editvisible:false
		})
	}
	render() {
		let isAdmin = this.props.isAdmin();
		let item = this.props.item;
		let index =this.props.index;
		let jdt;
		try {
			jdt = item.normal_count / item.all_count * 100;
		} catch (e) {
			jdt = 100;
		}

		return (
			<React.Fragment>
				<div className={index===0?"ws100s edu-back-white xiaoshou": "ws100s edu-back-white mt20 xiaoshou"}>
					{/*修改实训*/}
					{this.state.editvisible===true?<Createsignmodel
						{...this.state}
						{...this.props}
						hideCreatesign={()=>this.hideCreatesign()}
						settabsdata={()=>this.props.getsetdatas()}
						type={"edit"}
					/>:""}
					<div className="ws100s teacherentrydiv" onClick={isAdmin?(e)=>{e.stopPropagation();this.props.qiandaoxiangq(true,item.id)}:""}>
						<p className={isAdmin?"ws100s teachedivp ymaxnamewidthdivp xiaoshou color-blue":"ws100s teachedivp ymaxnamewidthdivp"} >
							{
								item.name
							}

						</p>

						<div className="ws100s sortinxdirection mt17">
							<div className="teachedivps">
								签到人数：
							</div>
							<div className="progressivps">
								<Progress percent={jdt} showInfo={false} strokeColor="#1890ff"/>
							</div>
							<div className="progressivpss">
								已签到 {item.normal_count ? item.normal_count : 0} / 应签到 {item.all_count ? item.all_count : 0}
							</div>
						</div>


						<div className="ws100s sortinxdirection  mt5">
							<div className="ws80s sortinxdirection">


								<div className="teachedivps  h40s">
									签到发起人：
								</div>
								<div className="teachedivpsy ymaxnamewidth60 h40s">
									{item.author.user_name}
								</div>

								<div className="teachedivps ml20 h40s">
									签到方式：
								</div>
								<div className="teachedivpsy ymaxnamewidth80 h40s">
									{item.mode ?
										item.mode === "QRCODE" ?
											"二维码签到"
											: item.mode === "NUMBER" ?
											"数字签到"
											: item.mode === "QUICK" ?
												"快捷签到"
												: ""
										: ""}
								</div>

								<div className="teachedivps ml20 h40s">
									开始结束时间：
								</div>
								<div className="teachedivpsy h40s">
									{item.attendance_date} {item.start_time}-{item.end_time}
								</div>
							</div>

							<style>
								{
									`
									.initials{
									cursor: initial !important;
									}
									`
								}
							</style>
							<div className="ws20s sortinxdirection">
								{
									isAdmin === true ?
										this.props.defaultActiveKey === "1" ?
											<div className="ws100s xaxisreverseorder">
												<div className="jiezhis h40s xiaoshou" onClick={(e)=>{e.stopPropagation();this.props.thisEnd(item.id)}}>截止</div>
												<div className="shanchu h40s xiaoshou" onClick={(e)=>{e.stopPropagation();this.props.thisdelete(item.id)}}>删除</div>
												<div className="shanchu h40s color-blue" onClick={(e)=>{e.stopPropagation();this.getdatalist(item.id)}}>编辑</div>
											</div>
											:
											(
												//是否有编辑权限
												item.edit_auth === true ?
													<div className="ws100s xaxisreverseorder">
														<div className="shanchu h40s xiaoshou" onClick={(e)=>{e.stopPropagation();this.props.thisdelete(item.id)}}>删除</div>
														<div className="shanchu h40s color-blue" onClick={(e)=>{e.stopPropagation();this.getdatalist(item.id,true,item.name)}}>编辑</div>
													</div>
													:
													<div className="ws100s xaxisreverseorder">
														<div className="jiezhis h40s color-reds xiaoshou" onClick={(e)=>{e.stopPropagation();this.props.thisdelete(item.id)}}>删除</div>
													</div>
											)
										:
										(
											this.props.defaultActiveKey === "1" ?
												<div className="ws100s xaxisreverseorder">
													{
														item.attendance_status?
															(
																item.attendance_status==="ABSENCE"&&item.attendance_mode!="TEACHER"?
																	<div className="qiandaobutton xiaoshou" onClick={(e)=>{e.stopPropagation();this.props.Signin(item.mode,item.id,item.attendance_code)}}>
																		签到
																	</div>
																	: item.attendance_status === "LEAVE" ?
																	<div className="qjqiandao initials">
																		请假
																	</div>
																	: item.attendance_status==="NORMAL"?
																		<div className="zcqiandao initials">
																			正常签到
																		</div>
																		:item.attendance_status==="ABSENCE"&&item.attendance_mode==="TEACHER"?<div className="kkqiandao initials">
																			旷课
																		</div>:""
															)
												    :
															""
													}

												</div>
												:
												<div className="ws100s xaxisreverseorder">
													{
														item.attendance_status?
															item.attendance_status === "NORMAL" ?
																<div className="zcqiandao initials">
																	正常签到
																</div>
																: item.attendance_status === "LEAVE" ?
																<div className="qjqiandao initials">
																	请假
																</div>
																: item.attendance_status === "ABSENCE" ?
																	<div className="kkqiandao initials">
																		旷课
																	</div>
																	:
																	""
															:
															""
													}




												</div>
										)

								}
							</div>

						</div>
					</div>
				</div>

			</React.Fragment>
		)
	}
}

export default Teacherentry;
