<template>
<div>
    <div class="header-wrapper">
        <div class="ui container">
            <el-row class="image_text">
                <h1>云脑镜像</h1>
            </el-row>    
        </div>
    </div>
    <div class="ui container" id="header">
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="公共镜像(云脑1)" name="first" v-loading="loading">
                <div class="ui sixteen wide column">
                    <div class="ui two column stackable grid">
                        <div class="column">
                            <el-input placeholder="请输入内容" v-model="search" class="input-with-select">
                                <el-button id="success" slot="append" icon="el-icon-search" @click="searchName()">搜索</el-button>
                            </el-input>
                        </div>

                        <!-- <div class="column right aligned">
                            <el-dropdown>
                                <span class="el-dropdown-link">
                                    排序<i class="el-icon-caret-bottom"></i>
                                </span>
                                <el-dropdown-menu slot="dropdown">
                                    <el-dropdown-item>最早创建</el-dropdown-item>
                                    <el-dropdown-item>最新创建</el-dropdown-item>
                                    <el-dropdown-item divided>按镜像字母顺序排序</el-dropdown-item>
                                    <el-dropdown-item>按镜像字母逆序排序</el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                        </div> -->
                    </div>
                </div>

                <el-row style="margin-top:15px;">

                    <el-table
                        :data="tableData"
                        style="width: 100%"
                        :header-cell-style="tableHeaderStyle"
                        :default-sort="{prop:'createtime',order:'descending'}">
                        <el-table-column
                            label="镜像名称"
                            width="350"
                            align="center"
                            prop="name"
                            sortable
                            >
                            <template slot-scope="scope">
                                <a class="text-over" style="cursor:default;color:#426290" :title="scope.row.name">{{ scope.row.name }}</a>
                            </template>
                        </el-table-column>
                        <el-table-column
                            label="文件路径/镜像描述"
                            width="450"
                            align="center"
                            >
                            <template slot-scope="scope">
                                <el-tooltip class="item" effect="dark" content="点击复制文件路径" placement="top">
                                    <a class="text-over" style="display:block;" @click="copyUrl(scope.row.place)">{{ scope.row.place }}</a>
                                </el-tooltip>
                                
                                <span class="text-over" :title="scope.row.description">{{ scope.row.description }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="provider"
                            label="提供者"
                            width="120"
                            align="center"
                            sortable>
                        </el-table-column>
                        <el-table-column
                            prop="createtime"
                            label="创建时间"
                            align="center"
                            sortable>
                        </el-table-column>
                    </el-table>
                </el-row>
                <div class="ui container" style="margin-top:50px;text-align:center">
                        <el-pagination
                            background
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="currentPage"
                            :page-size="pageSize"
                            :page-sizes="[5,10,20]"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="totalNum">
                        </el-pagination>
                </div>
                    
                
            </el-tab-pane>
            <el-tab-pane label="自定义镜像(云脑1)" name="second" v-loading="loading1">
                <div class="ui sixteen wide column">
                    <div class="ui two column stackable grid">
                        <div class="column">
                            <el-input placeholder="请输入内容" v-model="search" class="input-with-select">
                                <el-button slot="append" id="success" icon="el-icon-search" @click="searchName()">搜索</el-button>
                            </el-input>
                        </div>

                        <!-- <div class="column right aligned">
                            <el-dropdown>
                                <span class="el-dropdown-link">
                                    排序<i class="el-icon-caret-bottom"></i>
                                </span>
                                <el-dropdown-menu slot="dropdown">
                                    <el-dropdown-item>最早创建</el-dropdown-item>
                                    <el-dropdown-item>最新创建</el-dropdown-item>
                                    <el-dropdown-item divided>按镜像字母顺序排序</el-dropdown-item>
                                    <el-dropdown-item>按镜像字母逆序排序</el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                        </div> -->
                        
                    </div>
                    
                </div>

                <el-row style="margin-top:15px;">

                    <el-table
                        :data="tableData1"
                        style="width: 100%"
                        :header-cell-style="tableHeaderStyle"
                        :default-sort="{prop:'createtime',order:'descending'}">
                        <el-table-column
                            label="镜像名称"
                            width="350"
                            align="center"
                            prop="name"
                            sortable
                            >
                            <template slot-scope="scope">
                                <a class="text-over" :title="scope.row.name" style="cursor:default;color:#426290">{{ scope.row.name }}</a>
                            </template>
                        </el-table-column>
                        <el-table-column
                            label="文件路径/镜像描述"
                            width="450"
                            align="center"
                            
                            >
                            <template slot-scope="scope">
                                <el-tooltip class="item" effect="dark" content="点击复制文件路径" placement="top">
                                    <a class="text-over" style="display:block;" @click="copyUrl(scope.row.place)">{{ scope.row.place }}</a>
                                </el-tooltip>
                                
                                <span class="text-over" :title="scope.row.description">{{ scope.row.description }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="provider"
                            label="提供者"
                            width="120"
                            align="center"
                            sortable>
                        </el-table-column>
                        <el-table-column
                            prop="createtime"
                            label="创建时间"
                            align="center"
                            sortable>
                        </el-table-column>
                    </el-table>
                </el-row>
                <div class="ui container" style="margin-top:50px;text-align:center">
                        <el-pagination
                            background
                            @size-change="handleSizeChange1"
                            @current-change="handleCurrentChange1"
                            :current-page="currentPage1"
                            :page-size="pageSize1"
                            :page-sizes="[5,10,20]"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="totalNum1">
                        </el-pagination>
                </div>
                

            </el-tab-pane>
            <el-tab-pane label="公共镜像(云脑2)" name="third">
                
                <div class="ui sixteen wide column">
                    <div class="ui two column stackable grid">
                        <div class="column">
                            <el-input placeholder="请输入内容" v-model="search" class="input-with-select">
                                <el-button slot="append" id="success" icon="el-icon-search">搜索</el-button>
                            </el-input>
                        </div>

                        <!-- <div class="column right aligned">
                            <el-dropdown>
                                <span class="el-dropdown-link">
                                    排序<i class="el-icon-caret-bottom"></i>
                                </span>
                                <el-dropdown-menu slot="dropdown">
                                    <el-dropdown-item>最早创建</el-dropdown-item>
                                    <el-dropdown-item>最新创建</el-dropdown-item>
                                    <el-dropdown-item divided>按镜像字母顺序排序</el-dropdown-item>
                                    <el-dropdown-item>按镜像字母逆序排序</el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                        </div> -->
                        
                    </div>
                    
                </div>

                <el-empty :image-size="200"></el-empty>
            </el-tab-pane>
            <el-tab-pane label="自定义镜像(云脑2)" name="fourth">
                
                <div class="ui sixteen wide column">
                    <div class="ui two column stackable grid">
                        <div class="column">
                            <el-input placeholder="请输入内容" v-model="search" class="input-with-select">
                                <el-button slot="append" id="success" icon="el-icon-search">搜索</el-button>
                            </el-input>
                        </div>

                        <!-- <div class="column right aligned">
                            <el-dropdown>
                                <span class="el-dropdown-link">
                                    排序<i class="el-icon-caret-bottom"></i>
                                </span>
                                <el-dropdown-menu slot="dropdown">
                                    <el-dropdown-item>最早创建</el-dropdown-item>
                                    <el-dropdown-item>最新创建</el-dropdown-item>
                                    <el-dropdown-item divided>按镜像字母顺序排序</el-dropdown-item>
                                    <el-dropdown-item>按镜像字母逆序排序</el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                        </div>  -->
                    </div>
                </div>

                <el-empty :image-size="200"></el-empty>

            </el-tab-pane>
        </el-tabs>
  </div>
</div>

  
</template>

<script>

const {_AppSubUrl, _StaticUrlPrefix, csrf} = window.config;




export default {
  components: {
    
  },
  data() {
    return {
      activeName: 'first',
      search:'',
      currentPage:1,
      pageSize:10,
      totalNum:0,
      params:{page:1,size:10,name:''},
      tableData: [],
      loading:false,

      currentPage1:1,
      pageSize1:10,
      totalNum1:0,
      params1:{page:1,size:10,name:''},
      tableData1: [],
      loading1:false
    };
  },
  methods: {
    handleClick(tab, event) {
        if(tab.name=="first"){
            this.getImageList()
        }
        if(tab.name=="second"){
            this.getImageList1()
        }
        
      },
    tableHeaderStyle({row,column,rowIndex,columnIndex}){
        
        if(rowIndex===0){
            return 'background:#f5f5f6;color:#606266'
        }
        
    },
    handleSizeChange(val){
        this.params.size = val
        this.getImageList()


    },
    handleCurrentChange(val){
        console.log(val)
        this.params.page = val
        this.getImageList()

    },
    handleSizeChange1(val){
        this.params1.size = val
        this.getImageList1()


    },
    handleCurrentChange1(){
        this.params1.page = val
        this.getImageList1()

    },
    getImageList(){
        this.loading = true
        this.$axios.get('/explore/images/public',{
            params:this.params
        }).then((res)=>{
            
            this.totalNum = res.data.count
            this.tableData = res.data.rows
            this.loading = false 
        })
    },

    getImageList1(){
        this.loading1 = true
        this.$axios.get('/explore/images/custom',{
            params:this.params1
        }).then((res)=>{
            
            this.totalNum1 = res.data.count
            this.tableData1 = res.data.rows
            this.loading1 = false
        })
    },
    copyUrl(url){
        console.log(url)
        const cInput = document.createElement('input')
        cInput.value = url
        document.body.appendChild(cInput)
        cInput.select()
        document.execCommand('Copy')
        cInput.remove()

    },
    searchName(){
        if(this.activeName=='first'){
            this.params.name = this.search
            this.getImageList()
        }
        if(this.activeName=='second'){
            this.params1.name = this.search
            this.getImageList1()
        }
        
    }

  },
  watch:{
      search(val){
          if(!val && this.activeName=='first'){
              this.params.name = val
              this.getImageList()
          }
          if(!val && this.activeName=='second'){
              this.params1.name = val
              this.getImageList1()
          }
      }

  },
  mounted() {
      this.getImageList()
  },
  created() {
    
  }

};
</script>

<style scoped>
.header-wrapper {
    background-color: #f5f5f6;
    padding-top: 15px;
}
.image_text{
    padding:25px 0 55px 0 ;
}
#header{
    position: relative;
    top:-40px;
}
.el-dropdown-menu__item--divided{
    border-top: 1px solid blue;
}
.el-table thead{
    background-color: #f5f5f6;
}
#success{
    background-color: #4093ff;
    color: white;
}
.text-over{
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    white-space: nowrap;
}
</style>
