<template>
  <div class="app-container">
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="培训主题" prop="name">
            <el-input v-model="formData.name" placeholder="请输入培训主题" clearable :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="培训机构" prop="train_org">
            <el-input v-model="formData.train_org" placeholder="请输入培训机构" clearable :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="开始日期" prop="start_time">
            <el-date-picker v-model="formData.start_time"
                            type="datetime"
                            placeholder="选择日期时间">
            </el-date-picker>
           
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="结束日期" prop="end_time">
            <el-date-picker v-model="formData.end_time"
                            type="datetime"
                            placeholder="选择日期时间">
            </el-date-picker>
           
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="学时" prop="hours">
            <el-input v-model="formData.hours" placeholder="请输入学时" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>



        <el-col :span="12">
          <el-form-item label="考核方式" prop="kaohe_type">
            <el-input v-model="formData.kaohe_type" placeholder="请输入考核方式" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="选择学员" prop="employees">

            <!--<el-lable v-for="(item,index) in type_employees" :key="index">{{item.name}},</el-lable>-->
            <el-input v-model="formData.employeeList" placeholder="参加人员" clearable :style="{width: '80%'}"></el-input>
              <el-button type="text" @click="dialogVisible = true">选择</el-button>
              <el-dialog title="" :visible.sync="dialogVisible">
                <Userselet @closeMoule="closeMoule"></Userselet>
              </el-dialog>

             

          </el-form-item>
        </el-col>



        <el-col :span="12">
          <el-form-item label="培训讲师" prop="teacher">
            <el-input v-model="formData.teacher" placeholder="请输入培训讲师" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="培训内容" prop="teacher">
            <el-input type="textarea" :rows="2" v-model="formData.content"
                      placeholder="请输入培训内容"
                      clearable
                      :style="{width: '100%'}"></el-input>

          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="培训类型" prop="train_type">
            <el-select v-model="formData.train_type"
                       placeholder="请选择机构类型"
                       clearable
                       :style="{width: '100%'}">
              <el-option v-for="(item, index) in type_Options"
                         :key="index"
                         :label="item.name"
                         :value="item.value"
                         :disabled="item.disabled">

              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="培训备注" prop="remark">
            <el-input v-model="formData.remark" placeholder="请输入培训备注" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
</div>
</template>
<script>

  import { createTrain} from "@/api/train";
  import { getDictList } from "@/api/dict";
  import { genTree } from "@/utils";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import Userselet from '@/views/employee/userselet';
const defaultForm = {
  
}
export default {
  components: {Treeselect,Userselet},
  props: [],
  data() {
    return {
  
  dialogVisible: false,
      formData: Object.assign({}, defaultForm),
      rules: {},
    type_Options: [
        ],
    }
  },
  computed: {},
  watch: {},
  created() {
   this.getTypeOptions()
 
  },

  methods: {
   
  
  getTypeOptions() {
        getDictList({ type__code: "train_type" }).then(response => {
          this.type_Options = genTree(response.data);
        });
      
    },

    closeMoule(e) {

  
    
      this.type_employees = e;
        this.dialogVisible = false;
      var arrTemp = [];
      var arrName = [];
       for(let i=0;i<e.length;i++){
             
                  arrTemp.push(e[i].id);
                   arrName.push(e[i].name);
            }
      this.formData.employees = arrTemp;
     this.formData.employeeList=arrName
    }
,
    submitForm() {
        this.$refs["elForm"].validate(valid => {
          if (!valid) return;
          
          // TODO 提交表单
          createTrain(this.formData).then(response => {
           
            this.$message({
            type: 'success',
              message: '成功!'
          
            })
            this.$router.go(-1);
          });
          
        });
      },
       
  
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
  }
}
</script>
