<style lang="less">
.all-close {
    height: 64px;
    border-radius: 25px;
    background: #0f0c24;
    margin-bottom: 15px;
    display: flex;
    padding: 0 60rpx;
    box-sizing: border-box;
    align-items: center;

    .cont {
        font-size: 27rpx;
        color: #fff;
        // line-height: 64px;
        // text-align: center;
        flex: 1;
    }
    .check {
        width: 38px;
        height: 38px;
        // display: flex;
        // background: #ffe823;
        // align-items: center;
        // justify-content: center;
        // font-size: 46rpx;
        image {
            width: 100%;
            height: 100%;
            border-radius: 38px;
        }
    }
}
</style>

<template>
    <div
        class="all-close"
        v-on:click="showPopup"
    >
        <div class="cont">办公室已经没人了，我是最后一个走的</div>
        <div class="check">
            <!-- <image src="{{h5StaticPath}}icon_done_btn.svg" /> -->
        </div>

    </div>

</template>

<script>
import wepy from '@wepy/core'
import { specialLightSetHttp, queryEquipStatistics, changeAllAirHttp } from '@/packagesEnv/api/officehome.js'
import config from '@/config'
wepy.component({
  data: {
    h5StaticPath: config.h5StaticPath + '/',
    allSpaceList: [],
    lightSpaceList: [],
    airSpaceList: []
  },
  props: {
    floorInfo: Array,
    projectId: String
  },
  computed: {

  },
  watch: {

  },
  ready() {
    this.getEquipStatistics()
  },
  methods: {
    changeLight(status) {
      const setType = status === '打开' // 10关闭 12开启
      var paramsArr = []
      this.allSpaceList.forEach((citem) => {
        (citem.equipList || []).forEach((item) => {
          if (item.equipType == 'light') {
            paramsArr.push({
              id: item.id,
              switch: setType
            })
          }
        })
      })
      specialLightSetHttp(paramsArr).then((res) => {

      })
    },
        // 开关全部空调
    changeAllAir(status) {
      let paramsArr = []
      this.allSpaceList.forEach((sitem) => {
        const itemId = status === '打开' ? 12 : 10 // 10关闭 12开启
        paramsArr.push({
          projectId: this.projectId,
          objectId: sitem.id, // 空间id
          valueType: 1, // 固定为1 1
          itemId: itemId
        })
      })
            // console.log("paramsArr2", paramsArr);
      changeAllAirHttp(paramsArr).then((res) => {
        if (res.result == 'success') {
        } else {
        }
      })
    },
    getEquipStatistics() {
      var params1 = {
        floorId: this.floorInfo[0] && this.floorInfo[0].floorId,
        projectId: this.projectId
      }
      var params2 = {
        floorId: this.floorInfo[1] && this.floorInfo[1].floorId,
        projectId: this.projectId
      }
      Promise.all([queryEquipStatistics(params1), queryEquipStatistics(params2)]).then((res) => {
        var allSpaceList = [];
        (res || []).forEach((ritem) => {
          var spaceList = (ritem.data && ritem.data.spaceList) || []
          allSpaceList.push(...spaceList)
        })
                // || item.localName == '上格云休闲区'
        var filterSpaceArr = allSpaceList.filter((item) => {
          return item.localName == '图书休闲区'
        })
                // 没用
        this.airSpaceList = allSpaceList.filter((item) => {
          var airStatus = (item.equipStatusList || []).filter((eitem) => {
            return eitem.equipType == 'airConditioner'
          })

          var status = airStatus[0] && airStatus[0].status
                    // if(status !== 0){ console.log('this.airSpaceList-name', item.localName,status);}
          return status !== 0
        })
                // 没用
        this.lightSpaceList = allSpaceList.filter((item) => {
          var lightStatus = (item.equipStatusList || []).filter((eitem) => {
            return eitem.equipType == 'light'
          })

          var status = lightStatus[0] && lightStatus[0].status
                    // if(status !== 0){ console.log('this.lightSpaceList-name', item.localName,status);}
          return status !== 0
        })
                // console.log('this.lightSpaceList', this.lightSpaceList);
        this.allSpaceList = allSpaceList
      })
    },
    controlEquipStatistics() {
      this.changeLight('关闭')
      this.changeAllAir('关闭')
    },
    showPopup() {
      this.$emit('showAllClose')
    }
  }
})
</script>

<config>
{
    usingComponents: {
        
    }
}
</config>
