<!-- 人员登记 基本信息 -->
<script name="RegisterTrainning" lang="ts" setup>
import { dayjs } from 'element-plus'
import { getDictTextByValue } from '../common-register'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getTrainningList } from '@/api/resource/register'
import type { IDictType } from '@/commonInterface/resource-interface'

const props = defineProps({
  staffId: { type: String, default: '' },
})

const trainSiteDict = ref<Array<IDictType>>([])
const trainWayDict = ref<Array<IDictType>>([])

const trnListQuery = {
  id: '',
  limit: 10,
  offset: 1,
}
const trainColumns = ref<Array<TableColumn>>([
  { text: '培训编号', value: 'trainNo', align: 'center', width: '160' },
  { text: '培训时间', value: 'trainDate', align: 'center' },
  { text: '培训场地', value: 'trainSiteName', align: 'center' },
  { text: '培训内容', value: 'trainText', align: 'center' },
  { text: '培训方式', value: 'trainWayName', align: 'center' },
  { text: '值班领导', value: 'dutyLeader', align: 'center' },
  { text: '效果成绩', value: 'staffScore', align: 'center' },
]) // 表头
const trnTotal = ref<number>(0) // 数据总条数
const trainList = ref([]) // 表格数据

// 逻辑

const getTrainningListByStaffId = () => {
  getTrainningList(trnListQuery).then((res) => {
    if (res.code === 200) {
      trainSiteDict.value = JSON.parse(sessionStorage.getItem('bizTrainSite')!)
      trainWayDict.value = JSON.parse(sessionStorage.getItem('bizTrainWay')!)

      trnTotal.value = res.data.total
      trainList.value = res.data.rows.map((item: any) => ({
        ...item,
        trainDate: dayjs(item.trainDate).format('YYYY-MM-DD'),
        trainSiteName: getDictTextByValue(trainSiteDict.value, item.trainSite),
        trainWayName: getDictTextByValue(trainWayDict.value, item.trainWay),
      }))
    }
  })
}

watch(() => props.staffId, (newVal: string) => {
  trnListQuery.id = newVal

  getTrainningListByStaffId()
})
</script>

<template>
  <app-container>
    <el-form ref="ruleFormRef" label-position="right" label-width="110px" border stripe>
      <table-container title="训练情况">
        <!-- 表格区域 -->
        <normal-table id="registerTabel" :pagination="false" :data="trainList" :columns="trainColumns">
          <template #preColumns>
            <el-table-column label="序号" width="55" align="center">
              <template #default="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
          </template>

          <template #columns />
        </normal-table>
      </table-container>
    </el-form>
  </app-container>
</template>
