import Vue from 'vue'
import lib from 'lib'
import WjySdk from 'extSdk';

var type = lib.getParam("type")
var from = lib.getParam("from")

export default {
    activated() {
    },
    methods: {
        toCommentaryDetail(commentaryId){
            WjySdk.toCommentaryDetail(commentaryId)
        },
        toVideoDetail(articleId){
            WjySdk.toVideoDetail(articleId)
        },
        toggleFilm(index){
            $(".item-film").eq(index).toggleClass("active");
        },
        getRanklist(){
            let self = this
            let url = `${lib.apiUrl}/functionalTopic/ranklist.do`
            let param = {
                type : type,
                count : 25,
                timeline : self.timeline,
                channel : "LuciferChannel",
                ver : 1,
                os : 1,
                uid : 1,
                token : "lucifer_test_token"
            }

            if(self.articles.length>=250) {
                self.nextFlag = false
                return
            }
            
            self.isloading = true
            $.ajax({
                type: "get",
                url: url,
                data: param,
                dataType: "jsonp",

                success: function (ret) {
                    ret = lib.formatHttpProtocol(ret);

                    self.isloading = false
                    if(ret.code == 0) {
                        let data = ret.data

                        self.articles = self.articles.concat(data.articles)
                        self.timeline = data.timeline
                        self.nextFlag = data.next == 1 ? true : false
                    } else {
                        lib.showDialog(ret.msg)
                    }
                }
            })
        }
    },
    data() {
        return {
            articles : [],        //列表
            timeline : 0,         //翻页标志
            isloading : false,    //是否loading
            nextFlag : true       //下一页标志
        }
    },
    mounted() {
        if(!type || type==0) {
            lib.setTitle("豆瓣250");
        } else {
            lib.setTitle("IMDB250");
        }
        
        this.getRanklist()
    }
}