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

var cid = lib.getParam("cid"); //解说视频id
var articleId = lib.getParam("articleId"); //关联影片Id

var initMoreCommentaries = {} //初始化的解说视频列表

export default {
    data() {
        return {
            cid : cid,
            articleId : articleId,
            article : {}, //影片详情
            watchOnline : {}, //在线源
            moreCommentaries : {}, //更多解说
            curVideoUp : {},//当前up主
            curVideoUrl : "",
            curCommentarie : {},
            commentaryCount : 0,
            downloadUrl : lib.downloadUrl, //app下载地址
            articleType: 1,// 1:电影,2:电视剧,3:动画  
            areas : [], //地区
            categories : [], //电影分类
            actors : [{name : "不详"}], //演员
            recommends : [] //相关推荐
        }
    },
    mounted() {
        this.winHeight = window.innerHeight
        this.getCommentary();
        this.getRecommend();
    },
    activated() {
    },
    methods: {
        changeCommentTag(index){
            $(".tag-nav li").eq(index).addClass("active").siblings().removeClass("active");
            $(".tag-cont .tag-panel").eq(index).addClass("active").siblings().removeClass("active");
        },
        //获取文章详情
        getCommentary(callback){
            let self = this;
            let url = `${lib.apiUrl}/share/commentary.do`;
            let param = {
                cid : cid,
                channel : "LuciferChannel",
                ver : 1,
                os : 1,
                uid : 1,
                token : "lucifer_test_token"
            }

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

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

                        self.articleId = data.article.id;
                        self.article = data.article;
                        self.articleType = article.type;
                        self.moreCommentaries = data.moreCommentaries
                        self.commentaryCount = data.commentaryCount
                        self.areas = article.areas;
                        self.watchOnline = article.watchOnline ? article.watchOnline : 0;

                        self.curCommentarie = data.moreCommentaries[0]
                        self.curVideoUp = self.curCommentarie["up"];
                        self.curVideoUrl = self.curCommentarie["video"]["videoUrls"][0]["urls"][0];

                        if (article.filmmakers) {
                            let actors = article.filmmakers.actors
                            
                            self.actors = actors ? actors : [];
                        }

                        lib.setTitle(`${lib.appName}-${data.moreCommentaries[0].title}`);
                        lib.setWxShare({
                            title: `我在看《${data.moreCommentaries[0].title}》`, 
                            desc: `更多【${data.moreCommentaries[0]["up"].nick}】解说视频，快上${lib.appName}`, 
                            link: `${location.href}`, 
                            imgUrl: `${data.moreCommentaries[0].cover}`
                        });
                    } 
                }
            });
        },
        //相关推荐
        getRecommend(){
            let self = this;
            let url = `${lib.apiUrl}/share/recommend.do`;
            let param = {
                commentaryId : cid,
                channel : "LuciferChannel",
                ver : 1,
                os : 1,
                uid : 1,
                token : "lucifer_test_token"
            }

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

                success: (ret) => {
                    var ret = lib.formatHttpProtocol(ret);
                    
                    if(ret.code == 0) {
                        if(ret.data) self.recommends = ret.data;
                    } else {

                    }
                }
            });
        }
    },
    filters : {
        parseReleaseDate(value){
            return lib.handleTime(value).substring(0,11)
        }
    }
}