<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="60px"
        @submit.prevent="fnResetPagination"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="关键字" prop="KEYWORDS">
              <el-input v-model="searchForm.KEYWORDS" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label-width="10px">
              <el-button type="primary" native-type="submit">搜索</el-button>
              <el-button native-type="reset" @click="fnResetPagination">
                重置
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <layout-table
        :data="list"
        @get-data="fnGetData"
        v-model:pagination="pagination"
      >
        <el-table-column prop="QUESTIONNUMBER" label="题号" width="60" />
        <el-table-column label="试题类型" width="80">
          <template v-slot="{ row }">
            {{ translationStatus(row.QUESTIONTYPE, questionTypeOptions) }}
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="QUESTIONDRY"
          label="题干"
        />
        <el-table-column label="答案" width="55">
          <template v-slot="{ row }">
            <template v-if="row.QUESTIONTYPE === '3'">
              <span v-if="row.ANSWER === 'A'">正确</span>
              <span v-if="row.ANSWER === 'B'">错误</span>
            </template>
            <template v-else>
              <span>{{ row.ANSWER }}</span>
            </template>
          </template>
        </el-table-column>
      </layout-table>
    </layout-card>
  </div>
</template>

<script setup>
import { getQuestionListByCoursewareIdAndType } from "@/request/platform_resource_library.js";
import useListData from "@/assets/js/useListData.js";
import { useRoute } from "vue-router";
import { translationStatus } from "@/assets/js/utils.js";

const route = useRoute();
const { COURSEWAREID, COURSEWARETYPE } = route.query;
const questionTypeOptions = [
  { ID: "1", NAME: "单选题" },
  { ID: "2", NAME: "多选题" },
  { ID: "3", NAME: "判断题" },
];
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getQuestionListByCoursewareIdAndType, {
    otherParams: { COURSEWAREID, COURSEWARETYPE },
  });
</script>

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