<template>
  <el-form label-width="120px">
    <el-form-item label="审核结果">
      <el-select v-model="auditForm.auditResult" disabled>
        <el-option label="通过" value="PASS"></el-option>
        <el-option label="不通过" value="NOT_PASS"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="审核意见" style="margin-top: 15px">
      <el-input
        v-model="auditForm.auditRemark"
        type="textarea"
        placeholder="请输入内容"
        maxlength="200"
      ></el-input>
    </el-form-item>
    <div class="text-center" style="margin-top: 10px">
      <el-button type="primary" @click="submitAudit">确定</el-button>
    </div>
  </el-form>
</template>
<script>
import { QUESTION_API } from "@/constants/constants.js";
import { mapState } from "vuex";

export default {
  props: {
    paperIds: {
      type: Array,
      default: () => [],
    },
    auditResult: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      auditForm: { paperIds: [], auditResult: "", auditRemark: "" },
      loading: false,
    };
  },
  computed: {
    ...mapState({ user: (state) => state.user }),
  },
  //初始化查询
  created() {
    this.init();
  },
  methods: {
    init() {
      this.auditForm.paperIds = this.paperIds;
      this.auditForm.auditResult = this.auditResult;
    },
    submitAudit() {
      this.$http
        .post(
          QUESTION_API + "/paper/audit",
          new URLSearchParams(this.auditForm)
        )
        .then(() => {
          this.$notify({
            message: "保存成功",
            type: "success",
          });
          this.loading = false;
          this.$emit("afterAudit");
        })
        .catch((err) => {
          this.loading = false;
          this.$notify({
            type: "error",
            message: err.response.data.desc,
          });
          this.$emit("afterAudit");
        });
    },
  },
};
</script>
