import Vue from 'vue'
import lib from 'lib'
import ext from 'extSdk'
import _ from 'underscore'

var postId = lib.getParam("postId");

export default {
    data() {
        return {
            post : {},
            postUser : {}, //帖子详情
            postPics : [],
            postExtend : {},
            user : {},
            comments: [], //回复列表
            picList : [], //图片列表
            downloadUrl : lib.downloadUrl //app下载地址
        }
    },
    mounted() {
        this.getPost();
    },
    activated() {
        $("title").text(`${lib.appName}-动态详情`);
    },
    methods: {
        previewImage(picIndex){
            lib.setPreviewImage(this.picList,picIndex)
        },
        //分享动态
        getPost(){
            let self = this;
            let url = lib.apiUrl+"/share/post.do";
            let param = {
                postId : postId,
                channel : "LuciferChannel",
                ver : 1,
                os : 1,
                uid : 1,
                token : "lucifer_test_token"
            }

            $.ajax({
                type: "get",
                url: url,
                data: param,
                dataType: "jsonp",

                success: function (ret) {
                    var ret = lib.formatHttpProtocol(ret);
                    
                    if (ret.result == 1){
                        let data = ret.data;

                        self.post = data.post;
                        self.postUser = data.post.user;
                        self.postExtend = data.post.extend;
                        self.postPics = data.post.extend.pics;
                        self.comments = data.comments ? data.comments : [];
                        self.picList = data.post.extend.pics;
                        self.user = data.post.user;

                        lib.setTitle("微剧院-"+data.post.user.nick+"的动态");
                        lib.setWxShare({
                            title: `【${data.post.user.nick}】${data.post.extend.text}`, 
                            desc: `搜片源、看解说，快上5分钟看剧平台-微剧院`, 
                            link: `${location.href}`, 
                            imgUrl: `${data.post.user.head}`
                        });
                    } 
                }
            });
        }
    },
    filters : {
        parseTime(value){
            return lib.handleTime(value).substring(5,17)
        }
    }

}