<template>
  <div class="part-box is-border">
    <el-form inline>
      <el-form-item label="科目">
        <select-subject v-model="searchModel.subjectCode"></select-subject>
      </el-form-item>
      <el-form-item>
        <el-checkbox v-model="searchModel.group"> 按分组统计 </el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="toPage(1)">查询</el-button>
        <el-button @click="onExport">导出</el-button>
      </el-form-item>
    </el-form>
    <el-divider class="form-divider" />

    <el-table
      class="page-table"
      :data="dataList"
      :loading="loading"
      border
      stripe
      @sort-change="handleSortChange"
    >
      <el-table-column
        prop="subjectCode"
        label="科目"
        min-width="240"
        sortable
      />
      <el-table-column
        v-if="searchModel.group"
        prop="groupNumber"
        label="分组"
        min-width="60"
      />
      <el-table-column
        prop="totalCount"
        label="任务总量"
        min-width="110"
        sortable
      />
      <el-table-column
        prop="finishCount"
        label="已完成"
        min-width="100"
        sortable
      />
      <el-table-column
        prop="arbitrateCount"
        label="仲裁卷数"
        min-width="110"
        sortable
      />
      <el-table-column label="仲裁率" min-width="100" sortable>
        <template #default="scope">
          {{ (scope.row.arbitrateRatio * 100).toFixed(1) }}%
        </template>
      </el-table-column>
      <el-table-column
        prop="finishArbitrateCount"
        label="已完成仲裁"
        min-width="120"
        sortable
      />
      <el-table-column
        prop="waitArbitrateCount"
        label="待处理仲裁"
        min-width="120"
        sortable
      />
    </el-table>
    <el-pagination
      v-model:current-page="pagination.pageNumber"
      v-model:page-size="pagination.pageSize"
      :layout="pagination.layout"
      :total="pagination.total"
      @size-change="pageSizeChange"
      @current-change="toPage"
    />
  </div>
</template>

<script setup lang="ts">
  import { reactive } from 'vue';
  import { getGroupArbitrateStatList } from '@/api/mark';
  import {
    GroupArbitrateStatItem,
    GroupArbitrateStatFilter,
  } from '@/api/types/mark';
  import useTable from '@/hooks/table';
  import { downloadExport } from '@/utils/download-export';

  defineOptions({
    name: 'QualityMonitorGroup',
  });

  const searchModel = reactive<GroupArbitrateStatFilter>({
    subjectCode: null,
    group: false,
  });

  const {
    dataList,
    pagination,
    loading,
    toPage,
    pageSizeChange,
    handleSortChange,
  } = useTable<GroupArbitrateStatItem>(
    getGroupArbitrateStatList,
    searchModel,
    false
  );

  // 导出功能
  async function onExport() {
    await downloadExport('exportGroupArbitrateStatList', searchModel);
  }
</script>
