<template>
  <div v-loading="loading" class="skill-container flx-center">
    <div class="container">
      <img :src="baseURL + '/' + skillTrainData?.HbData?.[0].FPOSTERPICTURE" height="560" />
      <div class="train-list">
        <div
          v-for="(item, index) in trainList"
          :key="index"
          class="train-item"
          :class="queryList.type === item.type ? 'train-item-active' : ''"
          @click="handleChange(item)"
        >
          {{ item.name }}
        </div>
      </div>
      <div style="margin-bottom: 360px">
        <contentBlock
          v-loading="subLoading"
          :list="skillTrainData?.JcAqData"
          @change="toCommonDtail"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { baseURL } from '@/services'
import { getSkillTraining, getSkillTrainingList } from '@/services/api/skillTraining'
import contentBlock from '@/components/contentBlock.vue'

const route = useRoute()
const router = useRouter()
const loading = ref(true)
const subLoading = ref(true)
const queryList = ref({ pageIndex: 1, pageSize: 10, type: 'A' })
const skillTrainData: any = ref({})
const trainList = [
  { name: '基础安全培训', type: 'A' },
  { name: '专业技能培训', type: 'B' },
  { name: '专业知识培训', type: 'C' },
  { name: '职业发展培训', type: 'D' },
  { name: '团队管理培训', type: 'E' }
]

const handleChange = (row: any) => {
  queryList.value.type = row.type
  initSkillTrainingList()
}

const toCommonDtail = (row: any) => {
  router.push({
    path: '/commonDetail',
    query: { FID: row.FID, FormType: 'C', FTITLE: row.FTITLE }
  })
}

const initSkillTrainingList = async () => {
  subLoading.value = true
  const res: any = await getSkillTrainingList(queryList.value)
  if (res.code === 200) {
    skillTrainData.value.JcAqData = res.data
    subLoading.value = false
  }
}

const init = async () => {
  if (route.query?.type) queryList.value.type = route.query?.type as string
  const res: any = await getSkillTraining(queryList.value)
  if (res.code === 200) {
    skillTrainData.value.HbData = res.data.HbData
    loading.value = false
  }
  initSkillTrainingList()
}

init()
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
