<template>
  <div style="padding: 2px;">
    <el-input
      class="leftInput"
      clearable
      v-model="videoName"
      placeholder="请输入视频名称"
      @clear="search"
      size="mini"/>
    <el-button size="mini" type="primary" @click="search">搜索</el-button>
    <el-tabs
      v-model="activeName"
      @tab-click="handleClick"
    >
      <el-tab-pane label="华鑫" name="1">
        <el-tree class="leftTree" :data="data">
          <div slot-scope="{ node, data }" @dblclick="handleNodeClick(data)" style="width:100%">
            <div  style="width:100%">
              <span class="tree_span ">
               <i class=" el-icon-video-camera"/>{{data.videoName}}
              </span>
            </div>
          </div>
        </el-tree>
      </el-tab-pane>
      <el-tab-pane label="鸿海" name="2" :lazy="true">
        <el-tree class="leftTree" :data="data">
          <div slot-scope="{ node, data }" @dblclick="handleNodeClick(data)" style="width:100%">
            <div  style="width:100%">
              <span class="tree_span ">
               <i class=" el-icon-video-camera"/>{{data.videoName}}
              </span>
            </div>
          </div>
        </el-tree>
      </el-tab-pane>
    </el-tabs>
  </div>

</template>

<script>
import { videoInfoList } from "@/api/video/manage";
export default {
  name: "left",
  data() {
    return {
      data: [],
      videoName: "",
      params: {
        videoType: "1",
        isDel: "0"
      },
      activeName: "1",
      kindOptions: []
    };
  },
  created(){
    this.getVideoInfo();
  },
  methods: {
    handleNodeClick(data) {
      if(data.videoResource){
        this.$emit('playVideo',data);
      }
    },
    getVideoInfo(){
      videoInfoList(this.params).then(res =>{
        if(res.code == 200 && res.data){
           //this.data = res.data;
           this.getKindByType(res.data);
        }
      })
    },
    // 获取树数据
    getTreeData(data){
      let treeData = [];
      this.kindOptions.forEach(item =>{
        let kindData = {videoName: item.dictLabel,children: []};
        let videoInfo = data.filter(video => video.kind == item.dictValue ).sort((a, b) => Number(a.sort) - Number(b.sort));
        if(videoInfo){
          kindData.children = videoInfo
        }
        treeData.push(kindData);
      })
      this.data = treeData;
    },
    search(){
      this.params.videoName = this.videoName;
      this.getVideoInfo();
    },
    handleClick(tab, event) {
      this.params.videoType = tab.name;
      this.getVideoInfo();
    },
    getKindByType(data){
      if(this.activeName == '1'){
        this.getDicts("t_huaxin_video_kind").then(response => {
            this.kindOptions = response.data;
            this.getTreeData(data);
        });
      }else{
        this.getDicts("t_honghai_video_kind").then(response => {
            this.kindOptions = response.data;
            this.getTreeData(data);
        });
      }
    }
  }
}
</script>

<style scoped lang="scss">
  .leftInput{
    width: 184px;
    margin-right: 15px
  }
  .leftTree{
    height: calc(100vh - 194px);
    overflow-y: auto;
    &::-webkit-scrollbar {
      height: 6px;
      width: 6px;
      background:  #dfe4ed;
      position: absolute;
      top: 0;
    }
    &::-webkit-scrollbar-thumb {
      /*滚动条里面小方块*/
      // border-radius: 10px;
      // box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
      background: #cccccc;
      border-radius: 5px;
    }
  }

</style>
