import React,{ Component } from "react";
import '../../css/signincdi.css';
import axios from 'axios';
import Teacherentry from "../Teacherentry";
import NoneDatas from '../NoneDatas';
import LoadingSpin from '../../../../../common/LoadingSpin';
import { Modal, Button } from 'antd';

const { confirm } = Modal;

//在线学习
class Teaccomponent extends Component{
	//教师正在签到
	constructor(props){
		super(props);

		this.state={
       mydatas:[]
		}
	}

	componentDidMount() {
		this.setState({
			mydatas:this.props.datas
		})

	}




	componentDidUpdate = (prevProps) => {


	}
   //截止
	thisEnd=(attendance_id)=>{
		let thiss=this

		confirm({
			title: '提示',
			content: '确认截止此签到吗?',
			onOk() {
				const url = `/weapps/attendances/${attendance_id}/end.json`;
				var data={

				}
				axios.post(url, data)
					.then((result) => {
						if (result.data.status === 0) {
							// try {
							// 	this.props.showNotification(`截止成功`);
							// }catch (e) {
							//
							// }
							thiss.props.getsetdatas();
						}else{
							thiss.props.showNotification(result.data.message);

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

			},
		});

	}
   //删除
	thisdelete=(attendance_id)=>{
		let thiss=this
		confirm({
			title: '提示',
			content: '确认删除此签到吗?',
			onOk () {
				const url = `/weapps/attendances/${attendance_id}.json`;
				var data={

				}
				axios.delete(url, data)
					.then((result) => {
						if (result.data.status === 0) {
							// try {
							// 	thiss.props.showNotification(`删除成功`);
							// }catch (e) {
							//
							// }

							thiss.props.getsetdatas();
						}else{
							thiss.props.showNotification(result.data.message);

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

			},
		});

	}

  //学生签到
	Signin=(attendance_mode,attendance_id,code)=>{

		const url = `/weapps/course_member_attendances.json`;
		var data={

		}
		 if(attendance_mode==="QUICK"){
		 	//快捷签到
			 data={
				 attendance_mode:"QUICK",
				 attendance_id:attendance_id,
			 }
			 axios.post(url, data)
				 .then((result) => {
					 if (result.data.status === 0) {
					 	try {
							this.props.showNotification(`签到成功`);
						}catch (e) {

						}

						 this.props.getsetdatas();
					 }else{
						 this.props.showNotification(result.data.message);

					 }
				 }).catch((error) => {
			 })
		 }else if(attendance_mode==="QRCODE"){
			 //二维码签到
			 data={
				 attendance_mode:"QRCODE",
				 attendance_id:attendance_id,
				 code:code,
			 }
       this.props.GotomQrcodesodesy(data,true)
		 }else if(attendance_mode==="NUMBER"){
		 	//数字签到
			 data={
				 attendance_mode:"NUMBER",
				 attendance_id:attendance_id,
				 code:code,
			 }
			 this.props.Gotomodes(data,true)

		 }


	}



	render(){
		 let mydatas=this.props.datas?this.props.datas:[];
		 let Spin= this.props.Spin;
		return(
			<React.Fragment>
				<div className="ws100s mt20  h500">
					{
						Spin&&Spin===true?
							<LoadingSpin></LoadingSpin>
							:

							(
								mydatas&&mydatas.length>0?
									mydatas.map((object, index) => {
										return (
											<Teacherentry
												Signinnamestypes={(id,b,a)=>this.props.Signinnamestypes(id,b,a)}
												Signin={(a,b,c)=>this.Signin(a,b,c)}
												qiandaoxiangq={(b,id)=>this.props.qiandaoxiangq(b,id)}
												thisdelete={(id)=>this.thisdelete(id)}
												thisEnd={(id)=>this.thisEnd(id)}
												item={object} key={index}
												index={index}
												defaultActiveKey={this.props.defaultActiveKey}
												{...this.props}
												{...this.state}
											></Teacherentry>

										)
									})
									:
									<NoneDatas></NoneDatas>
							)

					}
				</div>
			</React.Fragment>
		)
	}
}
export default Teaccomponent;
