<template>
  <el-dialog
    :visible="visible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    title="模拟答题权限控制"
    width="650px"
  >
    <div class="permission-control">
      <el-checkbox v-model="permission.can_answer">可作答</el-checkbox>
      <el-checkbox v-model="permission.can_judge_correct">可判断对错（客观题）</el-checkbox>
      <el-checkbox v-model="permission.can_show_answer">可查看答案</el-checkbox>
      <el-checkbox v-model="permission.can_correct">可批改</el-checkbox>
      <el-checkbox v-model="permission.can_check_correct">可查看批改</el-checkbox>
    </div>

    <div slot="footer">
      <el-button @click="handleClose()">关闭</el-button>
      <el-button type="primary" @click="confirm()">保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'SimAnswerPermissionControl',
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    permissionControl: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      permission: {
        can_answer: true, // 可作答
        can_judge_correct: false, // 可判断对错
        can_show_answer: false, // 可查看答案
        can_correct: false, // 可批改
        can_check_correct: false, // 可查看批改
      },
    };
  },
  watch: {
    permissionControl: {
      handler(newVal) {
        this.permission = { ...newVal };
      },
      immediate: true,
      deep: true,
    },
  },
  methods: {
    handleClose() {
      this.$emit('update:visible', false);
    },
    confirm() {
      this.$emit('update:permissionControl', { ...this.permission });
      this.handleClose();
    },
  },
};
</script>

<style lang="scss" scoped></style>
