<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="100px"
        @submit.prevent="fnResetPagination"
      >
        <el-row>
          <el-col :span="5">
            <el-form-item label="课程名称" prop="KEYWORDS">
              <el-input v-model="searchForm.KEYWORDS" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="培训类型" prop="TRAINTYPE">
              <layout-learning-train-type
                v-model="searchForm.TRAINTYPE"
                type="trainingType"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="行业类型" prop="INDUSTRY_END_ID">
              <layout-learning-train-type
                v-model="searchForm.INDUSTRY_END_ID"
                type="industryType"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="岗位类型" prop="POSTTYPE">
              <layout-learning-train-type
                v-model="searchForm.POSTTYPE"
                type="postType"
                :search-value="searchForm.TRAINTYPE"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <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
        v-model:pagination="pagination"
        :data="list"
        @get-data="fnGetData"
      >
        <el-table-column label="序号" width="60">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column
          label="课件名称"
          prop="COURSEWARENAME"
          show-overflow-tooltip
        />
        <el-table-column label="上传时间" prop="CREATTIME" width="150" />
        <el-table-column label="培训类型" prop="TRAININGTYPE_NAME" />
        <el-table-column label="行业类型" prop="INDUSTRY_END_NAME" />
        <el-table-column label="岗位类型" prop="POSTTYPE_NAME" />
        <el-table-column label="培训教师" prop="TEACHERNAME" />
        <el-table-column label="学时" prop="CLASSHOUR" width="100" />
        <el-table-column label="课件时长" width="100">
          <template #default="{ row }">
            {{ secondConversion(row.VIDEOTIME) }}
          </template>
        </el-table-column>
        <el-table-column label="相关词条" prop="RELATEDTERMNAME" />
        <el-table-column label="习题数" prop="QUESTIONCOUNT" width="100" />
        <el-table-column label="操作" width="180">
          <template #default="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="fnPreview(row.VIDEOCOURSEWARE_ID, row.VIDEOFILES)"
            >
              预览
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/training_resource_management/video_courseware/view',
                  query: { VIDEOCOURSEWARE_ID: row.VIDEOCOURSEWARE_ID },
                })
              "
            >
              详情
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/training_resource_management/video_courseware/exercises',
                  query: {
                    COURSEWAREID: row.VIDEOCOURSEWARE_ID,
                    COURSEWARETYPE: 1,
                  },
                })
              "
            >
              课件习题
            </el-button>
          </template>
        </el-table-column>
      </layout-table>
    </layout-card>
    <layout-video
      v-model:visible="data.videoDialog.visible"
      :src="data.videoDialog.src"
    />
  </div>
</template>

<script setup>
import useListData from "@/assets/js/useListData.js";
import {
  getPreviewingVideo,
  getVideoCoursewareList,
} from "@/request/training_resource_management.js";
import LayoutLearningTrainType from "@/components/learning_train_type/index.vue";
import LayoutVideo from "@/components/video/index.vue";
import { secondConversion, serialNumber } from "@/assets/js/utils.js";
import { useRouter } from "vue-router";
import { reactive } from "vue";

const router = useRouter();
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getVideoCoursewareList);
const data = reactive({
  videoDialog: {
    visible: false,
    src: "",
  },
});
const fnPreview = async (VIDEOCOURSEWARE_ID, VIDEOFILES) => {
  const resData = await getPreviewingVideo({ VIDEOCOURSEWARE_ID, VIDEOFILES });
  data.videoDialog.src = JSON.stringify(resData.urlList);
  data.videoDialog.visible = true;
};
</script>

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