<template>
  <div class="mark-rule-set part-box">
    <Form ref="modalFormComp" :model="modalForm" :label-width="180">
      <FormItem label="分数处理方式：">
        <Select v-model="modalForm.roundUp" style="width: 200px">
          <Option
            v-for="(val, key) in SCORE_HANDLE_TYPE"
            :key="key"
            :value="key * 1"
            >{{ val }}</Option
          >
        </Select>
      </FormItem>
      <FormItem label="是否显示改档及改档打分：">
        <RadioGroup v-model="modalForm.changeStage">
          <Radio
            v-for="(val, key) in BOOLEAN_TYPE"
            :key="key"
            :label="key * 1"
            style="margin-right: 50px;"
            >{{ val }}</Radio
          >
        </RadioGroup>
      </FormItem>
      <FormItem label="阅卷员是否显示所有试卷：">
        <RadioGroup v-model="modalForm.scoreShowAllPaper">
          <Radio
            v-for="(val, key) in BOOLEAN_TYPE"
            :key="key"
            :label="key * 1"
            style="margin-right: 50px;"
            >{{ val }}</Radio
          >
        </RadioGroup>
      </FormItem>
      <FormItem>
        <Button type="primary" :disabled="isSubmit" @click="submit"
          >保存</Button
        >
      </FormItem>
    </Form>
  </div>
</template>

<script>
import { getParamsSet, updateScoreParams } from "@/api";
import { BOOLEAN_TYPE, SCORE_HANDLE_TYPE } from "@/constants/enumerate";

export default {
  name: "mark-rule-set",
  data() {
    return {
      isSubmit: false,
      workId: this.$route.params.workId,
      BOOLEAN_TYPE,
      SCORE_HANDLE_TYPE,
      initModalForm: {
        workId: "",
        roundUp: 0,
        changeStage: 0,
        scoreShowAllPaper: 0
      },
      modalForm: {}
    };
  },
  mounted() {
    this.modalForm = { ...this.initModalForm };
    this.getParamsSetInfo();
  },
  methods: {
    async getParamsSetInfo() {
      const data = await getParamsSet(this.workId);
      this.modalForm = this.$objAssign(this.modalForm, data);
    },
    async submit() {
      if (this.isSubmit) return;
      this.isSubmit = true;
      let result = true;
      await updateScoreParams(this.modalForm).catch(() => {
        result = false;
      });
      this.isSubmit = false;

      if (!result) return;
      this.$Message.success("保存成功！");
    }
  }
};
</script>
