<template>
  <q-dialog v-model="persistent" content-class="bg-grey-1" persistent transition-show="scale" transition-hide="scale">
    <q-card style="width: 800px;max-width:900px;">
      <q-card-section>
        <div class="text-h6">创建停课申请单</div>
      </q-card-section>
      <q-card-section class="q-pt-none">
        <!-- <div class="text-caption q-mb-lg q-px-md text-grey-6">基本资料</div> -->
        <div class="col flex items-center">
          <div class="col-2 text-grey-6">
            选择停课生效日期：
          </div>
          <el-date-picker v-model="msg.TakeEffectTime" value-format="yyyy-MM-dd" type="date" placeholder="选择日期"
            :picker-options="pickeroptions">
          </el-date-picker>
        </div>
        <q-input filled type="textarea" :rows="3" style="margin-top:20px;" stack-label maxlength="2000"
          v-model="msg.Remarks" :dense="false" class="col-12 q-pb-lg" label="申请备注" />
      </q-card-section>
      <q-card-actions align="right" class="bg-white">
        <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important" @click="closeSaveForm" />
        <q-btn label="立即提交" color="accent q-px-md" style="font-weight:400 !important" :loading="saveLoading"
          @click="save" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>

<script>
  import {
    setStopClassApply
  } from '../../api/teacher/student'
  export default {
    props: {
      setObj: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        persistent: true,
        saveLoading: false,
        msg: {
          Id: 0,
          ClassId: 0,
          CourseId: 0,
          OrderGuestId: 0,
          TakeEffectTime: "",
          OldStudentStatus: 0,
          Remarks: ""
        },
        pickeroptions: {
          disabledDate(time) {
            return time.getTime() <= Date.now()- 8.64e7;
          }
        },
      }
    },
    mounted() {
      if (this.setObj) {
        this.msg.ClassId = this.setObj.ClassId
        this.msg.CourseId = this.setObj.CourseId
        this.msg.OrderGuestId = this.setObj.Id
        this.msg.OldStudentStatus = this.setObj.GuestState
      }
    },
    methods: {
      closeSaveForm() {
        this.$emit('close')
        this.persistent = false
      },
      save() {
        if (this.msg.TakeEffectTime == "" || !this.msg.TakeEffectTime) {
          this.$q.notify({
            type: 'negative',
            position: "top",
            message: `请选择停课生效日期：`
          })
          return
        }
        if (this.msg.Remarks == "" || !this.msg.Remarks) {
          this.$q.notify({
            type: 'negative',
            position: "top",
            message: `请填写申请备注`
          })
          return
        }
        this.saveLoading = true
        setStopClassApply(this.msg).then(res => {
          this.saveLoading = false
          if (res.Code === 1) {
            this.$message.success("操作成功")
            this.$emit("success")
          } else {
            this.$message.error(res.Message)
          }
        }).catch(err => {
          this.saveLoading = false
        })
      }
    },
  }

</script>

<style>

</style>
