<style>
 @import "../../assets/css/advert/advmanager.css";
</style>
<template>
    <div class="advmanager-box">
       
        <div class="content" style="top:50px;">
            <vueWaterfallEasy v-if='addatas.length!=0' ref="waterfall" :imgsArr="addatas" @scrollReachBottom="handleCurrentChange" :maxCols='7' :imgWidth='208' :enablePullDownEvent='true'>
                <template slot-scope="props">
                    <span class="free"><i class="el-icon-share"></i> 0</span> 
                    <div class="zezhao">
                        <a :href='`/#/activity/makeAd?id=${props.value.ID}`'><i class="el-icon-edit" title="修改"></i></a>
                        <a :href='props.value.AdvertisingPicUrlStr' download="广告图.png"><i class="el-icon-download"  title="下载"></i></a>
                        <i class="el-icon-delete" title="删除" @click="deleteItem(props.value)"></i>
                    </div>
                </template>
                 <div slot="waterfall-over">没有更多了</div>
            </vueWaterfallEasy>

            <div v-if='addatas.length==0' style='width:100%;margin-top:50px;text-align:center;color: #ccc;'>
                <i class="iconfont icon-kong" style="font-size: 120px;"></i><br/>
                还没有广告哦，<a href='/#/activity/makeAd' style="color:rgb(0, 129, 255)">立即制作</a>
            </div>
        </div>
    </div>
</template>

<script>
import vueWaterfallEasy from 'vue-waterfall-easy'
import {getMyAd,delMyAd} from '../../api/AD/index'
export default {
    data(){
        return{
            lines:[],
            teams:[],
            modelTeams:[],
            countrys:[],
            addatas:[],
            pageIndex:1,
            pageSize:15,
            total:0,
            msg:{
                lineId:'0',
                teamId:'0',
                countryId:'0',
                type:'0'
            },
            user:{},
            model:{},
            isAdd:false,
            uploadType:0,
        }
    },
    components: {
        vueWaterfallEasy
    },
    mounted(){
        this.getaddatas(0)
    },
    methods:{
        deleteItem(x){
            delMyAd({ID:x.ID}).then(res=>{
                 if(res.Code==1){
                    this.$message.success('删除成功')
                    this.getaddatas(0)
                }else{
                    this.$message.error(res.Message)
                }
            })
        },
       
        handleCurrentChange(val) {
            this.pageIndex++
            this.getaddatas(1)
        },
        getaddatas(type){
            if(type==0){
                this.pageIndex=1
            }
            let msg={
               pageIndex:this.pageIndex,
               pageSize:this.pageSize
            }
            getMyAd(msg).then(res=>{
                if(res.Code===1){
                    res.Data.PageData.forEach(x=>{
                    x.src=`${x.AdvertisingPicUrlStr}?x-oss-process=image/resize,w_200`
                })
                if(res.Data.PageData.length==0){
                    this.$refs.waterfall.waterfallOver()
                }
                if(type==0){
                            this.addatas=res.Data.PageData
                }else{
                            this.addatas=this.addatas.concat(res.Data.PageData)
                }
                this.total=res.Data.pageCount
                }
            })
        },
    }
}
</script>