<template>
  <div>
    <div class="data-display">
      <ul class="list">
        <li>
          <p class="list-num">
            <i class='el-icon-s-order'></i>
            {{lederDelObjectCount}}
          </p>
          <p class="list-text">台账中待删除的对象</p>
        </li>
        <li>
          <p class="list-num">
            <i class="el-icon-s-help"></i>
            {{22}}
          </p>
          <p class="list-text">不能同步到物理世界的对象</p>
        </li>
        <li>
          <p class="list-num">
            <i class="el-icon-s-marketing"></i>
            {{notSyncDataCount}}
          </p>
          <p class="list-text">不能同步到物理世界的关系数据</p>
        </li>
        <li>
          <p class="list-num">
            <i class="el-icon-s-release"></i>
            {{postRelationInforCount}}
          </p>
          <p class="list-text">岗位和关联的资产信息点值不一致</p>
        </li>
      </ul>
    </div>
    <div class="progress">
      <p class="basic-statistics">基本统计</p>
      <div class="data equipment">
        <!-- 设备：本期只做前三个 -->
        <span class="contain-title">设备<i>{{`(${equipCount?equipCount:"0"})`}}</i></span>
        <div class="data-show" v-loading="isLoading" v-if="equipment.length">
          <div class="show-content" v-for="(item,index) in equipment" :key="index">
            <data-origin :id="'origin' + index" :renderData="item"></data-origin>
          </div>
        </div>
        <div v-if="!equipment.length" class="center" style="height: 60%;transform: translateY(30%);">
          <i class="icon-wushuju iconfont"></i>
          暂无数据
        </div>
      </div>
      <div class="data assets">
        <span class="contain-title">资产<i>{{`(${assetsCount?assetsCount:"0"})`}}</i></span>
        <div class="data-show" v-loading="isLoading" v-if="assets.length">
          <div class="show-content" v-for="(item,index) in assets" :key="index">
            <data-origin :id="'origin' + index" :renderData="item"></data-origin>
          </div>
        </div>
        <div v-if="!assets.length" class="center" style="height: 60%;transform: translateY(30%);">
          <i class="icon-wushuju iconfont"></i>
          暂无数据
        </div>
      </div>
      <div class="data parts">
        <span class="contain-title">部件<i>{{`(${partsCount?partsCount:'0'})`}}</i></span>
        <div v-if="!parts.length" class="center" style="height: 60%;transform: translateY(30%);">
          <i class="icon-wushuju iconfont"></i>
          暂无数据
        </div>
      </div>
      <div class="data business-space">
        <span class="contain-title">业务空间<i>{{`(${zoneSpaceCount?zoneSpaceCount:'0'})`}}</i></span>
        <div class="data-show" v-if="business.length">
          <div v-for="(item,index) in business" :key="index" class="show-content">
            <datafan :id="'datafan' + index" :renderData="item"></datafan>
          </div>
        </div>
        <div v-if="!business.length" class="center" style="height: 60%;transform: translateY(30%);">
          <i class="icon-wushuju iconfont"></i>
          暂无数据
        </div>
      </div>
      <div class="data system">
        <!-- 系统：本期只查询总数 -->
        <span class="contain-title">系统<i>{{`(${systemCount?systemCount:'0'})`}}</i></span>
        <div v-if="!system.length" class="center" style="height: 60%;transform: translateY(30%);">
          <i class="icon-wushuju iconfont"></i>
          暂无数据
        </div>
      </div>
      <div class="data tenant">
        <span class="contain-title">租户<i>{{`(${rentantCount?rentantCount:'0'})`}}</i></span>
        <div class="data-show" v-loading="isLoading" v-if="tenant.length">
          <div class="show-content" v-for="(item,index) in tenant" :key="index">
            <data-origin :id="'origin' + item + index" :renderData="item"></data-origin>
          </div>
        </div>
        <div v-if="!tenant.length" class="center" style="height: 60%;transform: translateY(30%);">
          <i class="icon-wushuju iconfont"></i>
          暂无数据
        </div>
      </div>
      <div class="data shaft">
        <span class="contain-title">竖井<i>{{`(${shaftCount?shaftCount:'0'})`}}</i></span>
        <div class="data-show" v-loading="isLoading" v-if="shaft.length">
          <div class="show-content" v-for="(item,index) in shaft" :key="index">
            <datafan :id="'origin' + shaft" :renderData="item" v-if="!item.needCountT"></datafan>
            <data-origin :id="'origin' + item + index" :renderData="item" v-else></data-origin>
          </div>
        </div>
        <div v-if="!shaft.length" class="center" style="height: 60%;transform: translateY(30%);">
          <i class="icon-wushuju iconfont"></i>
          暂无数据
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import {
  getCenoteType,
  queryLederDelObject,
  notSyncRelationData,
  postRelationInforAtpism,
  countEquip,
  countProperty,
  queryPart,
  queryZoneCount,
  queryPartitionRatio,
  queryDefaultFunTypes,
  countGeneralSys,
  queryRentCount,
  queryTenantCompletion,
  queryCenoteCount,
  queryShaftFunctionType,
  ShaftRelationBusinessSpace,
  getDataDictionary
} from "@/api/scan/request";
import dataOrigin from "@/components/ledger/report/dataorigin";
import datafan from "@/components/ledger/report/datafan";
import { queryDataSourceCount, synchronizeProj } from "@/fetch/point_http";

