<template>
  <div>
    <d2-container>
      <!-- <template slot="header">首页/报警参数</template> -->
      <div class="main">
        <div class="left">
          <!-- <el-input placeholder="输入关键字进行过滤" v-model="filterText">
          </el-input> -->

        <el-tree
            class="filter-tree"
            :filter-node-method="filterNode"
            v-loading="loading"
            :data="leftList"
            node-key="id"
            :props="defaultProps"
            :expand-on-click-node="false"
            @node-click="handleNodeClick"
            default-expand-all
            highlight-current
            :default-expanded-keys="this.defaultExpanded"
            ref="tree"
          >
            <span class="custom-tree-node" slot-scope="{ node, data }">
              <span v-if="node.level==1"> <i :class="node.icon"></i>{{ node.label }} </span>
               <span v-if="node.level==2"> <i :class="node.icon"></i>{{ node.label }} </span>
                <span v-if="node.level==3"> <i :class="node.icon"></i>{{ node.label }} </span>
                 <span v-if="node.level==4"> <i></i>{{ node.label }} </span>
            </span>
          </el-tree>
        </div>
        <div class="right">
           <div class="nav">当前所在位置:首页>报警参数</div>
          <div class="right_main">
            <div class="right_title"><i class="fa fa-lightbulb-o" aria-hidden="true" style="padding-right:5px"></i>报警参数</div>
            <div class="right_table">
          <div class="addBtn">
            <el-button type="primary" icon="el-icon-plus" @click="addTantou"
              >修改新增报警规则</el-button
            >
          </div>
          <el-form :model="formData" ref="formData" id="formLabel">
            <el-row style="margin-top: 10px">
              <el-col :span="12" :offset="2">
                <el-form-item label="报警启用状态:">
                  <el-radio-group v-model="formData.status">
                    <el-radio :label="1" :disabled="disabled">开</el-radio>
                    <el-radio :label="0" :disabled="disabled">关</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="10">
              <el-col :span="10" :offset="2">
                <h4>电话通知:</h4>
                <p>
                  电话1:
                  <span>{{ formData.telephoneNumber1 }}</span>
                </p>
                <p>
                  电话2:
                  <span>{{ formData.telephoneNumber2 }}</span>
                </p>
              </el-col>
              <el-col :span="10" :offset="2">
                <h4>短信通知:</h4>
                <p>
                  电话1:
                  <span>{{ formData.smsNumber1 }}</span>
                </p>
                <p>
                  电话2:
                  <span>{{ formData.smsNumber2 }}</span>
                </p>
              </el-col>
            </el-row>
          </el-form>
          </div>
          </div>
        </div>
      </div>
    </d2-container>

    <!-- //弹框 -->
    <el-dialog title="新增修改报警规则" :visible.sync="dialogAlarm" id="dialogStyle">
      <el-form :model="dialog">
        <el-form-item label="报警启用状态:" :label-width="formLabelWidth">
          <el-radio-group v-model="dialog.name">
            <el-radio label="开"></el-radio>
            <el-radio label="关"></el-radio>
          </el-radio-group>
        </el-form-item>
        <h4>电话通知:</h4>
        <el-form-item label="电话1:" :label-width="formLabelWidth">
          <el-input v-model="dialog.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话2:" :label-width="formLabelWidth">
          <el-input v-model="dialog.name" autocomplete="off"></el-input>
        </el-form-item>
         <h4>短信通知:</h4>
        <el-form-item label="电话1:" :label-width="formLabelWidth">
          <el-input v-model="dialog.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话2:" :label-width="formLabelWidth">
          <el-input v-model="dialog.name" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogAlarm = false">取 消</el-button>
        <el-button type="primary" @click="determine()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import api from "@/api";
