<!-- 飞控中心机库列表 -->
<template>
  <div class="list" :class="{ collapse: listCollapse }">
    <div class="list-header">
      <span class="list-header__text">机库列表</span>
      <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>
    <!-- 未进入机库或者进入机库后列表是展开的情况下，才显示收纳按钮 -->
    <div
      class="hangar-list_btn"
      @click="listCollapse = !listCollapse;"
      v-if="!hangar || (hangar && !listCollapse)"
    >
      <img style src="./assets/images/collapse.svg" />
    </div>
  </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: 420px;
  height: 85%;
  left: 0;
  top: 60px;
  // height: 86vh;
  z-index: 99;
  transition: 0.3s;
  border-radius: 5px 5px 0px 0px;
  overflow: visible;

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

    .hangar-list_btn {
      &::before {
        transform: translate(-63%, -50%) rotate(90deg) !important;
      }
    }
  }

  .hangar-list_btn {
    position: absolute;
    cursor: pointer;
    right: -35px;
    top: 50%;
    transform: translate(0, -50%);
    z-index: 99;

    &::before {
      content: "";
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-63%, -50%) rotate(-90deg);
      width: 0px;
      height: 0px;
      border-left: 7px solid transparent;
      border-right: 7px solid transparent;
      border-bottom: 9px solid #fff;
    }
  }
}
.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: #222222;
  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: #3c3c3c;
  padding: 0 16px;

  .list-header__text {
    vertical-align: bottom;
    font-family: PingFangSC, PingFang SC;
    font-weight: 600;
    font-size: 16px;
    color: #ffffff;
  }

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

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

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