<template>
  <div class="content-box">
    <div class="left">
      <!-- <el-icon :size="23" class="camera"><VideoCameraFilled /></el-icon> -->
      <span class="cameratxt">员工管理</span>
    </div>
    <div class="btm">
      <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="请选择日期"
              @change="searchBtn"
            />
          </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="addClick"
            ><span>添加</span></el-button
          >
          <!-- <el-button type="primary" color="rgba(0, 97, 255, 1)" @click="addlist"
            ><span>导出</span></el-button
          >
          <el-button type="primary" color="rgba(0, 97, 255, 1)" @click="addlist"
            ><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%"
          :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="80"
            align="center "
            type="index"
            label="序号"
          />
          <el-table-column align="center" prop="userName" label="姓名" />
          <!-- <el-table-column align="center" prop="cardNumber" label="微校卡号" /> -->
          <el-table-column align="center" prop="phone" label="手机号码" />
          <!-- <el-table-column align="center" prop="userMenuId" label="角色">
            <template #default="{ row }">
              <span>{{ row.userMenuName }}</span>
            </template>
          </el-table-column> -->
          <el-table-column align="center" prop="department" label="职务">
          </el-table-column>
          <el-table-column
            align="center"
            prop="createTime"
            width="280"
            label="创建时间"
          />
          <el-table-column align="center" label="操作" width="200">
            <template #default="scope">
              <div class="edit">
                <div
                  class="look"
                  v-if="flagBtn.bianji == 1"
                  @click="editClick(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>
      </div>

      <!-- 编辑按钮 -->
      <el-dialog
        class="editDialog"
        v-model="editVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :title="titleDialog"
        align-center
        width="600"
        :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="userDepartment">
            <!-- 0为其他，1为学生，4为教职工，5为校友 -->
            <el-input
              v-model.trim="editRuleForm.userDepartment"
              placeholder="请输入职务"
              clearable
              style="width: 500px"
            />
            <!-- <el-select
              style="width: 500; "
              v-model="editRuleForm.userDepartment"
              class="m-2"
              placeholder="请选择身份"
            >
              <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="userName">
            <el-input
              v-model.trim="editRuleForm.userName"
              placeholder="请输入姓名"
              clearable
              style="width: 500px"
            />
          </el-form-item>
          <el-form-item label="电话号码 :" prop="userPhone">
            <el-input
              v-model.trim="editRuleForm.userPhone"
              placeholder="请输入电话号码"
              clearable
              style="width: 500px"
            />
          </el-form-item>
          <!-- <el-form-item label="用户角色 :" prop="userRoles">
            <el-tree
              ref="userRolesRef"
              style="max-width: 600px"
              :data="rolesData.list"
              show-checkbox
              check-strictly
              node-key="id"
              :props="defaultProps"
              default-expand-all
              @check="(data, nodes) => editMemberCheckChange(data, nodes)"
            />
          </el-form-item> -->
          <el-form-item label="身份证号 :" prop="idCard">
            <el-input
              v-model.trim="editRuleForm.idCard"
              placeholder="请输入身份证号"
              clearable
              style="width: 500px"
            />
          </el-form-item>
          <el-form-item label="读卡 :" prop="schoolCard">
            <el-input
              v-model="editRuleForm.schoolCard"
              placeholder="请读取卡片"
              style="width: 500px"
            >
              <template #append>
                <div @click="readCard">读卡</div>
              </template>
            </el-input>
          </el-form-item>
          <el-form-item label="指纹 :" prop="fingerprint">
            <el-input
              v-model="editRuleForm.fingerprint"
              placeholder="请输入指纹"
              style="width: 500px"
            >
              <template #append>
                <div @click="entering">录入</div>
              </template>
            </el-input>
          </el-form-item>
          <el-form-item label="指纹备注 :" prop="fingerRemark">
            <el-select
              style="width: 500px"
              v-model="editRuleForm.fingerRemark"
              class="m-2"
              placeholder="请选择指纹备注"
              @change="fingerRemarkChange"
            >
              <el-option label="左手·拇指  " value="左手·拇指  " />
              <el-option label="左手·食指  " value="左手·食指  " />
              <el-option label="左手·中指  " value="左手·中指  " />
              <el-option label="左手·无名指" value="左手·无名指" />
              <el-option label="左手·小指  " value="左手·小指  " />
              <el-option label="右手·拇指  " value="右手·拇指  " />
              <el-option label="右手·食指  " value="右手·食指  " />
              <el-option label="右手·中指  " value="右手·中指  " />
              <el-option label="右手·无名指" value="右手·无名指" />
              <el-option label="右手·小指  " value="右手·小指  " />
            </el-select>
          </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(editRef)">取消</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>

      <!-- 指纹读取弹窗 -->
      <el-dialog
        class="fingerprint"
        v-model="addFingerprintVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        title="添加指纹"
        align-center
        width="550"
        :before-close="cancelAddFingerprint"
      >
        <div class="el-footer">
          <div style="height: 350px; margin: 30px auto">
            <el-steps direction="vertical" :active="stepindex">
              <el-step
                v-for="i in step.list"
                :key="i.id"
                :title="`步骤 ${i.id}`"
                :description="i.title"
              ></el-step>
            </el-steps>
          </div>
        </div>
      </el-dialog>

      <!-- 身份证读卡弹窗 -->
      <el-dialog
        class="addIdentityCard"
        v-model="addIdentityCardVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        title="添加身份证"
        align-center
        width="650"
        :before-close="cancelAddIdentityCard"
      >
        <!-- <div class="el-footer">
          {{ identityCardTitle }}
        </div>
        <div class="el-footer">卡号 :{{ identityCardNum }}</div> -->
        <div class="steps">
          <el-steps
            :space="200"
            :active="identityCardIndex"
            finish-status="success"
          >
            <el-step title="环境准备" />
            <el-step title="配置" />
            <el-step title="完成" />
          </el-steps>
        </div>
        <div
          class="title"
          v-if="identityCardIndex == 0 || identityCardIndex == 1"
          style="color: #fc2307"
        >
          {{ identityCardTitle }}
        </div>
        <div class="title" v-else style="color: #68c23c">
          {{ identityCardTitle }}
        </div>
        <div class="icons">
          <img
            v-if="identityCardIndex == 0 || identityCardIndex == 1"
            src="@/assets/icons/error.png"
            alt=""
          />
          <img
            v-if="identityCardIndex == 2"
            class="loading"
            src="@/assets/icons/loading.png"
            alt=""
          />
          <img
            v-if="identityCardIndex == 3"
            src="@/assets/icons/success.png"
            alt=""
          />
        </div>
        <div class="retry">可以尝试<span @click="retry">重试</span></div>
      </el-dialog>
    </div>
    <div class="bgImg" v-if="bgImg">
      <el-carousel
        @click="bgImg = false"
        ref="bgImgs"
        indicator-position
        arrow="always"
        :autoplay="false"
        trigger
      >
        <el-carousel-item v-for="item in bgImgList" :key="item.id">
          <img :src="item.url" alt="" />
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>

