<template>
  <div class="content-box">
    <div class="left">
      <!-- <el-icon :size="23" class="camera"><VideoCameraFilled /></el-icon> -->
      <div class="left_title">访客预约</div>
    </div>
    <div class="scroll">
      <div class="middle">
        <div class="filter">
          <div class="condition">
            <el-input
              :clearable="true"
              @clear="searchBtn"
              v-model="searchInput.keyWord"
              class="w-50 m-2"
              placeholder="请输入关键字"
            />
          </div>
          <el-button
            color="rgba(0, 97, 255, 1)"
            type="primary"
            class="search condition"
            @click="searchBtn"
          >
            查询</el-button
          >
          <div class="condition">
            <span>状态&nbsp;&nbsp;</span>
            <el-select
              v-model="searchInput.type"
              class="m-2"
              placeholder="请选择状态"
            >
              <el-option label="全部" value="0" />
              <el-option label="待审核" value="1" />
              <el-option label="已拒绝" value="2" />
              <el-option label="已推送" value="3" />
            </el-select>
          </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="请选择日期"
              style="width: 280px"
            />
          </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="请选择日期"
              style="width: 280px"
            />
          </div>
        </div>
        <!-- 按钮列表 -->
        <div class="gongneng">
          <el-button
            type="primary"
            plain
            color="rgba(0, 97, 255, 1)"
            @click="selDel"
            ><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" fixed type="selection" />
          <el-table-column align="center" fixed prop="name" label="姓名" />
          <el-table-column
            align="center"
            prop="phone"
            width="145"
            label="联系电话"
          />
          <el-table-column
            align="center"
            prop="icCard"
            width="210"
            label="证件号"
          />
          <el-table-column align="center" prop="txnum" label="同行人数" />
          <el-table-column align="center" prop="carNum" label="车牌号" />
          <el-table-column align="center" prop="thing" label="访问事由" />
          <el-table-column align="center" prop="status" label="状态">
            <template #default="scope">
              <span
                v-if="scope.row.status == 1"
                style="color: rgba(0, 97, 255, 1)"
                >待审核</span
              >
              <span
                v-if="scope.row.status == 2"
                style="color: rgba(212, 48, 48, 1)"
                >已拒绝</span
              >
              <span
                v-if="scope.row.status == 3"
                style="color: rgba(255, 87, 51, 1)"
                >已推送</span
              >
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="createTime"
            width="180"
            label="创建时间"
          />
          <el-table-column
            align="center"
            prop="comeTime"
            width="180"
            label="来访时间"
          />
          <el-table-column align="center" prop="interviewee" label="受访者" />
          <el-table-column
            align="center"
            prop="intervieweeBM"
            label="接待部门"
          />
          <el-table-column
            align="center"
            prop="intervieweePhone"
            width="145"
            label="受访者电话"
          />
          <el-table-column
            align="center"
            fixed="right"
            label="操作"
            width="120"
          >
            <template #default="scope">
              <div class="edit">
                <div class="look" @click="editClick(scope.row)">审核</div>
              </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="审核"
        align-center
        width="600"
        :before-close="cancelEdit"
      >
        <ul>
          <li>访客姓名：<span>张三</span></li>
          <li>访客手机号：<span>18956235689</span></li>
          <li>来访时间：<span>2023/10/22 12:00</span></li>
          <li>证件号：<span>362329200108698888</span></li>
          <li>访问事由：<span>给小孩送棉被</span></li>
          <li>车牌号：<span>无</span></li>
          <li>守访学生：<span>张三（4544）</span></li>
        </ul>
        <div class="options">
          <el-button
            color="rgba(41, 109, 227, 1)"
            class="queding"
            type="primary"
            @click="confirmEdit(editRef)"
          >
            同意，并推送
          </el-button>
          <el-button @click="cancelEdit(editRef)" color="rgba(212, 48, 48, 1)"
            >拒绝</el-button
          >
        </div>
      </el-dialog>
      <!-- 勾选删除 -->
      <el-dialog
        class="closeAccount"
        v-model="selDelVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        title="提示"
        align-center
        width="500"
        :before-close="cancelSelDel"
      >
        <div class="content">
          <img src="@/assets/images/warning.png" alt="" />
          <span>删除后数据将无法恢复，确定对选中的访问数据进行删除吗？</span>
        </div>
        <div class="option">
          <el-button
            color="rgba(41, 109, 227, 1)"
            class="queding"
            type="primary"
            @click="confirmCloseAccount"
          >
            确认
          </el-button>
          <el-button @click="cancelSelDel">取消</el-button>
        </div>
      </el-dialog>
    </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: [
    // {
    //   name: "张三",
    //   phone: "15012589658",
    //   icCard: "362502200202152356",
    //   txnum: "5",
    //   carNum: "赣K2536",
    //   thing: "接人",
    //   status: "1",
    //   createTime: "2023-12-13 09:39:30",
    //   comeTime: "2023-12-13 12:39:30",
    //   interviewee: "张四",
    //   intervieweeBM: "教师",
    //   intervieweePhone: "13646865956",
    // },
  ],
});

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

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

