<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>关键字&nbsp;&nbsp;</span>
            <el-input
              :clearable="true"
              @clear="searchBtn"
              v-model.trim="searchInput.keyWord"
              class="w-50 m-2"
              placeholder="请输入关键字"
            />
          </div>
          <div class="condition">
            <span>创建时间&nbsp;&nbsp;</span>
            <el-date-picker
              v-model="searchInput.createTime"
              type="daterange"
              range-separator="-"
              start-placeholder="起始时间"
              end-placeholder="结束时间"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              :prefix-icon="Calendar"
              placeholder="请选择日期"
            />
          </div>
          <el-button
            color="rgba(0, 97, 255, 1)"
            type="primary"
            class="search"
            @click="searchBtn"
            ><el-icon>
              <Search />
            </el-icon>
            <span>查询</span></el-button
          >
        </div>
        <!-- 按钮列表 -->
        <div class="gongneng" v-if="flagBtn.tianjia == 1">
          <el-button
            type="primary"
            color="rgba(0, 97, 255, 1)"
            @click="addRolesClick"
            ><span>添加角色</span></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%"
          default-expand-all
          :header-cell-style="{
            background: 'rgba(240, 243, 247, 1)',
            height: '50px',
            border: 0,
          }"
        >
          <!-- <el-table-column align="center" type="selection" width="80" /> -->
          <el-table-column
            width="100"
            align="center "
            type="index"
            label="序号"
          />
          <el-table-column align="center" prop="hName" label="角色级别">
            <template #default="{ row }">
              <span>{{ row.parentId == 0 ? "T0" : "T1" }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="name" label="父级角色名称">
            <template #default="{ row }">
              <span v-if="row.parentName">{{ row.parentName }}</span>
              <span v-else>/</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="name" label="角色名称">
            <template #default="{ row }">
              {{ row.name }}
            </template>
          </el-table-column>
          <el-table-column align="center" prop="createTime" label="创建时间" />
          <el-table-column align="center" label="操作" width="200">
            <template #default="{ row }">
              <div class="edit">
                <div
                  v-if="row.parentId == 0 && flagBtn.tianjia == 1"
                  class="look"
                  @click="addRolesClicks(row)"
                >
                  添加
                </div>
                <div
                  v-if="flagBtn.bianji == 1"
                  class="look"
                  @click="editClick(row)"
                >
                  编辑
                </div>
                <el-popconfirm
                  v-if="flagBtn.shanchu == 1"
                  width="220"
                  confirm-button-text="确认"
                  cancel-button-text="取消"
                  :icon="InfoFilled"
                  icon-color="#f89626"
                  title="是否删除此角色?"
                  @confirm="delRoles(row)"
                  @cancel="cancelEvent"
                >
                  <template #reference>
                    <div class="del">删除</div>
                  </template>
                </el-popconfirm>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <div class="pageSize">
          <span></span>
          <el-pagination
            background
            :current-page="currentPage"
            :page-size="pageSize"
            layout="total, prev, pager, next, jumper, slot"
            :total="total"
            @update:current-page="handleCurrentChange"
          />
        </div>
      </div>

      <!-- 添加角色 -->
      <el-dialog
        class="addRoles"
        v-model="addRolesVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :title="addRolesTitle"
        align-center
        width="900"
        :before-close="cancelAddRoles"
      >
        <div class="rolesNames">
          <span>角色名称: &nbsp;&nbsp;</span>
          <el-input
            :clearable="true"
            v-model.trim="addRoles.name"
            class="w-50 m-2"
            style="width: 450px"
            placeholder="请输入角色名称"
          />
        </div>
        <div class="rolesName">
          <div class="rolePermission">角色权限: &nbsp;&nbsp;</div>
          <div>
            <!-- <el-table
              :row-class-name="tableRowClassName"
              :data="addRolesData.list"
              style="width: 100%"
              :span-method="arraySpanMethod"
              :header-cell-style="{
                background: 'rgba(240, 243, 247, 1)',
                height: '50px',
              }"
            >
              <el-table-column align="center" prop="one" label="一级" />
              <el-table-column align="center" prop="two" label="二级" />
              <el-table-column width="600" label="功能">
                <template #default="{ row }">
                  <div class="checkBoxSel">
                    <el-tree
                      :ref="`addRolesData${row.four}`"
                      style="max-width: 600px"
                      :data="row.three"
                      show-checkbox
                      node-key="id"
                      :props="defaultProps"
                      default-expand-all
                      @check="
                        (data, nodes) => editMemberCheckChange(data, nodes, row)
                      "
                    />
                  </div>
                </template></el-table-column
              >
            </el-table> -->

            <table cellspacing="0" border-collapse="collapse">
              <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 :rowspan="4">房间管理</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.two)
                    "
                  />
                </td>
              </tr>
              <!-- 房型管理 3 -->
              <tr align="center">
                <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 :rowspan="2">授权管理</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.two)
                    "
                  />
                </td>
              </tr>
              <!-- 流程管理 8 -->
              <tr align="center">
                <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.two)
                    "
                  />
                </td>
              </tr>
              <!-- 统计报表 9 -->
              <tr align="center">
                <td>统计报表</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.one)
                    "
                  />
                </td>
              </tr>

              <!-- 黑名单管理 10 -->
              <tr align="center">
                <td>黑名单管理</td>
                <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.one)
                    "
                  />
                </td>
              </tr>
              <!-- 门锁管理 11 -->
              <tr align="center">
                <td rowspan="2">设备管理</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.two)
                    "
                  />
                </td>
              </tr>
              <!-- 水电表管理 12 -->
              <tr align="center">
                <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.two)
                    "
                  />
                </td>
              </tr>
              <!-- 角色管理 13 -->
              <tr align="center">
                <td rowspan="4">账号管理</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.two)
                    "
                  />
                </td>
              </tr>
              <!-- 账号管理 14 -->
              <tr align="center">
                <td>账号管理</td>
                <td>
                  <el-tree
                    ref="addRolesData14"
                    style="max-width: 600px"
                    :data="addRolesList14.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList14.two)
                    "
                  />
                </td>
              </tr>
              <!-- 员工管理 15 -->
              <tr align="center">
                <td>员工管理</td>
                <td>
                  <el-tree
                    ref="addRolesData15"
                    style="max-width: 600px"
                    :data="addRolesList15.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList15.two)
                    "
                  />
                </td>
              </tr>
              <!-- 用户管理 16 -->
              <tr align="center">
                <td>用户管理</td>
                <td>
                  <el-tree
                    ref="addRolesData16"
                    style="max-width: 600px"
                    :data="addRolesList16.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList16.two)
                    "
                  />
                </td>
              </tr>
              <!-- 系统设置 17 -->
              <tr align="center">
                <td>系统设置</td>
                <td>/</td>
                <td>
                  <el-tree
                    ref="addRolesData17"
                    style="max-width: 600px"
                    :data="addRolesList17.three"
                    show-checkbox
                    node-key="id"
                    :props="defaultProps"
                    default-expand-all
                    @check="
                      (data, nodes) =>
                        editMemberCheckChange(data, nodes, addRolesList17.one)
                    "
                  />
                </td>
              </tr>
            </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>

      <!-- 编辑按钮 -->
      <el-dialog
        class="editDialog"
        v-model="editVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :title="titleDialog"
        align-center
        width="550"
        :before-close="cancelEdit"
      >
        <el-form
          ref="editRef"
          :model="editRuleForm"
          :rules="editRules"
          label-width="90px"
          class="demo-ruleForm"
          :size="formSize"
          label-position="left"
          status-icon
        >
          <el-form-item label="水电编码 :" prop="SD_encoding">
            <el-input
              v-model.trim="editRuleForm.SD_encoding"
              placeholder="请输入水电编码"
              clearable
              style="width: 500px"
            />
          </el-form-item>
          <el-form-item label="电表编码 :" prop="DB_encoding">
            <el-input
              v-model.trim="editRuleForm.DB_encoding"
              placeholder="请输入电表编码"
              clearable
              style="width: 500px"
            />
          </el-form-item>
          <el-form-item label="房间号 :" prop="roomNum">
            <!-- <el-tree
              :data="roomNumData"
              :props="{
                label: 'label',
                children: 'children',
                value: 'value',
                disabled: 'disabled',
              }"
              node-key="id"
              show-checkbox
              ref="roomNumRef"
              @node-click="roomNumClick"
              @check-change="handleCheckChange"
            /> -->
            <el-cascader
              v-model="editRuleForm.roomNum"
              :options="roomNumData"
              :show-all-levels="false"
            />
          </el-form-item>
          <el-form-item class="options">
            <el-button
              color="rgba(41, 109, 227, 1)"
              class="queding"
              type="primary"
              @click="confirmEdit(editRef)"
            >
              确定
            </el-button>
            <el-button @click="cancelEdit">取消</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </div>
  </div>
