;
var decoration = new Vue({
    el:'#decoration',
    data:{
        iconflag:true,
        bgflag:false,
        logoShow:false,
        formData:new FormData(),
        params:{
            shopID:'',
            title:'',
            link:'',
            info:'',
            image:'',
        },
        shopBannerId:'',
        name:'',
        list:[],
    },
    methods:{
          uploadlogo:function () { //上传图片
            var _this = this;
            var inputDOM = _this.$refs.images;
            var file = inputDOM.files;
            _this.formData.append('file', file[0]);
            SupplierApi.uploadimg(_this.formData,function(response){
               _this.params.image = response.data;
               _this.logoShow = true;
               _this.iconflag = false;
                event.target.value = '';
            });
        },
        addpictures:function () {
            var _this = this;
            if(_this.list.length==4){
                 CAIMEI.dialog('主页广告图的上限是4张图');
            }else {
                _this.name = '添加主页广告图';
                _this.bgflag = true;
                _this.iconflag=true;
                _this.logoShow =false;
            }
        },
        submit:function(){//提交
            var _this = this;
            if(_this.name.indexOf('编辑') > -1) {
                _this.params.shopBannerID = _this.shopBannerId
            }
            if(_this.params.image==''){
                CAIMEI.dialog('请上传广告图片')
            }else {
            console.log(_this.params)
                SupplierApi.ShopBanner(_this.params,function (res) {
                   CAIMEI.dialog('提交成功');
                    location.reload()
                })
            }
        },
        editpictures:function(item){
             var _this = this;
            _this.name = '编辑主页广告图';
            _this.shopBannerId = item.shopBannerID;
            _this.bgflag = true;
            _this.params.title = item.title;
            _this.params.link = item.link;
            _this.params.info = item.info;
            _this.params.image = item.image;
            if(item.image !=''){
            _this.params.image=item.image;
            _this.logoShow = true;
            _this.iconflag = false;
             }else {
                _this.logoShow = false;
                _this.iconflag = true;
             }
        },
        deletepictures:function(item){
            var _this = this;
            var shopBannerId = item.shopBannerID;
            console.log(shopBannerId)
            CAIMEI.Modal('您确定要删除么？','取消','确定',function () {
                   SupplierApi.deleteShopBanner({shopBannerId:shopBannerId},function (res) {
                    if(res.code==0){
                        CAIMEI.dialog('删除成功');
                        location.reload()
                    }
                   })
            })
        },
        close:function () {
            var _this = this;
            _this.bgflag = false;
            _this.params.title = '';
            _this.params.link = '';
            _this.params.info = '';
            _this.params.image = '';
        }

    },
    mounted:function () {
        var _self = this;
         if(globalUserData){
              _self.params.shopID = globalUserData.shopId;

            }
        SupplierApi.dressUpList({shopId:_self.params.shopID},function (res) {
            if(res.code==0){
                console.log(res)
                if(res.data.length>0){
                _self.list =res.data;
                }
            }
        })
        $('.navLayout').find('.navList').removeClass("on").find('.con').hide().find('a').removeClass("on");
        $('.navLayout').find('.navList').eq(1).addClass("on").find('.con').show().find('a').eq(1).addClass("on");
    }
})
