<template>
  <div class="content-box">
    <div class="left">
      <!-- <el-icon :size="23" class="camera"><VideoCameraFilled /></el-icon> -->
      <span class="cameratxt">角色管理</span>
    </div>
    <div class="scroll">
      <div class="middle">
        <div class="filter">
          <div class="condition">
            <span>角色名称 :</span>
            <el-input
              clearable
              v-model.trim="searchInput.name"
              class="w-50 m-2"
              placeholder="请输入角色名称"
              style="width: 180px"
              @clear="searchBtn"
            />
          </div>
          <div class="condition">
            <span>创建时间 :</span>
            <el-date-picker
              v-model="searchInput.createTime"
              type="datetimerange"
              range-separator="-"
              start-placeholder="起始时间"
              end-placeholder="结束时间"
              format="YYYY-MM-DD HH:mm:ss"
              value-format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择日期"
            />
          </div>
          <el-button
            style="margin-left: 20px"
            color="rgba(38, 151, 255, 1)"
            type="primary"
            class="search"
            @click="searchBtn"
            ><span>查询</span></el-button
          >
          <el-button @click="resetBtn" plain color="rgba(43, 153, 255, 1)"
            >重置</el-button
          >
        </div>
        <!-- 按钮列表 -->
        <div class="gongneng">
          <el-button
            v-if="store.BtnRole('roleManagementSetting1')"
            type="primary"
            style="margin-left: 0"
            color="rgba(38, 151, 255, 1)"
            @click="addRolesClick"
            >添加角色</el-button
          >
        </div>
      </div>
      <div class="footer" v-loading="loading">
        <el-table
          :row-class-name="tableRowClassName"
          :data="tableData.list"
          @selection-change="handleSelectionChange"
          style="width: 100%"
          :header-cell-style="{
            background: 'rgba(240, 243, 247, 1)',
            height: '50px',
            border: 0,
          }"
        >
          <el-table-column
            width="80"
            align="center"
            label="序号"
            type="index"
            index="1"
          />
          <el-table-column align="center" prop="roleName" label="角色名称" />
          <el-table-column align="center" prop="createTime" label="创建时间" />
          <el-table-column align="center" label="操作" fixed="right">
            <template #default="{ row }">
              <div class="options" v-if="roleId == 1">
                <div v-if="row.id == 1"></div>
                <div v-else-if="row.id == 10">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else-if="row.id == 2">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else-if="row.id == 11">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else-if="row.id == 12">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else>
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                  <span
                    class="delete"
                    v-if="store.BtnRole('roleManagementSetting3')"
                    @click="deleteS(row)"
                    >删除</span
                  >
                </div>
              </div>
              <div class="options" v-if="roleId == 10">
                <div v-if="row.id == 1"></div>
                <div v-else-if="row.id == 10">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else-if="row.id == 2">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else-if="row.id == 11">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else-if="row.id == 12">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else>
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                  <span
                    class="delete"
                    v-if="store.BtnRole('roleManagementSetting3')"
                    @click="deleteS(row)"
                    >删除</span
                  >
                </div>
              </div>
              <div class="options" v-if="roleId == 2">
                <div v-if="row.id == 1"></div>
                <div v-else-if="row.id == 10">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else-if="row.id == 2">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else-if="row.id == 11">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else-if="row.id == 12">
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                </div>
                <div v-else>
                  <span
                    class="edit"
                    v-if="store.BtnRole('roleManagementSetting2')"
                    @click="updateS(row)"
                    >编辑</span
                  >
                  <span
                    class="delete"
                    v-if="store.BtnRole('roleManagementSetting3')"
                    @click="deleteS(row)"
                    >删除</span
                  >
                </div>
              </div>
              <div class="options" v-else></div>
              <!-- <span
                class="edit"
                v-if="store.BtnRole('roleManagementSetting2')"
                @click="updateS(row)"
                >编辑</span
              > -->
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <div class="pageSize">
          <span></span>
          <el-pagination
            background
            :current-page="currentPage"
            :page-size="pageSize"
            :page-sizes="[10, 20, 30, 40]"
            layout="total,sizes, prev, pager, next, jumper, slot"
            :total="total"
            @size-change="handleSizeChange"
            @update:current-page="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <!-- 添加角色 -->
    <el-dialog
      class="addRoles"
      v-model="addRolesVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="addRolesTitle"
      align-center
      width="1000"
      :before-close="cancelAddRoles"
    >
      <div class="rolesNames">
        <span>角色名称 : &nbsp;&nbsp;</span>
        <el-input
          :clearable="true"
          :disabled="addRolesTitle == '编辑角色'"
          v-model="addRoles.roleName"
          class="w-50 m-2"
          style="width: 450px"
          placeholder="请输入角色名称"
        />
      </div>
      <div class="rolesName">
        <div class="rolePermission">角色权限: &nbsp;&nbsp;</div>
        <div>
          <table cellspacing="0" border-collapse="collapse">
            <tbody>
              <tr align="center">
                <td>一级</td>
                <td>二级</td>
                <td>功能</td>
              </tr>
              <!-- 数据总览 1 -->
              <tr align="center">
                <td>数据总览</td>
                <td>/</td>
                <td>
                  <el-tree
                    ref="addRolesData1"
                    style="max-width: 600px"
                    :data="addRolesList1.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList1.one)
                    "
                  />
                </td>
              </tr>
              <!-- 学生信息管理 2 -->
              <tr align="center">
                <td>学生信息管理</td>
                <td>/</td>
                <td>
                  <el-tree
                    ref="addRolesData2"
                    style="max-width: 600px"
                    :data="addRolesList2.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList2.one)
                    "
                  />
                </td>
              </tr>
              <!-- 房源管理 3 -->
              <tr align="center">
                <td rowspan="3">房源管理</td>
                <td>楼栋信息管理</td>
                <td>
                  <el-tree
                    ref="addRolesData3"
                    style="max-width: 600px"
                    :data="addRolesList3.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList3.two)
                    "
                  />
                </td>
              </tr>
              <!-- 寝室信息管理 4 -->
              <tr align="center">
                <td>寝室信息管理</td>
                <td>
                  <el-tree
                    ref="addRolesData4"
                    style="max-width: 600px"
                    :data="addRolesList4.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList4.two)
                    "
                  />
                </td>
              </tr>
              <!-- 床位信息管理 5-->
              <tr align="center">
                <td>床位信息管理</td>
                <td>
                  <el-tree
                    ref="addRolesData5"
                    style="max-width: 600px"
                    :data="addRolesList5.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList5.two)
                    "
                  />
                </td>
              </tr>
              <!-- 学生住宿信息 6 -->
              <tr align="center">
                <td>学生住宿信息</td>
                <td>/</td>
                <td>
                  <el-tree
                    ref="addRolesData6"
                    style="max-width: 600px"
                    :data="addRolesList6.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList6.one)
                    "
                  />
                </td>
              </tr>
              <!-- 住宿信息统计 7 -->
              <tr align="center">
                <td>住宿信息统计</td>
                <td>/</td>
                <td>
                  <el-tree
                    ref="addRolesData7"
                    style="max-width: 600px"
                    :data="addRolesList7.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList7.one)
                    "
                  />
                </td>
              </tr>
              <!-- 访客信息管理 8 -->
              <tr align="center">
                <td>访客信息管理</td>
                <td>/</td>
                <td>
                  <el-tree
                    ref="addRolesData8"
                    style="max-width: 600px"
                    :data="addRolesList8.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList8.one)
                    "
                  />
                </td>
              </tr>
              <!-- 选宿舍金额设置 -->
              <tr align="center">
                <td>选宿舍金额设置</td>
                <td>/</td>
                <td>
                  <el-tree
                    ref="addRolesData12"
                    style="max-width: 600px"
                    :data="addRolesList12.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList12.one)
                    "
                  />
                </td>
              </tr>
              <!-- 用户管理 9 -->
              <tr align="center">
                <td rowspan="2">权限管理</td>
                <td>用户管理</td>
                <td>
                  <el-tree
                    ref="addRolesData9"
                    style="max-width: 600px"
                    :data="addRolesList9.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList9.two)
                    "
                  />
                </td>
              </tr>

              <!-- 角色管理 10 -->
              <tr align="center">
                <td>角色管理</td>
                <td>
                  <el-tree
                    ref="addRolesData10"
                    style="max-width: 600px"
                    :data="addRolesList10.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList10.two)
                    "
                  />
                </td>
              </tr>

              <!-- 操作日志 13 -->
              <tr align="center">
                <td>操作日志</td>
                <td>/</td>
                <td>
                  <el-tree
                    ref="addRolesData13"
                    style="max-width: 600px"
                    :data="addRolesList13.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList13.one)
                    "
                  />
                </td>
              </tr>

              <!-- 系统设置 11 -->
              <tr align="center">
                <td>系统设置</td>
                <td>/</td>
                <td>
                  <el-tree
                    ref="addRolesData11"
                    style="max-width: 600px"
                    :data="addRolesList11.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList11.one)
                    "
                  />
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <div class="options">
        <div class="btn">
          <el-button
            color="rgba(41, 109, 227, 1)"
            class="queding"
            type="primary"
            @click="confirmEdit"
          >
            确定
          </el-button>
          <el-button @click="cancelAddRoles">取消</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import {
  ref,
  watch,
  reactive,
  nextTick,
  onBeforeMount,
  onUnmounted,
} from "vue";
import { useRouter } from "vue-router";
import { ElMessage, ElMessageBox } from "element-plus";
import { dayjs } from "element-plus";
import lodash from "lodash";
import { https } from "@/utils/request"; // 绝对路径

