<template>
  <div class='box'>
    <el-row style="padding:0 10px;margin-bottom:10px;">
      <div style="float:left;">
        <label>选择时间范围 : </label>
        <el-date-picker
          v-model="value"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          @change="handleTime">
        </el-date-picker>
      </div>
      <div style="float:left;margin-left:10px;">
        <label>发现问题:</label>
        <span>{{ total }}</span>
      </div>
      <el-button style="float:right;" :disabled="total?false:true" @click="handleIssue">查看收集到的问题</el-button>
    </el-row>
    <div
      style="background:#fff;display:flex;align-items:center;border: 1px solid #e4e4e4;justify-content:center;height:100%;">
      <div class="center">
        <i class="icon-wushuju iconfont"></i>
        暂无数据
      </div>
    </div>
    <!-- <div class='condition'>
            <p>
                <span style="margin-right: 12px">建筑名称</span>
                <el-select v-model='buildVlaue' placeholder='请选择'>
                    <el-option
                        v-for='item in options'
                        :key='item.BuildId'
                        :label='item.BuildLocalName'
                        :value='item.BuildId'
                    ></el-option>
                </el-select>
            </p>
        </div>
        <el-tabs v-model='activeName' @tab-click='handleClick' style="background:#fff">
            <el-tab-pane label='现场无法找到的资产' name='first'>
                <saga-nofind :buildVlaue='buildVlaue' :floorsObj='floorsObj'></saga-nofind>
            </el-tab-pane>
            <el-tab-pane label='未画入模型的资产' name='second'>
                <saga-nopaint :buildVlaue='buildVlaue' :floorsObj='floorsObj'></saga-nopaint>
            </el-tab-pane>
            <el-tab-pane label='无对应岗位的资产' name='third'>
                <saga-nomap :buildVlaue='buildVlaue' :floorsObj='floorsObj' :allFamilyObj='allFamilyObj'></saga-nomap>
            </el-tab-pane>
            <el-tab-pane label='未扫楼验证的资产' name='fourth'>
                <saga-verify :buildVlaue='buildVlaue' :floorsObj='floorsObj' :allEquipObj='allEquipObj'></saga-verify>
            </el-tab-pane>
        </el-tabs> -->

    <!--    <assets-list :buildingData="options" :buildingId="buildValue" :active="activeName" ref="assetlist"></assets-list>-->
  </div>
</template>

<script>
import SagaNofind from './Nofind'
import SagaNopaint from './Nopaint'
import SagaVerify from './Noverify'
// import assetsList from './assetsList'
import { mapActions, mapGetters, mapState } from 'vuex'
//api
import {
  // buildingQuery,
  getAllbusiness,
  getEquipBelongs,
  problemQuery
} from '@/api/scan/request'
import { buildingQuery } from '@/api/object/build';

export default {
  name: 'build-assets',
  data() {
    return {
      activeName: 'first',
      buildVlaue: '',
      options: [],
      floorsObj: {},
      allFamilyObj: {},
      allEquipObj: {},
      value: '',//
      tabList: [
        { label: '现场无法找到的资产', name: "first" },
        { label: '未画入模型的资产', name: "second" },
        { label: '无对应岗位的资产', name: "third" },
        { label: '未扫楼验证的资产', name: "fourth" }
      ],
      total: 0,
    }
  },
  computed: {
    ...mapGetters('layout', ['projectId', 'userId', 'secret']),
    ...mapState('layout', ['errorReport'])

  },
  components: {
    SagaNofind,
    SagaNopaint,
    SagaVerify,
  },
  methods: {
    ...mapActions('layout', ['setErrorReport']),
    handleTime(val) {
      console.log(val)
      let param = {
        filters: `createTime > '${val[0]}';createTime < '${val[1]}'`,
        pageNumber: 1,
        pageSize: 50
      }
      problemQuery(param, res => {
        this.total = res.total
        this.setErrorReport(res.content)
      })

    },

    handleIssue() {
      this.$router.push({
        path: 'report'
      })
    },
    //获取建筑列表
    getBuilding() {
      buildingQuery({}, res => {
        this.options = res.content
        this.buildValue = res.content ? res.content[0].id : ''
      })
      // let param = {
      //   ProjId: this.projectId,
      //   UserId: this.userId
      // }
      // getBuildSelect(param).then(res => {
      //   if (res.data.Result == 'success') {
      //     let data = res.data.BuildList
      //     this.options = data
      //     this.buildVlaue = data.length ? data[0].BuildId : ''
      //   }
      // })
    },
    //获取所有楼层
    getFloors() {
      let param = {
        ProjId: this.projectId,
        secret: this.secret,
        id: this.projectId,
        type: ['Fl']
      }
      getAllbusiness(param).then(res => {
        if (res.data.Result == 'success') {
          res.data.Content.forEach(item => {
            this.floorsObj[item.infos.FloorID] = item.infos.FloorLocalName
          })

        }
      })
    },
    //获取设备组
    getAllFamily() {
      // getAllFamily().then(result => {
      //   if (result.data.Result == "success") {
      //     console.log(result.data.Content)
      //     let list = result.data.Content;
      //     list.forEach(ele => {
      //       this.allFamilyObj[ele.code] = ele
      //     })
      //     this.allEquipObj = {}
      //     this.getEquip(list)
      //   }
      // });
      let pa = {
        data: {
          orders: 'family asc',
          distinct: true,
          pageSize: 500,
          projection: ["family", "familyName"]
        }
      }
      getEquipBelongs(pa, res => {
        this.AllFamily = res.content.map(t => {
          return {
            Code: t.family,
            Name: t.familyName
          }
        })
      })
    },
    getEquip(list) {
      list.forEach(ele => {
        if (ele.content) {
          ele.content.forEach(keng => {
            this.allEquipObj[keng.code] = keng.name
          })
        }
      })
    },
    async init() {
      await this.getAllFamily();
      await this.getFloors();
      await this.getBuilding()
    }
  },
  created() {
    this.init()
  },
  watch: {
    projectId() {
      this.init()
    }
  }
}
</script>

<style scoped lang='less'>
.box {
  .condition {
    padding: 10px;
    display: flex;
    border: 1px solid #dfe6ec;
    background: #fff;
    margin-bottom: 10px;
  }

  /deep/ .el-tabs__nav {
    margin-left: 10px;
  }
}
</style>

