// package_first/pages/ProtectionActivity/index.js
import { 
    api_getIsApply,
    api_TiktokAdd
} from  '../../../api/attention.js';
import {integratDetail} from '../../../api/protection.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tikStatus:null,
        entersList:[
            {
                title:'关注抖音',
                iconPath:'../../../assets/img/attentionIcon.png',
                path: '/package_first/pages/AttentionMethod/index',
                isJoin: false,
                isShow: true,
                type: 'tiktok'
            },
            {
                title:'学习视频',
                iconPath:'../../../assets/img/video.png',
                path: '/package_first/pages/LearningVideo/index',
                isJoin: false,
                isShow: true,
                type: 'video'
            },
            {
                title:'志愿者活动',
                iconPath:'../../../assets/img/volunteer.png',
                path: '/package_first/pages/VolunteerActivity/index',
                isJoin: false,
                isShow: true,
                type: 'volunteer_activity'
            }
        ],
        // 护河活动积分
        integratData: {}

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getIntegral()
    },

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

    },

    // 获取积分明细
    async getIntegral() {
        const openid = wx.getStorageSync('openid')
        const res = await integratDetail({openid})
        if(res.code === 0) {
            const list = res.data
            const integratData = {}
            list.forEach(item=> {
                integratData[item.name] = item.value
            })
            this.setData({integratData})
        }
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getIsApply()
    },

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

    },

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

    },

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

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        
    },
    getIsApply(){
        const entersList = this.data.entersList
        const {tenantId} = wx.getStorageSync('tenant')
        const openid = wx.getStorageSync('openid')
        if(tenantId !== 5 ){
            entersList[0].isShow = false
            this.setData({ entersList })
        }else{
            const data = { openid }
            api_getIsApply(data).then(res=>{
                let tikStatus = res.data
                entersList[0].isJoin = res.data == 2 ? true:false
                this.setData({ entersList,tikStatus })
            })
        }

    },
    goPage(e){
        const { path } = e.currentTarget.dataset
        // if(path=='/package_first/pages/AttentionMethod/index'){
        //     wx.navigateTo({
        //         url: '/package_first/pages/AttentionMethod/index?status='+this.data.tikStatus
        //     })
        // }else{
        //     wx.navigateTo({
        //         url: path
        //     })
        // }
        wx.navigateTo({
        url: path
        })
    },
    homepage(e){
        wx.switchTab({
            url: `/pages/FirstPage/index`,
        })
    }
})