<script setup>
import { onMounted, reactive } from 'vue'
import { getRecordPage, iuserAdd, IuserUpdate, iuserDelete, iuserGetById } from './api'
import { baseModelOptions, baseFilterOptions, stausList } from './options'

// const { proxy } = getCurrentInstance();
const currentTime = new Date();
const year = currentTime.getFullYear();
const month = String(currentTime.getMonth() + 1).padStart(2, '0');
const day = String(currentTime.getDate()).padStart(2, '0');
const formattedTime = `${year}-${month}-${day}`;
const state = reactive({
  baseModelOptions: baseModelOptions(),
  baseFilterOptions: baseFilterOptions(),
  title: "实名管理",
  baseModelName: '实名信息',
  addBtnName: '新增人员',
  editBtnName: '',
  delBtnName: '',
  primaryKey: 'id',
  getTableFn: getRecordPage,
  addFn: iuserAdd,
  editFn: IuserUpdate,
  deleteFn: iuserDelete,
  detailFn: iuserGetById,
  showEditBtn: false,
  showDeleteBtn: false,
  columnCount: 1,
  hideControl: true,
  showAddBtn: false,
  hideselection: true,
  rowControl: {
    showEditBtn: false,
    showDelBtn: false
  },
  tableResult: {
    successCode: 0
  },
  permission: {//菜单管理中添加权限
    add: 'workAttendance:page:list',
    edit: 'workAttendance:page:list',
    delete: 'workAttendance:page:list',
    detail: 'workAttendance:page:list',
  },
  pageInfo: { total: 0, base: { limit: 8, current: 1 } },
  baseQuery: { actionTimeAfter:formattedTime + ' 00:00:00',actionTimeBefore:formattedTime + ' 23:59:59' },
  beforeFilter: (params) => {
    //1. 使用异步的方式
    return new Promise((resolve) => {
      //dosomething...
      resolve({
        attendanceType: params.attendanceType,
        personName: params.personName,
        actionTimeAfter: params.params && params.params.length > 0 ? params.params[0] : null,
        actionTimeBefore: params.params && params.params.length > 0 ? params.params[1] : null,
      })
    })
  },
  tableDataFormatter: function (params, res) {
    res.data.total = res.data.totalRows
    res.data.list = res.data.pageData
    return res.data.list
  },
})
onMounted(() => {

})
</script>

<template>
  <div class="app-container">
    <BaseTablePage :tableOptions="state">
      <template v-slot:column>
        <el-table-column type="index" align="center" label="序号" width="70" />
        <el-table-column label="姓名" align="center" prop="personName" />
        <el-table-column label="考勤方式" align="center" prop="enterOrExit">
          <template #default="scope">
            <span>{{ stausList().find(item => item.value === scope.row.attendanceType)?.label || '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="刷卡时间" align="center" prop="reportTime" />
        <el-table-column label="考勤点名称" align="center" prop="imageType">
          <template #default="scope">
            <span>{{ scope.row.siteName }}</span>
          </template>
        </el-table-column>
      </template>
    </BaseTablePage>
  </div>
</template>

<style scoped></style>
