<template>
  <div class="stk">
    <div class="stk_head">
      <div :class="viewLibTab == 1 ? 'ac' : ''" @click="onChangeViewLibTab(1)">视图</div>
      <div :class="viewLibTab == 2 ? 'bc' : ''" @click="onChangeViewLibTab(2)">机载</div>
    </div>
    <div class="content">
      <!-- 先注释，下次更新要用 -->
      <div class="head">
        <div class="aitype" v-if="viewLibTab == 1 && !moreShow">
          <el-select popper-class="mmc" v-model="aiType" placeholder="全部" @change="onChangeAiType">
            <el-option
              v-for="item in aiTypeList"
              :key="item.id"
              :label="item.value"
              :value="item.id"
            ></el-option>
          </el-select>
        </div>
        <div class="select" v-if="viewLibTab == 2">
          <!-- <div class="btns" :class="fileType == 0 ? 'bg' : ''" @click="onChangeFileType(0)">图片</div>
          <div class="btns" :class="fileType == 1 ? 'bg' : ''" @click="onChangeFileType(1)">视频</div> -->
          <el-radio-group v-model="fileType">
            <el-radio-button label="图片" @click="onChangeFileType(0)"></el-radio-button>
            <el-radio-button label="视频" @click="onChangeFileType(1)"></el-radio-button>
          </el-radio-group>
          <span class="iconfont icon-gengxin" @click="init"></span>
        </div>
        <div class="select" v-if="viewLibTab == 1 && !moreShow">
          <el-radio-group v-model="fileType2">
            <el-radio-button label="图片" @click="onChangeFileType2(0)"></el-radio-button>
            <el-radio-button label="视频" @click="onChangeFileType2(1)"></el-radio-button>
          </el-radio-group>
          <span class="iconfont icon-gengxin" @click="init"></span>
        </div>
        <div class="select" v-if="viewLibTab == 1 && moreShow">
          <div class="btns bg">返回</div>
        </div>
      </div>
      <p v-if="viewLibTab == 2 && fileType == 1">
        如遇视频无法播放，请
        <a href="http://32.128.6.52:4500/11.11平台部署/ChromeStandaloneSetup64.exe">下载最新谷歌</a>
      </p>
      <div class="lists">
        <!-- <div style="text-align: left">asfnjkfassfausfasn</div> -->
        <div class="boxs" :style="!moreShow ? 'height: 100%;' : ''" v-if="viewLibTab == 1">
          <div class="boxst" :style="!moreShow ? 'height: 100%;' : ''" v-if="!moreShow">
            <div class="images">
              <div
                class="box"
                v-for="(item2, index2) in photoList"
                :key="index2"
                :class="viewLibTab == 1 && fileType2 == 2 ? 'boxv2' : ''"
              >
                <img
                  v-if="viewLibTab == 1 && fileType2 == 1"
                  :src="item2.image"
                  crossorigin="anonymous"
                />

                <video controls v-if="viewLibTab == 1 && fileType2 == 2" :src="item2.image"></video>
                <div
                  class="down"
                  v-if="viewLibTab == 1 && fileType2 == 1"
                  @click="onDownload(item2.image)"
                >下载</div>
              </div>
            </div>
          </div>
          <div v-else>
            <el-checkbox-group v-model="checkList">
              <div
                class="box"
                :class="viewLibTab == 1 && fileType2 == 2 ? 'boxv2' : ''"
                v-for="(item, index) in morelist"
                :key="index"
              >
                <el-checkbox :label="item">
                  <video
                    controls
                    v-if="viewLibTab == 1 && fileType2 == 2"
                    :src="imgApi + '/uploads' + item.fileKey"
                  ></video>
                  <img v-else :src="imgApi + '/uploads' + item.fileKey" crossorigin="anonymous" />
                  <div class="down" v-if="viewLibTab == 1 && fileType2 == 1">下载</div>
                  <!-- <el-image
                          v-else
                          :src="imgApi + '/uploads' + item.fileKey"
                          fit="cover"
                          :preview-src-list="[imgApi + '/uploads' + item.fileKey]"
                  ></el-image>-->
                </el-checkbox>
              </div>
            </el-checkbox-group>
          </div>
        </div>
        <div class="boxs jz" v-else>
          <el-checkbox-group v-model="checkList">
            <div
              class="box"
              v-for="(item, index) in photoList"
              :key="index"
              :class="viewLibTab == 2 && fileType == 1 ? 'boxv2' : ''"
            >
              <el-checkbox :label="item.name">
                <el-image
                  v-if="viewLibTab == 2 && fileType == 0"
                  :src="item.image"
                  fit="cover"
                  :preview-src-list="[item.image]"
                ></el-image>

                <video controls v-if="viewLibTab == 2 && fileType == 1" :src="item.image"></video>
                <div
                  class="down"
                  v-if="viewLibTab == 2 && fileType == 0"
                  @click="onDownload(item.image)"
                >下载</div>
              </el-checkbox>
            </div>
          </el-checkbox-group>
        </div>
      </div>
      <div class="foot" v-if="moreShow || viewLibTab == 2 || fileType2 == 2">
        <div class="btns blue" v-if="selectAll">全选</div>
        <div class="btns blue" v-else>取消全选</div>
        <div class="btns" v-if="viewLibTab == 2">转存</div>
        <div class="btns red" style>删除</div>
      </div>
    </div>
  </div>
