<template>
  <div>
    <!-- <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 基础表格
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div> -->
    <el-row :gutter="20" class="elrow">
      <el-col :span="24">
        <el-card shadow="hover">
          <el-row class="flexrow">
            <el-col :span="5">
              <div class="grid-content grid-con-2">
                <div class="colposition">
                  <img src="../assets/img/ptyh.png" class="w100" alt="" />
                  <div class="grid-cont-right">
                    <div>到期房间</div>
                    <div class="grid-num">5</div>
                  </div>
                </div>
              </div>
            </el-col>
            <el-col :span="5" class="">
              <div class="grid-content grid-con-2">
                <div class="colposition">
                  <img src="../assets/img/gly.png" class="w100" alt="" />
                  <div class="grid-cont-right">
                    <div>本月到期房间</div>
                    <div class="grid-num">3</div>
                  </div>
                </div>
              </div>
            </el-col>
            <el-col :span="5" class="">
              <div class="grid-content grid-con-1">
                <div class="colposition">
                  <img src="../assets/img/yxfpz.png" class="w100" alt="" />
                  <div class="grid-cont-right">
                    <div>下月到期房间</div>
                    <div class="grid-num">11</div>
                  </div>
                </div>
              </div>
            </el-col>
            <el-col :span="9" class="">
              <schart
                ref="bar"
                class="schart"
                canvasId="bar"
                :options="options"
              ></schart>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
    </el-row>

    <el-card style="cardbg">
      <el-row
            :gutter="20"
            style="box-sizing: border-box; margin: 0 0 0 10px"
          >
            <el-col
              :span="6"
              style="background: #fff; height: 598px;overflow-y:auto;"
            >
              <el-card shadow="always" style="cardbg">
                <zTree :setting="setting" :nodes="zNodes" @onClick="onClick" />
              </el-card>
            </el-col>
            <el-col :span="18">
              <div class="container">
                <div class="handle-box">
                  <el-tabs v-model="activeName" @tab-click="handleClick">
                    <el-tab-pane label="全部房间" name="first"></el-tab-pane>
                    <el-tab-pane label="到期房间" name="second"></el-tab-pane>
                    <el-tab-pane label="本月到期房间" name="third"></el-tab-pane>
                    <el-tab-pane label="下月到期房间" name="fourth"></el-tab-pane>
                  </el-tabs>
                </div>
                <el-table
                  :data="tableData"
                  border
                  class="table"
                  ref="multipleTable"
                  height="400"
                  header-cell-class-name="table-header"
                  highlight-current-row
                  @current-change="handleCurrentChange"
                  v-if="activeName == 'first'"
                >
                  <el-table-column
                    prop="id"
                    label="ID"
                    align="center"
                  ></el-table-column>
                  <el-table-column prop="name" label="名称"></el-table-column>
                  <!-- <el-table-column prop="address" label="地址"></el-table-column> -->
                  <el-table-column prop="count" label="入住"></el-table-column>
                  <el-table-column
                    prop="address"
                    label="地址"
                  ></el-table-column>
                  <el-table-column label="户型" align="center">
                    <template #default="scope">
                      <div v-if="scope.row.layout == 0">单间</div>
                      <div v-if="scope.row.layout == 1">一室一厅</div>
                      <div v-if="scope.row.layout == 2">两室一厅</div>
                      <div v-if="scope.row.layout == 3">三室一厅</div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="acreage"
                    label="面积/m²"
                  ></el-table-column>
                </el-table>
                <el-table
                  :data="tableData1"
                  border
                  class="table"
                  ref="multipleTable"
                  height="400"
                  highlight-current-row
                  header-cell-class-name="table-header"
                  @current-change="handleCurrentChange"
                  v-if="activeName == 'second'"
                >
                  <el-table-column
                    prop="id"
                    label="ID"
                    align="center"
                  ></el-table-column>
                  <el-table-column prop="name" label="名称"></el-table-column>
                  <!-- <el-table-column prop="address" label="地址"></el-table-column> -->
                  <el-table-column prop="count" label="入住"></el-table-column>
                  <el-table-column
                    prop="address"
                    label="地址"
                  ></el-table-column>
                  <el-table-column label="户型" align="center">
                    <template #default="scope">
                      <div v-if="scope.row.layout == 0">单间</div>
                      <div v-if="scope.row.layout == 1">一室一厅</div>
                      <div v-if="scope.row.layout == 2">两室一厅</div>
                      <div v-if="scope.row.layout == 3">三室一厅</div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="acreage"
                    label="面积/m²"
                  ></el-table-column>
                </el-table>
                <el-table
                  :data="tableData2"
                  border
                  class="table"
                  ref="multipleTable"
                  height="400"
                  highlight-current-row
                  header-cell-class-name="table-header"
                  @current-change="handleCurrentChange"
                  v-if="activeName == 'third'"
                >
                  <el-table-column
                    type="selection"
                    width="55"
                    align="center"
                  ></el-table-column>
                  <el-table-column
                    prop="id"
                    label="ID"
                    align="center"
                  ></el-table-column>
                  <el-table-column prop="name" label="名称"></el-table-column>
                  <!-- <el-table-column prop="address" label="地址"></el-table-column> -->
                  <el-table-column prop="count" label="入住"></el-table-column>
                  <el-table-column
                    prop="address"
                    label="地址"
                  ></el-table-column>
                  <el-table-column label="户型" align="center">
                    <template #default="scope">
                      <div v-if="scope.row.layout == 0">单间</div>
                      <div v-if="scope.row.layout == 1">一室一厅</div>
                      <div v-if="scope.row.layout == 2">两室一厅</div>
                      <div v-if="scope.row.layout == 3">三室一厅</div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="acreage"
                    label="面积/m²"
                  ></el-table-column>
                </el-table>
                <el-table
                  :data="tableData3"
                  border
                  class="table"
                  ref="multipleTable"
                  height="400"
                  highlight-current-row
                  header-cell-class-name="table-header"
                  @current-change="handleCurrentChange"
                  v-if="activeName == 'fourth'"
                >
                  <el-table-column
                    type="selection"
                    width="55"
                    align="center"
                  ></el-table-column>
                  <el-table-column
                    prop="id"
                    label="ID"
                    align="center"
                  ></el-table-column>
                  <el-table-column prop="name" label="名称"></el-table-column>
                  <!-- <el-table-column prop="address" label="地址"></el-table-column> -->
                  <el-table-column prop="count" label="入住"></el-table-column>
                  <el-table-column
                    prop="address"
                    label="地址"
                  ></el-table-column>
                  <el-table-column label="户型" align="center">
                    <template #default="scope">
                      <div v-if="scope.row.layout == 0">单间</div>
                      <div v-if="scope.row.layout == 1">一室一厅</div>
                      <div v-if="scope.row.layout == 2">两室一厅</div>
                      <div v-if="scope.row.layout == 3">三室一厅</div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="acreage"
                    label="面积/m²"
                  ></el-table-column>
                </el-table>
                <div class="pagination">
                  <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                  ></el-pagination>
                </div>
              </div>
            </el-col>
          </el-row>
    </el-card>
    <!-- 编辑弹出框 -->
    <el-dialog title="编辑" v-model="editVisible" width="30%">
      <el-form ref="form" :model="form" label-width="70px">
        <el-form-item label="用户名">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="form.address"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="editVisible = false">取 消</el-button>
          <el-button type="primary" @click="saveEdit">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import Schart from "vue-schart";