import { storeToRefs } from "pinia";
import { useCounterStore } from "@/stores/index";

const router = useRouter();
const store = useCounterStore();

// 为避免解构时失去响应性
const { name, age, isCollapse, realAge, roleId } = storeToRefs(store);

// 表格数据
const loading = ref(false);
const tableData = reactive({
  list: [{}],
});

const searchInput = reactive({
  name: "",
  createTime: "",
}); // 搜索按钮数据

const currentPage = ref(1); // 当前页
const pageSize = ref(10);
const total = ref(); // 当前总数

// 添加角色
const addRolesTitle = ref("添加角色");
const addRolesVisible = ref(false);
const addRoles = reactive({
  id: "",
  roleName: "", //角色名称
  dataManagementSetting: [], //数据总览设置
  studentManagementSetting: [], //学生信息设置
  buildingManagementSetting: [], //楼栋管理设置
  dormitoryManagementSetting: [], //宿舍管理设置
  bedManagementSetting: [], //床位管理设置
  studentAccommodationSetting: [], // 学生住宿设置
  accommodationStatisticsSetting: [], // 住宿统计设置
  visitorManagementSetting: [], //访客管理设置
  roleManagementSetting: [], //角色管理设置
  accountManagementSetting: [], //用户管理设置
  dormitoryMoneySetting: [], //选宿舍金额设置
  settingManagementSetting: [], //设置管理设置
  logManagementSetting: [], // 操作日志
});

