<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button type="primary" @click="handleAdd">新增</el-button>
        <ExportBtn :getTableRef="() => $refs.table" :columns="exportCols" fileName="劳动合同台账" />
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="API.hrm.empcontract.list" row-key="id" stripe
        @row-click="(row)=>{t_id=row.id;mode='show';drawerVisible=true;}">
        <el-table-column label="部门" prop="dept_need_name" min-width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="员工姓名" prop="employee_name" min-width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="岗位" prop="post_name" min-width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="入职日期" prop="join_date" min-width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="合同结束日期" prop="end_contract" min-width="110" show-overflow-tooltip></el-table-column>
        <el-table-column label="变更次数" prop="counts" min-width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="应续签" prop="plan_renewal" min-width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="正常续签" prop="normal_renewal" min-width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="续签/变更(年)" prop="change_date" min-width="110" show-overflow-tooltip></el-table-column>
        <el-table-column label="变更原因" prop="change_reason" min-width="150" show-overflow-tooltip></el-table-column>
        <el-table-column label="审批状态" min-width="180">
          <template #default="scope">
            <el-tag :type="actStateEnum[scope.row.ticket_?.act_state]?.type">{{ actStateEnum[scope.row.ticket_?.act_state]?.text }}</el-tag>
            <el-tag type="info" effect="plain">{{ scope.row.ticket_?.state_?.name }}</el-tag>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
  <el-drawer title="劳动合同变更" v-model="drawerVisible" :size="'80%'" destroy-on-close>
    <empcontract_form :mode="mode" :t_id="t_id" @success="handleSuccess"></empcontract_form>
  </el-drawer>
</template>
<script setup>
import { ref } from 'vue'
import API from '@/api'
import empcontract_form from './empcontract_form.vue'
import ExportBtn from '@/components/scExportBtn/index.vue'
import { actStateEnum } from "@/utils/enum.js"
const drawerVisible = ref(false)
const mode = ref('add')
const t_id = ref(null)
const table = ref(null)
const handleAdd = () => { mode.value = 'add'; t_id.value = null; drawerVisible.value = true; }
const handleSuccess = () => { drawerVisible.value = false; table.value.refresh(); }
const exportCols = [
  { header: "部门", key: "dept_need_name", wch: 15 },
  { header: "员工姓名", key: "employee_name", wch: 10 },
  { header: "岗位", key: "post_name", wch: 12 },
  { header: "入职日期", key: "join_date", wch: 12 },
  { header: "合同结束日期", key: "end_contract", wch: 14 },
  { header: "变更次数", key: "counts", wch: 8 },
  { header: "应续签", key: "plan_renewal", wch: 12 },
  { header: "正常续签", key: "normal_renewal", wch: 12 },
  { header: "续签/变更(年)", key: "change_date", wch: 12 },
  { header: "变更原因", key: "change_reason", wch: 25 },
  { header: "审批状态", key: "_act_state_text", wch: 10 },
]
</script>