</template>

<script setup>
import {
  ref,
  reactive,
  watch,
  nextTick,
  onBeforeMount,
  onUnmounted,
} from "vue";
import { useRouter } from "vue-router";
import { ElMessage, ElMessageBox, ElLoading } from "element-plus";
import { Calendar } from "@element-plus/icons-vue";
import vidiconsApi from "@/api/vidicons.js";
import { dayjs } from "element-plus";
import lodash from "lodash";
import axios from "axios";
import { useStore } from "vuex";
const store = useStore();
const api = ref("");
const router = useRouter();
// 表格数据
const loading = ref(false);
const tableData = reactive({
  list: [],
});
const flagBtn = ref(); // 按钮权限
const searchInput = reactive({
  keyWord: "",
  createTime: "",
}); // 搜索按钮数据

watch(
  () => searchInput.createTime,
  (newVal, oldVal) => {
    console.log("监听时间:", newVal);
    if (newVal == null) {
      getList();
    }
  }
);
const currentPage = ref(1); // 当前页
const pageSize = ref(10);
const total = ref(); // 当前总数

// 添加角色
const addRolesTitle = ref("添加角色");
const addRolesVisible = ref(false);
const parentId = ref();
const addRoles = reactive({
  id: "",
  name: "",
  adminMenuId: "",
  houseStatusManagement: [], // 房态管理 1

  buildingManagement: [], // 楼栋单元管理 2
  houseTypeManagement: [], // 房型管理 3
  houseNumberManagement: [], // 房间列表 4
  housePriceManagement: [], // 房价管理 5

  houseOrderManagement: [], //订单管理 6

  dutyManagement: [], //值班管理 7
  processManagement: [], //流程管理 8

  reportManagement: [], //统计报表 9

  blacklistManagement: [], //黑名单管理 10

  doorLockManagement: [], //门锁管理 11
  hydropowerManagement: [], //水电表管理 12

  roleManagement: [], //角色管理 13
  accountManagement: [], //账号管理 14
  staffManagement: [], // 员工管理 15
  userManagement: [], //用户管理 16

  systemManagement: [], //系统设置 17
});

