js一个星期六天倒计时,星期日触发活动!

.js 

data: {
        t: 0,
        x: 0,
        f: 0,
        m: 0,
        styleid: 1,
    },
    
// 6天到计时
    timeDate: function() {
        var that = this
        var myDate = new Date();
        // console.log('得到今天到时间:' + myDate)
        var time = myDate.getTime();
        // console.log('得到当前时间到毫秒数:' + time)
        var day = myDate.getDay();
        // console.log('得到今天星期几:' + day)
        var day7 = 6 - day
        // console.log('离星期日还剩下几天:' + day7)
        var inta = 24 * 60 * 60 * 1000 * day7
        // console.log('离星期日还剩下整天的毫秒数:' + inta)
        if (day == 0) {
            // 今天是星期天
            that.setData({
                styleid: 1
            })
        } else {
            // 今天是123456
            var d = new Date();
            d.setHours(0);
            d.setMinutes(0);
            d.setSeconds(0);
            d.setMilliseconds(0);
            var ts = d.getTime()
            // console.log('今天0点的时间毫秒数:' + ts)
            var intc = ts + 24 * 60 * 60 * 1000 - time + inta
            // console.log('离星期日抽奖还剩下多少毫秒:' + intc)
            var t = parseInt(intc / (24 * 60 * 60 * 1000))
            // console.log('剩下的天数:' + t)
            var x = parseInt(intc / (60 * 60 * 1000) - (t * 24))
            // console.log('剩下的小时:' + x)
            var f = parseInt(intc / (60 * 1000) - (t * 24 * 60) - (x * 60))
            // console.log('剩下的分钟:' + f)
            var m = parseInt(intc / 1000 - (t * 24 * 60 * 60) - (x * 60 * 60) - (f * 60))
            // console.log('剩下的秒:' + m)
            that.setData({
                t,
                x,
                f,
                m,
                styleid: 0,
               
            })
            setTimeout(function() {
                that.timeDate()
            }, 1000)
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.timeDate()
    },

.wxml 

    <view class='wrap clearfix'  wx:if="{{styleid == 0}}"  '>
        砸蛋倒计时: {{t}}天{{x}}小时{{f}}分钟{{m}}秒
    </view>
    <view class='wrap clearfix'  wx:if="{{styleid == 1}}"  >
        您还有{{sign_count}}次机会
    </view>

猜你喜欢

转载自blog.csdn.net/weixin_42187290/article/details/85844568