// packageF/storeSign/storeSign/storeSign.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 日历
        year: "",
        month: "",
        m: "",
        w: "",
        show: false,
        intrShow: false,
        info: [],
        awardinfo: [],
        store_id: "",
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (options.id) {
            this.setData({
                store_id: options.id
            })
        }
        wx.setNavigationBarTitle({
            title: '门店签到',
        })
        this.getDataNum(1);
        this.getData();
    },
    showClose() {
        this.setData({
            intrShow: false,
            show: false
        })
    },
    showTap() {
        this.setData({
            intrShow: true
        })
    },
    goDetail() {
        wx.navigateTo({
            url: '/packageF/storeSign/storeSignDetail/storeSignDetail',
        })
    },
    getData() {
        let urlStr = app.getNetAddresss("plugin.store-attendance.frontend.dashboard.index");
        let json = {
            year: this.data.year,
            month: this.data.month,
            store_id: this.data.store_id
        };
        app._getNetWork({
            url: urlStr,
            data: json,
            success: (resdata) => {
                let res = resdata.data
                if (res.result == 1) {
                    this.setData({
                        info: res.data
                    })
                } else {
                    wx.showToast({
                        icon: 'none',
                        title: res.msg,
                        duration: 1500
                    });
                }
            },
            fail: function (res) {
                console.log(res);
            }
        });
    },
    attendance() {
        if (this.data.info.attended) {
            wx.showToast({
                title: '已签到',
                icon: 'none',
            })
            return
        }
        let urlStr = app.getNetAddresss("plugin.store-attendance.frontend.member.attendance");
        app._getNetWork({
            url: urlStr,
            data:{
                store_id:this.data.store_id
            },
            success: (resdata) => {
                let res = resdata.data
                if (res.result == 1) {
                    this.setData({
                        awardinfo: res.data.award,
                        show:true
                    })
                    this.getData();
                } else {
                    wx.showToast({
                        icon: 'none',
                        title: res.msg,
                        duration: 1500
                    });
                }
            },
            fail: function (res) {
                console.log(res);
            }
        });
    },
    getDataNum(num) {
        let date = new Date();
        let year = date.getFullYear();
        this.data.year = year;
        let month = date.getMonth() + num;
        this.data.month = month;
        let d = new Date(year, month, 0);
        this.data.m = d.getDate(); // 获取一个月多少天
        let wx = new Date(year, month - 1, 1); // 获取当月第一天是星期几
        let w1 = wx.getDay();
        this.data.w = w1 * 14.27;
        this.setData({
            w: this.data.w,
            m: this.data.m,
            month: this.data.month,
            year: this.data.year
        })
    },

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

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})