<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">
          <el-button
            color="rgba(0, 97, 255, 1)"
            type="primary"
            @click="addApply"
            plain
          >
            <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="150"
            align="center "
            type="index"
            label="序号"
          />
          <el-table-column align="center" prop="name" label="名称" />
          <el-table-column align="center" prop="type" 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="name">
            <el-input
              v-model="editRuleForm.name"
              placeholder="请输入名称"
              clearable
              style="width: 500px"
            />
          </el-form-item>
          <el-form-item label="类别 :" prop="type">
            <el-select
              v-model="editRuleForm.type"
              class="m-2"
              placeholder="请选择类别"
              style="width: 500px"
            >
              <el-option label="小程序" value="1" />
              <el-option label="管理端" value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="应用链接 :" prop="applyLink">
            <el-input
              v-model="editRuleForm.applyLink"
              placeholder="请输入应用链接"
              clearable
              style="width: 500px"
            />
          </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>
</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: "双人房",
      type: 150,
      teamName: 12,
    },
    {
      name: "双人房",
      type: 150,
      teamName: 12,
    },
    {
      name: "双人房",
      type: 150,
      teamName: 12,
    },
    {
      name: "双人房",
      type: 150,
      teamName: 12,
    },
  ],
});

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

// 编辑功能
const titleDialog = ref("");
const editVisible = ref(false);
const editRef = ref();
const editRuleForm = reactive({
  name: "", // 名称
  applyLink: "", // 类别
  type: "", // 应用链接
  id: "",
});

// 表单验证
const editRules = reactive({
  name: [{ required: true, message: "名称不能为空", trigger: "blur" }],
  type: [
    {
      required: true,
      message: "类别不能为空",
      trigger: "blur",
    },
  ],
  applyLink: [
    {
      required: true,
      message: "应用链接不能为空",
      trigger: "blur",
    },
  ],
});

// 查看房型列表
const getList = async () => {
  // loading.value = true;
  // let data = {
  //   page: currentPage.value,
  //   rows: pageSize.value,
  //   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 addApply = 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 confirmEdit = (formEl) => {
  if (!formEl) return;
  formEl.validate(async (valid, fields) => {
    if (valid) {
    }
  });
};

//编辑按钮  （-------------------------------------------）
const editClick = async (row) => {
  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 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 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: 20px 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;
        }
      }
    }

    :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: 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: 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: 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;

    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>
