<template>
  <div class="content-box">
    <div class="left">
      <!-- <el-icon :size="23" class="camera"><VideoCameraFilled /></el-icon> -->
      <span class="cameratxt">统计报表</span>
    </div>
    <div class="changeItems">
      <div
        class="changeItem"
        :class="changeIndex == 1 ? 'changeItem_active' : ''"
        @click="changeItem(1)"
      >
        支付成功订单
      </div>
      <div
        class="changeItem"
        :class="changeIndex == 2 ? 'changeItem_active' : ''"
        @click="changeItem(2)"
      >
        待结账
      </div>
    </div>
    <div v-if="changeIndex == 1">
      <div class="middle">
        <div class="filter">
          <div class="condition">
            <span>关键字&nbsp;&nbsp;</span>
            <el-input
              :clearable="true"
              @clear="searchBtn"
              v-model="searchInput.keyWord"
              class="w-50 m-2"
              placeholder="请输入关键字查询"
              style="width: 180px"
            />
          </div>
          <div class="condition">
            <span>创建时间&nbsp;&nbsp;</span>
            <!-- <el-date-picker
              v-model="searchInput.submitTime"
              type="date"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              :prefix-icon="Calendar"
              placeholder="请选择日期"
              style="width: 150px"
            /> -->
            <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="请选择日期"
            />
          </div>
          <div class="condition">
            <el-button
              style="margin-left: 20px"
              color="rgba(41, 109, 227, 1)"
              type="primary"
              class="search"
              @click="searchBtn"
              ><el-icon>
                <Search />
              </el-icon>
              <span>查询</span></el-button
            >
            <el-button
              style="margin-left: 20px"
              color="rgba(41, 109, 227, 1)"
              type="primary"
              plain
              @click="searchBtn"
            >
              导出</el-button
            >
          </div>
        </div>
      </div>
      <div class="footer" v-loading="loading">
        <el-table
          :row-class-name="tableRowClassName"
          :data="tableData.list"
          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="orderNum"
            width="180"
            label="订单编号"
          >
            <template #default="{ row }">
              {{ row.orderNum }}
            </template>
          </el-table-column>
          <el-table-column align="center" prop="userName" label="入住人" />
          <el-table-column align="center" prop="houseName" label="房型" />
          <el-table-column align="center" prop="userName" label="房号" />
          <el-table-column
            align="center"
            prop="userName"
            label="订单金额(元)"
          />
          <el-table-column
            align="center"
            prop="payTime"
            label="支付时间"
            width="180"
          />

          <el-table-column
            align="center"
            fixed="right"
            label="操作"
            width="150"
          >
            <template #default="scope">
              <div class="look" @click="clickOrderInfo(scope.row)">详情</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>
    </div>
    <div v-if="changeIndex == 2" class="regulation">
      <div class="middle">
        <div class="filter">
          <div class="condition">
            <span>关键字&nbsp;&nbsp;</span>
            <el-input
              :clearable="true"
              @clear="searchBtn"
              v-model="accounts.keyWord"
              class="w-50 m-2"
              placeholder="请输入关键字查询"
              style="width: 180px"
            />
          </div>
          <div class="condition">
            <span>创建时间&nbsp;&nbsp;</span>
            <!-- <el-date-picker
              v-model="searchInput.submitTime"
              type="date"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              :prefix-icon="Calendar"
              placeholder="请选择日期"
              style="width: 150px"
            /> -->
            <el-date-picker
              v-model="accounts.createTime"
              type="daterange"
              range-separator="-"
              start-placeholder="起始时间"
              end-placeholder="结束时间"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              :prefix-icon="Calendar"
              placeholder="请选择日期"
            />
          </div>
          <div class="condition">
            <el-button
              style="margin-left: 20px"
              color="rgba(41, 109, 227, 1)"
              type="primary"
              class="search"
              @click="searchBtn"
              ><el-icon>
                <Search />
              </el-icon>
              <span>查询</span></el-button
            >
            <el-button
              style="margin-left: 20px"
              color="rgba(41, 109, 227, 1)"
              type="primary"
              plain
              @click="searchBtn"
            >
              导出</el-button
            >
          </div>
        </div>
      </div>
      <div class="footer" v-loading="loading">
        <el-table
          :row-class-name="tableRowClassName"
          :data="tableData.list"
          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="orderNum"
            width="180"
            label="订单编号"
          >
            <template #default="{ row }">
              {{ row.orderNum }}
            </template>
          </el-table-column>
          <el-table-column align="center" prop="userName" label="入住人" />
          <el-table-column align="center" prop="houseName" label="房型" />
          <el-table-column align="center" prop="userName" label="房号" />
          <el-table-column align="center" prop="userName" label="待结账(元)" />
          <el-table-column
            align="center"
            fixed="right"
            label="操作"
            width="150"
          >
            <template #default="scope">
              <div class="look" @click="clickOrderInfo(scope.row)">详情</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页组件 -->
      <div class="pageSize">
        <span></span>
        <el-pagination
          background
          :current-page="currentPage2"
          :page-size="pageSize2"
          layout="total, prev, pager, next, jumper, slot"
          :total="total2"
          @update:current-page="handleCurrentChange2"
        />
      </div>
    </div>

    <!-- 详情弹窗区域 -->
    <el-dialog
      class="orderInfo"
      title="订单详情"
      v-model="orderInfoVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      align-center
      width="850"
      :before-close="orderInfoClose"
    >
      <div class="userinfo">用户信息</div>
      <div class="info">
        <div class="user">
          <div class="name">姓名</div>
          <el-input
            v-model="order.userName"
            placeholder="请输入关键字查询"
          ></el-input>
        </div>
        <div class="user">
          <div class="name">联系方式</div>
          <el-input v-model="order.userPhone"></el-input>
        </div>
      </div>
      <div class="info">
        <div class="user">
          <div class="name">订单号</div>

          <el-tooltip placement="top" :content="order.orderNo">
            <el-input v-model="order.orderNo"></el-input>
          </el-tooltip>
        </div>
        <div class="user">
          <div class="name">预付款金额（元）</div>
          <el-input v-model="order.allOfReceiveAmount"></el-input>
        </div>
      </div>
      <div class="info">
        <div class="user">
          <div class="name">入住时间</div>
          <el-input v-model="order.realStartTime"></el-input>
        </div>
        <div class="user">
          <div class="name">离住时间</div>
          <el-input v-model="order.realEndTime"></el-input>
        </div>
      </div>
      <div class="info">
        <div class="user">
          <div class="name">入住天数</div>
          <el-input v-model="order.housDay"></el-input>
        </div>
        <div class="user">
          <div class="name">支付时间</div>
          <el-input v-model="order.payTime"></el-input>
        </div>
      </div>

      <!-- 水费区域 -->
      <div class="rate">水费明细</div>
      <div class="water">
        表计：101 楼层：{{ order.roomNo }} 抄表时间：2022-07-27 15:15:15
      </div>
      <el-table
        :data="waterTable"
        max-height="93"
        style="width: 832px"
        stripe
        :cell-style="rowbg"
        :header-cell-style="{
          color: ' rgba(0, 0, 0, 1)',
          background: 'rgba(240, 243, 247, 1)',
        }"
      >
        <el-table-column
          prop="startOfWater"
          width="100"
          label="始码"
          align="center"
        ></el-table-column>

        <el-table-column
          prop="endOfWater"
          width="100"
          align="center"
          label="终码"
        ></el-table-column>

        <el-table-column
          prop="waterVolume"
          align="center"
          label="水量（吨）"
        ></el-table-column>
        <el-table-column
          prop="priceOfWater"
          align="center"
          label="水价（元）"
        ></el-table-column>
        <el-table-column
          prop="allowance"
          align="center"
          label="补助量（吨）"
        ></el-table-column>
        <el-table-column
          prop="cost"
          align="center"
          label="产生水费（元）"
          show-overflow-tooltip
        ></el-table-column>
      </el-table>

      <!-- 电费区域 -->
      <div class="rate">电费明细</div>
      <div class="water">
        表计：101 楼层：{{ order.roomNo }} 抄表时间：2022-07-27 15:15:15
      </div>
      <el-table
        :data="electricTable"
        max-height="93"
        style="width: 832px"
        stripe
        :cell-style="rowbg"
        :header-cell-style="{
          color: ' rgba(0, 0, 0, 1)',
          background: 'rgba(240, 243, 247, 1)',
        }"
      >
        <el-table-column
          prop="startOfElectric"
          width="100"
          label="始码"
          align="center"
        ></el-table-column>

        <el-table-column
          prop="endOfElectric"
          width="100"
          align="center"
          label="终码"
        ></el-table-column>

        <el-table-column
          prop="electricVolume"
          align="center"
          label="电量（度）"
        ></el-table-column>
        <el-table-column
          prop="priceOfElectric"
          align="center"
          label="电价（元）"
        ></el-table-column>
        <el-table-column
          prop="allowance"
          align="center"
          label="补助量（度）"
        ></el-table-column>
        <el-table-column
          prop="cost"
          align="center"
          label="产生电费（元）"
          show-overflow-tooltip
        ></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script setup>