const addRolesData1 = ref();
const addRolesList1 = reactive({
  one: "数据总览",
  two: "/",
  three: [
    {
      name: "全部",
      id: 0,
      children: [{ name: "查看页面", id: 1 }],
    },
  ],
  four: "1",
  checkedSel: [],
});

const addRolesData2 = ref();
const addRolesList2 = reactive({
  one: "学生信息管理",
  two: "/",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "导入", id: 1 },
        { name: "导出", id: 2 },
        { name: "新增", id: 3 },
        { name: "详情", id: 4 },
        { name: "编辑", id: 5 },
        { name: "删除", id: 6 },
        { name: "查看页面", id: 7 },
        { name: "现场报到", id: 8 },
      ],
    },
  ],
  four: "2",
  checkedSel: [],
});

const addRolesData3 = ref();
const addRolesList3 = reactive({
  one: "房源管理",
  two: "楼栋信息管理",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "导入", id: 1 },
        { name: "导出", id: 2 },
        { name: "新增", id: 3 },
        { name: "编辑", id: 4 },
        { name: "删除", id: 5 },
        { name: "查看页面", id: 6 },
      ],
    },
  ],
  four: "3",
  checkedSel: [],
});

const addRolesData4 = ref();
const addRolesList4 = reactive({
  one: "房源管理",
  two: "寝室信息管理",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "导入", id: 1 },
        { name: "导出", id: 2 },
        { name: "新增", id: 3 },
        { name: "批量保留", id: 4 },
        { name: "批量开放", id: 5 },
        { name: "保留", id: 6 },
        { name: "开放", id: 7 },
        { name: "编辑", id: 8 },
        { name: "删除", id: 9 },
        { name: "查看页面", id: 10 },
      ],
    },
  ],
  four: "4",
  checkedSel: [],
});

