<template>
  <div>
    <el-card class="!border-none" shadow="never">
      <el-form class="mb-[-16px]" :model="queryParams" inline>
        <el-form-item label="公司名称" prop="company_name">
          <el-input
            class="w-[280px]"
            v-model="queryParams.company_name"
            clearable
            placeholder="请输入公司名称"
          />
        </el-form-item>
        <el-form-item label="公司类型" prop="company_type">
          <el-input
            class="w-[280px]"
            v-model="queryParams.company_type"
            clearable
            placeholder="请输入公司类型"
          />
        </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"
          size="large"
          @cell-click="handleCurrentChange"
        >
          <el-table-column label="ID" prop="id" min-width="60" />>
          <el-table-column label="头像" min-width="100">
            <template #default="{ row }">
              <el-avatar :size="50" :src="row.avatar"></el-avatar>
            </template>
          </el-table-column>
          <el-table-column label="姓名" prop="name" min-width="100" />
          <el-table-column label="联系方式" prop="account" min-width="130" />
          <el-table-column
            label="隶属公司"
            prop="company.company_name"
            min-width="120"
            align="center"
          >
            <template #default="{ row }">
              {{ row.company.company_name || "/" }}
            </template>
          </el-table-column>
          <el-table-column
            label="所在乡镇"
            prop="street_name"
            min-width="120"
          />
          <el-table-column label="授权身份" prop="role_name" min-width="120" />
          <el-table-column
            label="是否签约"
            prop="is_contract"
            align="center"
            min-width="120"
          >
            <template #default="{ row }">
              <span v-if="row.is_contract == 1" style="color: #67c23a"
                >已签约</span
              >
              <span v-else style="color: #fe0000">未签约</span>
            </template>
          </el-table-column>
          <el-table-column
            label="最近登录时间"
            prop="login_time"
            min-width="180"
          />
          <el-table-column
            label="创建时间"
            prop="create_time"
            min-width="180"
            align="center"
          />
          <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 { useDictData } from "@/hooks/useDictOptions";
import { apiCompanyLists, apiCompanyDelete } from "@/api/company";
import { defineEmits } from "vue";
import { adminLists } from "@/api/perms/admin";

// 查询条件
const queryParams = reactive({
  level_two: "",
  level_one: "",
  company_name: "",
  organization_code: "",
  city: "",
  area: "",
  street: "",
  company_type: "",
  master_name: "",
  master_position: "",
  master_phone: "",
  master_email: "",
  other_contacts: "",
  area_manager: "",
  is_contract: "",
  account: "",
  password: "",
  deposit: "",
  deposit_time: "",
  qualification: "",
  status: "",
});

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

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

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

getLists();
</script>
