<template>
  <div>
    <el-form :model="searchForm" inline @submit.prevent>
      <el-form-item>
        <el-input
          v-model="searchForm.name"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-radio-group v-model="searchForm.status" @change="handleQuery">
          <el-radio :value="0"> 在职 </el-radio>
          <el-radio :value="1"> 离职 </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery" v-hasPermi="['finance:salary:search']">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="tableList" border stripe>
      <el-table-column type="index" width="50" />
      <el-table-column label="员工姓名" prop="name" />
      <el-table-column label="职位" prop="post" />
      <el-table-column label="手机号码" prop="mobile" />
      <el-table-column label="在职状态">
        <template #default="{ row }">
          {{ ['在职', '离职'][row.status] }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button
            type="primary"
            link
            @click="openForm(scope.row)"
            v-hasPermi="['finance:salary:set']"
          >
            工资条设置
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination
      :total="total"
      v-model:page="searchForm.pageNo"
      v-model:limit="searchForm.pageSize"
      @pagination="getList"
    />
    <DialogSalary ref="salaryDialogRef" @success="getList" />
  </div>
</template>

<script name="EmployeeList" setup>
import DialogSalary from './Comp/DialogSalary.vue'
// import * as SalaryApi from '@/api/finance/salary'
import { getEmployeePage } from '@/api/pers/employee'
import { removeNullField } from '@/utils'

const searchForm = ref({
  name: undefined,
  status: 0,
  pageNo: 1,
  pageSize: 20
})

onMounted(() => {
  handleQuery()
})

/** 搜索按钮操作 */
const handleQuery = () => {
  searchForm.value.pageNo = 1
  getList()
}

const loading = ref(false)
const tableList = ref([])
const total = ref(0)
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await getEmployeePage(removeNullField(searchForm.value))
    tableList.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

const salaryDialogRef = ref()
function openForm(row) {
  salaryDialogRef.value.open(row)
}
</script>

<style lang="scss" scoped></style>
