<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="130px"
        @submit.prevent="fnResetPagination"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="课程名称" prop="KEYWORDS">
              <el-input
                v-model="searchForm.KEYWORDS"
                placeholder="请输入课程名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="岗位培训类型" prop="POSTTYPE">
              <layout-learning-train-type
                v-model="searchForm.POSTTYPE"
                type="post"
                placeholder="请选择岗位培训类型"
              />
            </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="CURRICULUMNAME"
          label="课程名称"
          show-overflow-tooltip
        />
        <el-table-column
          show-overflow-tooltip
          prop="train_type_name"
          label="培训行业类型"
        >
          <template v-slot="{ row }">
            <div v-if="row.CURRENCY === '1'">通用</div>
            <div v-else>{{ row.train_type_name }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="post_type_name"
          label="岗位培训类型"
          show-overflow-tooltip
        />
        <el-table-column prop="CLASSHOUR" label="学时（分钟）" />
        <el-table-column prop="videoCount" label="视频课件数" />
        <el-table-column prop="dataCount" label="资料课件数" />
        <el-table-column label="操作" width="130">
          <template v-slot="{ row }">
            <el-button
              type="primary"
              text
              link
              :disabled="row.recordID !== '--'"
              @click="fnAdd(row.CURRICULUM_ID)"
            >
              添加
            </el-button>
            <el-button
              v-if="!row.COURSEPAPERS_ID"
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/platform_resource_library/curriculum/view',
                  query: {
                    CURRICULUM_ID: row.CURRICULUM_ID, // 课程ID
                  },
                })
              "
            >
              查看
            </el-button>
          </template>
        </el-table-column>
      </layout-table>
    </layout-card>
  </div>
</template>

<script setup>
import LayoutCard from "@/components/card/index.vue";
import LayoutLearningTrainType from "@/components/learning_train_type/index.vue";
import {
  getCurriculumList,
  joinMyCurriculum,
} from "@/request/platform_resource_library.js";
import useListData from "@/assets/js/useListData.js";
import { serialNumber } from "@/assets/js/utils.js";
import LayoutTable from "@/components/table/index.vue";
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(getCurriculumList);

const fnAdd = debounce(1000, async (CURRICULUM_ID) => {
  await ElMessageBox.confirm("确定要添加吗？", { type: "warning" });
  await joinMyCurriculum({ CURRICULUM_ID });
  ElMessage.success("添加成功");
  fnResetPagination();
});
</script>

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