const addRolesData5 = ref();
const addRolesList5 = reactive({
  one: "房源管理",
  two: "床位信息管理",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "导入", id: 1 },
        { name: "导出", id: 2 },
        { name: "新增", id: 3 },
        { name: "批量保留", id: 4 },
        { name: "批量开放", id: 5 },
        { name: "保留", id: 6 },
        { name: "开放", id: 7 },
        { name: "入住", id: 8 },
        { name: "退宿", id: 9 },
        // { name: "换床", id: 10 },
        // { name: "床位对调", id: 11 },
        { name: "删除", id: 12 },
        { name: "查看页面", id: 13 },
        { name: "编辑", id: 14 },
        { name: "所属专业", id: 15 },
        { name: "所属班级", id: 16 },
        { name: "辅导员", id: 17 },
        // {
        //   name: "编辑",
        //   id: 14,
        //   children: [
        //     { name: "所属专业", id: 15 },
        //     { name: "所属班级", id: 16 },
        //     { name: "辅导员", id: 17 },
        //   ],
        // },
      ],
    },
  ],
  four: "5",
  checkedSel: [],
});

const addRolesData6 = ref();
const addRolesList6 = reactive({
  one: "学生住宿信息",
  two: "/",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "导出", id: 1 },
        { name: "查看页面", id: 2 },
      ],
    },
  ],
  four: "6",
  checkedSel: [],
});

const addRolesData7 = ref();
const addRolesList7 = reactive({
  one: "住宿信息统计",
  two: "/",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "导出", id: 1 },
        { name: "查看页面", id: 2 },
      ],
    },
  ],
  four: "7",
  checkedSel: [],
});

const addRolesData8 = ref();
const addRolesList8 = reactive({
  one: "访客信息管理",
  two: "/",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "导出", id: 1 },
        { name: "新增", id: 2 },
        { name: "编辑", id: 3 },
        { name: "删除", id: 4 },
        { name: "查看页面", id: 5 },
      ],
    },
  ],
  four: "8",
  checkedSel: [],
});

const addRolesData9 = ref();
const addRolesList9 = reactive({
  one: "权限管理",
  two: "用户管理",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "新增", id: 1 },
        { name: "编辑", id: 2 },
        { name: "删除", id: 3 },
        { name: "查看页面", id: 4 },
      ],
    },
  ],
  four: "9",
  checkedSel: [],
});

const addRolesData10 = ref();
const addRolesList10 = reactive({
  one: "权限管理",
  two: "角色管理",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "新增", id: 1 },
        { name: "编辑", id: 2 },
        { name: "删除", id: 3 },
        { name: "查看页面", id: 4 },
      ],
    },
  ],
  four: "10",
  checkedSel: [],
});

const addRolesData12 = ref();
const addRolesList12 = reactive({
  one: "选宿舍金额设置",
  two: "/",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "导入", id: 1 },
        { name: "导出", id: 2 },
        { name: "新增", id: 3 },
        { name: "编辑", id: 4 },
        { name: "删除", id: 5 },
        { name: "查看页面", id: 6 },
      ],
    },
  ],
  four: "3",
  checkedSel: [],
});

const addRolesData13 = ref();
const addRolesList13 = reactive({
  one: "操作日志",
  two: "/",
  three: [
    {
      name: "全部",
      id: 0,
      children: [{ name: "查看页面", id: 1 }],
    },
  ],
  four: "13",
  checkedSel: [],
});

const addRolesData11 = ref();
const addRolesList11 = reactive({
  one: "系统设置",
  two: "/",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "修改", id: 1 },
        { name: "查看页面", id: 2 },
      ],
    },
  ],
  four: "11",
  checkedSel: [],
});

const defaultProps = ref({
  children: "children",
  label: "name",
});

const schoolData = ref();

