<template>
  <div class="audit-paper-wait">
    <el-form class="part-filter-form" :model="filter" inline>
      <el-form-item label="提交人">
        <el-input
          v-model="filter.creator"
          placeholder="请输入提交人姓名"
        ></el-input>
      </el-form-item>
      <el-form-item label="试卷名称">
        <el-input
          v-model="filter.paperName"
          placeholder="请输入试卷名称"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="toPage(1)">查询</el-button>
      </el-form-item>
    </el-form>

    <div>
      <el-table
        v-loading="loading"
        element-loading-text="拼命加载中"
        :data="dataList"
      >
        <el-table-column label="试卷名称" prop="paperName"> </el-table-column>
        <el-table-column label="课程" prop="courseName"> </el-table-column>
        <el-table-column label="提交人" prop="creator" width="150">
        </el-table-column>
        <el-table-column label="提交时间" prop="creationTime" width="153">
        </el-table-column>
        <el-table-column label="操作" width="170" fixed="right">
          <template slot-scope="scope">
            <div class="operate_left">
              <el-button
                size="medium"
                type="text"
                class="normal"
                @click="toDetail(scope.row)"
                >详情</el-button
              >
              <el-button
                size="medium"
                type="text"
                class="normal"
                @click="toAudit('PASS', scope.row.id)"
              >
                通过
              </el-button>
              <el-button
                size="medium"
                type="text"
                class="normal"
                @click="toAudit('NOT_PASS', scope.row.id)"
              >
                不通过
              </el-button>
              <!-- <el-dropdown>
                <el-button type="primary" size="mini" plain>
                  审核<i class="el-icon-more el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown" class="action-dropdown">
                  <el-dropdown-item>
                    <el-button
                      size="mini"
                      type="success"
                      plain
                      @click="toAudit('PASS', scope.row.id)"
                    >
                      通过
                    </el-button>
                  </el-dropdown-item>
                  <el-dropdown-item>
                    <el-button
                      size="mini"
                      type="danger"
                      plain
                      @click="toAudit('NOT_PASS', scope.row.id)"
                    >
                      不通过
                    </el-button>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown> -->
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="part-page">
        <el-pagination
          :current-page="currentPage"
          :page-size="pageSize"
          :page-sizes="[10, 20, 50, 100, 200, 300]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @current-change="toPage"
          @size-change="handleSizeChange"
        >
        </el-pagination>
      </div>
    </div>

    <!-- AuditPaperDialog -->
    <audit-paper-dialog
      ref="AuditPaperDialog"
      :info="curAuditInfo"
      @modified="getList"
    ></audit-paper-dialog>
  </div>
</template>

<script>
import AuditPaperDialog from "./AuditPaperDialog.vue";
import { auditPaperWaitPageListApi } from "../api";

export default {
  name: "AuditPaperWait",
  components: { AuditPaperDialog },
  data() {
    return {
      filter: { creator: "", paperName: "" },
      dataList: [],
      currentPage: 1,
      pageSize: 10,
      total: 0,
      curAuditInfo: {
        paperIds: [],
        auditResult: "",
      },
      loading: false,
    };
  },
  mounted() {
    this.toPage(1);
  },
  methods: {
    toPage(page) {
      this.currentPage = page;
      this.getList();
    },
    async getList() {
      this.loading = true;
      const res = await auditPaperWaitPageListApi({
        ...this.filter,
        curPage: this.currentPage,
        pageSize: this.pageSize,
      }).catch(() => {});
      this.loading = false;
      if (!res) return;
      this.dataList = res.data.content;
      this.total = res.data.totalElements;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.toPage(1);
    },
    toDetail(row) {
      this.$router.push({
        name: "ViewPaper",
        params: {
          id: row.id,
        },
      });
    },
    toAudit(auditResult, paperId) {
      this.curAuditInfo = { auditResult, paperIds: [paperId] };
      this.$refs.AuditPaperDialog.open();
    },
  },
};
</script>
