<template>
  <div class="content-box">
    <div class="left">
      <!-- <el-icon :size="23" class="camera"><VideoCameraFilled /></el-icon> -->
      <span class="cameratxt">校园安全</span>
    </div>
    <div>
      <div class="middle">
        <div class="filter">
          <div class="condition">
            <el-input
              :clearable="true"
              @clear="searchBtn"
              v-model="searchInput.keyWord"
              placeholder="请输入关键字"
            >
              <template #prefix>
                <el-icon class="el-input__icon"><search /></el-icon>
              </template>
            </el-input>
          </div>
          <el-button
            color="rgba(0, 97, 255, 1)"
            type="primary"
            class="search"
            @click="searchBtn"
          >
            查询</el-button
          >
          <div class="condition">
            <span>状态 :</span>
            <el-select
              v-model="searchInput.status"
              class="m-2"
              placeholder="请选择状态"
            >
              <el-option label="全部" value="1" />
              <el-option label="已处理" value="2" />
              <el-option label="未处理" value="3" />
            </el-select>
          </div>
        </div>
        <!-- 按钮列表 -->
        <div class="gongneng">
          <!-- <el-button
            type="primary"
            color="rgba(0, 97, 255, 1)"
            @click="addClick"
            plain
            >新建身份</el-button
          > -->
          <el-button
            type="primary"
            color="rgba(0, 97, 255, 1)"
            @click="importExcel"
            plain
            >导出</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="100"
            align="center "
            type="index"
            label="序号"
          />
          <el-table-column align="center" prop="userName" label="姓名" />
          <el-table-column align="center" prop="type" label="类型" />
          <el-table-column align="center" prop="position" label="地点" />
          <el-table-column align="center" prop="img" label="图片">
            <template #default="{ row }">
              <div class="img">
                <img @click="imgClick(row)" :src="row.img" alt="" />
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="remark"
            show-overflow-tooltip
            width="220"
            label="备注"
          />
          <el-table-column align="center" prop="status" label="状态" />
          <el-table-column
            align="center"
            prop="time"
            width="200"
            label="时间"
          />
          <el-table-column align="center" label="操作" width="200">
            <template #default="scope">
              <div class="edit">
                <div class="look" @click="editClick(scope.row)">处理</div>
                <el-popconfirm
                  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>

      <!-- 分页组件 -->
      <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="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">
            <el-input
              v-model="editRuleForm.userDepartment"
              placeholder="请输入身份"
              clearable
              style="width: 500px"
            />
          </el-form-item>
          <el-form-item label="应用管理 :" prop="userName">
            <el-select
              v-model="editRuleForm.userName"
              multiple
              placeholder="请选择应用管理"
              style="width: 500px"
            >
              <el-option label="学生肖像" value="1" />
              <el-option label="车辆预约" value="2" />
              <el-option label="校园打卡" value="3" />
              <el-option label="校园报修" value="4" />
            </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> -->
    </div>
    <div class="bgImg" v-if="bgImg">
      <el-carousel
        @click="bgImg = false"
        ref="bgImgs"
        indicator-position
        arrow="always"
        :autoplay="false"
        trigger
      >
        <el-carousel-item>
          <img :src="showImg" alt="" />
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>

<script setup>
import {
  ref,
  reactive,
  watch,
  nextTick,
  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: [
    {
      userName: "张三",
      type: "越界",
      position: "教学楼",
      img: "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2021%2F1123%2F77d07411j00r30gwf004dc000go00b4m.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
      remark: "请规范好学生行为",
      status: "已处理",
      time: "2023-12-02 11:05:30",
    },
    {
      userName: "王卿",
      type: "越界",
      position: "教学楼",
      img: "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2021%2F1123%2F77d07411j00r30gwf004dc000go00b4m.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
      remark: "请规范好学生行为",
      status: "已处理",
      time: "2023-12-02 11:05:30",
    },
    {
      userName: "李明",
      type: "越界",
      position: "教学楼",
      img: "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2021%2F1123%2F77d07411j00r30gwf004dc000go00b4m.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
      remark: "请规范好学生行为",
      status: "已处理",
      time: "2023-12-02 11:05:30",
    },
    {
      userName: "涂涂",
      type: "越界",
      position: "教学楼",
      img: "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2021%2F1123%2F77d07411j00r30gwf004dc000go00b4m.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
      remark: "请规范好学生行为",
      status: "已处理",
      time: "2023-12-02 11:05:30",
    },
    {
      userName: "小红",
      type: "越界",
      position: "教学楼",
      img: "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2021%2F1123%2F77d07411j00r30gwf004dc000go00b4m.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
      remark: "请规范好学生行为",
      status: "已处理",
      time: "2023-12-02 11:05:30",
    },
    {
      userName: "小明",
      type: "越界",
      position: "教学楼",
      img: "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2021%2F1123%2F77d07411j00r30gwf004dc000go00b4m.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
      remark: "请规范好学生行为",
      status: "已处理",
      time: "2023-12-02 11:05:30",
    },
    {
      userName: "例子",
      type: "越界",
      position: "教学楼",
      img: "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2021%2F1123%2F77d07411j00r30gwf004dc000go00b4m.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
      remark: "请规范好学生行为",
      status: "已处理",
      time: "2023-12-02 11:05:30",
    },
  ],
});