export default {
  data() {
    return {
      lederDelObjectCount: null,// 台账中待删除的对象
      notSyncDataCount: null,// 不能同步到物理世界的关系数据
      postRelationInforCount: null,// 岗位和关联的资产信息点值不一致
      equipCount: null,// 设备总数
      equipment: [],// 设备数据
      assetsCount: null,// 资产总数
      assets: [],// 资产数据
      parts: [],// 部件数据
      partsCount: null,// 部件总数
      zoneSpaceCount: null,// 业务空间总数
      zoneType: [// 分区类型
        {
          "Code": "GeneralZone",
          "Name": "默认分区",
          "Rel_type": "99"
        },
        {
          "Name": "供电分区",
          "Rel_type": "1",
          "Code": "PowerSupplyZone"
        },
        {
          "Name": "照明分区",
          "Rel_type": "2",
          "Code": "LightingZone"
        },
        {
          "Name": "网络分区",
          "Rel_type": "3",
          "Code": "NetworkZone"
        },
        {
          "Code": "AirConditioningZone",
          "Name": "空调分区",
          "Rel_type": "4"
        },
        {
          "Name": "采暖分区",
          "Rel_type": "5",
          "Code": "HeatingZone"
        },
        {
          "Name": "洁净分区",
          "Rel_type": "6",
          "Code": "CleanZone"
        },
        {
          "Name": "生活给水分区",
          "Rel_type": "7",
          "Code": "DomesticWaterSupplyZone"
        },
        {
          "Code": "FireZone",
          "Name": "防火分区",
          "Rel_type": "8"
        },
        {
          "Name": "安防分区",
          "Rel_type": "9",
          "Code": "SecurityZone"
        },
        {
          "Name": "租户分区",
          "Rel_type": "10",
          "Code": "TenantZone"
        },
        {
          "Name": '功能分区',
          'Rel_type': '11',
          "Code": 'FunctionZone'
        }
      ],
      partProtion: [],// 业务空间-各分区占比数据
      defaultPart: [],// 业务空间-默认分区功能类型占比数据
      business: [],// 业务空间数据
      systemCount: null,// 系统总数
      system: [],// 系统数据
      rentantCount: null,// 租户总数
      tenant: [],// 租户数据
      shaftCount: null,// 竖井总数
      shaft: [],// 竖井数据
      ShaftFunType: null,// 竖井功能类型
      shaftPartProtion: [],// 竖井-按功能类型占比数据
      params: null,
      isLoading: false,
      color: ["#3485d6", "#a384fc", "#4caf50", "#ff6316", "#fd8bbe", "#03a9f3", "#ea615b"]
    }
  },
  components: {
    dataOrigin,
    datafan
  },
  mounted() { },
  created() {
    this.params = {
      ProjectId: this.projectId
    }
    this.getFunctionType();
    this.getStatisticsCount();
    this.getEquipCount();
    this.getAssetsCount();
    this.getPartsCount();
    this.getSystemCount();
    this.getTenantCount();
    // this.getShaftCount();
    this.getShaftFunType();
  },
  computed: {
    ...mapGetters('layout', ['projectId'])
  },
  methods: {
    zoneTypeConversion(item) {// 分区类型转换
      this.zoneType.map(it => {
        if (item.Name === it.Code) {
          item.Name = it.Name;
        }
      })
    },
    functionTypeTranstion(item, type) {// 默认分区功能类型转换
      type.map(it => {
        if (item.Name === it.Code) {
          item.Name = it.Name;
          this.defaultPart.push({
            name: item.Name,
            value: item.Count
          });
          // this.defaultPart.map((item, index) => {
          //   item.itemStyle = {color:this.color}
          // })
        }
        if (it.Content) {
          this.functionTypeTranstion(item, it.Content)
        }
      })
    },
    getFunctionType() {// 获取默认分区功能类型
      let params = {
        ProjectId: this.projectId,
        type: "GeneralZone",
        data: {
          Filters: "InfoPointCode='RoomFuncType'",
          Projection: ["DataSource", "InfoPointCode"]
        }
      }
      getDataDictionary(params, res => {
        this.functionType = JSON.parse(res.Content[0].DataSource)
        this.getZoneSpaceCount();
      })
    },
    toPercent(point) {// 小数转换成百分比
      if (point == 0) {
        return 0;
      }
      var str = Number(point * 100).toFixed(2);
      str += "%";
      return str;
    },
    getShaftFunType() {// 获取数据功能类型
      getCenoteType(this.param, res => {
        this.ShaftFunType = res.Content;
        this.getShaftCount();
      })
    },
    shaftFunTypeTranstion(item) {// 竖井功能类型转换
      this.ShaftFunType.map((it, index) => {
        if (item.Name === it.Id) {
          item.Name = it.Name;
        }
      })
    },

    getStatisticsCount() {// 获取顶部统计数据
      let params = {
        ProjectId: this.projectId,
        Filters: "taskState = -1"
      }

      // 台账中待删除的对象
      queryLederDelObject(params, res => {
        this.lederDelObjectCount = res.Count;
      })

      // 不能同步到物理世界的对象

      // 不能同步到物理世界的关系数据
      notSyncRelationData(this.params, res => {
        this.notSyncDataCount = res.Count;
      })

      // 岗位和关联的资产信息点值不一致
      postRelationInforAtpism(this.params, res => {
        this.postRelationInforCount = res.Count;
      })
    },
    getEquipCount() {// 获取设备总数
      countEquip(this.params, res => {
        this.equipCount = res.Count;
        this.getEquipOtherCount();
      })
    },
    getEquipOtherCount() {// 获取设备数据
      // 未关联资产
      let param = {
        ProjectId: this.projectId,
        Filters: "PropertyId isNull"
      }
      countEquip(param, res => {
        this.equipment.push({
          title: '未关联资产',
          tips: '设备未关联资产数量',
          contentValueO: '未关联',
          contentValueT: '已关联',
          text: '',
          needCountO: res.Count,
          needCountT: this.equipCount - res.Count,
          text: `总数${this.equipCount}`
        })
      })

      // 现场验证状态占比
      let par = {
        ProjectId: this.projectId,
        Filters: "taskState = 0 or taskState = 1"
      }
      countEquip(par, res => {
        let text = this.toPercent(res.Count / this.equipCount)
        this.equipment.push({
          title: '现场验证状态占比',
          tips: '设备状态为未找到、已找到的数量与设备总数占比',
          contentValueO: '已验证',
          contentValueT: '未验证',
          text: '',
          needCountO: res.Count,
          needCountT: this.equipCount - res.Count,
          text: text
        })
        this.getEquipBIMIDCount();
      })
    },
    getEquipBIMIDCount() {// 设备-与模型对应占比
      let pa = {
        ProjectId: this.projectId,
        Filters: "not BimID isNull"
      }
      countEquip(pa, res => {
        let text = this.toPercent(res.Count / this.equipCount)
        this.equipment.push({
          title: '与模型对应占比',
          tips: '"BIM模型中编码"有值的设备数量与设备总数占比',
          contentValueO: '有BIMID',
          contentValueT: '无BIMID',
          text: '',
          needCountO: res.Count,
          needCountT: this.equipCount - res.Count,
          text: text
        })
        this.isLoading = false;
      })
    },
    getAssetsCount() {// 获取资产数据
      countProperty(this.params, res => {
        // 获取资产总数
        this.assetsCount = res.Count;
      })

      // 未关联资产
      let param = {
        ProjectId: this.projectId,
        Filters: " EquipmentId isnull"
      }
      countProperty(param, res => {
        this.assets.push({
          title: '未关联资产',
          tips: '资产未关联设备数量',
          contentValueO: '未关联',
          contentValueT: '已关联',
          text: `总数${this.assetsCount}`,
          needCountO: res.Count,
          needCountT: this.assetsCount - res.Count
        })
      })

      // 现场验证状态占比
      let par = {
        ProjectId: this.projectId,
        Filters: " taskState = 0 or taskState = 1"
      }
      countProperty(par, res => {
        let text = res.Count / this.assetsCount;
        text = this.toPercent(text);
        this.assets.push({
          title: '现场验证状态占比',
          tips: '资产状态为未找到、已找到的数量与资产总数占比',
          contentValueO: '已验证',
          contentValueT: '未验证',
          text: text,
          needCountO: res.Count,
          needCountT: this.assetsCount - res.Count
        })
      })

      // 有无坐标占比
      let pa = {
        ProjectId: this.projectId,
        Filters: " not BIMLocation isnull"
      }
      countProperty(pa, res => {
        let text = res.Count / this.assetsCount;
        text = this.toPercent(text);
        this.assets.push({
          title: '有无坐标占比',
          tips: '有坐标的资产数量百分比',
          contentValueO: '有坐标',
          contentValueT: '无坐标',
          text: text,
          needCountO: res.Count,
          needCountT: this.assetsCount - res.Count
        })
      })
    },
    getPartsCount() {// 获取部件数据
      queryPart(this.params, res => {
        this.partsCount = res.Count;
      })
    },
    getZoneSpaceCount() {// 获取业务空间数据

      // 获取业务空间总数
      queryZoneCount(this.params, res => {
        this.zoneSpaceCount = res.Count;
      })

      // 获取业务空间的各分区占比
      queryPartitionRatio(this.params, res => {
        res.Content.map(item => {
          this.zoneTypeConversion(item);
          this.partProtion.push({
            name: item.Name,
            value: item.Count
          })
        })
        this.business.push({
          title: '各分区占比',
          tips: '各类型分区实例数量与实例总数占比',
          needCountO: this.partProtion,
        })
      })

      // 获取业务空间默认分区功能类型占比
      queryDefaultFunTypes(this.params, res => {
        res.Content.map(item => {
          this.functionTypeTranstion(item, this.functionType);
        })
        this.business.push({
          title: '默认分区功能类型占比',
          tips: '默认分区实例的功能区类型占比',
          needCountO: this.defaultPart,
        })
      })
    },
    getSystemCount() {// 获取系统数据
      countGeneralSys(this.params, res => {
        this.systemCount = res.Count;
      })
    },
    getTenantCount() {// 获取租户数据

      // 获取租户总数
      queryRentCount(this.params, res => {
        this.rentantCount = res.Count;
      })

      // 租户-关联业务空间完成度
      queryTenantCompletion(this.params, res => {
        let text = res.Count / this.rentantCount;
        text = this.toPercent(text);
        this.tenant.push({
          title: '关联业务空间完成度',
          tips: '已关联业务空间的租户数量百分比',
          contentValueO: '已关联',
          contentValueT: '未关联',
          text: '',
          needCountO: res.Count,
          needCountT: this.rentantCount - res.Count,
          text: text
        })
      })
    },
    getShaftCount() {// 获取竖井数据

      // 获取竖井总数
      queryCenoteCount(this.params, res => {
        this.shaftCount = res.Count;
      })

      // 获取竖井按功能类型占比
      queryShaftFunctionType(this.params, res => {
        res.Content.map(item => {
          this.shaftFunTypeTranstion(item);
          this.shaftPartProtion.push({
            name: item.Name,
            value: item.Count
          })
        })
        this.shaft.push({
          title: '按功能类型占比',
          tips: '竖井实例的竖井功能占比',
          needCountO: this.shaftPartProtion,
        })
      })

      // 获取竖井关联业务空间完成度
      ShaftRelationBusinessSpace(this.params, res => {
        let text = this.toPercent(res.Count / this.shaftCount);
        this.shaft.push({
          title: '关联业务空间完成度',
          tips: '已关联业务空间的竖井数量百分比',
          contentValueO: '已关联',
          contentValueT: '未关联',
          needCountO: res.Count,
          needCountT: this.shaftCount - res.Count,
          text: text
        })
      })
    }
  },
}
</script>

