<template>
  <div class="hired-personnel-list">
    <h2 class="mb10">{{ props.title }} - {{ props.label }}</h2>

    <el-table :data="pageList.records" stripe border v-loading="loading" style="width: 100%">
      <el-table-column prop="tcperson" label="人员姓名" />
      <el-table-column prop="tcsex" label="性别" >
        <template #default="{ row }">
          {{ row.tcsex === '1' ? '男' : row.tcsex === '2' ? '女' : '未知' }}
        </template>
      </el-table-column>
      <el-table-column prop="tcposition" label="职称" />
      <el-table-column prop="tcname" label="证书名称" />
      <!-- 根据你的返回字段调整列 -->
    </el-table>

    <el-pagination
      class="mt20"
      background
      layout="prev, pager, next, total"
      :current-page="pageList.pageCurrent"
      :page-size="pageList.pageSize"
      :total="pageList.total"
      @current-change="handlePageChange"
    />
  </div>
</template>


<script setup>
import {ref, reactive, defineProps, watch} from "vue"
import {getApi} from "@/api/tobAcco_api.js"

const props = defineProps({
  orgCode: String,
  title: String,
  label: String,
})

const loading = ref(false)

let pageList = reactive({
  records: [],
  pageSize: 10,
  pageCurrent: 1,
  total: 0,
})

/** 请求接口 */
const getInfoList = () => {
  if (!props.orgCode) return
  loading.value = true
  getApi(
    {
      orgCode: props.orgCode,
      pageCurrent: pageList.pageCurrent,
      pageSize: pageList.pageSize,
    },
    "/mosty-jcgl/aqy/querySecurityChildList"
  )
    .then((res) => {
      if (res) {
        pageList.records = res.records || []
        pageList.total = res.total || 0
      }
    })
    .finally(() => {
      loading.value = false
    })
}

/** 页码切换 */
const handlePageChange = (page) => {
  pageList.pageCurrent = page
  getInfoList()
}

// props 变化时自动重新加载
watch(
  () => [props.orgCode, props.label],
  () => {
    pageList.pageCurrent = 1
    getInfoList()
  },
  {immediate: true}
)
</script>


<style scoped lang="scss">
.hired-personnel-list {
  padding: 10px;

  h2 {
    font-size: 18px;
    font-weight: bold;
  }

  .el-pagination {
    text-align: right;
  }
}
</style>
