<template>
  <el-form ref="form" :model="user" :rules="rules" label-width="80px">
	  <el-row>
		  <el-col :span="8">
			 <el-form-item label="姓名" prop="userName">
			   <el-input v-model="user.userName" placeholder="请输入姓名" type="password" show-password/>
			 </el-form-item> 
		  </el-col>
		  <el-col :span="8">
		  		<el-form-item label="联系方式" prop="userPhone">
		  		  <el-input v-model="user.userPhone" placeholder="请输入联系方式" type="password" show-password/>
		  		</el-form-item>	  
		  </el-col>
		  <el-col :span="24"  v-for="(item,index) in user.registerTeacherClassList " :key= "index">
			<el-col :span="8">
				<el-form-item label="班级名称" prop="classId">
						  <el-select v-model="item.classId" placeholder="请选择班级名称">
						    <el-option
						      v-for="dict in kiueseghs"
						      :key="dict.deptId"
						      :label="dict.deptName"
						      :value="dict.deptId"
							  clearable
							  @keyup.enter.native="handleQuery"
						    ></el-option>
						  </el-select>
				</el-form-item>	  
			</el-col>
			<el-col :span="8">
				<el-form-item label="学科" prop="discipline">
					   <el-select v-model="item.discipline" placeholder="请选择学科">
					     <el-option
					       v-for="dict in dict.type.sys_subject"
					       :key="dict.value"
					       :label="dict.label"
					       :value="dict.value"
					     ></el-option>
					   </el-select>
					 </el-form-item>			  
			</el-col>  
			<el-col :span="2">
				<div class="hyeoa" style="margin-top: 10px;">
					 <el-tooltip class="item" effect="dark" content="新增信息,请慎重操作" placement="top-start">
					      <img src="../../../../assets/images/icon_tc_add.png" alt="" class="hueyde" @click="tijea(index)" />
					    </el-tooltip>
						<el-tooltip class="item" effect="dark" content="删除无法恢复,请慎重操作" placement="top-start">
						     <img src="../../../../assets/images/delei.png" alt="" class="hueydele" @click="naeyrfakjf(index, item)" />
						   </el-tooltip>
				</div>
			</el-col>
		  </el-col>
	  </el-row>
   
    
    <el-form-item>
      <el-button type="primary" size="mini" @click="submit">保存</el-button>
      <el-button type="danger" size="mini" @click="close">关闭</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { updateUserPwd } from "@/api/system/user";
import { listDept} from "@/api/system/dept";

export default {
	dicts: ['sys_subject'],
  data() {
    const equalToPassword = (rule, value, callback) => {
      if (this.user.newPassword !== value) {
        callback(new Error("两次输入的密码不一致"));
      } else {
        callback();
      }
    };
    return {
      user: {
        oldPassword: undefined,
        newPassword: undefined,
        confirmPassword: undefined,
		registerTeacherClassList:[
			{
			      classId:null,
			      className:null,
			      discipline:null
			  }
		]
      },
      // 表单校验
      rules: {
        oldPassword: [
          { required: true, message: "旧密码不能为空", trigger: "blur" }
        ],
        newPassword: [
          { required: true, message: "新密码不能为空", trigger: "blur" },
          { min: 6, max: 20, message: "长度在 6 到 20 个字符", trigger: "blur" }
        ],
        confirmPassword: [
          { required: true, message: "确认密码不能为空", trigger: "blur" },
          { required: true, validator: equalToPassword, trigger: "blur" }
        ]
      },
	  kiuesegh:[]
    };
  },
  created() {
  	this.getdept(0)
  },
  methods: {
	  getdept(val){
	  		  let kuesf={'parentId':val}
	  		  // this.kiuesegh = []
	  		listDept(kuesf).then(response => {
	  		  this.deptOptions = this.handleTree(response.data, "deptId");
	  		  this.deptOptions.filter(rou =>{
	  			  if(rou.children != undefined){
	  			  	rou.children.filter(rour =>{
	  			  					  this.kiuesegh.push(rour)
	  			  	})		  
	  			  }
	  			  // this.kiuesegh = rou.children
	  			  // this.kiuesegh.push(rou.children)
	  			  console.log(rou.children)
	  		  })
	  		  this.kiueseghs = this.kiuesegh
	  		  // this.deptOptions = response.data
	  		  console.log(this.kiuesegh)
	  		});  
	  },
	  // 点击新增
	  tijea(index) {
	  	console.log(index+ 1)
	  	// this.nameutaiL = index+ 1
	   //   this.cascaderKey = index + 1
	  	this.user.registerTeacherClassList.push({
	  		classId:null,
	  		className:null,
	  		discipline:null
	  	});
	    // this.nhyeojd = true
	  },
	  // 点击删除
	  naeyrfakjf(index, item) {
	    if(this.user.registerTeacherClassList.length == 1){
	      this.$message.error('信息必填不可全删除');
	      return  false
	    }
	  	var that = this
	  	this.$confirm('是否确认删除信息?', '警告', {
	  		confirmButtonText: '确定',
	  		cancelButtonText: '取消',
	  		type: 'warning'
	  	})
	  		.then(function() {
	  			 return  that.user.registerTeacherClassList.splice(index, 1)
	  		})
	  		.then(() => {
	  			// this.getList();
	  			// this.msgSuccess('删除成功');
	  		});
	  
	  },
    submit() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateUserPwd(this.user.oldPassword, this.user.newPassword).then(response => {
            this.$modal.msgSuccess("修改成功");
          });
        }
      });
    },
    close() {
      this.$tab.closePage();
    }
  }
};
</script>
<style type="text/css">
	.hyeoa {
		height: 100%;
		display: flex;
		align-items: center;
		margin-left: 10px;
	}
	.hueyde {
		width: 18px;
		height: 18px;
		margin: 0 5px;
		margin-right: 10px;
	}
	.hueydele {
		width: 15px;
		height: 18px;
	}
</style>