const addRolesData1 = ref(); // 房态管理
const addRolesList1 = 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: 18 },
        { name: "查看密码", id: 19 },
        { name: "退款", id: 20 },
      ],
    },
  ],
  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 },
      ],
    },
  ],
  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: 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 },
      ],
    },
  ],
  four: "4",
  checkedSel: [],
});

const addRolesData5 = ref(); // 房价管理
const addRolesList5 = reactive({
  one: "房间管理",
  two: "房价管理",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "批量改价", id: 4 },
        { name: "改价记录", id: 5 },
        { name: "查看界面", id: 7 },
      ],
    },
  ],
  four: "5",
  checkedSel: [],
});

const addRolesData6 = ref(); // 订单管理
const addRolesList6 = 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: "6",
  checkedSel: [],
});

const addRolesData7 = ref(); // 课表管理
const addRolesList7 = reactive({
  one: "授权管理",
  two: "值班管理",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "导入值班", id: 1 },
        { name: "导出", id: 2 },
        { name: "查看界面", id: 3 },
        { name: "删除", id: 4 },
        { name: "添加", id: 5 },
      ],
    },
  ],
  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 },
        { name: "规则设置", id: 6 },
        // { name: "导出", id: 7 },
      ],
    },
  ],
  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 },
      ],
    },
  ],
  four: "9",
  checkedSel: [],
});

const addRolesData10 = ref(); // 黑名单管理
const addRolesList10 = reactive({
  one: "黑名单管理",
  two: "/",
  three: [
    {
      name: "全部",
      id: 0,
      children: [
        { name: "移出", id: 1 },
        { name: "查看界面", id: 2 },
      ],
    },
  ],
  four: "10",
  checkedSel: [],
});

const addRolesData11 = ref(); // 门锁管理
const addRolesList11 = 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: "NFC设置", id: 15 },
      ],
    },
  ],
  four: "11",
  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: "12",
  checkedSel: [],
});

const addRolesData13 = ref(); // 角色管理
const addRolesList13 = 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: "13",
  checkedSel: [],
});

const addRolesData14 = ref(); // 账号管理
const addRolesList14 = 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: "14",
  checkedSel: [],
});

const addRolesData15 = ref(); // 员工管理
const addRolesList15 = 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: "15",
  checkedSel: [],
});

const addRolesData16 = ref(); // 用户管理
const addRolesList16 = 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: "16",
  checkedSel: [],
});

const addRolesData17 = ref(); // 系统设置
const addRolesList17 = 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 },
      ],
    },
  ],
  four: "17",
  checkedSel: [],
});
// const addRolesData = reactive({
//   list: [
//     {
//       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: 18 },
//           ],
//         },
//       ],
//       four: "1",
//       checkedSel: [],
//     },
//     {
//       one: "房间管理",
//       two: "楼栋单元管理",
//       three: [
//         {
//           name: "全部",
//           id: 0,
//           children: [
//             { name: "添加", id: 1 },
//             { name: "修改", id: 2 },
//             { name: "删除", id: 3 },
//             { name: "查看界面", id: 4 },
//           ],
//         },
//       ],
//       four: "2",
//       checkedSel: [],
//     },
//     {
//       one: "房间管理",
//       two: "房型管理",
//       three: [
//         {
//           name: "全部",
//           id: 0,
//           children: [
//             { name: "添加", id: 1 },
//             { name: "修改", id: 2 },
//             { name: "删除", id: 3 },
//             { name: "查看界面", id: 6 },
//           ],
//         },
//       ],
//       four: "3",
//       checkedSel: [],
//     },
//     {
//       one: "房间管理",
//       two: "房间列表",
//       three: [
//         {
//           name: "全部",
//           id: 0,
//           children: [
//             { name: "添加", id: 1 },
//             { name: "修改", id: 2 },
//             { name: "删除", id: 3 },
//             { name: "查看界面", id: 4 },
//             { name: "批量导入", id: 5 },
//           ],
//         },
//       ],
//       four: "4",
//       checkedSel: [],
//     },
//     {
//       one: "房间管理",
//       two: "房价管理",
//       three: [
//         {
//           name: "全部",
//           id: 0,
//           children: [
//             { name: "批量改价", id: 4 },
//             { name: "改价记录", id: 5 },
//             { name: "查看界面", id: 7 },
//           ],
//         },
//       ],
//       four: "5",
//       checkedSel: [],
//     },
//     {
//       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 },
//           ],
//         },
//       ],
//       four: "6",
//       checkedSel: [],
//     },
//     {
//       one: "授权管理",
//       two: "值班管理",
//       three: [
//         {
//           name: "全部",
//           id: 0,
//           children: [
//             { name: "导入值班", id: 1 },
//             { name: "导出", id: 2 },
//             { name: "查看界面", id: 3 },
//           ],
//         },
//       ],
//       four: "7",
//       checkedSel: [],
//     },
//     {
//       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 },
//           ],
//         },
//       ],
//       four: "8",
//       checkedSel: [],
//     },
//     {
//       one: "统计报表",
//       two: "/",
//       three: [
//         {
//           name: "全部",
//           id: 0,
//           children: [
//             { name: "查看界面", id: 1 },
//             { name: "导出", id: 2 },
//             { name: "详情", id: 3 },
//           ],
//         },
//       ],
//       four: "9",
//       checkedSel: [],
//     },
//     {
//       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: "NFC设置", id: 15 },
//           ],
//         },
//       ],
//       four: "10",
//       checkedSel: [],
//     },
//     {
//       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: "11",
//       checkedSel: [],
//     },
//     {
//       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: "12",
//       checkedSel: [],
//     },
//     {
//       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: "13",
//       checkedSel: [],
//     },
//     {
//       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: "14",
//       checkedSel: [],
//     },
//     {
//       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: "15",
//       checkedSel: [],
//     },

