<!--
    设备清单
-->
<template>
  <div id="deviceList">
    <saga-title :mess="mess"></saga-title>
    <div class="table-main">
      <div class="search-header">
        <floor-cascader @change="changeFloor"></floor-cascader>
        <my-cascader ref="cascader" @change="changeDevice"></my-cascader>
      </div>
      <hanson-table @getJson="change" ref="tableMain"></hanson-table>
    </div>
    <!-- <table-transfers></table-transfers> -->
  </div>
</template>
<script>
import sagaTitle from "@/components/list/title";
import floorCascader from "@/components/lib/floorCascader";
import myCascader from "@/components/lib/cascaders/assets";
import hansonTable from "@/components/handsontables/assets";
import tableTransfers from "@/components/transfers/tableTransfers";

import { getNumber, getFamilyList, getSpaceName } from "@/api/request"
export default {
  components: {
    sagaTitle,
    floorCascader,
    myCascader,
    hansonTable,
    tableTransfers
  },
  data() {
    return {
      mess: {
        perjectName: "",
        name: [
          {
            key: "资产",
            num: 0
          },
          {
            key: "岗位",
            num: 0
          }
        ]
      },
      param: {
        buildId: "",
        floorId: "",
        deviceId: "",
        ProjId: this.$route.query.projId,
        secret: this.$route.query.secret
      },
      list: []
    };
  },
  created() {
    this.getProjName()
  },
  mounted() { },
  methods: {
    getProjName() {
      let param = {
        list: [{ id: this.param.ProjId }],
        perjectId: this.param.ProjId,
        secret: this.param.secret,
      }
      getSpaceName(param).then(res => {
        if (res.data.Result == "success") {
          this.mess.perjectName = res.data.Content[0].infos.ProjLocalName
          this.getNumber()
        } else {
          this.$message.error("请求失败：" + res.data.ResultMsg)
        }
      }).catch(_ => {
        this.$message.error("请求失败")
      })
    },
    getFamilyList() {
      let param = {
        ProjId: this.param.ProjId,
        secret: this.param.secret,
        data: { type: "Pe" }
      }
      getFamilyList(param, res => {
        this.$refs.cascader.pushData(res.Content)
      })
    },
    //获取header的list
    getNumber() {
      let param = {
        ProjId: this.param.ProjId,
        secret: this.param.secret,
        data: { type: "Pe" }
      }
      getNumber(param, res => {
        this.mess.name[0].num = res.content.count
        this.mess.name[1].num = res.content.bindingCount
        this.getFamilyList()
      })
    },
    //修改楼层
    changeFloor(value) {
      if (value[0]) {
        this.param.buildId = value[0]
      }
      if (value[1]) {
        this.param.floorId = value[1]
      } else {
        this.param.floorId = null
      }
      if (!!this.param.deviceId) {
        this.$refs.tableMain.getHeaderData(this.param);
      } else {
        return;
      }
    },

    //新建资产后进行刷新
    change(val) {
      console.log(val)
      this.$refs.cascader.setValue([val.code])
      this.param.deviceId = val.code
      this.getNumber()
      if (!!this.param.deviceId) {
        this.$refs.tableMain.getHeaderData(this.param);
      }
    },

    //修改设备族
    changeDevice(value) {
      console.log(value)
      this.param.deviceId = value.code
      if (!!value) {
        this.$refs.tableMain.getHeaderData(this.param);
      } else {
        return;
      }
    }
  }
};
</script>
<style lang="less" scoped>
#deviceList {
  overflow: hidden;
  height: 100%;
  background-color: #f6f6f6;
  .table-main {
    position: absolute;
    top: 140px;
    bottom: 10px;
    left: 10px;
    right: 10px;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 10px;
  }
  .search-header {
    overflow: hidden;
    padding-bottom: 10px;
    border-bottom: 1px solid #bcbcbc;
  }
}
</style>
