var PreviewPanel = {
    template: '<div class="preview-wrap">\
    			<p class="c-t-center c-bold">{{modelName}}</p>\
    			<div v-html="content" class="mtb10 c-333"></div>\
    			<div v-for="(url,i) in imgs" class="mtb10"><img :src="url" width="100%" /></div>\
    			<div class="foot-btns">\
	    			<a class="back-btn c-t-center mr15" @click="goBack">\
		    			返回\
		    		</a>\
	    		</div>\
    </div>',
    props: [],
    data: function() {
        return {
        	content: "",
        	modelName:"",
        	createTime: "",
        	imgs: []
        }
    },
//  beforeRouteEnter: function (to, from, next) {
//	    next(function(vm) {
//	    	var query = vm.$route.query
//	    	if(query && query.modelCode) {
//	    		vm.modelCode = query.modelCode
//	    		vm.listDetail()
//	    	}
//	    })
//	},
	created: function() {
		var vm = this
		EventBus.$on('preview-template', function(data) {
			var regN = /\n/g;
			vm.content = data.content.replace(regN,"<br/>").replace(/ /g, "&nbsp;");
			vm.modelName = data.modelName
        	vm.imgs = data.imgs
		})
	},
    methods: {
    	listDetail: function() {
        	var vm = this
        	guidanceAPI.listDetail({
        		modelCode: vm.modelCode
        	}).then(function(res) {
        		var data = res.data
        		if(data) {
        			var regN = /\n/g;
        			vm.content = data.content.replace(regN,"<br/>").replace(/ /g, "&nbsp;");
        			vm.modelName = data.modelName
        			vm.createTime = data.createTime
        			vm.imgs = _.map(data.imagesUrls, function(s) {
        				return httpRequest.getImgUrl(s)
        			})
        		}
        	})
        },
        getDetail: function (){
            var regN = /\n/g;
            var regRN = /\r\n/g;
            var content = detail.content.replace(/ /g, "&nbsp;");
            content = content.replace(regN,"<br/>");

            var p = "<p class='c-f14 c-333'>"+content+"</p>",
                images = "";
            for(i=0; i<detail.images.length; i++){
                var src = detail.images[i];
                if(!(src.indexOf("file://") > -1)){
                    src = getImgUrl(detail.images[i]);
                }
                
                images += "<div class='mtb10'><img src='"+src+"' width='100%'></div>";
            }
            $(".content").append(p+images);
        },
        goBack: function() {
        	this.$router.back()
        }
    }
}