<template>
  <div>
    <el-form
      :model="form"
      ref="form"
      label-position="right"
      label-width="80px;"
      :inline="true"
    >
      <el-form-item
        label="主教老师"
        prop="coreTeacher"
        :rules="[{ required: true, message: '请选择主教老师' }]"
      >
        <el-select
          v-model.trim="form.coreTeacher"
          placeholder="请选择主教老师"
          clearable
          filterable
        >
          <el-option
            v-for="(item, index) in teacherList"
            :key="index"
            :label="item.realName"
            :value="String(item.id)"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="助教老师"
        prop="assistant"
        v-if="type!='HIGH'&&type!='HIGH_ONLINE'&&type!='MUSIC_NETWORK'"
      >
        <el-select
          v-model.trim="form.assistant"
          placeholder="请选择助教老师"
          filterable
          clearable
          collapse-tags
          multiple
        >
          <el-option
            v-for="(item, index) in cooperationList"
            :key="index"
            :label="item.realName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <el-button @click="$emit('close')">取 消</el-button>
      <el-button type="primary" @click="subresetTeacher">确 定</el-button>
    </div>
  </div>
</template>
<script>
export default {
  props: ['teacherList', 'cooperationList', 'detail', 'activeType'],
  data() {
    return {
      form: {
        coreTeacher: '',
        assistant: [],
      },
    }
  },
  computed: {
    type() {
      return this.detail?.type
    }
  },
  mounted() {
    const row = this.detail
    for (let i in row.classGroupTeacherMapperList) {
      if (row.classGroupTeacherMapperList[i].teacherRole == "BISHOP") {
        this.form.coreTeacher = String(row.classGroupTeacherMapperList[i].userId);
      }
      if (row.classGroupTeacherMapperList[i].teacherRole == "TEACHING") {
        this.form.assistant.push(row.classGroupTeacherMapperList[i].userId);
      }
    }
  },
  methods: {
    subresetTeacher () {
      this.$refs.form.validate(some => {
        if (some) {
          this.$emit('submited', {...this.form});
        } else {
          return;
        }
      });
    }
  }
};
</script>