const searchInput = reactive({
  keyWord: "",
  status: "1",
}); // 搜索按钮数据

const currentPage = ref(1); // 当前页
const pageSize = ref(7);
const total = ref(7); // 当前总数
const bgImg = ref(false);
const showImg = ref();

// 编辑功能
const titleDialog = ref("");
const editVisible = ref(false);
const editRef = ref();
const editRuleForm = reactive({
  userDepartment: "", // 用户部门
  userName: "", // 用户名
  userRoles: "", // 用户角色
  schoolCard: "", // 微校卡号
  idNumber: "", // 身份证号
  fingerprint: "", // 指纹
  id: "",
});

// 表单验证
const editRules = reactive({
  userDepartment: [
    { required: true, message: "身份不能为空", trigger: "blur" },
  ],
  userName: [
    {
      required: true,
      message: "应用管理不能为空",
      trigger: "blur",
    },
  ],
  userRoles: [
    {
      required: true,
      message: "用户角色不能为空",
      trigger: "blur",
    },
  ],
  schoolCard: [
    {
      required: true,
      message: "微校卡号不能为空",
      trigger: "blur",
    },
  ],
  idNumber: [
    {
      required: true,
      message: "身份证号不能为空",
      trigger: "blur",
    },
  ],
  fingerprint: [
    {
      required: true,
      message: "指纹不能为空",
      trigger: "blur",
    },
  ],
});

// 查看房型列表
const getList = async () => {
  //   loading.value = true;
  //   let data = {
  //     page: currentPage.value,
  //     rows: pageSize.value,
  //     hName: searchInput.keyWord, // 房型名称
  //     managerId: sessionStorage.getItem("token"),
  //   };
  //   let res = await axios({
  //     method: "post",
  //     url: api.value + "/mhotel/housequeryPage.action",
  //     headers: {
  //       // token: sessionStorage.getItem("token"),
  //       // user_head: sessionStorage.getItem("userhead"),
  //     },
  //     params: data,
  //   });
  //   console.log(res, "房型管理");
  //   if (res.data.code == 200) {
  //     loading.value = false;
  //     tableData.list = res.data.data.pageList;
  //     total.value = res.data.data.total;
  //     // ElMessage({
  //     //   type: "success",
  //     //   showClose: true,
  //     //   message: res.data.message,
  //     //   center: true,
  //     // });
  //   } else {
  //     loading.value = false;
  //     ElMessage({
  //       type: "error",
  //       showClose: true,
  //       message: res.data.message,
  //       center: true,
  //     });
  //   }
};

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

//处理按钮  （-------------------------------------------）
const editClick = async () => {
  titleDialog.value = "处理";
  // editVisible.value = true;
  //   let data = {
  //     linkId: row.id,
  //   };
  //   let res = await axios({
  //     method: "post",
  //     url: api.value + "/mhotel/uploadgetByLinkId.action",
  //     headers: {},
  //     params: data,
  //   });
  //   console.log(res, "编辑中查找图片");
  //   if (res.data.code == 200) {
  //     // res.data.data.fileInfoList.forEach((item) => {
  //     //   item.uid = item.id;
  //     // });
  //     // fileList.list = res.data.data.fileInfoList;
  //     // ruleForm.fileListJson = fileList.list;
  //     res.data.data.forEach((item) => {
  //       item.uid = item.id;
  //     });
  //     fileList.list = res.data.data;
  //     ruleForm.fileListJson = fileList.list;
  //     // ElMessage({
  //     //   type: "success",
  //     //   showClose: true,
  //     //   message: res.data.message,
  //     //   center: true,
  //     // });
  //   } else {
  //     ElMessage({
  //       type: "error",
  //       showClose: true,
  //       message: res.data.message,
  //       center: true,
  //     });
  //   }
};

// 查看图片
const imgClick = (row) => {
  bgImg.value = true;
  showImg.value = row.img;
};

//删除按钮
const del = async (row) => {
  let data = {
    id: row.id,
  };
  //   let res = await axios({
  //     method: "post",
  //     url: api.value + "/mhotel/housedelHouser.action",
  //     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 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();
});
onUnmounted(() => {
  // document.removeEventListener("keyup", Enters);
});
</script>

<style scoped lang="scss">
.content-box {
  width: 97.5%;
  height: 89%;
  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);
    }
  }

  .middle {
    width: 96%;
    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 {
        color: #fff;
        margin: 0 40px 0 0;
      }

      .condition {
        display: flex;
        align-items: center;
        margin: 10px 20px 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: 96%;
    height: 540px;
    margin: 10px auto 30px;

    .el-table--fit {
      height: 100%;

      :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;
        .img {
          display: flex;
          align-items: center;
          justify-content: center;
          margin: 5px 0;
          img {
            width: 60px;
            height: 60px;
            cursor: pointer;
          }
        }
      }

      .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: 30px 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: 50px 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;

    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;
      }
    }
  }
  .bgImg {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 99999999;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);

    // border-radius: 50px;
    :deep(.el-carousel__container) {
      width: 100%;
      height: calc(100vh);

      .el-carousel__item {
        display: flex;
        justify-content: center;

        img {
          height: 100%;
        }
      }
    }
  }
}

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