<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-select
              style="width: 180px"
              v-model="searchInput.status"
              class="m-2"
              placeholder="选择状态"
              :clearable="true"
              @change="searchBtn"
            >
              <el-option label="正常" value="1" />
              <el-option label="冻结" value="2" />
            </el-select>
          </div>
          <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="daterange"
              range-separator="-"
              start-placeholder="起始时间"
              end-placeholder="结束时间"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              :prefix-icon="Calendar"
              placeholder="请选择日期"
              style="width: 240px"
              @change="searchBtn"
            />
          </div>

          <el-button
            style="margin-left: 20px"
            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">
          <el-button
            type="primary"
            v-if="flagBtn.tianjia == 1"
            color="rgba(0, 97, 255, 1)"
            @click="addlist"
            >添加</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 align="center" type="selection" width="80" /> -->
          <el-table-column
            width="120"
            align="center"
            label="序号"
            type="index"
            index="1"
          />
          <el-table-column align="center" prop="userNumber" label="账号" />
          <el-table-column align="center" prop="adminName" label="角色">
            <template #default="{ row }">
              <span>{{ row.adminMenuName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="adminName"
            label="可管理部门"
            width="230"
          >
            <template #default="{ row }">
              <div class="ul" style="display: flex; flex-wrap: wrap">
                <el-tag
                  v-for="i in row.checkOrg"
                  :key="i.name"
                  style="margin: 5px"
                  type="primary"
                  >{{ i.name }}</el-tag
                >
              </div>
              <!-- <div
                class="ul"
                v-if="row.checkOrg.length <= 5"
                style="display: flex; flex-wrap: wrap"
              >
                <el-tag
                  v-for="i in row.checkOrg"
                  style="margin: 5px"
                  type="primary"
                  >{{ i.name }}</el-tag
                >
              </div>
              <div class="ul" v-else style="display: flex; flex-wrap: wrap">
                <el-tag v-for="i in 3" style="margin: 5px" type="primary">{{
                  row.checkOrg[i].name
                }}</el-tag>
                <el-tooltip
                  class="box-item"
                  effect="light"
                  placement="right"
                  popper-class="tag_title"
                  trigger="hover"
                >
                  <template #content>
                    <el-tag
                      v-for="i in row.checkOrg"
                      style="margin: 5px"
                      type="primary"
                      >{{ i.name }}</el-tag
                    >
                  </template>
                  <el-tag style="margin: 5px; cursor: pointer" type="primary"
                  >...</el-tag>
                </el-tooltip>
              </div> -->
            </template>
          </el-table-column>
          <el-table-column align="center" prop="name" label="真实姓名" />
          <el-table-column align="center" prop="phoneNumber" label="手机号码" />
          <el-table-column align="center" prop="department" label="身份">
            <template #default="{ row }">
              <span v-if="row.department == 0">其他</span>
              <span v-if="row.department == 1">学生</span>
              <span v-if="row.department == 4">教职工</span>
              <span v-if="row.department == 5">校友</span>
              <span v-if="row.department == 6">访客应用身份</span>
              <span v-if="row.department == 7">临时人员</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="createTime" label="创建时间" />

          <el-table-column align="center" label="操作" width="180">
            <template #default="scope">
              <div class="options">
                <div
                  v-if="flagBtn.bianji == 1"
                  class="look"
                  @click="edit(scope.row)"
                >
                  编辑
                </div>
                <el-popconfirm
                  v-if="flagBtn.shanchu == 1"
                  width="220"
                  confirm-button-text="确认"
                  cancel-button-text="取消"
                  :icon="InfoFilled"
                  icon-color="#f89626"
                  title="是否删除此账号?"
                  @confirm="del(scope.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>
        <!-- 添加账号弹窗 -->
        <el-dialog
          class="addStaff"
          v-model="addDialogVisible"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          :title="dialongTitle"
          align-center
          width="609"
          :before-close="cancelAdd"
        >
          <el-form
            ref="ruleFormRef"
            :model="ruleForm"
            :rules="rules"
            label-width="100px"
            class="demo-ruleForm"
            :size="formSize"
            label-position="left"
            status-icon
          >
            <el-form-item label="微校卡号 :" prop="cardNum">
              <el-select
                v-model="ruleForm.cardNum"
                popper-class="more-tag-data"
                filterable
                remote
                :remote-method="conteactMethod"
                placeholder="请选择微校卡号"
                style="width: 400px"
                @change="schoolCardChange"
              >
                <el-option
                  v-for="item in schoolCardList"
                  :key="item.id"
                  :label="item.cardNumber"
                  :value="item.cardNumber"
                  style="padding: 0"
                >
                  <div
                    style="float: left; width: 100%; padding: 0 20px"
                    @click="schoolCardChanges(item)"
                  >
                    <span style="display: inline-block; width: 80px">{{
                      item.userName
                    }}</span>
                    <span style="display: inline-block; width: 120px"
                      >部门 : {{ item.departmentName }}</span
                    >
                    <span>微校卡号 : {{ item.cardNumber }}</span>
                  </div>
                </el-option>
                <template #footer>
                  <div class="addStudentMore">
                    <el-button
                      v-if="
                        schoolCardPage < schoolCardTotalPage &&
                        schoolCardTotalPage != 0
                      "
                      @click="addschoolCardListMore"
                      >加载更多+</el-button
                    >
                  </div>
                </template>
              </el-select>
            </el-form-item>
            <el-form-item label="姓名 :" prop="corpnName">
              <el-input
                v-model.trim="ruleForm.corpnName"
                placeholder="请输入姓名"
                clearable
                style="width: 400px"
                :disabled="true"
              />
            </el-form-item>
            <el-form-item label="身份 :" prop="department">
              <el-select
                style="width: 400px"
                v-model="ruleForm.department"
                class="m-2"
                placeholder="请选择身份"
                :disabled="true"
              >
                <el-option label="学生" value="1" />
                <el-option label="教职工" value="4" />
                <el-option label="校友" value="5" />
                <el-option label="访客应用身份" value="6" />
                <el-option label="临时人员" value="7" />
                <el-option label="其他" value="0" />
              </el-select>
            </el-form-item>
            <el-form-item label="手机号码 :" prop="corpnPhone">
              <el-input
                v-model.trim="ruleForm.corpnPhone"
                placeholder="请输入手机号码"
                clearable
                style="width: 400px"
                :disabled="true"
              />
            </el-form-item>
            <el-form-item label="用户名 :" prop="adminName">
              <el-input
                v-model.trim="ruleForm.adminName"
                placeholder="请输入用户名"
                clearable
                style="width: 400px"
              />
            </el-form-item>
            <el-form-item label="密码 :" prop="password">
              <el-input
                v-model.trim="ruleForm.password"
                placeholder="请输入密码"
                clearable
                style="width: 400px"
              />
            </el-form-item>
            <el-form-item label="角色 :" prop="adminMenuId">
              <el-tree
                style="max-width: 600px; width: 400px"
                :data="roleData"
                ref="editMemberTree"
                show-checkbox
                default-expand-all
                check-strictly
                node-key="id"
                :props="defaultProps"
                @check="editMemberCheckChange"
              />
            </el-form-item>
            <el-form-item label="部门 :" prop="icCard">
              <el-select
                style="width: 400px"
                v-model="ruleForm.icCard"
                class="m-2"
                placeholder="请选择部门"
                multiple
                filterable
                remote
                reserve-keyword
                remote-show-suffix
                :clearable="true"
              >
                <el-option
                  v-for="i in departmentList"
                  :label="i.name"
                  :key="i.id"
                  :value="i.id"
                />
              </el-select>
            </el-form-item>

            <el-form-item class="options">
              <el-button
                color="rgba(0, 97, 255, 1)"
                class="queding"
                type="primary"
                @click="submitAdd(ruleFormRef)"
              >
                确定
              </el-button>
              <el-button @click="cancelAdd(ruleFormRef)">取消</el-button>
            </el-form-item>
          </el-form>
        </el-dialog>
      </div>
    </div>
  </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 { Calendar } from "@element-plus/icons-vue";
import { dayjs } from "element-plus";
import lodash, { reduce } from "lodash";
import axios from "axios";
import { useStore } from "vuex";
const store = useStore();
const router = useRouter();
// 表格数据
const loading = ref(false);
const tableData = reactive({
  list: [],
});
const activeIndex = ref(); // 默认跳转路由
const dialongTitle = ref("新增账号"); // 弹窗标题

const searchInput = reactive({
  status: "",
  name: "",
  createTime: "",
}); // 搜索按钮数据
const flagBtn = ref(); // 按钮权限
const departmentList = ref(); // 部门

watch(
  () => searchInput.createTime,
  (newVal, oldVal) => {
    console.log("监听时间:", newVal);
    if (newVal == null) {
      getList();
    }
  },
);

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

const api = ref("");
const schoolCardList = ref();
const schoolCardSearch = ref(); // 微信卡号下拉框搜索词
const schoolCardPage = ref(1);
const schoolCardSize = ref(20);
const schoolCardTotalPage = ref();
const addDialogVisible = ref(false); // 控制添加账号弹窗
const editMemberTree = ref(); // 角色ref
const roleData = ref(); // 角色列表

const defaultProps = ref({
  children: "children",
  label: "name",
});
// 表单数据
const formSize = ref("default");
const ruleFormRef = ref();
const ruleForm = reactive({
  adminMenuId: "",
  cardNum: "",
  corpnName: "",
  corpnPhone: "",
  adminName: "",
  password: "",
  department: "",
  icCard: "",
  id: "",
  usersId: "",
});
var checkUserName = (rule, value, callback) => {
  if (!value) {
    return callback(new Error("请输入用户名）"));
  }

  var reg = /^[a-zA-Z0-9]{5,16}$/;
  if (!reg.test(value)) {
    callback(new Error("必须为5-16个数字或字母！"));
  } else {
    callback();
  }
};
var checkFullName = (rule, value, callback) => {
  if (!value) {
    return callback(new Error("请输入姓名"));
  }

  var reg =
    /^[\u3400-\u4db5\u4e00-\u9fa5\u9fa6-\u9fbb\u{f900}-\u{faff}]{2,6}$/u;
  if (!reg.test(value)) {
    callback(new Error("必须为2-6个汉字！"));
  } else {
    callback();
  }
};
var checkPhone = (rule, value, callback) => {
  if (!value) {
    return callback(new Error("请输入手机号"));
  }
  setTimeout(() => {
    var reg = /^1[3456789]\d{9}$/;
    if (!reg.test(value)) {
      callback(new Error("手机号格式不对"));
    } else {
      callback();
    }
  }, 100);
};
// 表单验证
const rules = reactive({
  corpnName: [
    { required: true, message: "姓名不能为空", trigger: "blur" },
    { validator: checkFullName, trigger: "blur" },
  ],
  adminName: [
    { required: true, message: "用户名不能为空", trigger: "blur" },
    { validator: checkUserName, trigger: "blur" },
  ],
  cardNum: [{ required: true, message: "微校卡号不能为空", trigger: "blur" }],
  // ^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*,\._\+(){}])[0-9a-zA-Z!@#$%^&*,\\._\+(){}]{8,20}$
  password: [
    {
      required: true,
      message: "密码不能为空",
      trigger: "blur",
    },
    {
      min: 8,
      max: 20,
      pattern:
        // /^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*,\._\+(){}])[0-9a-zA-Z!@#$%^&*,\\._\+(){}]{8,20}$/,
        /^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z]).{8,20}$/,
      message: "请输入8-20位正确密码（大小写字母·数字·（字符可选填））",
      trigger: "blur",
    },
  ],
  againPass: [
    {
      required: true,
      message: "确认密码不能为空",
      trigger: "blur",
    },
    {
      min: 8,
      max: 20,
      pattern:
        /^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*,\._\+(){}])[0-9a-zA-Z!@#$%^&*,\\._\+(){}]{8,20}$/,
      message: "请输入8-20位正确密码（大小写字母·字符·数字）",
      trigger: "blur",
    },
  ],
  adminMenuId: [
    {
      required: true,
      message: "角色不能为空",
      trigger: "blur",
    },
  ],
  department: [
    {
      required: true,
      message: "部门不能为空",
      trigger: "blur",
    },
  ],
  corpnPhone: [
    {
      required: true,
      message: "电话号码不能为空",
      trigger: "blur",
    },
    // { validator: checkPhone, trigger: "blur" },
  ],
  icCard: [{ required: true, message: "部门不能为空", trigger: "blur" }],
  // desc: [{ required: true, message: "Please input activity form", trigger: "blur" }],
});

