<template>
  <q-dialog v-model="persistent" content-class="bg-grey-1" persistent transition-show="scale" transition-hide="scale">
    <q-card style="width: 500px;max-width:500px;">
      <q-card-section>
        <div class="text-h6">{{optionTitle}}</div>
      </q-card-section>
      <q-card-section class="q-pt-none scroll" style="max-height: 70vh">
        <div class="row wrap">
          <q-radio v-model="objOption.IsOpen" :val="1" label="私有" />
          <q-radio v-model="objOption.IsOpen" :val="2" label="公开" />
        </div>
      </q-card-section>
      <q-separator />
      <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" class="q-px-md" style="font-weight:400 !important" :loading="saveLoading"
          @click="setIsOpenInfo" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>

<script>
  import {
    GetPaper,
    batchSetIsOpen
  } from '../../api/teacher/index'
  export default {
    props: {
      saveObj: {
        type: Object,
        default: null
      },

    },
    data() {
      return {
        persistent: true,
        optionTitle: "", //标题
        objOption: {
          PaperIds: [],
          IsOpen: 1, //开放状态
        },
        saveLoading: false
      }
    },
    created() {

    },
    mounted() {
      this.initObj()
    },
    methods: {
      initObj() {
        if (this.saveObj) {
          this.objOption.PaperIds.push(this.saveObj.PaperId);
          this.objOption.IsOpen=this.saveObj.IsOpen;
        }
        this.optionTitle = "修改试卷开放权限"
      },
      closeSaveForm() {
        this.$emit('close')
        this.persistent = false
      },
      setIsOpenInfo() {
        this.saveLoading = true;
        batchSetIsOpen(this.objOption).then(res => {
          this.saveLoading = false
          this.$q.notify({
            icon: 'iconfont icon-chenggong',
            color: 'accent',
            timeout: 2000,
            message: '数据保存成功！',
            position: 'top'
          })
          this.$emit("success")
          this.closeSaveForm()
        }).catch(() => {
          this.saveLoading = false
        })
      },
    },
  }

</script>
<style>
</style>