import zTree from "../components/zTree1.vue";
import { httpGet, httpPost } from "../api";
export default {
  name: "campus",
  data() {
    return {
       steplist: [
        { src: "../assets/img/1.png", title: "房源选择" },
        { src: "../assets/img/2.png", title: "人员退租" },
      ],
      stepindex: 0,
      stepindex1: 0,
      query: {
        address: "",
        name: "",
        pageIndex: 1,
        pageSize: 20,
        activeName: "first"
      },
      activeName: "first",
      options: {
        type: "bar",
        title: {
          text: "近6个月即将到期房间-柱状图",
        },
        xRorate: 25,
        labels: ["周一", "周二", "周三", "周四", "周五"],
        datasets: [
          {
            label: "已到期房间",
            data: [234, 278, 270, 190, 230],
          },
          {
            label: "本月到期房间",
            data: [164, 178, 190, 135, 160],
          },
          {
            label: "下月到期房间",
            data: [144, 198, 150, 235, 120],
          },
        ],
      },
      tableData: [],
      tableData1: [],
      tableData2: [],
      tableData3:[],
      multipleSelection: [],
      delList: [],
      editVisible: false,
      pageTotal: 0,
      form: {},
      idx: -1,
      id: -1,
      showIndex: 0,
      ztreeObj: null,
      uselist: [],
      zNodes: [],
      setting: {
        edit: {
          enable: true,
          drag: {
            isMove: true,
          },
          showRemoveBtn: false,
          showRenameBtn: false,
        },
        check: {
          enable: false,
        },
        data: {
          simpleData: {
            enable: true,
            pIdKey: "pid",
          },
        },
        view: {
          showIcon: true,
          addHoverDom: this.addHoverDom,
          removeHoverDom: this.removeHoverDom,
        },
      },
      fatherid:0
    };
  },
  components: {
    Schart,
    zTree
  },
  created() {
    this.getalllist();
  },
  methods: {
    onClick: function (evt, treeId, treeNode) {
      // 点击事件
      this.fatherid=treeNode.pid
      this.fatherMethod(treeNode.pid);
    },
    fatherMethod(id) {
      var q = {
        ancestor: id,
      };
      var data = {
        q: JSON.stringify(q),
        pageNum:1,
        pageSize:20
      };
      httpGet(data, this.$api.getSiteList).then((res) => {
        this.tableData = res.data.list;
        this.pageTotal = res.data.total;
        var tableData1 = [],
          tableData2 = [];
        res.data.list.map((li, index) => {
          if (li.id == id) {
            this.tableData.splice(index, 1);
          } else if (li.count == 0) {
            tableData2.push(li);
          } else if (li.count > 0) {
            tableData1.push(li);
          }
        });
        this.tableData1 = tableData1;
        this.tableData2 = tableData2;
      });
    },
    fatherMethod1(pageNum) {
      var q = {
        ancestor: this.fatherid,
      };
      var data = {
        q: JSON.stringify(q),
        pageNum:pageNum,
        pageSize:20
      };
      httpGet(data, this.$api.getSiteList).then((res) => {
        this.tableData = res.data.list;
        this.pageTotal = res.data.total;
        var tableData1 = [],
          tableData2 = [];
        res.data.list.map((li, index) => {
          if (li.id == id) {
            this.tableData.splice(index, 1);
          } else if (li.count == 0) {
            tableData2.push(li);
          } else if (li.count > 0) {
            tableData1.push(li);
          }
        });
        this.tableData1 = tableData1;
        this.tableData2 = tableData2;
      });
    },
    // 获取所有房间
    getalllist() {
      var data = {};
      httpGet(data,  this.$api.getTree).then((res) => {
        this.zNodes = res.data;
      });
    },
    handleClick(tab, event) {
      if (tab.name == "second") {
        this.pageTotal = this.tableData1.length;
      } else if (tab.name == "third") {
        this.pageTotal = this.tableData2.length;
      }
    },
    handleChange(value) {
      console.log(value);
    },
    // 触发搜索按钮
    handleSearch() {
      this.$set(this.query, "pageIndex", 1);
      this.getData();
    },
    // 删除操作
    handleDelete(index) {
      // 二次确认删除
      this.$confirm("确定要删除吗？", "提示", {
        type: "warning",
      })
        .then(() => {
          this.$message.success("删除成功");
          this.tableData.splice(index, 1);
        })
        .catch(() => {});
    },
    // 多选操作
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    delAllSelection() {
      const length = this.multipleSelection.length;
      let str = "";
      this.delList = this.delList.concat(this.multipleSelection);
      for (let i = 0; i < length; i++) {
        str += this.multipleSelection[i].name + " ";
      }
      this.$message.error(`删除了${str}`);
      this.multipleSelection = [];
    },
    handleCurrentChange(val) {

    },
    // 编辑操作
    handleEdit(index, row) {
      this.idx = index;
      this.form = row;
      this.editVisible = true;
    },
    // 保存编辑
    saveEdit() {
      this.editVisible = false;
      this.$message.success(`修改第 ${this.idx + 1} 行成功`);
      this.$set(this.tableData, this.idx, this.form);
    },
    // 分页导航
    handlePageChange(val) {
      console.log(val,this.query)
      if(this.activeName=='first'){
        this.$set(this.query, "pageIndex", val);
        this.fatherMethod1(val)
      }else if(this.activeName == 'second'){

      }else if(this.activeName == 'third'){

      }else if(this.activeName == 'fourth'){

      }
    },
  },
};
</script>

