<template>
  <div class="uav-list" :class="{ collapse: listCollapse }">
    <div class="uav-list_btn" @click="collapseFlagfn">
      <img style src="./assets/images/collapse.svg" />
    </div>
    <div class="uav-list-header">
      <img class="uav-list-header__icon" src="./assets/images/uav_list_header.png" />
      <span class="uav-list-header__text">无人机列表</span>
    </div>
    <div class="uav-search">
      <el-input
        class="uav-search__input"
        clearable
        placeholder="请输入无人机名称/机构名称"
        v-model="uavSearchContent"
        v-on:keyup.enter.native="onUavSearch"
      >
        <i
          slot="suffix"
          class="el-input__icon el-icon-search"
          style="color: rgba(123, 181, 213, 1)"
        ></i>
      </el-input>
      <el-button class="uav-search__btn" @click="onUavSearch" v-hover>搜索</el-button>
    </div>
    <List
      class="uav-list-main"
      @exit
      :containerStyle="{
          width: '400PX',
          height: '275px',
        }"
      :list="uavList"
      @refresh="initList"
    />
    <div></div>
  </div>
</template>

<script>
import { Control_API } from "../../../../api";
import List from "./components/list";
// import data from "./data.json";

export default {
  components: {
    List,
  },
  data() {
    return {
      uavList: [], // 无人机列表
      uavSearchContent: "", // 无人机搜索内容
      timeHandle: null, // 定时刷新句柄
      deviceType: 1, // 设备类型 1无人机
    };
  },
  computed: {
    // 收起列表按钮
    listCollapse: {
      get() {
        return this.$store.state.MMCFlightControlCenter.listCollapse;
      },
      set(val) {
        this.$store.commit("MMCFlightControlCenter/setState", {
          key: "listCollapse",
          value: val,
        });
      },
    },
  },
  mounted() {
    this.initList();
    this.timeHandle = setInterval(() => {
      this.initList();
    }, 10000);
  },
  beforeDestroy() {
    clearInterval(this.timeHandle);
  },
  methods: {
    async initList() {
      let res = await Control_API.getUavTree({
        serchKey: this.uavSearchContent,
        deviceType: this.deviceType,
      });
      this.uavList = res.data;
    },
    collapseFlagfn() {
      this.listCollapse = !this.listCollapse;
    },
    /**
     * 无人机搜索
     */
    onUavSearch() {
      this.initList();
    },
  },
};
</script>

<style lang="scss" scoped>
.collapse {
  transform: translateX(-100%);
  transition: 0.3s;

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

.uav-list {
  display: flex;
  flex-direction: column;
  position: absolute;
  width: 420px;
  height: 85%;
  left: 0;
  top: 60px;
  // height: 86vh;
  z-index: 99;
  transition: 0.3s;
  background: #222222;
  border-radius: 5px 5px 0px 0px;
  // border: 1px solid #70daf9;
  .uav-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;
    }
  }
}

.uav-list-header {
  flex-shrink: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  width: 100%;
  height: 33px;
  background: #3c3c3c;
  border-radius: 5px 5px 0px 0px;

  .uav-list-header__text {
    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;
  }

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

::v-deep .uav-search {
  flex-shrink: 0;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  // margin-bottom: 7px;
  margin-top: 14px;

  .uav-search__input {
    width: 317px;
    height: 32px;
    border-radius: 4px;

    .el-input__icon {
      line-height: 32px;
      color: #a8abb2 !important;
    }

    input {
      height: 32px;
      background: #191919;
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 12px;
      color: #fff;
      border: 1px solid #4b4b4b;

      &::placeholder {
        font-size: 12px;
        color: #a8abb2;
      }
    }
  }

  .uav-search__btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 79px;
    height: 32px;
    font-size: 14px;
    color: #fff;
    border-radius: 4px;
    border: 0;
    background: #3388ff;
  }
}

.uav-list-main {
  margin-top: 20px;

  /* 滚动条整体样式 */
  &::-webkit-scrollbar {
    width: 10px; /* 滚动条宽度 */
  }

  /* 滚动条滑块样式 */
  &::-webkit-scrollbar-thumb {
    background-color: #02173d; /* 滑块颜色 */
  }

  /* 滚动条滑块悬停样式 */
  &::-webkit-scrollbar-thumb:hover {
    background-color: #112d5b; /* 悬停时滑块颜色 */
  }

  &::-webkit-scrollbar-track-piece {
    /* background-color: #182F5C; */
  }

  &::-webkit-scrollbar-track {
    background-color: #182f5c;
  }
}
</style>