// 获取账户列表
const getList = async () => {
  loading.value = true;
  let data = {
    page: currentPage.value, // 当前页
    size: pageSize.value, // 一页数据条数
    permissionSettingId: sessionStorage.getItem("permissionSettingId"),
    keyWord: searchInput.name,
    status: searchInput.status,
  };
  if (searchInput.createTime) {
    data.startTime = searchInput.createTime[0];
    data.endTime = searchInput.createTime[1];
  }
  let res = await axios({
    method: "get",
    url: api.value + "/admin/getListPage",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("user_head"),
    },
    params: data,
  });
  console.log(res, "账号信息");
  if (res.data.code == 200) {
    res.data.data.records.forEach((item) => {
      if (item.adminMenu) {
        item.adminMenuName = item.adminMenu.name;
      } else {
        item.adminMenuName = "";
      }
    });
    res.data.data.records.forEach((i) => {});

    tableData.list = res.data.data.records;
    total.value = res.data.data.total;
    loading.value = false;
    // ElMessage({
    //   type: "success",
    //   showClose: true,
    //   message: res.data.message,
    //   center: true,
    // });
  } else {
    loading.value = false;
    if (res.data.code == 500) {
      console.log(res.data);
      if (res.data.message == "无效token,请重新登入") {
        router.push({ path: "/login" });
      }
    }
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

// 部门数据
const departmentData = async () => {
  let res = await axios({
    method: "post",
    url: api.value + "/organization/queryAll",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("user_head"),
    },
  });
  console.log(res, "部门数据");
  if (res.data.code == 200) {
    departmentList.value = res.data.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

// 微校卡号数据
const schoolData = async () => {
  schoolCardPage.value = 1;
  let data = {
    permissionSettingId: sessionStorage.getItem("permissionSettingId"),
    page: schoolCardPage.value,
    size: schoolCardSize.value,
    keyWord: schoolCardSearch.value,
  };
  let res = await axios({
    method: "post",
    url: api.value + "/admin/getUsersPage",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("user_head"),
    },
    data: data,
  });
  console.log(res, "微校卡号人");
  if (res.data.code == 200) {
    schoolCardList.value = res.data.data.records;
    schoolCardTotalPage.value = res.data.data.pages;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};
// 微校卡号搜索
const conteactMethod = (query) => {
  console.log(query);
  schoolCardSearch.value = query;
  schoolData();
};
// 加载更多微校卡号
const addschoolCardListMore = async () => {
  if (schoolCardPage.value < schoolCardTotalPage.value) {
    schoolCardPage.value++;
    // console.log(conteactListInput.value, "滚动里面");
    let data = {
      permissionSettingId: sessionStorage.getItem("permissionSettingId"),
      page: schoolCardPage.value,
      size: schoolCardSize.value,
      keyWord: schoolCardSearch.value,
    };
    let res = await axios({
      method: "post",
      url: api.value + "/admin/getUsersPage",
      headers: {
        token: sessionStorage.getItem("token"),
        user_head: sessionStorage.getItem("user_head"),
      },
      data: data,
    });
    console.log(res, "微校卡号人员加载更多");
    if (res.data.code == 200) {
      // schoolCardList.value = res.data.data.records;
      // schoolCardTotalPage.value = res.data.data.pages;
      schoolCardList.value = [
        ...schoolCardList.value,
        ...res.data.data.records,
      ];
    } else {
      ElMessage({
        type: "error",
        showClose: true,
        message: res.data.message,
        center: true,
      });
    }
  } else {
    console.log("数据全部加载完成");
  }
};
// 改变微校卡号
const schoolCardChange = async (value) => {
  console.log(value);
  // let data = {
  //   permissionSettingId: sessionStorage.getItem("permissionSettingId"),
  //   page: 1,
  //   size: 20,
  //   keyWord: value,
  // };
  // let res = await axios({
  //   method: "post",
  //   url: api.value + "/admin/getUsersPage",
  //   headers: {
  //     token: sessionStorage.getItem("token"),
  //     user_head: sessionStorage.getItem("user_head"),
  //   },
  //   data: data,
  // });
  // console.log(res, "微校卡号人");
  // if (res.data.code == 200) {
  //   let resdata = res;
  //   ruleForm.corpnName = res.data.data.records[0].userName;
  //   ruleForm.corpnPhone = res.data.data.records[0].phone;
  //   ruleForm.department = res.data.data.records[0].department;
  // } else {
  //   ElMessage({
  //     type: "error",
  //     showClose: true,
  //     message: res.data.message,
  //     center: true,
  //   });
  // }
};
const schoolCardChanges = async (row) => {
  ruleForm.corpnName = row.userName;
  ruleForm.corpnPhone = row.phone;
  ruleForm.department = row.department;
};
// 角色列表数据
const roleList = async () => {
  let res = await axios({
    method: "get",
    url: api.value + "/admin-menu/getRole",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("user_head"),
    },
  });
  console.log(res, "角色列表");
  if (res.data.code == 200) {
    roleData.value = res.data.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

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

// 添加账号
const addlist = () => {
  dialongTitle.value = "新增账号";
  addDialogVisible.value = true;
  ruleForm.corpnPhone = "";
  ruleForm.corpnName = "";
  ruleForm.adminName = "";
  ruleForm.cardNum = "";
  ruleForm.adminMenuId = "";
  ruleForm.password = "";
  ruleForm.department = "";
  ruleForm.icCard = "";
  ruleForm.id = "";
  ruleForm.usersId = "";
  nextTick(() => {
    editMemberTree.value.setCheckedKeys([]);
  });
};
// 勾选角色
const editMemberCheckChange = (data, nodes) => {
  // console.log(data, nodes, "勾选角色");
  editMemberTree.value.setCheckedKeys([]);
  nextTick(() => {
    editMemberTree.value.setCheckedKeys([data.id]);
    ruleForm.adminMenuId = data.id;
  });
};
// 取消添加员工
const cancelAdd = () => {
  addDialogVisible.value = false;
  ruleFormRef.value.resetFields();
};
//编辑按钮
const edit = (row) => {
  console.log(row);
  dialongTitle.value = "编辑信息";
  addDialogVisible.value = true;
  ruleForm.id = row.id;
  ruleForm.corpnPhone = row.phoneNumber;
  ruleForm.corpnName = row.name;
  ruleForm.adminName = row.userNumber;
  ruleForm.cardNum = row.cardNumber;
  ruleForm.adminMenuId = row.adminMenu.id;
  ruleForm.password = row.passWord;
  ruleForm.department = row.department;
  ruleForm.usersId = row.usersId;
  if (row.checkOrg) {
    let arr = [];
    row.checkOrg.forEach((i) => {
      arr.push(i.id);
    });
    ruleForm.icCard = arr;
  }
  nextTick(() => {
    if (row.adminMenu) {
      editMemberTree.value.setCheckedKeys([row.adminMenu.id]);
    }
  });
};
// 确认添加员工
const submitAdd = lodash.debounce(async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      if (ruleForm.id) {
        let data = {
          permissionSettingId: sessionStorage.getItem("permissionSettingId"),
          cardNumber: ruleForm.cardNum,
          admin: {
            adminMenuId: ruleForm.adminMenuId,
            // usersId: ruleForm.cardNum,
            name: ruleForm.corpnName,
            userNumber: ruleForm.adminName,
            passWord: ruleForm.password,
            phoneNumber: ruleForm.corpnPhone,
            department: ruleForm.department,
            checkOrg: ruleForm.icCard.join(","),
            id: ruleForm.id,
            usersId: ruleForm.usersId,
          },
        };
        let res = await axios({
          method: "post",
          url: api.value + "/admin/update",
          headers: {
            token: sessionStorage.getItem("token"),
            user_head: sessionStorage.getItem("user_head"),
          },
          data: data,
        });
        console.log(res, "编辑账号");
        if (res.data.code == 200) {
          getList();
          ElMessage({
            type: "success",
            showClose: true,
            message: res.data.message,
            center: true,
          });
          addDialogVisible.value = false;
          ruleFormRef.value.resetFields();
        } else {
          ElMessage({
            type: "error",
            showClose: true,
            message: res.data.message,
            center: true,
          });
        }
      } else {
        let data = {
          permissionSettingId: sessionStorage.getItem("permissionSettingId"),
          adminMenuId: ruleForm.adminMenuId,
          cardNumber: ruleForm.cardNum,
          name: ruleForm.corpnName,
          userNumber: ruleForm.adminName,
          passWord: ruleForm.password,
          phoneNumber: ruleForm.corpnPhone,
          department: ruleForm.department,
          checkOrg: ruleForm.icCard.join(","),
        };
        let res = await axios({
          method: "post",
          url: api.value + "/admin/save",
          headers: {
            token: sessionStorage.getItem("token"),
            user_head: sessionStorage.getItem("user_head"),
          },
          data: data,
        });
        console.log(res, "添加账号");
        if (res.data.code == 200) {
          getList();
          ElMessage({
            type: "success",
            showClose: true,
            message: res.data.message,
            center: true,
          });
          addDialogVisible.value = false;
          ruleFormRef.value.resetFields();
        } else {
          ElMessage({
            type: "error",
            showClose: true,
            message: res.data.message,
            center: true,
          });
        }
      }
    } else {
      console.log("error submit!", fields);
    }
  });
}, 1000);

