<!--
    系统清单
-->
<template>
  <div id="deviceList">
    <saga-title :mess="mess"></saga-title>
    <div class="table-main">
      <div class="search-header">
        <floor-cascader :type="'no'" @change="changeFloor"></floor-cascader>
        <my-cascader ref="cascader" @change="changeDevice"></my-cascader>
      </div>
      <hanson-table @close="close" ref="tableMain"></hanson-table>
    </div>
    <table-transfers></table-transfers>
  </div>
</template>
<script>
import sagaTitle from "@/components/ledger/lib/title";
import floorCascader from "@/components/ledger/lib/floorCascader";
import myCascader from "@/components/ledger/lib/system";
import hansonTable from "@/components/ledger/handsontables/system";
import tableTransfers from "@/components/ledger/tableTransfers";
import {
    mapGetters,
    mapActions
} from "vuex";
import { getAllbusiness, getFamilyList, getSpaceName } from "@/api/scan/request"
import Handsontable from "handsontable-pro"
    import 'handsontable-pro/dist/handsontable.full.css'
    import zhCN from 'handsontable-pro/languages/zh-CN';

export default {
  components: {
    sagaTitle,
    floorCascader,
    myCascader,
    hansonTable,
    tableTransfers
  },
  data() {
    return {
      mess: {
        perjectName: "",
        name: [
          {
            key: "系统",
            num: 0
          }
        ]
      },
      param: {
        buildId: "",
        floorId: "",
        deviceId: "",
        ProjId: '',
        secret: ''
      }
    };
  },
  computed: {
        ...mapGetters("peojMess", [
            "projectId",
            "secret",
            "userId"
        ])
    },
  created() {
      this.param.ProjId = this.projectId
      this.param.secret = this.secret
    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.getAllbusiness()
        } else {
          this.$message.error("请求失败：" + res.data.ResultMsg)
        }
      }).catch(_ => {
        this.$message.error("请求失败")
      })
    },
    getFamilyList() {
      let param = {
        ProjId: this.param.ProjId,
        secret: this.param.secret,
        data: { type: "Sy" }
      }
      getFamilyList(param, res => {
        if (this.$refs.cascader) {
              this.$refs.cascader.pushData(res.Content)
          }
      })
    },
    close(val) {
      this.getProjName()
      console.log(val)
      if (!!val && !!val.code) {
          if(this.$refs.cascader)
        this.$refs.cascader.changeVal([val.code])
      }
    },

    //获取header的list
    getAllbusiness() {
      let param = {
        ProjId: this.param.ProjId,
        secret: this.param.secret,
        data: {
          criteria: {
            type: ["Sy"]
          },
          returnInfos: ["SystemID"]
        }
      }
      getAllbusiness(param).then(res => {
        if (res.data.Result == "success") {
          this.mess.name[0].num = res.data.Count
          this.getFamilyList()
        } else {
          this.$message.error("请求失败" + res.data.resultMsg)
        }
      }).catch(res => { this.$message.error("请求失败") })
    },

    //修改楼层
    changeFloor(value) {
      console.log(this.param);
      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) {
          if(this.$refs.tableMain)
        this.$refs.tableMain.getHeaderData(this.param);
      } else {
        return;
      }
    },

    //修改设备族
    changeDevice(value) {
      console.log(value)
      this.param.deviceId = value.code
      if (!!value) {
          if(this.$refs.tableMain)
        this.$refs.tableMain.getHeaderData(this.param);
      } else {
        return;
      }

    }
  }
};
</script>
<style lang="scss" scoped>
#deviceList {
  overflow: hidden;
  height: 100%;
  background-color: #f6f6f6;
  position: relative;
  .table-main {
    position: absolute;
    top: 76px;
    bottom: 10px;
    left: 0;
    right: 0;
    background-color: #fff;
    // border-radius: 5px;
    padding: 10px;
  }
  .search-header {
    overflow: hidden;
    padding-bottom: 10px;
    border-bottom: 1px solid #bcbcbc;
  }
}
</style>
