<template>
  <div>
    <el-form class="mb-[-16px]" :model="queryParams" inline>
      <el-form-item label="用户昵称" prop="nickname">
        <el-input
          class="w-[280px]"
          v-model="queryParams.nickname"
          clearable
          placeholder="请输入用户昵称"
        />
      </el-form-item>
      <el-form-item label="用户账号" prop="account">
        <el-input
          class="w-[280px]"
          v-model="queryParams.account"
          clearable
          placeholder="请输入用户账号"
        />
      </el-form-item>
      <el-form-item label="用户电话" prop="mobile">
        <el-input
          class="w-[280px]"
          v-model="queryParams.mobile"
          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>
    <div v-loading="pager.loading" class="mt-4">
      <el-table :data="pager.lists">
        <el-table-column label="ID" prop="id" width="100" />
        <el-table-column label="头像" prop="avatar" width="60">
          <template #default="{ row }">
            <el-image :src="row.avatar" style="width: 50px; height: 50px" />
          </template>
        </el-table-column>
        <el-table-column
          label="真实姓名"
          prop="real_name"
          show-overflow-tooltip
        />
        <el-table-column
          label="用户昵称"
          prop="nickname"
          show-overflow-tooltip
        />
        <el-table-column
          label="用户账号"
          prop="account"
          show-overflow-tooltip
        />
        <el-table-column label="用户电话" prop="mobile" show-overflow-tooltip />
        <el-table-column label="用户性别" prop="sex">
          <template #default="{ row }">
            <span>{{ row.sex ? "男" : "女" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120" fixed="right">
          <template #default="{ row }">
            <el-button
              type="primary"
              link
              @click="bindUser(row)"
            >
              绑定该用户
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="flex mt-4 justify-end">
      <pagination v-model="pager" @change="getLists" />
    </div>
  </div>
</template>

<script lang="ts" setup name="userLists">
import { usePaging } from "@/hooks/usePaging";
import { useDictData } from "@/hooks/useDictOptions";
import { apiUserLists, apiUserDelete, apiUserDetail } from "@/api/user";
import { timeFormat } from "@/utils/util";
import feedback from "@/utils/feedback";


// 查询条件
const queryParams = reactive({
  nickname: "",
  account: "",
  mobile: "",
  is_disable: "",
});


// 获取字典数据
const { dictData } = useDictData("sex_type,system_disable");

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

const emits = defineEmits(["onBindUser"]);
// 绑定用户
const bindUser = (row: any) => {
    emits('onBindUser', row)
};

getLists();
</script>
