<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="100px"
        @submit.prevent="fnResetPagination"
      >
        <el-row>
          <el-col :span="8">
            <el-form-item label="班级名称" prop="KEYWORDS">
              <el-input
                v-model="searchForm.KEYWORDS"
                placeholder="请输入班级名称"
              />
            </el-form-item>
          </el-col>
          <el-col v-show="!data.searchFromCollapse" :span="8">
            <el-form-item label="开始时间" prop="STARTTIME">
              <el-date-picker
                v-model="searchForm.STARTTIME"
                type="date"
                value-format="YYYY-MM-DD"
                format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
          <el-col v-show="!data.searchFromCollapse" :span="8">
            <el-form-item label="结束时间" prop="ENDTIME">
              <el-date-picker
                v-model="searchForm.ENDTIME"
                type="date"
                value-format="YYYY-MM-DD"
                format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
          <el-col v-show="!data.searchFromCollapse" :span="8">
            <el-form-item label="状态" prop="STATUS">
              <el-select v-model="searchForm.STATUS">
                <el-option
                  v-for="item in data.statusList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </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-button type="primary" @click="derivedRecord">导出</el-button>
              <el-button
                v-if="data.searchFromCollapse"
                type="text"
                @click="data.searchFromCollapse = false"
                >展开 <i class="el-icon-arrow-down"
              /></el-button>
              <el-button
                v-else
                type="text"
                @click="data.searchFromCollapse = true"
                >合并 <i class="el-icon-arrow-up"
              /></el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <layout-table
        ref="tableRef"
        v-model:pagination="pagination"
        :data="list"
        @get-data="fnGetData"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column label="序号" width="60">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column prop="NAME" label="班级名称" />
        <el-table-column prop="DEPARTMENT_NAME" label="部门" />
        <el-table-column prop="POST_NAME" label="工种" />
        <el-table-column prop="STATE" label="班级状态">
          <template #default="{ row }">
            <template v-if="row.STATE === '1'"> 未申请 </template>
            <template v-if="row.STATE === '4'"> 待开班 </template>
            <template v-if="row.STATE === '5'"> 培训中 </template>
            <template v-if="row.STATE === '6'"> 培训结束 </template>
          </template>
        </el-table-column>
        <el-table-column prop="TRAININGTYPE_NAME" label="培训类型" />
        <el-table-column prop="POSTTYPE_NAME" label="岗位类型" />
        <el-table-column prop="TRAINLEVEL_NAME" label="培训级别" />
        <el-table-column prop="SUM_CLASSHOUR" label="任务学时" />
        <el-table-column prop="COMPLETE_CLASSHOUR" label="已学学时" />
        <el-table-column prop="COMPLETE_CLASSHOUR" label="考试结果">
          <template #default="{ row }">
            <template v-if="row.STAGEEXAMSTATE === '0'"> 不考试 </template>
            <template v-else-if="row.STAGEEXAMSTATE === '1'"> 待考试 </template>
            <template v-else-if="row.STAGEEXAMSTATE === '2'">
              考试未通过
            </template>
            <template v-else-if="row.STAGEEXAMSTATE === '3'">
              考试通过
            </template>
            <template v-else-if="row.STAGEEXAMSTATE === '4'"> 未参加 </template>
          </template>
        </el-table-column>
        <el-table-column prop="START_TIME" label="开始时间" />
        <el-table-column prop="END_TIME" label="结束时间" />
        <el-table-column label="操作">
          <template #default="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="fnPersonnelRegistrationForm(row.STUDENT_ID, row.USER_ID)"
            >
              人员登记表
            </el-button>
            <el-button
              v-if="
                row.STATE === '6' ||
                (row.EXAMINATION === 1 &&
                  parseInt(row.STAGEEXAMSCORE) > -1 &&
                  parseInt(row.STUDYSTATE) !== 5) ||
                (row.EXAMINATION === 0 && parseInt(row.STUDYSTATE) > 1)
              "
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/archives_management/user/class/archives',
                  query: {
                    CLASS_ID: row.CLASS_ID,
                    CLASS_NAME: row.NAME,
                    STUDENT_ID: row.STUDENT_ID,
                    STUDENT_NAME: row.STUDENT_NAME,
                    CORP_NAME: row.CORP_NAME,
                    RECORDOR_SIGN: row.RECORDOR_SIGN,
                    ASSESSOR_SIGN: row.ASSESSOR_SIGN,
                    SAFETYDEPTOR_SIGN: row.SAFETYDEPTOR_SIGN,
                    POSTTYPE: row.POSTTYPE,
                    POSTTYPE_NAME: row.POSTTYPE_NAME,
                    INDUSTRY_ALL_NAME: row.INDUSTRY_ALL_NAME,
                    INDUSTRY_ALL_TYPE: row.INDUSTRY_ALL_TYPE,
                    TRAINLEVEL: row.TRAINLEVEL,
                    TRAINLEVEL_NAME: row.TRAINLEVEL_NAME,
                    PERSONNEL_TYPE: row.PERSONNEL_TYPE,
                  },
                })
              "
            >
              档案详情
            </el-button>
            <el-button v-else disabled type="primary" text link>
              档案详情
            </el-button>
          </template>
        </el-table-column>
      </layout-table>
      <personnel-registration-form
        v-model:visible="data.personnelRegistrationFormDialog.visible"
        :student-id="data.personnelRegistrationFormDialog.STUDENT_ID"
        :user-id="data.personnelRegistrationFormDialog.USER_ID"
      />
    </layout-card>
  </div>
</template>

<script setup>
import { serialNumber } from "@/assets/js/utils.js";
import useListData from "@/assets/js/useListData.js";
import { reactive, ref } from "vue";
import PersonnelRegistrationForm from "./components/personnel_registration_form.vue";
import { getUserClassesList } from "@/request/training_archive_management.js";
import { useRoute } from "vue-router";
import router from "@/router/index.js";

const route = useRoute();
const tableRef = ref(null);
const { USER_ID } = route.query;
const data = reactive({
  searchFromCollapse: true,
  statusList: [
    { value: 1, label: "未申请" },
    { value: 4, label: "待开班" },
    { value: 5, label: "培训中" },
    { value: 6, label: "培训结束" },
  ],
  personnelRegistrationFormDialog: {
    visible: false,
    STUDENT_ID: "",
    USER_ID: "",
  },
});
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getUserClassesList, {
    otherParams: { USER_ID },
  });
const fnPersonnelRegistrationForm = (STUDENT_ID, USER_ID) => {
  data.personnelRegistrationFormDialog.STUDENT_ID = STUDENT_ID;
  data.personnelRegistrationFormDialog.USER_ID = USER_ID;
  data.personnelRegistrationFormDialog.visible = true;
};
</script>

<style scoped></style>