//删除按钮
const del = async (row) => {
  // console.log(row);
  let data = {
    id: row.id,
    permissionSettingId: sessionStorage.getItem("permissionSettingId"),
  };
  let res = await axios({
    method: "get",
    url: api.value + "/admin/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 cancelEvent = () => {
  ElMessage({
    type: "info",
    showClose: true,
    message: "取消删除",
    center: true,
  });
};
// 重置密码
const reset = async (row) => {
  // console.log(row);
  let data = {
    id: row.id,
  };
  let res = await axios({
    method: "post",
    url: api.value + "/mhotel/managerAdminremovePwd.action",
    headers: {
      // token: sessionStorage.getItem("token"),
      // user_head: sessionStorage.getItem("userhead"),
    },
    params: data,
  });
  if (res.data.code == 200) {
    getList();
    ElMessage({
      type: "success",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

// 多选框功能
// const handleSelectionChange = (val) => {
//   console.log(val);
//   selectData.list = val;
// };

// 表格斑马纹颜色修改
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(() => {
  api.value = store.state.user.api;
  const btnflag = JSON.parse(sessionStorage.getItem("btnflag"));
  flagBtn.value = btnflag.account;
  console.log(flagBtn.value, "按钮权限");

  getList();
  roleList();
  schoolData();
  departmentData();
});
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: #000;
    font-size: 18px;
    font-weight: 600;
    .camera {
      margin-right: 15px;
      color: #4392f7;
    }
  }
  .scroll {
    width: calc(100%);
    height: calc(100% - 61px);
    display: flex;
    flex-direction: column;
  }
  .middle {
    width: calc(100% - 60px);
    margin: 0 auto;

    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 {
        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;
        }
        span {
          margin: 0 10px 0 0;
        }
      }
    }
    .gongneng {
      margin: 10px 0;
      .el-button {
        color: #fff;
        margin-right: 15px;
      }
    }
    :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: calc(100% - 60px);
    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;
        .reset {
          color: rgba(9, 101, 98, 1);
          cursor: pointer;
        }
        .look {
          margin: 0 15px;
          color: rgba(30, 125, 251, 1);
          cursor: pointer;
        }
        .del {
          color: rgba(212, 48, 48, 1);
          cursor: pointer;
        }
      }
    }

    // 添加员工弹窗样式
    :deep(.addStaff) {
      //   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 20px 10px 20px;
        .el-input {
          width: 200px;
          .el-input__suffix-inner {
            color: rgba(61, 81, 232, 1);
          }
        }

        .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;
    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;
      }
    }
  }
}
.el-input {
  width: 192px;
}
</style>
<style lang="scss">
//添加成员 联系人下拉框样式
.more-tag-data {
  // border: 1px solid red;
  .el-select-dropdown__wrap {
    height: 200px;
  }
}
.el-popper {
  .addStudentMore {
    text-align: center;
  }
}
.el-popper.tag_title {
  width: 450px;
  height: 75%;
  overflow: auto;
  // border: 1px solid #409eff;
}
</style>
