// package_first/pages/LearningVideo/index.js
import {api_westreamVideo} from  '../../../api/learining';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list:[],
        params: {
            openid: null
        },
        userPage:{
            page:1,
            limit:10
        },
        total:0,
        current: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        const openid = wx.getStorageSync('openid')
        this.setData({
            params:{ openid }
        })
    },

    /* 更新数据 */
    updateList(e) {
        let list = this.data.list.concat(e.detail || [])
        this.setData({ list })
    },
    /* 重置数据 */
    resetList() {
        this.setData({ list: [] })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.setData({
            current:'/westreamVideo/index' 
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        if(this.data.userPage.page*this.data.userPage.limit<this.data.total){
            this.data.userPage.page++
            this.setData({
                userPage:this.data.userPage
            })
            this.westreamVideo()
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
    westreamVideo(){
        const tenantObj = wx.getStorageSync('tenant')
        const openid = wx.getStorageSync('openid')
        let data = {
            tenantId:tenantObj.tenantId,
            openid : openid,
            ...this.data.userPage
        }
        api_westreamVideo(data).then(res=>{
            let list = []
            if(this.data.userPage.page==1){
                list = res.data.records
            }else{
                list = [...this.data.list,...res.data.records]
            }
            let total = res.data.total
            this.setData({
                total,
                list,
            })
            // if(list.status == 0){
            //     data.entersList[0].isstudy = true
            // }else if(list.status == 1){
            //     data.entersList[1].isstudy = true
            // }
        })
    },
    handleDetail(e){
        const data = JSON.stringify(e.currentTarget.dataset.item)
        wx.navigateTo({
            url: '/package_first/pages/videoDetail/index?data='+ encodeURIComponent(data)
        })
    }

})