<script setup>
import {
  ref,
  reactive,
  watch,
  nextTick,
  onMounted,
  onBeforeMount,
  onUnmounted,
} from "vue";
import { useRouter } from "vue-router";
import { ElMessage, ElMessageBox } 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: "",
}); // 搜索按钮数据

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

// 编辑功能
const titleDialog = ref("");
const editVisible = ref(false);
const editRef = ref();
const editRuleForm = reactive({
  userDepartment: "", // 职务
  userName: "", // 用户名
  userPhone: "", // 电话
  userRoles: "", // 用户角色
  schoolCard: "", // 卡号
  idCard: "", // 身份证号
  fingerprint: "", // 指纹
  fingerRemark: "", // 指纹备注
  id: "",
});
const rolesData = reactive({ list: [] });
const userRolesRef = ref();
const defaultProps = ref({
  children: "children",
  label: "name",
});

// 表单验证
const editRules = reactive({
  userDepartment: [
    { required: true, message: "职务不能为空", trigger: "blur" },
  ],
  userName: [
    {
      required: true,
      message: "姓名不能为空",
      trigger: "blur",
    },
  ],
  userPhone: [
    {
      required: true,
      message: "电话号码不能为空",
      trigger: "blur",
    },
  ],
  userRoles: [
    {
      required: true,
      message: "用户角色不能为空",
      trigger: "blur",
    },
  ],
  schoolCard: [
    {
      required: true,
      message: "卡号不能为空",
      trigger: "blur",
    },
  ],
  idCard: [
    {
      required: true,
      message: "身份证号不能为空",
      trigger: "blur",
    },
  ],
  fingerprint: [
    {
      required: true,
      message: "指纹不能为空",
      trigger: "change",
    },
  ],
  fingerRemark: [
    {
      required: true,
      message: "指纹备注不能为空",
      trigger: "change",
    },
  ],
});
// 添加用户（---------------------------------------------------------）
const editMemberCheckChange = (data, nodes) => {
  console.log(data, nodes);
  // userRolesRef.value.setCheckedKeys([]);
  // nextTick(() => {
  //   userRolesRef.value.setCheckedKeys([data.id]);
  //   editRuleForm.userRoles = data.id;
  // });
};

