<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.nickname"
            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="avatar" min-width="80">
            <template #default="{ row }">
              <img style="width: 50px; height: 50px" :src="row.avatar" />
            </template>
          </el-table-column>
          <el-table-column label="名称" prop="nickname" min-width="100" />
          <el-table-column
            label="电话"
            prop="mobile"
            min-width="140"
            show-tooltip-when-overflow
          />
          <el-table-column
            label="公司"
            prop="company.company_name"
            min-width="160"
            show-tooltip-when-overflow
          />
          <!-- <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 Popup from "@/components/popup/index.vue";
import { defineEmits } from "vue";
import { getUserList } from "@/api/user";
const { optionsData } = useDictOptions<{
  role: any[];
}>({
  role: {
    api: roleAll,
  },
});
// 查询条件
const queryParams = reactive({
  company_id: "",
});
const props = defineProps({
  company_id: {
    type: String || Number,
    defaults: 0,
  },
});
queryParams.company_id = props.company_id;

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

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

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

getLists();
</script>
