var app = getApp()
Page({
    data: {
        type: 1,
        currentTab: 0,
        labelList: [
            '休闲',
            '免费'
        ],
        homelist: [],
        IMG_NAME: app.IMG_NAME
    },
    onLoad(options) {
        // 页面初始化 options为页面跳转所带来的参数
        wx.setNavigationBarTitle({
            title: options.name
        })
    },
    onShow(e) {
        let that = this
        // wx.setStorageSync('token', '535e73059d2f4301b78d05326e1a55d8')
        app.AjaxRequest('get', {
                'content-type': 'application/json',
                'Authorization': 'Bearer ' + app.Getopenid()
            }, '/activity/list', {},
            function (res) {
                if (res.code == 0) {
                    for (var i in res.rows) {
                        let day = res.rows[i].actBegin.slice(5, 7) + '月' + res.rows[i].actBegin.slice(8, 10) + '日'
                        res.rows[i].day = day
                    }
                    that.setData({
                        homelist: res.rows
                    })
                }
            })
    },
    //滑动切换
    swiperTab: function (e) {
        var that = this
        that.setData({
            currentTab: e.detail.current
        })
    },
    //点击切换
    clickTab: function (e) {
        var that = this
        if (this.data.currentTab === e.target.dataset.current) {
            return false
        } else {
            that.setData({
                currentTab: e.target.dataset.current
            })
        }
    },
    navDetail(e) {
        let that = this
        let index = e.currentTarget.dataset.index
        if (wx.getStorageSync('token')) {
            wx.navigateTo({
                url: '/pages/community/eventDetails/eventDetails?id=' + that.data.homelist[index].id
            })
        } else {
            app.getlogin()
        }
    }
})