<template>
  <div>
    <q-dialog v-model="show" persistent transition-show="scale" transition-hide="scale" @input="changeDig">
      <q-card style="width: 400px;max-width:900px;">
        <q-card-section class="row items-center q-pb-none">
          <div class="text-h6">换老师</div>
          <q-space />
          <q-btn icon="close" flat round dense @click="changeDig(false)" />
        </q-card-section>
        <q-card-section class="q-pt-none scroll" style="max-height: 70vh">
          <q-select filled v-model="teacherObj.Tid" stack-label option-value="TId" option-label="TeacherName"
            :options="TeacherList" label="教师列表" class="col-10" map-options emit-value>
            <template v-slot:no-option>
              <q-item>
                <q-item-section class="text-grey">
                  未找到相关数据
                </q-item-section>
              </q-item>
            </template>
          </q-select>
        </q-card-section>
        <q-separator />
        <q-card-actions align="right" class="bg-white">
          <q-btn label="取消" flat color="grey-10" @click="changeDig(false)" />
          <q-btn label="确定" color="accent" @click="save" />
        </q-card-actions>
      </q-card>
    </q-dialog>
  </div>
</template>
<script>
  import {
    SetScrollTeacher,
  } from "../../../api/studyabroad/subscribe.js";
  import {
    getTeacherDropDownList,
  } from "../../../api/school/index";
  export default {
    model: {
      prop: "show",
      event: "changeshow"
    },
    props: {
      saveObj: {
        type: Object,
        default: null
      },
      date: {
        type: String,
        default: ""
      },
      show: {
        type: Boolean,
        default: false
      },
    },
    data() {
      return {
        teacherObj: {
          TeacherName: "",
          Tid: 0,
        },
        TeacherList: []
      };
    },
    watch: {
      show(val) {
        if (val) {
          this.teacherObj.TeacherName = this.save.TeacherName;
          this.teacherObj.Tid = this.saveObj.Tid;
        }
      }
    },
    created() {
      this.getTeacherList();
    },
    mounted() {

    },
    methods: {
      //开关弹窗
      changeDig(val) {
        this.$emit("changeshow", val);
      },
      //获取教师下拉
      getTeacherList() {
        getTeacherDropDownList({
          LeaveStatus: 1,
          IsShow: 1
        }).then(res => {
          this.TeacherList = res.Data;
        });
      },
      save() {
        if (this.teacherObj.Tid == 0) {
          this.$q.notify({
            message: "请选择老师",
            position: "top"
          });
          return;
        }
        const saveMsg = {
          Date: this.date,
          TeacherId: this.saveObj.Tid,
          ShiftSort: this.saveObj.ShiftSort,
          RoomId: this.saveObj.RoomId,
          NewTeacherId: this.teacherObj.Tid,
        };
        SetScrollTeacher(saveMsg).then(res => {
          if (res.Code == 1) {
            this.$q.notify({
              message: "操作成功",
              position: "top"
            });

            var tempTeacher = this.TeacherList.find(qitem => qitem.TId == this.teacherObj.Tid);
            this.$emit("success", {
              Name: tempTeacher.TeacherName,
              Id: this.teacherObj.Tid
            });
            this.teacherObj.TeacherName = "";
            this.teacherObj.Tid = 0;
            this.changeDig(false)
          }
        });
      }
    }
  };

</script>
