<template>
  <el-dialog
    class="push-set-dialog"
    :visible.sync="modalIsShow"
    title="推送云阅卷设置"
    top="10vh"
    width="600px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    @open="visibleChange"
  >
    <el-form label-width="150px">
      <el-form-item label="是否推送客观分：">
        <el-radio-group v-model="modalForm.objectiveScorePush">
          <el-radio :label="true">是</el-radio>
          <el-radio :label="false">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否推送违纪考生：">
        <el-radio-group v-model="modalForm.examStudentBreachPush">
          <el-radio :label="true">是</el-radio>
          <el-radio :label="false">否</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button type="primary" :disabled="isSubmit" @click="submit"
        >确认</el-button
      >
      <el-button @click="cancel">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { pushCloudMarkExam } from "@/api/examwork-exam";

const initModalForm = {
  examId: null,
  objectiveScorePush: true,
  examStudentBreachPush: true,
};

export default {
  name: "PushSetDialog",
  props: {
    examId: {
      type: [String, Number],
      default: "",
    },
  },
  data() {
    return {
      modalIsShow: false,
      isSubmit: false,
      modalForm: { ...initModalForm },
    };
  },
  methods: {
    visibleChange() {
      this.modalForm = { ...initModalForm, examId: this.examId };
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
    async submit() {
      if (this.isSubmit) return;
      this.isSubmit = true;
      const data = await pushCloudMarkExam(this.modalForm).catch(() => {});
      this.isSubmit = false;

      if (!data) return;

      this.$message.success("操作成功！");
      this.$emit("modified");
      this.cancel();
    },
  },
};
</script>
