<template>
  <div>
    <el-form :model="searchForm" inline @submit.prevent>
      <el-form-item>
        <el-input
          v-model="searchForm.nameOrPhone"
          placeholder="输入学员姓名/手机号"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-select
          v-model="searchForm.status"
          placeholder="选择考试结果"
          @change="handleQuery"
          style="width: 150px"
          clearable
        >
          <el-option label="合格" :value="1" />
          <el-option label="不合格" :value="0" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery"> 搜索 </el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="tableList"
      highlight-current-row
      max-height="calc(100vh - 320px)"
    >
      <el-table-column type="index" width="55" align="center" />
      <el-table-column label="姓名" prop="name" />
      <el-table-column label="手机号" prop="phone" />
      <el-table-column label="无人机类型" prop="carType" />
      <el-table-column label="驾驶员类型" prop="driverType" />
      <el-table-column label="交卷时间" prop="createTime" />
      <el-table-column label="模考时长" prop="during" />
      <el-table-column label="得分" prop="score" />
      <el-table-column label="答题结果" prop="status">
        <template #default="{ row }">
          <el-tag v-if="row.status == 0" type="danger">不合格</el-tag>
          <el-tag v-else type="success">合格</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100">
        <template #default="{ row }">
          <el-button type="text" @click="handleView(row)">查看明细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      style="margin-bottom: 0"
      v-show="total > 0"
      :total="total"
      v-model:page="searchForm.pageNo"
      v-model:limit="searchForm.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup>
const searchForm = ref({
  nameOrPhone: '',
  pageNo: 1,
  pageSize: 100
})

const loading = ref(false)
const total = ref(0)
const tableList = ref([])

onMounted(() => {
  handleQuery()
})
function getList() {
  loading.value = true
  tableList.value = [
    {
      id: 1,
      question: '1+1=？',
      answer: 'B',
      yourAnswer: 'B',
      status: '1',
      createTime: ''
    }
  ]
  total.value = 1
  loading.value = false
}

function handleQuery() {
  searchForm.value.pageNo = 1
  getList()
}

function handleView(row) {
  console.log(row)

  alert('查看每一题的记录，类似做题记录，+显示未做题')
}
</script>

<style lang="scss" scoped></style>