//     {
//       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: "16",
//       checkedSel: [],
//     },
//   ],
// });

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

// 编辑功能
const titleDialog = ref("");
const editVisible = ref(false);
const editRef = ref();
const editRuleForm = reactive({
  SD_encoding: "",
  DB_encoding: "",
  roomNum: "",
  id: "",
});
// 树形结构配置
const roomNumRef = ref();
const roomNumData = [
  {
    value: 1,
    label: "Level one 1",
    children: [
      {
        value: 11,
        label: "Level two 1-1",
      },
      {
        value: 12,
        label: "Level two 1-2",
      },
    ],
  },
  {
    value: 2,
    label: "Level one 2",
    children: [
      {
        value: 21,
        label: "Level two 2-1",
      },
      {
        value: 22,
        label: "Level two 2-2",
      },
    ],
  },
];
// 表单验证
const editRules = reactive({
  SD_encoding: [
    { required: true, message: "水电编码不能为空", trigger: "blur" },
  ],
  DB_encoding: [
    {
      required: true,
      message: "电表编码不能为空",
      trigger: "blur",
    },
  ],
  roomNum: [
    {
      required: true,
      message: "房间号不能为空",
      trigger: "blur",
    },
  ],
});

// 查看房型列表
const getList = async () => {
  loading.value = true;
  let data = {
    page: currentPage.value,
    size: pageSize.value,
    keyWord: searchInput.keyWord, // 房型名称
    adminMenuId: sessionStorage.getItem("permissionSettingId"),
  };
  if (searchInput.createTime) {
    data.startTime = searchInput.createTime[0];
    data.endTime = searchInput.createTime[1];
  }
  let res = await axios({
    method: "get",
    url: api.value + "/admin-menu/adminListPage",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("user_head"),
    },
    params: data,
  });
  console.log(res, "角色管理");
  if (res.data.code == 200) {
    loading.value = false;
    tableData.list = res.data.data.records;
    total.value = res.data.data.total;
  } else {
    loading.value = false;
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

// 搜索功能
const searchBtn = lodash.debounce(async () => {
  getList();
}, 300);

// 添加角色（------------------------------------------------）
// 合并表格行或列
// const arraySpanMethod = ({ row, column, rowIndex, columnIndex }) => {
//   if (columnIndex === 0) {
//     if (rowIndex === 1) {
//       return {
//         rowspan: 2,
//         colspan: 1,
//       };
//     }
//     if (rowIndex === 2) {
//       return {
//         rowspan: 0,
//         colspan: 0,
//       };
//     }
//     if (rowIndex === 4) {
//       return {
//         rowspan: 2,
//         colspan: 1,
//       };
//     }
//     if (rowIndex === 5) {
//       return {
//         rowspan: 0,
//         colspan: 0,
//       };
//     }
//     if (rowIndex === 7) {
//       return {
//         rowspan: 2,
//         colspan: 1,
//       };
//     }
//     if (rowIndex === 8) {
//       return {
//         rowspan: 0,
//         colspan: 0,
//       };
//     }
//     if (rowIndex === 9) {
//       return {
//         rowspan: 2,
//         colspan: 1,
//       };
//     }
//     if (rowIndex === 10) {
//       return {
//         rowspan: 0,
//         colspan: 0,
//       };
//     }
//   }
// };

const addRolesClick = () => {
  addRolesTitle.value = "添加一级角色";
  parentId.value = "";
  addRoles.name = "";
  addRoles.id = "";
  addRoles.adminMenuId = "";
  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 (addRolesData11.value) {
    addRolesData11.value.setCheckedKeys([]);
  }
  if (addRolesData12.value) {
    addRolesData12.value.setCheckedKeys([]);
  }
  if (addRolesData13.value) {
    addRolesData13.value.setCheckedKeys([]);
  }
  if (addRolesData14.value) {
    addRolesData14.value.setCheckedKeys([]);
  }
  if (addRolesData15.value) {
    addRolesData15.value.setCheckedKeys([]);
  }
  if (addRolesData16.value) {
    addRolesData16.value.setCheckedKeys([]);
  }
  if (addRolesData17.value) {
    addRolesData17.value.setCheckedKeys([]);
  }
};
const addRolesClicks = (row) => {
  addRolesTitle.value = "添加二级角色";
  parentId.value = row.id;
  addRoles.name = "";
  addRoles.id = "";
  addRoles.adminMenuId = "";
  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 (addRolesData11.value) {
    addRolesData11.value.setCheckedKeys([]);
  }
  if (addRolesData12.value) {
    addRolesData12.value.setCheckedKeys([]);
  }
  if (addRolesData13.value) {
    addRolesData13.value.setCheckedKeys([]);
  }
  if (addRolesData14.value) {
    addRolesData14.value.setCheckedKeys([]);
  }
  if (addRolesData15.value) {
    addRolesData15.value.setCheckedKeys([]);
  }
  if (addRolesData16.value) {
    addRolesData16.value.setCheckedKeys([]);
  }
  if (addRolesData17.value) {
    addRolesData17.value.setCheckedKeys([]);
  }
};
const cancelAddRoles = () => {
  addRolesVisible.value = false;
};

//编辑按钮  （-------------------------------------------）
const editClick = async (row) => {
  addRolesTitle.value = "编辑角色";
  addRolesVisible.value = true;
  addRoles.name = row.name;
  parentId.value = row.parentId;
  console.log(row);
  let data = {
    adminMenuId: row.id,
    permissionSettingId: sessionStorage.getItem("permissionSettingId"),
  };
  let res = await axios({
    method: "get",
    url: api.value + "/admin-menu/getMenuPermissionSetting",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("user_head"),
    },
    params: data,
  });
  console.log(res);
  if (res.data.code == 200) {
    addRoles.id = res.data.data.id;
    addRoles.adminMenuId = res.data.data.adminMenuId;
    // 房态管理 1
    if (res.data.data.houseStatusManagement) {
      addRoles.houseStatusManagement =
        res.data.data.houseStatusManagement.split(",");
      addRolesData1.value.setCheckedKeys(
        res.data.data.houseStatusManagement.split(",")
      );
    }

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

    // 房型管理 3
    if (res.data.data.houseTypeManagement) {
      addRoles.houseTypeManagement =
        res.data.data.houseTypeManagement.split(",");
      addRolesData3.value.setCheckedKeys(
        res.data.data.houseTypeManagement.split(",")
      );
    }
    // 房间列表 4
    if (res.data.data.houseNumberManagement) {
      addRoles.houseNumberManagement =
        res.data.data.houseNumberManagement.split(",");
      addRolesData4.value.setCheckedKeys(
        res.data.data.houseNumberManagement.split(",")
      );
    }

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

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

    // 值班管理 7
    if (res.data.data.dutyManagement) {
      addRoles.dutyManagement = res.data.data.dutyManagement.split(",");
      addRolesData7.value.setCheckedKeys(
        res.data.data.dutyManagement.split(",")
      );
    }
    // 流程管理 8
    if (res.data.data.processManagement) {
      addRoles.processManagement = res.data.data.processManagement.split(",");
      addRolesData8.value.setCheckedKeys(
        res.data.data.processManagement.split(",")
      );
    }

    // 统计报表 9
    if (res.data.data.reportManagement) {
      addRoles.reportManagement = res.data.data.reportManagement.split(",");
      addRolesData9.value.setCheckedKeys(
        res.data.data.reportManagement.split(",")
      );
    }

    // 黑名单管理 10
    if (res.data.data.blacklistManagement) {
      addRoles.blacklistManagement =
        res.data.data.blacklistManagement.split(",");
      addRolesData10.value.setCheckedKeys(
        res.data.data.blacklistManagement.split(",")
      );
    }

    // 门锁管理 11
    if (res.data.data.doorLockManagement) {
      addRoles.doorLockManagement = res.data.data.doorLockManagement.split(",");
      addRolesData11.value.setCheckedKeys(
        res.data.data.doorLockManagement.split(",")
      );
    }
    // 水电表管理 12
    if (res.data.data.hydropowerManagement) {
      addRoles.hydropowerManagement =
        res.data.data.hydropowerManagement.split(",");
      addRolesData12.value.setCheckedKeys(
        res.data.data.hydropowerManagement.split(",")
      );
    }

    // 角色管理 13
    if (res.data.data.roleManagement) {
      addRoles.roleManagement = res.data.data.roleManagement.split(",");
      addRolesData13.value.setCheckedKeys(
        res.data.data.roleManagement.split(",")
      );
    }

    // 账号管理 14
    if (res.data.data.accountManagement) {
      addRoles.accountManagement = res.data.data.accountManagement.split(",");
      addRolesData14.value.setCheckedKeys(
        res.data.data.accountManagement.split(",")
      );
    }
    // 员工管理 15
    if (res.data.data.staffManagement) {
      addRoles.staffManagement = res.data.data.staffManagement.split(",");
      addRolesData15.value.setCheckedKeys(
        res.data.data.staffManagement.split(",")
      );
    }

    // 用户管理 16
    if (res.data.data.userManagement) {
      addRoles.userManagement = res.data.data.userManagement.split(",");
      addRolesData16.value.setCheckedKeys(
        res.data.data.userManagement.split(",")
      );
    }
    // 系统设置 17
    if (res.data.data.systemManagement) {
      addRoles.systemManagement = res.data.data.systemManagement.split(",");
      addRolesData17.value.setCheckedKeys(
        res.data.data.systemManagement.split(",")
      );
    }
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

const cancelEdit = () => {
  addRolesVisible.value = false;
};
// 勾选角色权限
const editMemberCheckChange1 = (data, nodes, row) => {
  console.log(data, nodes, row, "勾选角色");
};
const editMemberCheckChange = (data, nodes, name) => {
  console.log(data, nodes, name, "勾选角色");
  // editMemberTree.value.setCheckedKeys([]);
  if (name == "房态管理") {
    addRoles.houseStatusManagement = nodes.checkedKeys;
  } else if (name == "楼栋单元管理") {
    addRoles.buildingManagement = nodes.checkedKeys;
  } else if (name == "房型管理") {
    addRoles.houseTypeManagement = nodes.checkedKeys;
  } else if (name == "房间列表") {
    addRoles.houseNumberManagement = nodes.checkedKeys;
  } else if (name == "房价管理") {
    addRoles.housePriceManagement = nodes.checkedKeys;
  } else if (name == "订单管理") {
    addRoles.houseOrderManagement = nodes.checkedKeys;
  } else if (name == "值班管理") {
    addRoles.dutyManagement = nodes.checkedKeys;
  } else if (name == "流程管理") {
    addRoles.processManagement = nodes.checkedKeys;
  } else if (name == "统计报表") {
    addRoles.reportManagement = nodes.checkedKeys;
  } else if (name == "黑名单管理") {
    addRoles.blacklistManagement = nodes.checkedKeys;
  } else if (name == "门锁管理") {
    addRoles.doorLockManagement = nodes.checkedKeys;
  } else if (name == "水电表管理") {
    addRoles.hydropowerManagement = nodes.checkedKeys;
  } else if (name == "角色管理") {
    addRoles.roleManagement = nodes.checkedKeys;
  } else if (name == "账号管理") {
    addRoles.accountManagement = nodes.checkedKeys;
  } else if (name == "员工管理") {
    addRoles.staffManagement = nodes.checkedKeys;
  } else if (name == "用户管理") {
    addRoles.userManagement = nodes.checkedKeys;
  } else if (name == "系统设置") {
    addRoles.systemManagement = nodes.checkedKeys;
  }
};
// 确定
const confirmEdit = async () => {
  const loading = ElLoading.service({
    lock: true,
    text: "Loading",
    background: "rgba(0, 0, 0, 0.7)",
  });
  if (addRoles.id) {
    let data = {
      id: addRoles.id,
      name: addRoles.name,
      adminMenuId: addRoles.adminMenuId,
      permissionSettingId: sessionStorage.getItem("permissionSettingId"),
      houseStatusManagement: addRoles.houseStatusManagement.join(","),

      buildingManagement: addRoles.buildingManagement.join(","),
      houseTypeManagement: addRoles.houseTypeManagement.join(","),
      houseNumberManagement: addRoles.houseNumberManagement.join(","),
      housePriceManagement: addRoles.housePriceManagement.join(","),

      houseOrderManagement: addRoles.houseOrderManagement.join(","),

      dutyManagement: addRoles.dutyManagement.join(","),
      processManagement: addRoles.processManagement.join(","),

      reportManagement: addRoles.reportManagement.join(","),

      blacklistManagement: addRoles.blacklistManagement.join(","),

      doorLockManagement: addRoles.doorLockManagement.join(","),
      hydropowerManagement: addRoles.hydropowerManagement.join(","),

      roleManagement: addRoles.roleManagement.join(","),
      accountManagement: addRoles.accountManagement.join(","),
      staffManagement: addRoles.staffManagement.join(","),
      userManagement: addRoles.userManagement.join(","),

      systemManagement: addRoles.systemManagement.join(","),
    };
    console.log(data, "编辑参数");
    if (!addRoles.name) {
      ElMessage({
        type: "warning",
        showClose: true,
        message: "角色名称不能为空",
        center: true,
      });
      return false;
    }
    let res = await axios({
      method: "post",
      url: api.value + "/admin-menu/updateMenuPermissionSetting",
      headers: {
        token: sessionStorage.getItem("token"),
        user_head: sessionStorage.getItem("user_head"),
      },
      data: data,
    });
    if (res.data.code == 200) {
      if (addRoles.id == sessionStorage.getItem("permissionSettingId")) {
        store.commit("ROLELIST", addRoles.id);
        setTimeout(() => {
          window.location.reload();
        }, 1000);
      }
      addRolesVisible.value = false;
      loading.close();
      ElMessage({
        type: "success",
        showClose: true,
        message: res.data.message,
        center: true,
      });
    } else {
      ElMessage({
        type: "error",
        showClose: true,
        message: res.data.message,
        center: true,
      });
    }
  } else {
    let data = {
      name: addRoles.name,
      adminMenuId: sessionStorage.getItem("permissionSettingId"),
      // permissionSettingId: sessionStorage.getItem("permissionSettingId"),
      houseStatusManagement: addRoles.houseStatusManagement.join(","),

      buildingManagement: addRoles.buildingManagement.join(","),
      houseTypeManagement: addRoles.houseTypeManagement.join(","),
      houseNumberManagement: addRoles.houseNumberManagement.join(","),
      housePriceManagement: addRoles.housePriceManagement.join(","),

      houseOrderManagement: addRoles.houseOrderManagement.join(","),

      dutyManagement: addRoles.dutyManagement.join(","),
      processManagement: addRoles.processManagement.join(","),

      reportManagement: addRoles.reportManagement.join(","),

      blacklistManagement: addRoles.blacklistManagement.join(","),

      doorLockManagement: addRoles.doorLockManagement.join(","),
      hydropowerManagement: addRoles.hydropowerManagement.join(","),

      roleManagement: addRoles.roleManagement.join(","),
      accountManagement: addRoles.accountManagement.join(","),
      staffManagement: addRoles.staffManagement.join(","),
      userManagement: addRoles.userManagement.join(","),

      systemManagement: addRoles.systemManagement.join(","),
    };
    if (!addRoles.name) {
      ElMessage({
        type: "warning",
        showClose: true,
        message: "角色名称不能为空",
        center: true,
      });
      return false;
    }
    if (parentId.value) {
      data.parentId = parentId.value;
      let res = await axios({
        method: "post",
        url: api.value + "/admin-menu/saveSecondary",
        headers: {
          token: sessionStorage.getItem("token"),
          user_head: sessionStorage.getItem("user_head"),
        },
        data: data,
      });
      console.log(res, "添加T1角色");
      if (res.data.code == 200) {
        getList();
        // if (addRoles.id == sessionStorage.getItem("permissionSettingId")) {
        //   store.commit("ROLELIST", addRoles.id);
        //   setTimeout(() => {
        //     window.location.reload();
        //   }, 1000);
        // }
        loading.close();
        addRolesVisible.value = false;
        ElMessage({
          type: "success",
          showClose: true,
          message: res.data.message,
          center: true,
        });
      } else {
        ElMessage({
          type: "error",
          showClose: true,
          message: res.data.message,
          center: true,
        });
      }
    } else {
      let res = await axios({
        method: "post",
        url: api.value + "/admin-menu/saveParent",
        headers: {
          token: sessionStorage.getItem("token"),
          user_head: sessionStorage.getItem("user_head"),
        },
        data: data,
      });
      console.log(res, "添加T0角色");
      if (res.data.code == 200) {
        getList();
        loading.close();
        addRolesVisible.value = false;
        ElMessage({
          type: "success",
          showClose: true,
          message: res.data.message,
          center: true,
        });
      } else {
        ElMessage({
          type: "error",
          showClose: true,
          message: res.data.message,
          center: true,
        });
      }
    }
  }
};

//删除按钮
const delRoles = async (row) => {
  let data = {
    adminMenuId: row.id,
    permissionSettingId: sessionStorage.getItem("permissionSettingId"),
  };
  let res = await axios({
    method: "get",
    url: api.value + "/admin-menu/delete",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("user_head"),
    },
    params: data,
  });
  if (res.data.code == 200) {
    if (tableData.list.length == 1 && currentPage.value != 1) {
      currentPage.value = currentPage.value - 1;
    }
    getList();
    ElMessage({
      type: "success",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
  // console.log(res);
};

// 多选框功能
const handleSelectionChange = (val) => {
  console.log(val);
  selectData.list = val;
};
//导出功能
// const importExcel = async () => {
//   if (searchInput.createTime == null) {
//     searchInput.createTime = "";
//   }
//   let data = new FormData();
//   data.set("car_number", searchInput.carnumber);
//   data.set("create_time", searchInput.createTime);
//   let res = await axios({
//     method: "post",
//     url: api.value + "/carBook/cinfotoExcel.action",
//     headers: {
//       token: sessionStorage.getItem("token"),
//     },
//     data: data,
//   });
//   // console.log(res, "导出账号");
//   if (res.data.code == 200) {
//     // const elt = document.createElement("a");
//     // elt.setAttribute(
//     //   "href",
//     //   "https://chtech.ncjti.edu.cn/carstop" + res.data.downurl
//     // );
//     // elt.setAttribute("download", "file.png");
//     // elt.style.display = "none";
//     // document.body.appendChild(elt);
//     // elt.click();
//     var downloadPath = "https://chtech.ncjti.edu.cn/carstop" + res.data.downurl;
//     console.log("获得地址数据:", downloadPath);
//     var downloadLink = document.createElement("a");
//     downloadLink.style.display = "none"; // 使其隐藏
//     downloadLink.href = downloadPath;
//     downloadLink.download = "";
//     downloadLink.click();
//     document.body.appendChild(downloadLink);
//     document.body.removeChild(downloadLink);
//     ElMessage({
//       type: "success",
//       showClose: true,
//       message: res.data.message,
//       center: true,
//     });
//   } else {
//     ElMessage({
//       type: "error",
//       showClose: true,
//       message: res.data.message,
//       center: true,
//     });
//   }
// };
// 表格斑马纹颜色修改
const tableRowClassName = ({ row, rowIndex }) => {
  if (rowIndex % 2 === 0) {
    return "even";
  } else if (rowIndex % 2 !== 0) {
    return "odd";
  }
  return "";
};
// 分页
const handleCurrentChange = (value) => {
  // console.log(value);
  currentPage.value = value;
  getList();
};

onBeforeMount(async () => {
  api.value = store.state.user.api;
  getList();
  const btnflag = JSON.parse(sessionStorage.getItem("btnflag"));
  flagBtn.value = btnflag.userRoles;
  console.log(flagBtn.value, "按钮权限");
});
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: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: 0px 3px 10px rgba(0, 97, 255, 0.2);

  .left {
    // width: calc(100wh - 40px);
    display: flex;
    align-items: center;
    height: 60px;
    margin: 0 30px;
    border-bottom: 1px solid #ccc;
    color: rgb(0, 0, 0);
    font-size: 18px;
    font-weight: 600;

    span {
      margin-right: 20px;
      cursor: pointer;
    }

    .is_active {
      color: rgba(111, 182, 184, 1);
    }
  }

  .scroll {
    width: calc(100% - 60px);
    height: calc(100% - 61px);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
  }

  .middle {
    width: 100%;
    color: #000;

    // border-bottom: 1px solid rgb(231, 231, 231);
    .filter {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      // margin: 10px 0 0 0;

      .search {
        color: #fff;
      }

      .condition {
        display: flex;
        align-items: center;
        margin: 10px 30px 10px 0;

        :deep(.el-input .el-input__inner) {
          font-size: 14px;
        }

        span {
          margin: 0 10px 0 0;
        }
      }
    }

    .gongneng {
      margin: 10px 0 20px 0;

      span {
        color: #fff;
      }
      .el-button {
        margin-right: 10px;
      }
    }

    :deep(.cont) {
      width: 60%;
      margin: 20px auto;
    }

    :deep(.download) {
      display: flex;
      align-items: center;
      margin: 10px;
    }

    :deep(.download span) {
      font-size: 16px;
      margin-left: 20px;
    }

    :deep(.cont .el-button) {
      margin-left: 60px;
      margin-bottom: 30px;
    }

    :deep(.cont .accomplish) {
      width: 100%;
      display: flex;
      justify-content: center;
    }

    :deep(.cont .accomplish .el-button) {
      width: 50%;
      margin: 0;
    }
  }

  .footer {
    width: 100%;
    flex: 1;
    overflow: auto;

    .el-table--fit {
      height: calc(100% - 60px);

      :deep(.el-table__header-wrapper) {
        background-color: #000;
        font-size: 16px;

        tr {
          color: #000;
        }
      }

      :deep(.el-table__row) {
        height: 50px;
        font-size: 16px;
        color: #000;
      }

      :deep(.el-table__row):nth-child(2n) {
        .el-table-fixed-column--right {
          background-color: rgba(240, 243, 247, 1);
        }
      }

      :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(.edit) {
        display: flex;
        align-items: center;
        justify-content: center;
        color: rgba(111, 182, 184, 1);
      }

      :deep(.look) {
        padding: 0 10px;
        cursor: pointer;
        color: rgba(30, 125, 251, 1);
      }

      .del {
        padding: 0 10px;
        color: rgba(212, 48, 48, 1);
        cursor: pointer;
      }

      // :deep(.look):hover {
      //   color: red;
      // }
      // :deep(.del):hover {
      //   color: red;
      // }
    }
  }

  // 添加角色
  :deep(.addRoles) {
    //   height: 420px;
    border-radius: 11px;
    .el-dialog__header {
      border-radius: 11px 11px 0 0;
      background: rgba(237, 241, 245, 1);
      font-weight: 600;
      margin: 0;
      .el-dialog__headerbtn {
        outline: none;
      }
    }
    .el-dialog__body {
      padding: 20px 30px 10px 30px;

      .rolesName {
        margin: 15px 0;
        color: #000;
        height: 600px;
        overflow: auto;
        .rolePermission {
          margin: 10px 0;
        }
      }
      .el-table--fit {
        height: 600px;

        .el-table__header-wrapper {
          background-color: #000;
          font-size: 16px;
          tr {
            color: #000;
            th {
              border-left: 1px solid #dcdfe6 !important;
              &:last-child {
                border-right: 1px solid #dcdfe6 !important;
              }
              .cell {
                text-align: center;
              }
            }
          }
        }

        .el-table__row {
          height: 50px;
          font-size: 16px;
          color: #000;
          .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;
          }
        }

        .el-table__row td {
          padding: 0;
          // border: 0;
        }
        td {
          border-left: 1px solid #dcdfe6;
          .checkBoxSel {
            padding-left: 20px;
            .el-checkbox {
              .el-checkbox__label {
                color: #000;
              }
            }
          }
          &:last-child {
            border-right: 1px solid #dcdfe6;
          }
        }
        .el-table__row:hover {
          td {
            background-color: #ffffff !important;
          }
        }

        .el-button--primary {
          margin-left: 5px;
        }

        // .el-table__body .even {
        //   background-color: #fff;
        // }

        // .el-table__body .odd {
        //   background-color: rgba(240, 243, 247, 1);
        // }
      }
      table {
        width: 840px;
        // 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 10px 0;
        width: 100%;
        .btn {
          display: flex;
          flex-direction: row-reverse;
        }
        .queding {
          color: #fff;
          margin-left: 15px;
        }
      }
    }
  }
  // 编辑按钮
  :deep(.editDialog) {
    //   height: 420px;
    border-radius: 11px;
    .el-dialog__header {
      border-radius: 11px 11px 0 0;
      background: rgba(237, 241, 245, 1);
      font-weight: 600;
      margin: 0;
      .el-dialog__headerbtn {
        outline: none;
      }
    }
    .el-dialog__body {
      padding: 30px 20px 10px 20px;
      .el-form-item__content {
        width: 200px;
        .el-tree-node__content {
          //   border: 1px solid red;
          .el-checkbox {
            display: none;
          }
        }
        .el-tree-node__children {
          .el-checkbox {
            display: block;
          }
        }
      }
      .options {
        margin: 10px 20px 20px 0;
        width: 100%;
        .el-form-item__content {
          display: flex;
          flex-direction: row-reverse;
        }
        .queding {
          color: #fff;
          margin-left: 15px;
        }
      }
    }
  }

  .pageSize {
    display: flex;
    align-items: center;
    justify-content: space-between;
    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;
      }
    }
  }
}

.el-input {
  width: 192px;
}
</style>
