<!-- 
    TODO 系统管理 / 用户管理
 -->
<template>
  <el-container :style="{ height: containerHeight + 'px' }">
    <el-aside
      width="210px"
      style="border-right: 1px solid #dfe6ec"
    >
      <!-- Aside content 左侧部门-->
      <LeftTree @treeClick="treeClick" />
    </el-aside>
    <el-main>
      <!-- 搜索栏-->
      <el-form
        :model="listParm"
        label-width="80px"
        :inline="true"
      >
        <el-form-item class="item-search">
          <el-input
            v-model="listParm.loginName"
            placeholder="请输入用户姓名"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            :icon="Search"
            @click="searchBtn"
          >
            搜索
          </el-button>
          <el-button
            :icon="RefreshRight"
            style="color: #ff7670"
            @click="resetBtn"
          >
            重置
          </el-button>
          <el-button
            v-permission="['sys:user:add']"
            :icon="Plus"
            type="primary"
            @click="addBtn"
          >
            新增
          </el-button>
        </el-form-item>
      </el-form>
      <!-- 用户列表 -->
      <el-table
        :height="tableHeigth"
        :data="tableData.list"
        border
        stripe
      >
        <el-table-column
          prop="oldId"
          label="旧系统编号"
          :min-width="100"
        />
        <el-table-column
          prop="loginName"
          label="姓名"
          :min-width="110"
        />
        <el-table-column
          prop="nickName"
          label="昵称"
          :min-width="110"
        />
        <el-table-column
          prop="username"
          label="登录名"
          :min-width="120"
        />
        <el-table-column
          prop="deptName"
          label="所属部门"
          :min-width="110"
        />
        <el-table-column
          prop="mobile"
          label="电话"
          :min-width="120"
        />
        <el-table-column
          prop="email"
          label="邮箱"
          :min-width="170"
        />
        <el-table-column
          label="操作"
          fixed="right"
          :width="155"
        >
          <template #default="scope">
            <DropDownButtons
              :model-value="scope.row"
              :action-options="usersActionOptions"
              @click-change="handleClickChange"
            />
            <!-- <el-button
              v-permission="['sys:user:edit']"
              size="mini"
              type="primary"
              :icon="Edit"
              @click="editBtn(scope.row)"
            >
              编辑
            </el-button>
            <el-button
              v-permission="['sys:user:assign']"
              size="mini"
              type="primary"
              :icon="Setting"
              @click="assignBtn(scope.row)"
            >
              分配角色
            </el-button>
            <el-button
              v-permission="['sys:user:delete']"
              size="mini"
              type="danger"
              :icon="Delete"
              @click="deleteBtn(scope.row.id)"
            >
              删除
            </el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 
            
            size-change:
            -->
      <el-pagination
        v-model:current-page="listParm.pageNum"
        :page-sizes="[10, 20, 40, 80, 100]"
        :page-size="listParm.pageSize"
        :total="listParm.total"
        layout="total, sizes, prev, pager, next, jumper"
        background
        @size-change="sizeChange"
        @current-change="currentChange"
      />
    </el-main>
  </el-container>
  <!-- 新增、编辑弹框 -->
  <AddAndEdit
    ref="userAddRef"
    @save="save"
  />
  <!-- 分配角色弹框 -->
  <AssignRole ref="assignRoleRef" />
  <!-- 数据权限弹窗 -->
  <DataPermisitonSet
    ref="dataPermisitonSetRef"
    @save-confirm="hanelDataPermisitonSave"
  />
</template>
<script setup lang="ts" name="userList">
import AddAndEdit from "./AddAndEdit.vue";
import AssignRole from "./AssignRole.vue";
import {
  Search,
  Plus,
  RefreshRight,
  Edit,
  Delete,
  Setting
} from "@element-plus/icons-vue";
import { ref, onMounted, nextTick } from "vue";
import LeftTree from "./LeftTree.vue";
import useUserTable from "@/composables/user/useUserTable";
import useUser from "@/composables/user/useUser";
import DropDownButtons from "@/components/DropDownButtons/index.vue";
import DataPermisitonSet from '@/views/system/dataPermission/dataPermisitonSet.vue';
//容器的高度
const containerHeight = ref(0);

//表格的高度
const tableHeigth = ref(0);

//表格列表
const {
  listParm,
  getUserList,
  tableData,
  treeClick,
  sizeChange,
  currentChange,
  searchBtn,
  resetBtn,
  usersActionOptions
} = useUserTable();

//表格的增删改查
const {
  addBtn,
  editBtn,
  deleteBtn,
  assignBtn,
  userAddRef,
  save,
  assignRoleRef,
  dataPermisitonSetRef,
  handleClickChange,
  hanelDataPermisitonSave
} = useUser(getUserList);

onMounted(() => {
  //注意：需要放到nextTick
  nextTick(() => {
    containerHeight.value = window.innerHeight - 100;
    tableHeigth.value = window.innerHeight - 220;
  });
});
</script>
