<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">
      <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 { mapState } from "vuex";
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: {
    ...mapState("MMCFlightControlCenter", ["showAirwayEdit"]),
    // 收起列表按钮
    listCollapse: {
      get() {
        return this.$store.state.MMCFlightControlCenter.listCollapse;
      },
      set(val) {
        this.$store.commit("MMCFlightControlCenter/setState", {
          key: "listCollapse",
          value: val,
        });
      },
    },
  },
  watch: {
    showAirwayEdit(newVal) {
      if (newVal) {
        this.listCollapse = true;
      }
    },
  },
  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: 100%;
  left: 0;
  top: 0;
  // height: 86vh;
  z-index: 99;
  transition: 0.3s;
  background: #222222;
  // 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: 54px;
  padding: 0 16px;

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

.uav-search::v-deep {
  flex-shrink: 0;
  padding: 0 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .uav-search__input {
    width: 292px;
    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: 80px;
    height: 32px;
    font-size: 14px;
    color: #fff;
    border-radius: 2px;
    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>