<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" inline>
                <el-form-item label="管理员名称" prop="name">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.name"
                        clearable
                        placeholder="请输入管理员名称"
                    />
                </el-form-item>
                <el-form-item label="请选择管理员角色" prop="role_id">
                    <el-select class="w-[280px]" v-model="queryParams.role_id">
            <el-option label="全部" value />
            <el-option
              v-for="(item, index) in optionsData.role"
              :key="index"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none" v-loading="pager.loading" shadow="never">
            <div class="mt-4">
         <el-table :data="pager.lists" @cell-click="handleCurrentChange">
          <el-table-column label="账号" prop="account" min-width="120" />
          <el-table-column label="名称" prop="name" min-width="100" />
          <el-table-column label="角色" prop="role_name" min-width="100" show-tooltip-when-overflow />
          <el-table-column label="部门" prop="dept_name" min-width="100" show-tooltip-when-overflow />
          <el-table-column label="创建时间" prop="create_time" min-width="180" />
          <el-table-column label="最近登录时间" prop="login_time" min-width="180" />
          <el-table-column label="最近登录IP" prop="login_ip" min-width="120" />
        </el-table>
            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup name="companyLists">
import { usePaging } from '@/hooks/usePaging'
import { roleAll } from "@/api/perms/role";
import { useDictData,useDictOptions } from '@/hooks/useDictOptions'
import { adminLists} from "@/api/perms/admin";
import { defineEmits } from 'vue'
const { optionsData } = useDictOptions<{
  role: any[];
}>({
  role: {
    api: roleAll,
  },
});
// 查询条件
const queryParams = reactive({
    name: "",
    role_id: "",
})

// 选中数据
const emits = defineEmits(['customEvent'])

// 选中数据子父传递
const handleCurrentChange = (value: any) => {
    emits('customEvent', value)
}

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: adminLists,
    params: queryParams
})

getLists()
</script>
