Vue.component('uploadimg', {
	props : ['curid','flag','type'],//curID当前组件id，flag组件内索引值
	template : '<label style="cursor:pointer;" :id="flag"><input type="file" @change="upload" style="display:none;"><slot></slot></label>',
	methods : {
		upload:function(event) {
            var file = event.target.files[0];
            var self = this;
            var type = this.type;
            var curid = this.curid;
            var flag = this.flag;
            if (file) {
                var formData = new FormData()
                formData.append('imgFile', file);
                $.ajax({
                    url: '/index.php?s=/Home/File/upload', 
                    data: formData,
                    type:"post",
                    dataType: "json",
                    processData:false,
                    contentType: false,
                    success: function(obj){
                        //alert(JSON.stringify(obj));
                        if(obj.error==0){
                            self.$nextTick(function () {
                                $('#'+flag+' img').attr('src',obj.url);
                            });
                            self.$emit('complete',curid,flag,type,obj.url);//向主Vue传递数据
                        }else{
                            alert(obj.message);
                        }
                    }
                });    
            }
        }
	}
})