// 编辑功能
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 selDelVisible = ref(false);

// 预约记录分页数据
const getList = async () => {
  // loading.value = true;
  let data = {
    currentPage: currentPage.value,
    pageCount: pageCount.value,
    // userId: "", // 当前用户ID
    type: searchInput.type, // 类型
    // managerId: sessionStorage.getItem("token"),
  };
  let res = await axios({
    method: "get",
    url: api.value + "wanzai/api/smartVisitor/appointmentPageRecord",
    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.list;
    total.value = res.data.data.totalCount;
    // 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 cancelEdit = () => {
  editVisible.value = false;
  editRef.value.resetFields();
};

//删除按钮
const selDel = async () => {
  selDelVisible.value = true;
  // 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,
  //   });
  // }
};
const cancelSelDel = () => {
  selDelVisible.value = false;
};

// 多选框功能
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 {
  min-width: 1000px;
  width: calc(100vw - 260px);
  height: calc(100vh - 105px);
  margin: 20px auto;
  background-color: #fff;
  color: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: 0px 3px 10px rgba(0, 97, 255, 0.2);

  .left {
    // width: calc(100wh - 40px);
    display: flex;
    align-items: center;
    height: 60px;
    margin: 0 30px;
    border-bottom: 1px solid #ccc;
    color: rgb(0, 0, 0);
    font-size: 18px;
    font-weight: 600;
    .left_title {
      height: 60px;
      line-height: 60px;
    }
  }
  .scroll {
    height: calc(100% - 61px);
    overflow: auto;
  }
  .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;
      }

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

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

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

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

    :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: 550px;
    margin: 10px auto 30px;

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

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

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

      :deep(.el-table__row) {
        height: 50px;
        font-size: 14px;
        // color: #000;
        td {
          padding: 0;
          // border: 0;
        }
        &:hover {
          td {
            background-color: rgba(223, 236, 254, 1);
          }
        }
      }

      .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);
        .el-table_1_column_1 {
          background-color: rgba(240, 243, 247, 1);
        }
        .el-table_1_column_2 {
          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;
      ul {
        margin: 0;
        padding: 0;
        li {
          list-style: none;
          color: #000;
          font-weight: 400;
          font-size: 16px;
          margin-bottom: 10px;
        }
      }
      .options {
        margin: 30px 20px 20px 0;
        width: 100%;
        display: flex;
        flex-direction: row-reverse;
        .queding {
          color: #fff;
          margin-left: 15px;
        }
      }
    }
  }
  // 注销账号
  :deep(.closeAccount) {
    // height: 600px;
    overflow: hidden;
    border-radius: 11px;

    .el-dialog__header {
      border-radius: 11px 11px 0 0;
      background: rgba(245, 249, 255, 1);
      font-weight: 600;
      height: 60px;
      padding: 0 20px;
      line-height: 60px;
      margin: 0;
      border-bottom: 1px solid rgba(230, 230, 230, 1);

      .el-dialog__headerbtn {
        outline: none;
      }
    }

    .el-dialog__body {
      padding: 0px 20px 20px 20px;
      // height: 200px;
      // display: flex;
      // flex-direction: column-reverse;
      .content {
        height: 80px;
        font-size: 16px;
        padding: 20px 30px;
        display: flex;
        img {
          width: 25px;
          height: 25px;
          margin: 0 8px 0 0;
        }
      }
      .option {
        display: flex;
        flex-direction: row-reverse;
        align-items: center;
        margin: 10px 0;

        .queding {
          margin-left: 20px;
        }
      }
    }
  }

  .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;
      }
    }
  }
}

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