import {
  ref,
  reactive,
  nextTick,
  watch,
  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 changeIndex = ref(1); // 支付成功订单 待结账 切换

const searchInput = reactive({
  keyWord: "", // 关键字
  submitTime: "", // 提交时间
  approvalTime: "", // 审批时间
  status: 0, // 审批状态
  flowType: "", // 审批流程类型
  department: "", // 部门
  createTime: "",
}); // 搜索按钮数据

const nowDay = ref(dayjs().format("YYYY-MM-DD HH:mm:ss"));
// 表格数据
const loading = ref(false);
const tableData = reactive({
  list: [
    // {
    //   userName: "124145523",
    //   teamName: "",
    //   schoolName: "李四",
    //   userPhone: "1455532141",
    //   userZzname: "三人房",
    //   buildName: 21,
    //   workTypeName: 2300,
    //   acceptanceTime: "2023-08-03 21:09:12",
    // },
    // {
    //   userName: "124145523",
    //   teamName: "",
    //   schoolName: "李四",
    //   userPhone: "1455532141",
    //   userZzname: "三人房",
    //   buildName: 21,
    //   workTypeName: 2300,
    //   acceptanceTime: "2023-08-03 21:09:12",
    // },
    // {
    //   userName: "124145523",
    //   teamName: "",
    //   schoolName: "李四",
    //   userPhone: "1455532141",
    //   userZzname: "三人房",
    //   buildName: 21,
    //   workTypeName: 2300,
    //   acceptanceTime: "2023-08-03 21:09:12",
    // },
  ],
});

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

const orderInfoVisible = ref(false); // 详情弹窗
const order = reactive({
  userName: "", // 姓名
  userPhone: "", // 联系方式
  orderNo: "", // 订单号
  allOfReceiveAmount: "", // 预付款金额（元）
  realStartTime: "", // 入住时间
  realEndTime: "", // 离住时间
  housDay: "", // 入住天数
  payTime: "", // 支付时间
  roomNo: "", // 水费明细
});
const waterTable = ref(); // 水费明细
const electricTable = ref(); // 电费明细

// 待结账 (---------------------------------------------------------------------)
const accounts = reactive({
  keyWord: "", // 关键字
  createTime: "", // 创建时间
});
const currentPage2 = ref(1); // 当前页
const pageSize2 = ref(10);
const total2 = ref(); // 当前总数

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

// 切换 支付成功订单 待结账
const changeItem = (ind) => {
  changeIndex.value = ind;
  if (ind == 1) {
    getList();
  } else if (ind == 2) {
    getList();
  }
};

// 查看员工列表
const getList = async () => {
  loading.value = true;
  let data = {
    page: currentPage.value, // 当前页
    rows: pageSize.value, // 一页数据条数
    ledgerParam: searchInput.keyWord,
    managerId: sessionStorage.getItem("token"),
  };
  if (searchInput.createTime) {
    data.payStartTime = searchInput.createTime[0];
    data.payEndTime = searchInput.createTime[1];
  }

  if (searchInput.status) {
    if (searchInput.status != 0) {
      data.orderStatus = searchInput.status;
    }
  }
  let res = await axios({
    method: "post",
    url: api.value + "/mhotel/bookquearyBookPage.action",
    headers: {
      // token: sessionStorage.getItem("token"),
      // user_head: sessionStorage.getItem("userhead"),
    },
    params: data,
  });
  console.log(res, "用户列表");
  if (res.data.code == 200) {
    tableData.list = res.data.data.bookIPage.pageList;
    total.value = res.data.data.bookIPage.total;
    loading.value = false;
    // 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 clickOrderInfo = (row) => {
  orderInfoVisible.value = true;
  console.log(row);
};
// 关闭详情弹窗
const orderInfoClose = () => {
  orderInfoVisible.value = false;
};

// 表格斑马纹颜色修改
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();
};
//  待结账 分页
const handleCurrentChange2 = (value) => {
  // console.log(value);
  currentPage2.value = value;
  getList();
};

onBeforeMount(async () => {
  api.value = store.state.user.api;
  changeItem(changeIndex.value);
});
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 {
      display: inline-block;
      height: 60px;
      line-height: 60px;
      margin-right: 20px;
      cursor: pointer;
    }

    .is_active {
      color: rgba(111, 182, 184, 1);
    }
  }

  .top {
    width: 96%;
    height: 150px;
    margin: 20px auto;

    ul {
      padding: 0;
      margin: 0;
      height: 100%;
      list-style: none;
      display: flex;

      li {
        background-color: rgba(242, 242, 242, 1);
        border-radius: 10px;
        flex: 1;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        p {
          font-size: 40px;
          font-weight: 700;
          color: #000;
          margin: 0;
        }

        span {
          color: #000;
          font-size: 18px;
          font-weight: 400;
        }
      }

      li:not(:last-child) {
        margin-right: 36px;
      }
    }
  }

  //   切换 申请记录 规则设置
  .changeItems {
    display: flex;
    margin: 15px 0 0 30px;
    .changeItem {
      //   width: 80px;
      padding: 0 10px;
      height: 30px;
      background-color: rgba(230, 230, 230, 1);
      text-align: center;
      line-height: 30px;
      font-size: 14px;
      margin-right: 15px;
      border-radius: 3px;
      color: rgba(166, 166, 166, 1);
      cursor: pointer;
    }
    .changeItem_active {
      background-color: rgba(222, 234, 252, 1);
      color: rgba(0, 97, 255, 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;
      }

      .condition {
        display: flex;
        align-items: center;
        margin: 10px 30px 10px 0;
        font-size: 14px;

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

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

      span {
        color: #fff;
      }
    }

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

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

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

        tr {
          color: #000;
        }
      }

      :deep(.el-table__row) {
        height: 50px;
        font-size: 15px;
        color: #000;

        .orderNum {
          color: rgba(111, 182, 184, 1);
          cursor: pointer;
        }
      }

      :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(.look) {
        color: rgba(0, 97, 255, 1);
        cursor: pointer;
      }
    }
  }
  //   订单详情
  :deep(.orderInfo) {
    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 38px;
      height: 750px;
      overflow: auto;

      .userinfo {
        font-size: 18px;
        font-weight: 500;
        color: rgba(0, 0, 0, 1);
        text-align: left;
        margin-top: 15px;
      }

      .info {
        display: flex;

        .user {
          margin-right: 120px;
          .name {
            text-align: left;
            padding: 12px 0;
          }

          .el-input {
            width: 283px;
            // height: 30px;
            opacity: 1;
            // margin-right: 81px;
            // .el-input__inner {
            //   color: #000;
            // }
          }
        }
      }

      .rate {
        font-size: 18px;
        font-weight: 500;
        color: rgba(0, 0, 0, 1);
        text-align: left;
        margin: 15px 0;
      }

      .water {
        text-align: left;
        font-size: 16px;
        font-weight: 400;
        color: rgba(0, 0, 0, 1);
      }

      .el-table {
        margin: 10px 0;

        tr {
          height: 48px;
        }

        .el-table__body-wrapper {
          overflow: visible;
        }
      }
    }
  }

  //   待结账页面样式
  .regulation {
    .condition {
      color: #000;
      margin: 20px 30px;
      font-size: 14px;
    }
    .hint {
      color: rgba(212, 48, 48, 1);
    }
  }

  .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(111, 182, 184, 1);
        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;
      }
    }
  }
}
</style>
