import React,{ Component } from "react";

import { Modal , Form, Input,Button} from 'antd';
import axios from 'axios';

class Studentssignmodel extends Component {
  constructor(props) {
    super(props)
  }
  setdatas=()=>{
		this.props.form.validateFields((err, values) => {
			if (!err) {
				const url = `/weapps/course_member_attendances.json`;
				let data={
					code:values.name,
					attendance_mode:"NUMBER",
					attendance_id:this.props.Studentssigntypedata.attendance_id,
				}
				axios.post(url, data)
					.then((result) => {
						if (result.data.status === 0) {
							try {
								this.props.showNotification(`签到成功`);
							}catch (e) {

							}
							this.props.getsetdatas();
							this.props.Gotomodes(null,false)
						}else{
							this.props.showNotification(result.data.message);

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



	}
  render() {
    const { getFieldDecorator } =  this.props.form;
    const formItemLayout = {
      wrapperCol: { span: 25},
    };

    const leftbuton={
      "width":"130px",
      "height":"40px",
      "border":"1px solid rgba(76,172,255,1)",
      "borderRadius":"4px",
    }

    const rightbuton={
      "width":"130px",
      "height":"40px",
      "background":"#4CACFF",
      "borderRadius":"4px",
    }
    return(
      <React.Fragment>
        {this.props.Studentssigntype?<Modal
          title="签到码签到"
          visible={this.props.Studentssigntype}
          closable={false}
          footer={null}
        >

          <Form {...formItemLayout}>

            <Form.Item>
              {getFieldDecorator('name', {
                rules: [{ required: true, message: '请输入签到码' }],
              })(<Input placeholder="请输入签到码"/>)}
            </Form.Item>

            <div className={"mt20 marginauto clearfix edu-txt-center"}>
              <a>
                <Button type="primary" ghost style={leftbuton} onClick={()=>this.props.Gotomodes(null,false)}>
                  取消
                </Button>
              </a>

              <a>
                <Button type="primary" className={"ml20"} style={rightbuton} onClick={()=>this.setdatas()}>
                  确定
                </Button>
              </a>

            </div>


          </Form>
        </Modal>:""}
      </React.Fragment>

    )
  }

}




const Studentssignmodels = Form.create({ name: 'Studentssignmodel' })(Studentssignmodel);

export default Studentssignmodels
