<template>
  <el-dialog title="批量关联资产" :visible.sync="dialog.linkAssets" width="900px">
    <el-row>
      <device-parts></device-parts>
    </el-row>
    <el-row style="margin-top:30px;">
      <!-- <build-floor></build-floor> -->
      <span class="condition-title">建筑楼层：</span>
      <el-cascader placeholder="请选择建筑楼层" :options="bfoptions" v-model="buildFloor" filterable size="small" @change="handleChangeBf"></el-cascader>
    </el-row>
    <el-row style="margin-top:30px;">
      <zone-space :isWidth="false"></zone-space>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClickClose">取 消</el-button>
      <el-button type="primary" @click="toAddDevice">确 认</el-button>
    </span>
  </el-dialog>
</template>
<script>

import { floorQuery, buildingQuery } from '@/api/scan/request'

import { mapGetters } from "vuex"
import buildFloor from "@/components/ledger/lib/buildFloor"
import zoneSpace from "@/components/ledger/lib/zoneSpace"
import deviceParts from "@/components/ledger/lib/deviceParts"
export default {
  components: {
    buildFloor,
    zoneSpace,
    deviceParts
  },
  props: {
    dialog: {
      type: Object,
      default: function () {
        return {
          linkAssets: false
        };
      }
    }
  },
  computed: {
    ...mapGetters("layout", ["projectId", "secret", "userId"])
  },
  data() {
    return {
      bfoptions: [], //建筑楼层列表
      buildFloor: ['all'], //选择的建筑楼层
    };
  },
  created() {
    this.getData()
  },
  mounted() { },
  methods: {
    //获取数据
    getData() {
      let data, buildParams = {
        PageNumber: 1,
        PageSize: 500,
        Projection: [
          "BuildID",
          "BuildLocalName"
        ]
      }, floorParams = {
        Orders: "FloorSequenceID desc",
        PageNumber: 1,
        PageSize: 500,
        Projection: [
          "BuildID",
          "FloorID",
          "FloorLocalName",
          "FloorSequenceID"
        ]
      }
      let promise1 = new Promise((resolve, reject) => {
        buildingQuery(buildParams, res => {
          resolve(res)
        })
      })
      let promise2 = new Promise((resolve, reject) => {
        floorQuery(floorParams, res => {
          resolve(res)
        })
      })
      Promise.all([promise1, promise2]).then(values => {
        let builData = values[0].Content, floorData = values[1].Content
        data = builData.map(build => {
          return {
            value: build.BuildID,
            label: build.BuildLocalName
          }
        })
        data.unshift({
          value: "all",
          label: "全部"
        }, {
            value: "noKnow",
            label: "不在建筑内"
          })
        data.forEach(build => {
          floorData.forEach(floor => {
            if (build.value == floor.BuildID && floor.FloorID && floor.FloorLocalName && this.type == "yes") {
              if (build.children) {
                build.children.push({
                  value: floor.FloorID,
                  label: floor.FloorLocalName,
                  FloorSequenceID: floor.FloorSequenceID
                })
              } else {
                build.children = []
                build.children.push({
                  value: "all",
                  label: "全部"
                }, {
                    value: 'noKnow',
                    label: "不在楼层内"
                  }, {
                    value: floor.FloorID,
                    label: floor.FloorLocalName,
                    FloorSequenceID: floor.FloorSequenceID
                  })
              }
            }
          })
        })
        this.bfoptions = data
      })
    },
    // 修改建筑楼层
    handleChangeBf() {

    },
    handleClickClose() {
      this.dialog.linkAssets = false
    }
  },
  watch: {
    
  }
};
</script>

<style lang="less" scoped>
  .condition-title{
    margin-left: 10px;
    margin-right: 12px;
    color: #999999;
    font-size: 14px;
  }
</style>