// 获取账户列表
const getList = async () => {
  loading.value = true;
  let params = {
    currentPage: currentPage.value, // 当前页
    pageCount: pageSize.value, // 一页数据条数
    keyWord: searchInput.name,
  };
  if (searchInput.createTime) {
    params.startTime = searchInput.createTime[0];
    params.endTime = searchInput.createTime[1];
  }

  let res = await https.get(
    "/welcome/api/welcomeRole/listRole",
    "params",
    params,
  );
  console.log(res, "角色查询");
  if (res.code == 200) {
    tableData.list = res.data.list;
    total.value = res.data.totalCount;
    loading.value = false;
  } else {
    loading.value = false;
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
const schoolList = async () => {
  let res = await https.get("/welcome/api/welcome-build/schoolGroup", "params");
  console.log(res, "校区数据");
  if (res.code == 200) {
    schoolData.value = res.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
// 搜索功能
const searchBtn = lodash.debounce(async () => {
  getList();
}, 300);
const resetBtn = lodash.debounce(async () => {
  searchInput.name = null;
  searchInput.createTime = null;
  getList();
}, 300);

// 添加角色（------------------------------------------------）
// 合并表格行或列
const addRolesClick = () => {
  addRolesTitle.value = "添加角色";
  addRoles.roleName = "";
  addRoles.id = "";
  addRolesVisible.value = true;
  if (addRolesData1.value) {
    addRolesData1.value.setCheckedKeys([]);
  }
  if (addRolesData2.value) {
    addRolesData2.value.setCheckedKeys([]);
  }
  if (addRolesData3.value) {
    addRolesData3.value.setCheckedKeys([]);
  }
  if (addRolesData4.value) {
    addRolesData4.value.setCheckedKeys([]);
  }
  if (addRolesData5.value) {
    addRolesData5.value.setCheckedKeys([]);
  }
  if (addRolesData6.value) {
    addRolesData6.value.setCheckedKeys([]);
  }
  if (addRolesData7.value) {
    addRolesData7.value.setCheckedKeys([]);
  }
  if (addRolesData8.value) {
    addRolesData8.value.setCheckedKeys([]);
  }
  if (addRolesData9.value) {
    addRolesData9.value.setCheckedKeys([]);
  }
  if (addRolesData10.value) {
    addRolesData10.value.setCheckedKeys([]);
  }
  if (addRolesData12.value) {
    addRolesData12.value.setCheckedKeys([]);
  }
  if (addRolesData13.value) {
    addRolesData13.value.setCheckedKeys([]);
  }
  if (addRolesData11.value) {
    addRolesData11.value.setCheckedKeys([]);
  }
};
const updateS = async (row) => {
  addRolesTitle.value = "编辑角色";
  console.log(row);
  addRolesVisible.value = true;
  addRoles.id = row.id;
  addRoles.roleName = row.roleName;
  setTimeout(() => {
    // 房态管理 1
    if (addRolesData1.value) {
      console.log(row.dataManagementSetting.split(","));
      addRoles.dataManagementSetting = row.dataManagementSetting.split(",");
      addRolesData1.value.setCheckedKeys(row.dataManagementSetting.split(","));
    }

    // 楼栋单元管理 2
    if (addRolesData2.value) {
      addRoles.studentManagementSetting =
        row.studentManagementSetting.split(",");
      addRolesData2.value.setCheckedKeys(
        row.studentManagementSetting.split(","),
      );
    }

    // 房型管理 3
    if (addRolesData3.value) {
      addRoles.buildingManagementSetting =
        row.buildingManagementSetting.split(",");
      addRolesData3.value.setCheckedKeys(
        row.buildingManagementSetting.split(","),
      );
    }
    // 房间列表 4
    if (addRolesData4.value) {
      addRoles.dormitoryManagementSetting =
        row.dormitoryManagementSetting.split(",");
      addRolesData4.value.setCheckedKeys(
        row.dormitoryManagementSetting.split(","),
      );
    }

    // 房价管理 5
    if (addRolesData5.value) {
      addRoles.bedManagementSetting = row.bedManagementSetting.split(",");
      addRolesData5.value.setCheckedKeys(row.bedManagementSetting.split(","));
    }

    // 订单管理 6
    if (addRolesData6.value) {
      addRoles.studentAccommodationSetting =
        row.studentAccommodationSetting.split(",");
      addRolesData6.value.setCheckedKeys(
        row.studentAccommodationSetting.split(","),
      );
    }

    // 值班管理 7
    if (addRolesData7.value) {
      addRoles.accommodationStatisticsSetting =
        row.accommodationStatisticsSetting.split(",");
      addRolesData7.value.setCheckedKeys(
        row.accommodationStatisticsSetting.split(","),
      );
    }
    // 流程管理 8
    if (addRolesData8.value) {
      addRoles.visitorManagementSetting =
        row.visitorManagementSetting.split(",");
      addRolesData8.value.setCheckedKeys(
        row.visitorManagementSetting.split(","),
      );
    }
    // 用户管理 9
    if (addRolesData9.value) {
      addRoles.accountManagementSetting =
        row.accountManagementSetting.split(",");
      addRolesData9.value.setCheckedKeys(
        row.accountManagementSetting.split(","),
      );
    }
    // 角色管理 10
    if (addRolesData10.value) {
      addRoles.roleManagementSetting = row.roleManagementSetting.split(",");
      addRolesData10.value.setCheckedKeys(row.roleManagementSetting.split(","));
    }
    // 选宿舍金额设置 12
    if (addRolesData12.value) {
      if (row.dormitoryMoneySetting) {
        addRoles.dormitoryMoneySetting = row.dormitoryMoneySetting.split(",");
        addRolesData12.value.setCheckedKeys(
          row.dormitoryMoneySetting.split(","),
        );
      }
    }
    // 操作日志 13
    if (addRolesData13.value) {
      if (row.logManagementSetting) {
        addRoles.logManagementSetting = row.logManagementSetting.split(",");
        addRolesData13.value.setCheckedKeys(row.logManagementSetting.split(","));
      }
    }

    // 系统设置 11
    if (addRolesData11.value) {
      addRoles.settingManagementSetting =
        row.settingManagementSetting.split(",");
      addRolesData11.value.setCheckedKeys(
        row.settingManagementSetting.split(","),
      );
    }
  }, 100);
};
const deleteS = async (row) => {
  ElMessageBox.confirm("是否删除此数据?", "提示!!!", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      let data = {
        roleId: row.id,
      };
      let res = await https.get(
        "/welcome/api/welcomeRole/deleteRole",
        "params",
        data,
      );
      if (res.code == 200) {
        ElMessage({
          type: "success",
          showClose: true,
          message: res.message,
          center: true,
        });
        getList();
      } else {
        ElMessage({
          type: "error",
          showClose: true,
          message: res.message,
          center: true,
        });
      }
    })
    .catch(() => {
      loading.value = false;
    });
};

// 勾选角色权限
const editMemberCheckChange = (data, nodes, name) => {
  if (name == "数据总览") {
    addRoles.dataManagementSetting = nodes.checkedKeys;
  } else if (name == "学生信息管理") {
    addRoles.studentManagementSetting = nodes.checkedKeys;
  } else if (name == "楼栋信息管理") {
    addRoles.buildingManagementSetting = nodes.checkedKeys;
  } else if (name == "寝室信息管理") {
    addRoles.dormitoryManagementSetting = nodes.checkedKeys;
  } else if (name == "床位信息管理") {
    addRoles.bedManagementSetting = nodes.checkedKeys;
  } else if (name == "学生住宿信息") {
    addRoles.studentAccommodationSetting = nodes.checkedKeys;
  } else if (name == "住宿信息统计") {
    addRoles.accommodationStatisticsSetting = nodes.checkedKeys;
  } else if (name == "访客信息管理") {
    addRoles.visitorManagementSetting = nodes.checkedKeys;
  } else if (name == "用户管理") {
    addRoles.accountManagementSetting = nodes.checkedKeys;
  } else if (name == "角色管理") {
    addRoles.roleManagementSetting = nodes.checkedKeys;
  } else if (name == "选宿舍金额设置") {
    addRoles.dormitoryMoneySetting = nodes.checkedKeys;
  } else if (name == "操作日志") {
    addRoles.logManagementSetting = nodes.checkedKeys;
  } else if (name == "系统设置") {
    addRoles.settingManagementSetting = nodes.checkedKeys;
  }
};

// 确定
const confirmEdit = async () => {
  if (!addRoles.roleName) {
    ElMessage({
      type: "warning",
      showClose: true,
      message: "角色名称不能为空",
      center: true,
    });
    return;
  }
  let data = {
    roleName: addRoles.roleName,
    dataManagementSetting: addRoles.dataManagementSetting.join(","),
    studentManagementSetting: addRoles.studentManagementSetting.join(","),
    buildingManagementSetting: addRoles.buildingManagementSetting.join(","),
    dormitoryManagementSetting: addRoles.dormitoryManagementSetting.join(","),
    bedManagementSetting: addRoles.bedManagementSetting.join(","),
    studentAccommodationSetting: addRoles.studentAccommodationSetting.join(","),
    accommodationStatisticsSetting:
      addRoles.accommodationStatisticsSetting.join(","),
    visitorManagementSetting: addRoles.visitorManagementSetting.join(","),
    roleManagementSetting: addRoles.roleManagementSetting.join(","),
    accountManagementSetting: addRoles.accountManagementSetting.join(","),
    dormitoryMoneySetting: addRoles.dormitoryMoneySetting.join(","),
    settingManagementSetting: addRoles.settingManagementSetting.join(","),
    logManagementSetting:addRoles.logManagementSetting.join(",")
  };
  if (addRoles.id) {
    data.id = addRoles.id;
    let res = await https.post(
      "/welcome/api/welcomeRole/updateRole",
      "data",
      data,
    );
    console.log(res);

    if (res.code == 200) {
      getList();
      addRolesVisible.value = false;
      ElMessage({
        type: "success",
        showClose: true,
        message: res.message,
        center: true,
      });
    } else {
      ElMessage({
        type: "error",
        showClose: true,
        message: res.message,
        center: true,
      });
    }
  } else {
    let res = await https.post(
      "/welcome/api/welcomeRole/saveRole",
      "data",
      data,
    );
    if (res.code == 200) {
      getList();
      addRolesVisible.value = false;
      ElMessage({
        type: "success",
        showClose: true,
        message: res.message,
        center: true,
      });
    } else {
      ElMessage({
        type: "error",
        showClose: true,
        message: res.message,
        center: true,
      });
    }
  }
};
const cancelAddRoles = () => {
  addRolesVisible.value = false;
  if (addRolesData1.value) {
    addRolesData1.value.setCheckedKeys([]);
  }
  if (addRolesData2.value) {
    addRolesData2.value.setCheckedKeys([]);
  }
  if (addRolesData3.value) {
    addRolesData3.value.setCheckedKeys([]);
  }
  if (addRolesData4.value) {
    addRolesData4.value.setCheckedKeys([]);
  }
  if (addRolesData5.value) {
    addRolesData5.value.setCheckedKeys([]);
  }
  if (addRolesData6.value) {
    addRolesData6.value.setCheckedKeys([]);
  }
  if (addRolesData7.value) {
    addRolesData7.value.setCheckedKeys([]);
  }
  if (addRolesData8.value) {
    addRolesData8.value.setCheckedKeys([]);
  }
  if (addRolesData9.value) {
    addRolesData9.value.setCheckedKeys([]);
  }
  if (addRolesData10.value) {
    addRolesData10.value.setCheckedKeys([]);
  }
  if (addRolesData12.value) {
    addRolesData12.value.setCheckedKeys([]);
  }
  if (addRolesData13.value) {
    addRolesData13.value.setCheckedKeys([]);
  }
  if (addRolesData11.value) {
    addRolesData11.value.setCheckedKeys([]);
  }
};

// 表格斑马纹颜色修改
const tableRowClassName = ({ row, rowIndex }) => {
  if (rowIndex % 2 === 0) {
    return "even";
  } else if (rowIndex % 2 !== 0) {
    return "odd";
  }
  return "";
};
// 每页显示条数
const handleSizeChange = (value) => {
  console.log(value, "每页显示条数");
  pageSize.value = value;
  getList();
};
// 分页
const handleCurrentChange = (value) => {
  // console.log(value);
  currentPage.value = value;
  getList();
};

onBeforeMount(() => {
  getList();
  schoolList();
});
onUnmounted(() => {
  // document.removeEventListener("keyup", Enters);
});
</script>

<style scoped lang="scss">
.content-box {
  width: calc(100% - 40px);
  height: calc(100% - 105px);
  margin: 20px auto;
  background-color: #fff;
  color: #000;
  display: flex;
  flex-direction: column;

  .svg {
    width: 22px;
    height: 22px;
  }

  .left {
    width: calc(100% - 60px);
    height: 60px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #ccc;
    color: #000;
    font-size: 18px;
    font-weight: 600;
    .camera {
      margin-right: 15px;
      color: #4392f7;
    }
  }
  .scroll {
    width: calc(100% - 60px);
    height: calc(100% - 61px);
    margin: 0 auto;
    display: flex;
    flex-direction: column;

    .middle {
      width: calc(100%);
      color: #000;
      .filter {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        .search {
          margin-left: 0 !important;
          color: #fff;
        }
        .condition {
          display: flex;
          align-items: center;
          margin: 10px 30px 10px 0;
          :deep(.el-input .el-input__inner) {
            font-size: 14px;
          }
          .el-select {
            width: 220px;
          }
          span {
            margin: 0 10px 0 0;
          }
        }
      }
      .gongneng {
        margin: 10px 0;
        .el-button {
          color: #fff;
          margin-right: 15px;
        }
      }
    }
    .footer {
      width: calc(100%);
      flex: 1;
      margin: 0 auto;
      overflow: auto;

      .el-table--fit {
        height: calc(100% - 60px);
        :deep(.el-table__header-wrapper) {
          background-color: #000;
          font-size: 15px;
          color: #000;
          .cell {
            color: #000;
          }
        }
        :deep(.el-table__row) {
          height: 50px;
          font-size: 15px;
          color: #000;
        }
        :deep(.el-table__row td) {
          padding: 0;
          border: 0;
        }

        .el-button--primary {
          margin-left: 5px;
        }
        :deep(.el-table__body .even) {
          background-color: #fff;
        }
        :deep(.el-table__body .odd) {
          background-color: rgba(240, 243, 247, 1);
        }
        :deep(.options) {
          display: flex;
          justify-content: center;
          align-items: center;
          .edit {
            margin: 0 15px 0 0;
            color: rgba(0, 186, 173, 1);
            cursor: pointer;
          }
          .delete {
            color: rgba(212, 48, 48, 1);
            cursor: pointer;
          }
        }
      }

      .pageSize {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin: 0 30px;
        height: 60px;

        span {
          color: #000;
        }

        .el-pagination {
          // width: 1600px;
          :deep(.el-pagination__total) {
            color: #000;
          }

          :deep(.el-pagination__goto) {
            color: #000;
          }

          :deep(.el-pagination__classifier) {
            color: #000;
          }

          :deep(.el-input__wrapper) {
            border: 1px solid rgba(0, 0, 0, 1);
            border-radius: 5px;
            box-shadow: none;
          }

          :deep(.el-pager li) {
            margin: 0 5px;
            border: 1px solid rgba(0, 0, 0, 1);
            border-radius: 5px;
            background-color: transparent;
          }

          :deep(.el-pager li.is-active) {
            // background-color: rgba(0, 97, 255, 0.8);
            border: 1px solid rgba(0, 97, 255, 1);
            color: rgba(0, 97, 255, 1);
          }

          :deep(.btn-prev) {
            margin-right: 5px;
            border: 1px solid rgba(0, 0, 0, 1);
            border-radius: 5px;
            background-color: transparent;
          }

          :deep(.btn-next) {
            margin-left: 5px;
            border: 1px solid rgba(0, 0, 0, 1);
            border-radius: 5px;
            background-color: transparent;
          }
        }
      }
    }
  }

  :deep(.addRoles) {
    .el-dialog__body {
      padding: 15px 30px 10px 30px;
      height: 750px;
      overflow: auto;
      .rolesName {
        margin: 15px 0;
        color: #000;
        // height: 600px;
        overflow: auto;
        .rolePermission {
          margin: 10px 0;
        }
      }
      table {
        width: 100%;
        // height: 600px;
        tr {
          td {
            border-top: 1px solid #7c7c7c;
            border-left: 1px solid #7c7c7c;
          }
          td:nth-child(1) {
            width: 120px;
          }
          td:last-child {
            border-right: 1px solid #7c7c7c;
            padding: 10px 0;
            .el-tree {
              .el-tree-node__children {
                display: flex;
                flex-wrap: wrap;
                .el-tree-node {
                  width: 140px;
                  .el-tree-node__content {
                    padding-left: 0 !important;
                  }
                }
                // border: 1px solid red;
              }
            }
          }
        }
        tr:nth-child(1) {
          td {
            height: 40px;
          }
        }
        tr:last-child {
          td {
            border-bottom: 1px solid #7c7c7c;
          }
        }
      }

      .options {
        margin: 10px 20px 20px 0;
        width: 100%;
        .btn {
          display: flex;
          flex-direction: row-reverse;
        }
        .queding {
          color: #fff;
          margin-left: 15px;
        }
      }
    }
  }
}
</style>
