<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="80px"
        @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="岗位培训类型"
              prop="POSTTYPE"
              label-width="120px"
            >
              <layout-learning-train-type
                v-model="searchForm.POSTTYPE"
                type="post"
              />
            </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 label="序号" width="60">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="EXAMNAME"
          label="试卷名称"
          show-overflow-tooltip
        />
        <el-table-column
          show-overflow-tooltip
          prop="post_type_name"
          label="培训行业类型"
        />
        <el-table-column
          prop="train_type_name"
          label="岗位培训类型"
          show-overflow-tooltip
        />
        <el-table-column label="试题数" width="100">
          <template v-slot="{ row }">
            {{
              Number(row.DUOXUANTICOUNT) +
              Number(row.DANYUANTICOUNT) +
              Number(row.PANDUITICOUNT)
            }}
          </template>
        </el-table-column>
        <el-table-column prop="EXAMSCORE" label="总分数" width="100" />
        <el-table-column prop="PASSSCORE" label="及格分数" width="100" />
        <el-table-column label="试卷状态" width="100">
          <template v-slot="{ row }">
            <span v-if="row.STATE === 0">启用</span>
            <span v-if="row.STATE === 1">禁用</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="130">
          <template v-slot="{ row }">
            <el-button
              type="primary"
              text
              link
              :disabled="row.recordID !== '--'"
              @click="fnAdd(row.STAGEEXAMPAPERINPUT_ID)"
            >
              添加
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/platform_resource_library/paper/view',
                  query: {
                    STAGEEXAMPAPERINPUT_ID: row.STAGEEXAMPAPERINPUT_ID,
                  },
                })
              "
            >
              查看
            </el-button>
          </template>
        </el-table-column>
      </layout-table>
    </layout-card>
  </div>
</template>
<script setup>
import LayoutLearningTrainType from "@/components/learning_train_type/index.vue";
import {
  getPaperList,
  setPaperJoin,
} from "@/request/platform_resource_library.js";
import useListData from "@/assets/js/useListData.js";
import { serialNumber } from "@/assets/js/utils.js";
import { debounce } from "throttle-debounce";
import { ElMessage, ElMessageBox } from "element-plus";
import { useRouter } from "vue-router";

const router = useRouter();
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getPaperList);
const fnAdd = debounce(1000, async (STAGEEXAMPAPERINPUT_ID) => {
  await ElMessageBox.confirm("确定要添加吗？", { type: "warning" });
  await setPaperJoin({ STAGEEXAMPAPERINPUT_ID });
  ElMessage.success("添加成功");
  fnResetPagination();
});
</script>

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