<!-- 飞控中心机库列表 -->
<template>
  <div class="list" :class="{ collapse: listCollapse }">
    <div class="list-header">
      <div>
        <img class="list-header__icon" src="./assets/images/uav_list_header.png" />
        <span class="list-header__text">机库列表</span>
      </div>
      <div class="list-header__count">
        共{{ count.sumCount }}架 /
        <span class="online">{{ count.onlineCount }}在线</span>
        /
        {{ count.offlineCount }}离线
      </div>
    </div>
    <div class="cpt-observe-nest-list">
      <div class="ctx-box pl5">
        <div class="list-box pr14">
          <template v-if="list && list.length">
            <Item v-for="item in list" :key="item.id" :data="item" />
          </template>
        </div>
      </div>
    </div>
    <!-- 未进入机库或者进入机库后列表是展开的情况下，才显示收纳按钮 -->
    <img
      v-if="!hangar || (hangar && !listCollapse)"
      @click="listCollapse = !listCollapse;"
      style="transform: rotate(180deg)"
      src="./assets/images/hs.png"
      class="nsetLeftBox_btn"
    />
  </div>
  <!-- </Dialog> -->
</template>

<script>
import { Control_API } from "../../../../api";
import Item from "./components/item";
import { mapState } from "vuex";

export default {
  name: "List",
  props: {},
  components: { Item },
  data() {
    return {
      list: [],
      deviceType: 2, // 设备类型 2鹰巢
    };
  },

  computed: {
    ...mapState("MMCFlightControlCenter", ["listCollapse"]),
    ...mapState("MMCFlightControlCenter/hangar", ["hangar"]),
    count() {
      let countObj = {
        onlineCount: 0,
        offlineCount: 0,
        sumCount: 0,
      };
      this.list.forEach((item) => {
        countObj.onlineCount += item?.onLineCount || 0;
        countObj.offlineCount += item?.offLineCount || 0;
      });
      countObj.sumCount = countObj.onlineCount + countObj.offlineCount;
      return countObj;
    },
    // 收起列表按钮
    listCollapse: {
      get() {
        return this.$store.state.MMCFlightControlCenter.listCollapse;
      },
      set(val) {
        this.$store.commit("MMCFlightControlCenter/setState", {
          key: "listCollapse",
          value: val,
        });
      },
    },
  },
  watch: {},

  mounted() {
    this.getList();
  },
  methods: {
    async getList() {
      let res = await Control_API.getUavTree({ name: "", deviceType: this.deviceType });
      this.list = res.data;
    },
  },
};
</script>

<style lang="scss" scoped>
.list {
  display: flex;
  flex-direction: column;
  position: absolute;
  width: 460px;
  height: 85%;
  left: 0;
  top: 60px;
  // height: 86vh;
  z-index: 99;
  transition: 0.3s;
  border-radius: 10px 10px 0px 0px;
  overflow: visible;

  &.collapse {
    transform: translateX(-100%);
  }

  .nsetLeftBox_btn {
    position: absolute;
    cursor: pointer;
    right: -22px;
    top: 50%;
    transform: translate(0, -50%);
  }
}
.healthy {
  box-sizing: border-box;
  padding: 0 5px;
  display: flex;
  align-items: center;
  backdrop-filter: blur(3px);
  font-size: 16px;
  font-weight: bold;
  height: 100%;

  .healthy--total {
    color: #cad8d9;
  }

  .healthy--un {
    color: #d54a15;
  }
}
.nestlist {
  background: rgba(4, 18, 50, 0.5);
}
.cpt-observe-nest-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  background: rgba(12, 34, 73, 0.7);
  overflow-y: auto;

  .search-box {
    flex-shrink: 0;
    display: flex;
    height: 36px;
    padding: 0 10px;
    background: #000000;
    border: 1px solid #3dcdff;
    border-radius: 2px;
    box-sizing: border-box;

    ::v-deep .el-input {
      height: 36px;

      input {
        height: 36px;
        background-color: transparent;
        border: none;
        padding: 0;

        font-family: Microsoft YaHei;
        font-size: 16px;
        color: #08c2d1;
        font-weight: 400;
      }

      .el-input__suffix {
        display: flex;
        align-items: center;
      }
    }

    .search-icon-box {
      display: flex;
      align-items: center;
      cursor: pointer;

      .iconfont {
        font-size: 24px;
        color: #08ffff;
      }

      &:hover {
        .iconfont {
          opacity: 0.8;
        }
      }
    }
  }

  .ctx-box {
    flex: 1;
    overflow: auto;
    height: 100%;
    /* backdrop-filter: blur(3px); */
    position: relative;
    top: 0px;
  }
}
.jianj {
  display: flex;
  align-items: center;
  height: 100%;
}
.jl {
  margin: 0 0 0 5px;
  color: #70daf9 !important;
  font-weight: 700 !important;
}
.list-header {
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  // width: 100%;
  height: 33px;
  background: linear-gradient(
    180deg,
    #9198ff 0%,
    rgba(45, 81, 153, 0.45) 40%,
    #05091a 100%
  );
  box-shadow: inset 0px 0px 10px 2px #3f9dff;
  border-radius: 10px 10px 0px 0px;
  border: 1px solid #427dff;

  .list-header__text {
    vertical-align: bottom;
    font-size: 20px;
    font-family: YouSheBiaoTiHei;
    color: #14faff;
    line-height: 26px;
    text-shadow: 0px 1px 1px rgba(2, 32, 56, 0.2);
    background: linear-gradient(
      135deg,
      #f7b67d 38%,
      #f9eacb 58%,
      #f5d2a6 79%,
      #f59743 100%
    );
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  .list-header__icon {
    width: 26px;
    margin-left: 9px;
  }

  .list-header__count {
    color: #fff;
    font-weight: 500;
    margin-right: 16px;
    font-size: 14px;

    .online {
      font-size: 16px;
      font-weight: 900;
      color: #31db24;
    }
  }
}
</style>
