<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-input v-model="searchForm.question" 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="question" />
      <el-table-column label="图片" prop="img" />
      <el-table-column label="选项" prop="option" />
      <el-table-column label="正确答案" prop="answer" />
      <el-table-column label="答题时间" prop="createTime" />
      <el-table-column label="姓名" prop="name" />
      <el-table-column label="手机号" prop="phone" />
      <el-table-column label="答题选择" prop="yourAnswer" />
      <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>

    <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({
  question: '',
  status: '',
  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()
}
</script>

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