</template>

<script>
import { flightTaskAPI, Control_API } from "../../../../../../../../api";

export default {
  name: "ViewLib",
  data() {
    return {
      checkList: [], // 多选结果
      selectAll: false, //全选
      viewLibTab: 1, // 视图库tab索引, 1: 视图, 2: 机载
      aiType: 1, // 图片类型
      aiTypeList: [
        // 普通图片或ai图片选项
        {
          id: 1,
          value: "图片",
        },
        {
          id: 2,
          value: "AI图片",
        },
        // {
        //   id: 0,
        //   value: "全部",
        // },
        // {
        //   id: 1,
        //   value: "人脸识别",
        // },
        // {
        //   id: 2,
        //   value: "车辆识别",
        // },
        // {
        //   id: 9,
        //   value: "人流识别",
        // },
        // {
        //   id: 4,
        //   value: "游泳识别",
        // },
        // {
        //   id: 5,
        //   value: "跌倒检测",
        // },
        // {
        //   id: 6,
        //   value: "异物检测",
        // },
        // {
        //   id: 7,
        //   value: "火焰烟雾",
        // },
        // {
        //   id: 8,
        //   value: "车辆朝向",
        // },
        // {
        //   id: 9,
        //   value: "车辆类型检测",
        // },
        // {
        //   id: 10,
        //   value: "车道分割线",
        // },
        // {
        //   id: 11,
        //   value: "绿化带分割",
        // },
        // {
        //   id: 10,
        //   value: "车牌识别",
        // },
      ], //视图库类型
      fileType: 1, //视图文件类型
      fileType2: 1, //机载文件类型
      photoList: [], //资源列表
      moreShow: false, //显示更多
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    async init() {
      let res = await Control_API.getSortieImage({
        imageType: this.aiType,
        page: 1,
        pageSize: 999,
      });
      this.photoList = res.data.records;
    },
    /**
     * 视图库tab更改
     */
    async onChangeViewLibTab(index) {
      this.viewLibTab = index;
    },
    /**
     * 图片ai类型切换
     */
    onChangeAiType() {
      this.init();
    },
    /**
     * 更改视图中文件类型
     */
    onChangeFileType(i) {
      this.fileType = i;
      this.init();
    },
    /**
     * 更改机载中文件类型
     */
    onChangeFileType2(i) {
      this.fileType2 = i;
      this.init();
    },
    onDownload(url) {
      window.open(url, "_self");
    },
  },
};
</script>

<style lang="scss" scoped>
.stk::v-deep {
  position: absolute;
  right: 70px;
  top: 190px;
  width: 470px;
  height: 450px;
  background: #222222;
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
  border-radius: 10px;

  .stk_head {
    display: flex;
    cursor: pointer;
    background: #3c3c3c;
    border-radius: 10px 10px 0px 0px;

    div {
      padding: 0 8px;
      // width: 243px;
      width: 100%;
      text-align: center;
      line-height: 36px;
      font-size: 16px;
      font-family: YouSheBiaoTiHei;
      color: #ffffff;
      text-shadow: 0px 1px 1px rgba(2, 32, 56, 0.2);
      height: 36px;
    }

    .ac {
      background: #3388ff;
      border-radius: 10px 0px 0px 0px;
    }

    .bc {
      background: #3388ff;
      border-radius: 0px 10px 0px 0px;
    }
  }

  .content {
    margin-top: 10px;
    padding: 0 15px;
    display: flex;
    flex-direction: column;
    height: 405px;

    > p {
      font-size: 14px;
      color: #fff;
      cursor: default;
      a {
        cursor: pointer;
        color: #00ffff;
      }
    }
    .foot {
      flex-shrink: 0;
      margin-top: 12px;
      display: flex;
      // justify-content: space-between;
      align-items: center;
      gap: 12px;
      .btns {
        width: 64px;
        height: 32px;
        text-align: center;
        line-height: 32px;
        font-size: 14px;
        font-family: MicrosoftYaHei;
        color: #ffffff;
        background: url("../../assets/images/zc.png") no-repeat;
        background-size: 100% 100%;
        cursor: pointer;
      }
      .blue {
        background: url("../../assets/images/qx.png") no-repeat;
        background-size: 100% 100%;
      }
      .red {
        background: url("../../assets/images/red.png") no-repeat;
        background-size: 100% 100%;
      }
    }
    .head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex-shrink: 0;

      .btns {
        width: 64px;
        height: 32px;
        text-align: center;
        line-height: 32px;
        font-size: 14px;
        font-family: MicrosoftYaHei;
        color: #ffffff;
        background: url("../../assets/images/zc.png") no-repeat;
        background-size: 100% 100%;
        cursor: pointer;
      }
      .bg {
        background: url("../../assets/images/qx.png") no-repeat;
        background-size: 100% 100%;
      }

      .blue {
        background: url("../../assets/images/qx.png") no-repeat;
        background-size: 100% 100%;
      }

      .select {
        display: flex;
        align-items: center;
        gap: 10px;

        .iconfont {
          color: #fff;
        }

        .btns {
          margin-right: 16px;
          width: 64px;
          height: 32px;
          text-align: center;
          line-height: 32px;
          font-size: 14px;
          font-family: MicrosoftYaHei;
          color: #ffffff;
          background: url("../../assets/images/zc.png") no-repeat;
          background-size: 100% 100%;

          // &:hover {
          //   background: url("../../assets/images/qx.png") no-repeat;
          //   background-size: 100% 100%;
          // }
        }
        .bg {
          background: url("../../assets/images/qx.png") no-repeat;
          background-size: 100% 100%;
        }

        .el-select {
          width: 80px;
          height: 32px;

          .el-input--suffix {
            width: 100%;
            height: 100%;

            .el-input__inner {
              width: 100%;
              height: 100%;
            }
          }

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

    .lists {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      overflow-y: auto;
      overflow-x: hidden;
      margin-top: 10px;
    }
    .boxs {
      display: flex;
      flex-wrap: wrap;
      align-content: flex-start;
      height: 100%;
    }
    .boxst {
      width: 100%;
      display: flex;
      flex-direction: column;
      height: 100%;
      .name {
        margin: 0 8px;
        display: flex;
        justify-content: space-between;
        color: #fff;
      }

      .images {
        display: flex;
        flex-wrap: wrap;
        align-content: flex-start;

        .box {
          position: relative;
          width: 135px;
          height: 88px;
          background: #ffffff;
          border-radius: 2px;
          margin-left: 8px;
          margin-bottom: 14px;

          .el-image {
            width: 138px;
            height: 88px;
            background: #ffffff;
            border-radius: 2px;
          }
          img {
            width: 135px;
            height: 88px;
          }
          .down {
            position: absolute;
            bottom: 0;
            right: -3px;
            width: 30px;
            height: 20px;
            text-align: center;
            line-height: 20px;
            background: rgba($color: #000000, $alpha: 0.6);
            color: #fff;
            font-size: 12px;
            display: none;
          }
          &:hover {
            .down {
              display: block;
            }
          }
        }

        .boxv2 {
          width: 430px;
          height: 120px;
          margin-left: 0;

          video {
            width: 430px;
            height: 120px;
          }
        }
      }
    }
  }

  .down {
    cursor: pointer;
  }

  .icon-gengxin {
    cursor: pointer;
  }
}
</style>