<style scoped>
.steps {
  background: rgba(236, 239, 255, 0.8);
  display: flex;
  flex-wrap: wrap;
  height: 44px;
  width: 100%;
  margin-bottom: 40px;
  box-sizing: border-box;
  align-items: center;
  text-align: center;
  justify-content: center;
}

.step {
  cursor: pointer;
  width: 25%;
  position: relative;
  height: 100%;
  line-height: 44px;
}

.steps .l1 {
  width: 22px;
  height: 22px;
  margin-right: 9px;
  vertical-align: middle;
}

.steps span {
  vertical-align: middle;
  font-size: 16px;
  font-family: Microsoft YaHei;
  font-weight: 700;
  color: #666;
}

.steps .r2 {
  width: 28px;
  height: 44px;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.steps .stepcolor {
  color: #8078ea;
}

.handle-box {
  margin-bottom: 10px;
  position: relative;
}

.nextstep {
  position: absolute;
  right: 0;
  top: 0;
  padding: 6px 15px;
  background: #6971ab;
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}

.table {
  width: 100%;
  font-size: 14px;
}

.red {
  color: #ff0000;
}

.mr10 {
  margin-right: 10px;
}

.mright {
  margin-right: 10px;
  display: inline-block;
}

.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}

.elrow {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
}

