<template>
  <div class="">
    <q-dialog
      v-model="show"
      persistent
      transition-show="scale"
      transition-hide="scale"
      @input="changeDig"
    >
      <q-card style="width: 600px;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">
          <div class="row col q-mr-lg q-col-gutter-md changeCourse">
            <q-field filled dense label="日期" stack-label class="col-12">
              <template v-slot:control>
                <el-date-picker
                  v-model="msg.StartDate"
                  type="date"
                  size="mini"
                  placeholder="开始日期"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  :clearable="false"
                  @change="getData"
                  :picker-options="pickerOptions"
                />
              </template>
            </q-field>
            <q-field filled dense label="上课时段" stack-label class="col-12">
              <template v-slot:control>
                <div v-for="(item, index) in dataList" :key="index">
                  <q-radio
                    v-model="courseCheckList"
                    v-for="(_item, _index) in item.SubList"
                    :key="_index"
                    :val="_item"
                    @input="courseCheck(item.TeacherId, _item)"
                    v-if="_item.ClassType==3" 
                  >
                    {{ item.TeacherName }} {{ _item.CourseName }}
                    {{ _item.RoomName }} {{ _item.StartTime }}-{{
                      _item.EndTime
                    }}
                  </q-radio>
                </div>
              </template>
            </q-field>
          </div>
        </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" size="sm" @click="saveData" />
        </q-card-actions>
      </q-card>
    </q-dialog>
  </div>
</template>
<script>
import { GetAppointmentPlanStat,SetAppointmentStuTransfer } from "../../../api/studyabroad/subscribe.js";
export default {
  model: {
    prop: "show",
    event: "changeshow"
  },
  props: {
    saveObj: {
      type: Object,
      default: null
    },
    show: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    show(val) {
      if (val) {
        this.msg.StartDate = this.saveObj.date;
        this.getData();
      }
    }
  },
  data() {
    return {
      pickerOptions: {
        disabledDate: time => {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      msg: {
        StartDate: "",
        EndDate: "",
        TeacherId: 0,
        ClassRoomId: 0,
        ClassType: 3,
        AppointState: 1
      },
      dataList: [],
      saveMsg: {
        AppointmentIds:"",
        TeacherId:"",
        Date:"",
        ShiftSort:""
      },
      courseCheckList:"",
    };
  },

  methods: {
    //开关弹窗
    changeDig(val) {
      this.$emit("changeshow", val);
    },
    getData() {
      this.msg.EndDate = this.msg.StartDate;
      GetAppointmentPlanStat(this.msg).then(res => {
        if (res.Data && res.Data.length > 0) {
          this.dataList = res.Data[0].RList;
          //排除当前课程
          this.dataList.map((e,i)=>{
            if(e.SubList){
              e.SubList.map((_e,_i)=>{
                if(_e.GuestList&&_e.GuestList.length>0){
                  let ids=_e.GuestList.map(x=>x.AppointmentId).toString()
                  if(ids.indexOf(this.saveObj.ids)>-1){
                    this.dataList[i].SubList.splice(_i,1)
                  }
                }
              })
            }
          })
        }
      });
    },
    courseCheck(id,item){
      this.saveMsg.TeacherId=id
      this.saveMsg.ShiftSort=item.ShiftSort
    },
    saveData(){
      this.saveMsg.Date=this.msg.StartDate
      this.saveMsg.AppointmentIds=this.saveObj.ids
      SetAppointmentStuTransfer(this.saveMsg).then(res=>{
        this.changeDig(false)
        this.$q.notify({
            message: "操作成功",
            position: "top"
          });
        this.$emit('success')
      })
    }
  }
};
</script>
<style>
.changeCourse .el-input__inner {
  border: none;
  background-color: transparent;
  width: 100%;
}
</style>
