<template>
  <div class="part-box is-border">
    <el-form inline>
      <el-form-item label="考点">
        <el-input
          v-model.trim="searchModel.point"
          placeholder="请选择"
          clearable
          style="width: 120px"
        >
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-space wrap>
          <el-button type="primary" @click="toPage(1)">查询</el-button>
          <el-button @click="exportData">导出</el-button>
        </el-space>
      </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
        property="totalStudents"
        label="考生总数"
        min-width="100"
        sortable
      />
      <el-table-column
        property="scannedSheets"
        label="已扫张数"
        min-width="100"
        sortable
      />
      <el-table-column
        property="scannedStudents"
        label="已扫人数"
        min-width="100"
        sortable
      />
      <el-table-column
        property="manualAbsent"
        label="人工指定缺考"
        min-width="100"
        sortable
      />
      <el-table-column label="扫描进度" width="120" sortable>
        <template #default="scope">
          <el-progress
            :percentage="scope.row.progress"
            :color="getProgressColor(scope.row.progress)"
          />
        </template>
      </el-table-column>
    </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 { getScanPointList } from '@/api/scan';
  import { ScanItem, ScanPointListFilter } from '@/api/types/scan';
  import useTable from '@/hooks/table';

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

  const searchModel = reactive<ScanPointListFilter>({
    point: '',
  });

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

  function getProgressColor(progress: number) {
    if (progress < 30) return '#f56c6c';
    if (progress < 70) return '#e6a23c';
    return '#67c23a';
  }

  function exportData() {
    // TODO: 实现导出功能
  }
</script>