export default {
  name: "hardwareParame",
  data() {
    return {
      disabled:false,
      // label宽度
      formLabelWidth: "120px",
      // 弹框默认关闭
      dialogAlarm: false,
      filterText: "",
      //默认展开的节点
      defaultProps: {
        children: "children",
        label: "orgName",
      },
       loading: false,
      //默认展开的节点
      defaultExpanded: [],
      cfbh: "",
      //左侧树数据
      leftList: [
        
      ],
      // 日期插件
      //

      formInline: {
        sbNames: "",
      },
      formData: {
        status: 0,
        totalStatus: 0,
        totalThreshold: "",
        timeThreshold: "",
        telephoneNumber1: "",
        telephoneNumber2: "",
        smsNumber1: "",
        smsNumber2: "",
        id: "",
      },
      //弹框字段
      dialog: {
        name: "",
      },
    };
  },
  // watch: {
  //   filterTest(val) {
  //     this.$refs.tree.filter(val);
  //   },
  // },
  methods: {
    //获取左侧树
    getLeftTree() {
      this.loading = true;
      let params = {
        orgName:this.orgName,
      };

      api
        .leftTree(params)
        .then((res) => {
          if (res.code == 200) {
            console.log(res);
            this.leftList = [];
            if (res.data) {
              this.leftList = res.data;
           

              // if (res.data[0].id) {
              //   this.defaultExpanded.push(res.data[0].id);
              //   if (res.data[0].children) {
              //     this.defaultExpanded.push(
              //       res.data[0].children[0].children[0].id
              //     );

              //     this.cfbh =
              //       res.data[0].children[0].children[0].children[0].id;
                 
              //     setTimeout(() => {
              //          document.getElementsByClassName("el-tree-node__content")[0].style.display="none"
              //       document.getElementsByClassName("el-tree-node__content")[1].style.display="none"
              //       this.$refs.tree.setCurrentKey(this.cfbh);
              //       this.$refs.tree.setCurrentKey(this.cfbh);
              //     }, 100);
              //     console.log(this.leftList);
              //       this.getList();
              //   }
              // }
               var lastLevel=res.data;
              if(lastLevel.length>0){
                lastLevel=res.data[0]
                while(lastLevel.children&&lastLevel.children.length>0){
                  lastLevel=lastLevel.children[0];
                }
           
                this.defaultExpanded.push(lastLevel.id);
                this.cfbh=lastLevel.id
                setTimeout(()=>{
                    this.$refs.tree.setCurrentKey(this.cfbh);
                
                },200)
                this.getList();
              }
            }
          } else {
            this.$message({
              type: "error",
              message: res.msg,
            });
          }
          this.loading = false;
        })
        .catch((error) => {
          this.loading = false;
          console.log(error);
        });
    },
     //点击左侧树节点
    handleNodeClick(data,node) {
    
    // if(node.level ===4){
    //  this.cfbh=data.id;
    //  console.log(  this.cfbh,";;;")
    // }
    // this.getList();
      if(node.childNodes.length===0){
            this.cfbh = data.id;
        console.log(this.cfbh, ";;;");
        this.getList();
      }
    },
     filterNode(value, data) {
      if (!value) return true;
      return data.orgName.indexOf(value) !== -1;
    },
    // filterNode(value, data) {
    //   if (!value) return true;
    //   return data.label.indexOf(value) !== -1;
    // },
     //获取列表数据
    getList() {
     
     var houseId=this.cfbh
    
      api
        .alarmParams(houseId)
        .then((res) => {
          if (res.code == 200) {
            console.log(res,"报警参数")
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    search() {},
    reset() {},
    //新增
    addTantou() {
      this.dialogAlarm = true;
    },
    //表格序号
    indexMethod(index) {
      // return (
      //   (this.pagination.curPage - 1) * this.pagination.pageSize + index + 1
      // );
    },
    //弹框确定按钮
    determine() {},
  },
  mounted(){
    this.getLeftTree();
  }
};
</script>
<style lang="scss" scoped>
.main {
  height: 100%;
  display: flex;
  .left{
    height:calc(100vh - 144px)
  }
  .right {
    margin-left: 20px;
    width: calc(100% - 280px);
    .nav {
      padding: 10px 0 10px 10px;
      color: #fff;

      font-size: 14px;

      background: #004a93;
    }
  }
  .addBtn {
    margin-bottom: 20px;
  }
   h4 {
    font-size: 16px;
    font-weight: 700;
    line-height: 40px;
    color:#fff;
  }
  p {
    color: #525357;
    font-size: 14px;
    line-height: 40px;
    position: relative;
    color:#fff;
  }
}
 
 


</style>