<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="group_id">
          <el-select class="w-[280px]" v-model="queryParams.group_id">
            <el-option label="全部" value />
            <el-option
              v-for="(item, index) in roleList"
              :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" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" />
          <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 justify-end mt-4">
        <pagination v-model="pager" @change="getLists" />
      </div>

      <template #footer>
        <div style="float: right;">
          <el-button @click="offPop">取消</el-button>
          <el-button type="primary" @click="handleCurrentChange">确定</el-button>
        </div>
       
      </template>

    </el-card>
  </div>
</template>

<script lang="ts" setup name="companyLists">
import { usePaging } from "@/hooks/usePaging";
import {apiUserRoleLists} from "@/api/newTask.ts"
import { defineEmits } from "vue";
import { getUserList } from "@/api/user";


const roleList=ref([])
const getRoleList=async()=>{
  let res=await apiUserRoleLists()
  roleList.value=res

}

// 查询条件
const queryParams = reactive({
  nickname:"",
  group_id:""

});
const props = defineProps({
  company_id: {
    type: String || Number,
    defaults: 0,
  },
});

// 选中数据

// 选中数据
const selectData = ref<any[]>([])

// 表格选择后回调事件
const handleSelectionChange = (val: any[]) => {
    selectData.value = val.map((item) => ( {id:item.id,nickName:item.nickname} ))
}
const emits = defineEmits(["customEvent",'off']);

// 选中数据子父传递
const handleCurrentChange = () => {

  emits("customEvent", selectData);
};
const offPop=()=> (
  emits("off")
)

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