<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="核算年月" prop="yearAndMonth">
        <el-date-picker
          v-model="queryParams.yearAndMonth"
          type="month"
          style="width: 100%"
          value-format="X"
          placeholder="选择核算年月"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table
        row-key="id"
        show-summary
        v-loading="loading"
        :data="list"
        :stripe="true"
        :show-overflow-tooltip="true"
        @selection-change="handleRowCheckboxChange"
    >
<!--    <el-table-column type="selection" width="55" />-->
      <el-table-column label="项目名称" align="center" prop="projectName" />
<!--      <el-table-column label="应发工资" align="center" prop="code" />-->
      <el-table-column label="实发工资" align="center" prop="realPaySalary" />
      <el-table-column label="公司承担社保" align="center" prop="shebao" />
      <el-table-column label="公积金" align="center" prop="gongjijin" />
      <el-table-column label="公司承担管理费" align="center" prop="guanlifei" />
      <el-table-column label="税金" align="center" prop="shuijin" />
      <el-table-column label="商业保险" align="center" prop="shangyebaoxian" />
    </el-table>
  </ContentWrap>

</template>
<script setup lang="ts">
import { isEmpty } from '@/utils/is'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { SalaryMonthRecordApi, SalaryMonthRecord } from '@/api/hr/salarymonthrecord'
import {InsuranceMonthRecord} from "@/api/hr/insurancemonthrecord";

/** 薪资档案选项 列表 */
defineOptions({ name: 'HrSalaryArchivesOption' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref([]) // 列表的数据
const total = ref(0) // 列表的总页数
// 获取当前年月的时间戳
// 获取当前年月的时间戳
function getCurrentMonthTimestamp() {
  //获取当前年月的时间戳
  const date = new Date();
  const year = date.getFullYear();
  const month = date.getMonth();
  console.log(new Date(year, month, 1).getTime())
  return new Date(year, month, 1).getTime()/1000;
}
const date = new Date();
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  yearAndMonth: getCurrentMonthTimestamp(),
  year: date.getFullYear(),
  month: date.getMonth()+1,
  projectCode: undefined,
  projectName: undefined,
})

const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await SalaryMonthRecordApi.getSalaryProjectReportList(queryParams)
    list.value = data
    // total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  // 将时间戳转为 YYYY-MM 格式
  const date = new Date(queryParams.yearAndMonth*1000)
  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, '0') // 月份从0开始
  queryParams.year = year
  queryParams.month = month
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  queryFormRef.value.yearAndMonth = getCurrentMonthTimestamp()
  handleQuery()
}



const checkedIds = ref<number[]>([])
const handleRowCheckboxChange = (records: SalaryArchivesOption[]) => {
  checkedIds.value = records.map((item) => item.id);
}


/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
