<template>
  <div>
    <el-form :model="searchForm" inline @submit.prevent>
      <el-form-item>
        <el-input
          v-model="searchForm.userName"
          placeholder="输入学员姓名/手机号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="searchForm.question"
          placeholder="输入题目"
          clearable
          @keyup.enter="handleQuery"
        />
      </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 - 260px)"
    >
      <el-table-column type="index" width="55" align="center" />
      <el-table-column label="题目" prop="question" />
      <el-table-column label="图片">
        <template #default="{ row }">
          <img v-if="row.imageUrl" :src="row.imageUrl" width="100" height="100" />
        </template>
      </el-table-column>
      <el-table-column label="选项">
        <template #default="{ row }">
          <div v-for="(item, index) in optionArr" :key="index">
            <span v-if="row['choose' + item]">{{ item }}. {{ row['choose' + item] }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="正确答案" prop="trueAnswer" />
      <el-table-column label="收藏人" prop="userName" />
      <el-table-column label="手机号" prop="phone" />
      <el-table-column label="收藏时间" prop="createTime" />
    </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>
import { searchCollectRecords } from '@/api/uav/record'

const searchForm = ref({
  question: '',
  nameOrPhone: '',
  pageNo: 1,
  pageSize: 100
})

const optionArr = ['A', 'B', 'C', 'D', 'E']

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

onMounted(() => {
  handleQuery()
})
function getList() {
  loading.value = true
  try {
    searchCollectRecords(searchForm.value).then((res) => {
      tableList.value = res.list
      total.value = res.total
    })
  } finally {
    loading.value = false
  }
}

function handleQuery() {
  searchForm.value.pageNo = 1
  getList()
}
</script>

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