import {
    getInviteRanking
} from '~/api/global'
import {
    getInviteList
} from '~/api/user'
import event from '~/mixins/event'
Page({
    behaviors: [event],
    data: {
        userInfo: {},
        ranking: '',
        gap: '',
        myCount: '',
        userList: [],
        inviteList: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    async onLoad(options) {
        wx.setNavigationBarColor({
            frontColor: '#ffffff',
            backgroundColor: '#2DCE66'
        })
        this.setData({
            userInfo: getApp().globalData.userInfo
        })
        let {
            list
        } = await getInviteList({
            pageSize: 9999
        })
        let {
            userList,
            ranking,
            gap,
            myCount
        } = await getInviteRanking()
        this.setData({
            inviteList: list,
            userList,
            ranking,
            gap,
            myCount
        })
    },

    jumpIndex() {
        wx.switchTab({
            url: '/pages/index/index',
        })
    },
    jumpUserInfo({
        currentTarget
    }) {
        if (!currentTarget.dataset.uid) {
            return
        }
        wx.navigateTo({
            url: `/pages/personal/index?uid=${currentTarget.dataset.uid}`,
        })
    },
    showTranscript() {
        this.selectComponent("#popUp").showModal()
    },
    closeTranscript() {
        this.selectComponent("#popUp").hideModal()
    },
    onShareAppMessage() {
        return {
            title: '这个小程序太赞了！孩子朗读能力蹭蹭上涨，推荐你试试！',
            path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
            imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-2.jpg'
        }
    }
})