import Vue from 'vue'
import lib from 'lib'

export default {
    data() {
        return {
            winHeight : 0,
            isHasDlfooter : !lib.checkWjyAgent(),
            latestUsers : [], //上一期排行榜用户列表
            latestShow : {},  //上一场次的信息	
            userBonus : {},   //当前用户信息
            userHeadInfo : {},
            totalTopUsers : [], //总榜前三用户 
            totalLastUsers : [] //总榜剩余用户         
        }
    },
    mounted() {
        this.winHeight = $(window).height()
        this.getOscarRankList()
    },
    activated() {
        let page = lib.getParam("page")

        if(page.match("totalrank")) {
            lib.setTitle("玩家总榜")
        } else {
            lib.setTitle("上期榜单")
        }

        lib.setWxShare({
            title : "百万奥斯卡-微剧院",
            desc : "【百万奥斯卡】影视知识大问答，百万奖金等你拿。",
            link : location.href,
            imgUrl: `//h5-glance.duowan.com/_src/img/icon-logo.png`
        })
    },
    methods: {
        clossDlfooterCallback(){
            this.isHasDlfooter = false
        },
        //玩家排行
        getOscarRankList(){
            let self = this
            let url = `${lib.apiUrl}/share/oscarRankList.do`
            let uid = lib.getParam("uid"),token = lib.getParam("token")
            let param = {
                channel : "LuciferChannel",
                ver : 1,
                os : 1,
                uid : uid || 1,
                token : token || "lucifer_test_token"
            }

            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.latestUsers = data.latestUsers
                        self.userBonus = data.userBonus

                        self.totalTopUsers = data.totalUsers.splice(0,3) //截取前三,改变数组
                        self.totalLastUsers = data.totalUsers  
 
                        if(data.latestShow) self.latestShow = data.latestShow
                        if(data.userBonus) self.userHeadInfo = data.userBonus.userHeadInfo
                    } else {
                        lib.showDialog(ret.msg)
                    }
                }
            })
        }
    },
    filters : {
        parseBonus(value){
            if(value>1e6){
                return Math.floor((value/1e4))/100+"万"
            } else {
                return "￥"+(value/100)
            }
        },
        parseReleaseDate(value){
            return lib.handleTime(value,2)
        }
    }
}