<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="roomObj"
            stack-label
            option-value="RoomId"
            option-label="RoomName"
            :options="ClassRoomList"
            label="教室列表"
            class="col-10"
          >
            <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 {
  SetScrollRoom
} from "../../../api/studyabroad/subscribe.js";
import { queryClassRoomList } 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
    },
    room: {
      type: [Number, String],
      default: 0
    }
  },
  data() {
    return {
      roomObj: {},
      ClassRoomList: []
    };
  },
  watch: {
    show(val) {
        if(val){
             this.roomObj={
                 RoomName:this.saveObj.RoomName
             }
        }
     
    }
  },
  mounted() {
    this.getClassRoomList();
  },
  methods: {
    //开关弹窗
    changeDig(val) {
      this.$emit("changeshow", val);
    },
    //获取教室下拉
    getClassRoomList() {
      queryClassRoomList({}).then(res => {
        if (res.Code == 1) {
          this.ClassRoomList = res.Data;
        }
      });
    },
    save() {
      if (this.roomId == 0) {
        this.$q.notify({
          message: "请选择教室",
          position: "top"
        });
        return;
      }
      const saveMsg = {
        Date: this.date,
        TeacherId: this.saveObj.Tid,
        ShiftSort: this.saveObj.ShiftSort,
        RoomId: this.roomObj.RoomId,
      };
      SetScrollRoom(saveMsg).then(res => {
        if (res.Code == 1) {
          this.$q.notify({
            message: "操作成功",
            position: "top"
          });
          this.$emit("success", {Name:this.roomObj.RoomName,Id:this.roomObj.RoomId});
          
          this.roomObj=""
          this.changeDig(false)
        }
      });
    }
  }
};
</script>