.grid-content {
  position: relative;
  z-index: 99;
  display: flex;
  align-items: center;
  overflow: hidden;
  justify-content: space-around;
  -webkit-box-align: center;
}

/* 加的 */
.colposition {
  display: flex;
  align-items: center;
  position: relative;
  box-sizing: border-box;
  border: 2px solid hsla(0, 0%, 100%, 0.2);
  /* width: 100%; */
}

.grid-cont-right {
  flex: 1;
  text-align: left;
  padding-left: 20px;
  box-sizing: border-box;
  font-size: 16px;
  color: #666;
  font-size: 14px;
  line-height: 32px;
}

.grid-num {
  font-size: 24px;
}

.grid-con-icon {
  font-size: 50px;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  color: #fff;
}

.grid-con-1 {
  position: relative;
}

.grid-con-1::before {
  position: absolute;
  content: "";
  top: 50%;
  right: 0;
  width: 1px;
  transform: translateY(-50%);
  height: 70px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  border-left: 1px dashed #666;
}

.grid-con-1 .grid-con-icon {
  background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
  /* color: rgb(45, 140, 240); */
  color: #333;
}

.grid-con-2 .grid-con-icon {
  background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
  /* color: rgb(45, 140, 240); */
  color: #333;
}

.grid-con-3 .grid-con-icon {
  background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
  color: rgb(242, 94, 67);
}

.nulldiv {
  text-align: center;
  color: #999;
  font-size: 16px;
  font-weight: 400;
}

.nullimg {
  margin: 30px auto;
  max-width: 300px;
}

.el-card__body {
  padding: 0;
}

.cardbg {
  height: 460px;
  overflow-y: scroll;
  background: #fff;
  margin: 20px;
  padding: 0;
}

.pagehead {
  position: relative;
}

.pagehead .fjry {
  font-size: 16px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #333;
  position: relative;
  margin-bottom: 20px;
}

.pagehead .fjry::before {
  content: "";
  width: 3px;
  height: 18px;
  position: absolute;
  left: -30px;
  top: 50%;
  transform: translateY(-50%);
  background: #8078ea;
  border-radius: 1px;
  margin: 0 10px 0 18px;
}
.secondcontent {
  border-top: 1px solid#EEE;
  padding-top: 20px;
}
.secondcontent .el-form-item {
  width: 32%;
}
.secondcontent .w250 {
  width: 250px;
}
.bottomcontent {
  margin-top: 30px;
}
.flexrow{display: flex;align-items: center;}
</style>
