const app = getApp(); const util = require("../../../utils/util.js"); const card = require('../../../utils/card.js'); Page({ repeatClick: true, data: { // 导航头组件所需的参数 nvabarData: { showCapsule: 1, title: '积分抽奖', white: true, address: '' }, // 导航头的高度 height: app.globalData.height * 2 + 20, showRemark: false, couponContent: "¥ 2 优惠券", thinkImg: "http://pos.juweiyun.cn/373001/file/wechatApp%E8%B0%A2%E8%B0%A2%E5%8F%82%E4%B8%8E.png", pointImg: "http://pos.juweiyun.cn/373001/file/wechatApp200%E7%A7%AF%E5%88%86.png", couponImg: "http://pos.juweiyun.cn/373001/file/wechatApp%E5%88%B8.png", click: true, selectIndex: -1, dayCount: 0, pointValue: 0, pointFlag: 0 }, onLoad: function(options) { // util.setNavTitle4Color("积分抽奖", "#FF7C06", "#ffffff"); this.setData({ height: app.systemInfo.windowHeight * 2 + app.globalData.height * 2 + 200 }) this.load_lucky_draw_item(); }, load_lucky_draw_item: function() { var that = this; if (!app.globalData.groupId) { util.showWaring("缺少参数 groupId"); return; } card.memberActivity(function(success) { console.log(success); var result = success.data; if (result.status == 1) { var prizes = []; var index = 1; if (result.list.length >= 1) { var id = result.list[0].id; var dayCount = result.list[0].peopleDayCount; var totalCount = result.list[0].peopleTotalCount; var pointValue = result.list[0].pointValue; var pointFlag = result.list[0].pointFlag; that.load_lucky_draw_join_number(id, dayCount); for (var item of result.list[0].prizes) { var prize = item; prize.img = prize.type == 0 ? that.data.pointImg : prize.type == 2 ? that.data.couponImg : prize.type == 9 ? that.data.thinkImg : ""; prize.index = index; prizes.push(prize); index++; } that.setData({ prizes: prizes, totalCount: totalCount, id: id, dayCount: dayCount, count: dayCount, pointValue: pointValue, pointFlag: pointFlag }) if (result.list[0].ruleDesc) { that.setData({ ruleDesc: result.list[0].ruleDesc.split('\n') }) } } else { util.showWaring("暂时没有积分活动") that.setData({ count: 0 }) } } else { util.showWaring("暂时没有积分活动") that.setData({ count: 0 }) } }, function(error) { console.log(error); wx.showToast({ title: "网络连接不稳定, 请重试", icon: "none" }) }) }, load_lucky_draw_join_number: function(id, day) { var that = this; card.memberActivityJoinNumber(id, function(success) { var result = success.data; if (result.status == 1) { var count = 0; if (day - result.countDay > 0) { count = day - result.countDay } that.setData({ count: count, }) } }, function(error) { console.log(error); wx.showToast({ title: "网络连接不稳定, 请重试", icon: "none" }) }) }, lucky_draw: function() { var that = this; var count = that.data.count; console.log("----------", count); if (count <= 0) { util.showWaring("抽奖机会已经用完"); return; } if (!that.data.id) { util.showWaring("暂时没有积分活动"); return; } if (that.data.pointFlag != 1) { util.showWaring("此活动不是积分活动"); return; } console.log(that.repeatClick); if (that.repeatClick) { that.repeatClick = false; wx.showLoading({ title: '抽奖中!', }) that.setData({ count: that.data.count - 1 }) card.memberActivityLuckyDraw(that.data.id, function(success) { wx.hideLoading(); //重新加载抽奖次数 that.load_lucky_draw_join_number(that.data.id, that.data.dayCount); var result = success.data; console.log("----------------", result); if (result.status == 1) { var i = 1; var j = 1; var inter; var time = 100; inter = setInterval(function() { if (that.data.selectIndex != -1) { if (i == 50) { clearInterval(inter) that.setData({ index: that.data.selectIndex }) } else { if (j == 9) { j = 1; } that.setData({ index: j }) } } else { if (j == 9) { j = 1; } that.setData({ index: j }) } i++; j++; }, time); for (var item of that.data.prizes) { if (item.id == result.prizeId) { that.setData({ selectIndex: item.index }) setTimeout(function() { if (item.type != 9) { that.repeatClick = true; that.setData({ showRemark: true, couponContent: item.name, upWindowTitle: "获得了" + item.name }) } else { util.showWaring(item.name); } }, 5000) break; } } that.setData({ prizeId: result.prizeId, prizeNo: result.prizeNo }) } else { util.showWaring(result.message); } setTimeout(function(){ that.repeatClick = true; },5900) }, function(error) { that.repeatClick = true; wx.hideLoading(); console.log(error); wx.showToast({ title: "网络连接不稳定, 请重试", icon: "none" }) }) } }, my_know: function() { this.setData({ showRemark: false }) }, luckyDrawRecord: function() { wx.navigateTo({ url: 'luckyDrawRecord', }) }, onShow: function() { }, onHide: function() { }, onShareAppMessage: function() { return { title: '积分抽奖', path: '/pages/tabbar/launch' } } })