<template>
  <div class="part-box is-border">
    <el-form inline>
      <el-form-item label="签到表编号">
        <el-input
          v-model.trim="searchModel.code"
          placeholder="请选择"
          clearable
          style="width: 200px"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select
          v-model="searchModel.upload"
          placeholder="请选择"
          clearable
          style="width: 120px"
        >
          <el-option label="已上传" :value="true" />
          <el-option label="未上传" :value="false" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-space wrap>
          <el-button type="primary" @click="toPage(1)">查询</el-button>
          <el-button>总数：{{ pagination.total }}</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
    >
      <el-table-column prop="code" label="签到表编号" sortable />
      <el-table-column prop="picCount" label="图片数量" sortable />
      <el-table-column label="操作" width="100" fixed="right">
        <template #default="scope">
          <el-button type="primary" link @click="onView(scope.row)">
            查看
          </el-button>
        </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>

  <!-- 查看图片 -->
  <el-image-viewer
    v-if="showPreview"
    :url-list="curStudentSheetUrls"
    show-progress
    @close="showPreview = false"
  />
</template>

<script setup lang="ts">
  import { reactive, ref } from 'vue';
  import { getSignPaperStatList } from '@/api/scan';
  import { SignPaperStatItem, SignPaperStatListFilter } from '@/api/types/scan';
  import useTable from '@/hooks/table';

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

  const searchModel = reactive<SignPaperStatListFilter>({
    code: '',
    upload: undefined,
  });

  const { dataList, pagination, loading, toPage, pageSizeChange } =
    useTable<SignPaperStatItem>(getSignPaperStatList, searchModel, true);

  // 查看图片
  const showPreview = ref(false);
  const curStudentSheetUrls = ref<string[]>([]);
  function onView(row: SignPaperStatItem) {
    showPreview.value = true;
    curStudentSheetUrls.value = row.urls || [];
  }
</script>