// 添加指纹弹窗（-----------------------------------------------）
const addFingerprintVisible = ref(false);
const stepindex = ref(0); // 录取指纹步骤
const step = reactive({
  list: [
    { id: 1, title: "" },
    { id: 2, title: "" },
    { id: 3, title: "" },
    { id: 4, title: "" },
  ],
}); // 指纹步骤数据
const ws = ref("");

// 添加身份证弹窗(-------------------------------------------)
const addIdentityCardVisible = ref(false);
// const wsidentityCard = ref("");
const identityCardTitle = ref("");
// const identityCardNum = ref(""); // 身份证卡号
const identityCardIndex = ref(0); // 读卡步骤

// 用户管理
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 + "/employeeUsers/getUsersPage",
    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 rolesList = async () => {
  let res = await axios({
    method: "get",
    url: api.value + "/users-menu/getUserRole",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("user_head"),
    },
    // params: data,
  });
  console.log(res, "角色列表");
  if (res.data.code == 200) {
    rolesData.list = res.data.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

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

// 用户角色改变
const userhandleChange = (value) => {
  console.log(value);
};

// 添加按钮 （-------------------------------------------）
const addClick = async () => {
  titleDialog.value = "新增员工";
  editVisible.value = true;
  editRuleForm.id = "";
  editRuleForm.userDepartment = ""; // 职务
  editRuleForm.userName = ""; // 用户名
  editRuleForm.userPhone = ""; // 电话
  editRuleForm.userRoles = ""; // 用户角色
  editRuleForm.schoolCard = ""; // 卡号
  editRuleForm.idNumber = ""; // 身份证号
  editRuleForm.fingerprint = ""; // 指纹
  editRuleForm.fingerRemark = ""; // 指纹备注
};
// 切换手指头删除指纹
const fingerRemarkChange=()=>{
  editRuleForm.fingerprint=""
}
//编辑按钮  （-------------------------------------------）
const editClick = async (row) => {
  titleDialog.value = "编辑员工";
  console.log(row);
  editVisible.value = true;
  editRuleForm.id = row.id;
  editRuleForm.userDepartment = row.department;
  editRuleForm.userName = row.userName;
  editRuleForm.userPhone = row.phone;
  editRuleForm.schoolCard = row.idCardInformation;
  editRuleForm.idCard = row.idCard;
  editRuleForm.fingerprint = row.fingerprint;
  editRuleForm.fingerRemark = row.fingerRemark;
};

const cancelEdit = () => {
  editVisible.value = false;
  editRef.value.resetFields();
};

// 确定编辑
const confirmEdit = (formEl) => {
  if (!formEl) return;
  formEl.validate(async (valid, fields) => {
    if (valid) {
      if (editRuleForm.id) {
        let data = {
          adminMenuId: sessionStorage.getItem("permissionSettingId"),
          employeeUsers: {
            id:editRuleForm.id,
            department: editRuleForm.userDepartment,
            userName: editRuleForm.userName,
            idCard: editRuleForm.idCard,
            phone: editRuleForm.userPhone,
            idCardInformation: editRuleForm.schoolCard,
            fingerprint: editRuleForm.fingerprint,
            fingerRemark: editRuleForm.fingerRemark,
          },
        };
        let res = await axios({
          method: "post",
          url: api.value + "/employeeUsers/updateDetails",
          headers: {
            token: sessionStorage.getItem("token"),
            user_head: sessionStorage.getItem("user_head"),
          },
          data: data,
        });
        console.log(res, "编辑用户管理");
        if (res.data.code == 200) {
          getList();
          editVisible.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 data = {
          adminMenuId: sessionStorage.getItem("permissionSettingId"),
          cardNumber: editRuleForm.schoolCard,
          idCard: editRuleForm.idCard,
          fingerprint: editRuleForm.fingerprint,
          fingerRemark: editRuleForm.fingerRemark,
          userName: editRuleForm.userName,
          phone: editRuleForm.userPhone,
          department: editRuleForm.userDepartment,
        };
        let res = await axios({
          method: "post",
          url: api.value + "/employeeUsers/saveUsers",
          headers: {
            token: sessionStorage.getItem("token"),
            user_head: sessionStorage.getItem("user_head"),
          },
          data: data,
        });
        console.log(res, "添加用户管理");
        if (res.data.code == 200) {
          getList();
          editVisible.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 del = async (row) => {
  let data = {
    adminMenuId: sessionStorage.getItem("permissionSettingId"),
    userId: row.id,
  };
  let res = await axios({
    method: "get",
    url: api.value + "/employeeUsers/deleteUsers",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
    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 entering = () => {
  addFingerprintVisible.value = true;
  step.list = [
    { id: 1, title: "" },
    { id: 2, title: "" },
    { id: 3, title: "" },
    { id: 4, title: "" },
  ];
  stepindex.value = 0;
  var wsUrl = "ws://localhost:8181/";
  let websocket = new WebSocket(wsUrl);
  ws.value = websocket;
  websocket.onopen = function (evt) {
    var params = { type: 101, data: null };
    websocket.send(JSON.stringify(params));
  };
  websocket.onmessage = function (evt) {
    // console.log(evt.data, "输出指纹数据");
    let data = JSON.parse(evt.data);
    if (data.type == 0) {
      // console.log(JSON.parse(evt.data).data.portNames[1]); // 获取到 USB接口
      console.log(data.data.portNames);
      let num=0
      if(data.data.portNames){
        num=data.data.portNames.length
        console.log(JSON.parse(evt.data).data.portNames[num-1]);
      }
      let params1 = {
        type: 1,
        data: {
          type: 0,
          portName: JSON.parse(evt.data).data.portNames[num-1],
          baudRate: 115200,
        },
      };
      websocket.send(JSON.stringify(params1));
    } else if (data.type == 110) {
      console.log("已获取设备信息");
    } else if (data.type == 11) {
      var params2 = {
        type: 2,
        data: {
          totalStep: 4,
        },
      };
      websocket.send(JSON.stringify(params2));
    } else if (data.type == 21) {
      if (data.data.step == 0) {
        // console.log("请按压指纹");
        ElMessage({
          message: "请开始按压指纹",
          type: "success",
        });
      } else {
        // console.log(`请按下同一指纹，第${data.data.step}次按压`);
        if (data.data.step <= 4) {
          step.list.forEach((item) => {
            if (item.id == data.data.step) {
              item.title = `请按下同一指纹，第${data.data.step}次录入指纹成功`;
            }
          });
        }
        stepindex.value = data.data.step;
      }
      // _this.$message.warning("请将手指按在传感器上");
      if (data.data.step > 4) {
        var params = {
          type: 3,
          data: {
            id: data.data.id,
          },
        };
        websocket.send(JSON.stringify(params));
      }
    } else if (data.type == 31) {
      editRuleForm.fingerprint = data.data.template;

      console.log(data.data.template, "指纹数据");
      addFingerprintVisible.value = false;
      ws.value.close();
      ElMessage({
        message: "指纹录取成功",
        type: "success",
      });
      // setTimeout(() => {
      //   _this.fingerprintShow = false;
      //   ws.value.close();
      // }, 1500);
    } else {
      ElMessage({
        message: "设备连接失败，请刷新重新录入",
        type: "error",
      });
    }
  };
  websocket.onclose = function (evt) {
    console.log("关闭连接");
    // ws.value.close();
  };
  websocket.onerror = function (evt) {
    // console.log("错误提示");
  };
};
// 关闭指纹录入
const cancelAddFingerprint = () => {
  addFingerprintVisible.value = false;
  // var wsUrl = "ws://localhost:8181/";
  // const websocket = new WebSocket(wsUrl);
  ws.value.close();
};
// 读卡操作（---------------------------------------------）
const Card = () => {
  var wsUrl = "ws://localhost:8181/";
  let websocket = new WebSocket(wsUrl);
  // wsidentityCard.value = websocket;
  websocket.onopen = function (evt) {
    var params = { type: 104, data: null };
    websocket.send(JSON.stringify(params));
  };

  websocket.onmessage = function (evt) {
    let data = JSON.parse(evt.data);
    console.log(data);
    if (data.type == 141) {
      identityCardTitle.value = "请插入设备";
      identityCardIndex.value = 0;
    } else if (data.type == 150) {
      identityCardTitle.value = "配置失败，请放置卡片";
      identityCardIndex.value = 1;
    } else if (data.type == 140) {
      console.log(data.data.uid, "读取的卡号");

      identityCardIndex.value = 2;
      identityCardTitle.value = "读卡中";

      if (data.data.uid) {
        setTimeout(() => {
          identityCardIndex.value = 3;
          identityCardTitle.value = "读卡成功";
          addIdentityCardVisible.value = false;
        }, 1500);
      }
      editRuleForm.schoolCard = data.data.uid;

      // ElMessage({
      //   type: "success",
      //   showClose: true,
      //   message: "添加卡片成功",
      //   center: true,
      // });

      // identityCardTitle.value = "获取卡号成功";

      // addIdentityCardVisible.value = false;
      // identityCardVisible.value = false;
      // identityCardRef.value.resetFields();

      // setTimeout(() => {
      //   _this.icCardShow = false;
      // }, 2000);
    }
  };
};
// 身份证读卡 下一步
const readCard = () => {
  addIdentityCardVisible.value = true;
  Card();
};
// 重试 身份卡
const retry = () => {
  // identityCardNum.value = "";
  Card();
};
const cancelAddIdentityCard = () => {
  addIdentityCardVisible.value = false;
  identityCardIndex.value = 0;
};

// 多选框功能
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.user;
  console.log(flagBtn.value, "按钮权限");
});
onUnmounted(() => {
  // document.removeEventListener("keyup", Enters);
});
</script>

<style scoped lang="scss">
.content-box {
  min-width: 800px;
  width: calc(100vw - 260px);
  height: calc(100vh - 105px);
  margin: 20px auto;
  border-radius: 8px;
  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;
    margin: 0 30px;
    border-bottom: 1px solid #ccc;
    color: rgb(0, 0, 0);
    font-size: 18px;
    font-weight: 600;

    span {
      display: block;
      height: 60px;
      line-height: 60px;
      margin-right: 20px;
    }

    .is_active {
      color: rgba(111, 182, 184, 1);
    }
  }
  .btm {
    width: calc(100% - 60px);
    height: calc(100% - 60px);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
  }
  .middle {
    width: calc(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: calc(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(.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: 20px 30px 10px 30px;
      .el-form-item__content {
        width: 200px;
        .el-input-group__append {
          background-color: rgba(222, 234, 252, 1);
          color: rgba(0, 97, 255, 1);
          cursor: pointer;
          user-select: none;
        }
      }
      .options {
        margin: 30px 20px 20px 0;
        width: 100%;
        .el-form-item__content {
          display: flex;
          flex-direction: row-reverse;
        }
        .queding {
          color: #fff;
          margin-left: 15px;
        }
      }
    }
  }

  // 指纹弹窗
  :deep(.fingerprint) {
    width: 611px;
    height: 486px;
    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: 0;
      .elbody {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 20px 20px;
        font-size: 18px;
        color: #000;
        border-bottom: 0.5px solid #ccc;

        i {
          cursor: pointer;
        }
      }
    }
    .el-dialog__footer {
      .el-button--primary {
        background: rgba(41, 109, 227, 1);
      }
    }
  }

  // 身份证读取
  :deep(.addIdentityCard) {
    //   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;
      height: 330px;
      font-size: 16px;
      font-weight: 600;
      color: #000;
      .el-steps {
        width: 600px;
        transform: translateX(90px);
        margin: 0 0 40px 0;
      }
      .title {
        text-align: center;
      }
      .icons {
        display: flex;
        justify-content: center;
        img {
          width: 70px;
          margin: 40px 0;
        }
        .loading {
          animation: move 3s linear;
        }
        @keyframes move {
          0% {
            transform: rotate(0);
          }
          100% {
            transform: rotate(360deg);
          }
        }
      }
      .retry {
        text-align: center;
        span {
          color: red;
          padding: 0 8px;
          cursor: pointer;
        }
      }
    }
  }

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

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

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

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

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

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

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

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

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

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