<style lang="scss" scoped>
.data-display {
  width: 100%;
  margin-bottom: 10px;
  ul {
    display: flex;
    li {
      flex: 1;
      background: white;
      border: 1px solid #c9c9c9;
      text-align: center;
      padding: 20px;
      box-sizing: border-box;
      p {
        color: #333;
        i {
          margin-right: 20px;
        }
      }
      p:nth-child(1) {
        font-size: 24px;
      }
      + li {
        margin-left: 10px;
      }
    }
  }
}
.progress {
  width: 100%;
  .basic-statistics {
    border-bottom: 1px dashed #c9c9c9;
    padding-bottom: 10px;
    margin-bottom: 10px;
  }
  .data {
    // background: white;
    margin-bottom: 20px;
    height: 280px;
    .contain-title {
      height: 30px;
      line-height: 30px;
      border-left: 8px solid black;
      display: inline-block;
      margin: 8px 8px;
      font-weight: 600;
      padding-left: 8px;
      cursor: default;
      i {
        margin-left: 6px;
        font-weight: normal;
      }
    }
  }
}
.data-show {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  .show-content {
    background: white;
    overflow: hidden;
    margin-right: 10px;
    margin-bottom: 10px;
    border: 1px solid #c9c9c9;
    border-radius: 5px;
  }
}
</style>