|
|
import {
|
|
|
request
|
|
|
} from "../../request/index.js";
|
|
|
var WxParse = require('../../wxParse/wxParse.js');
|
|
|
const a = getApp()
|
|
|
// pages/LuckDraw/LuckDraw.js
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
// 活动id
|
|
|
id: 0,
|
|
|
// 顾问id
|
|
|
advisers_id: 0,
|
|
|
// 抽奖总数据
|
|
|
indexData: '',
|
|
|
play: true,
|
|
|
// 活动详情富文本
|
|
|
content: '',
|
|
|
// 奖品列表
|
|
|
awardList: [],
|
|
|
DrawList: ['关于小象', '活动规则', '获奖记录'],
|
|
|
imagesUrl: a.globalData.baseUrl,
|
|
|
// 新增
|
|
|
titleName: '',
|
|
|
showBindPhone: false,
|
|
|
title: false,
|
|
|
mode: 'rect',
|
|
|
indicatorPos: 'bottomCenter',
|
|
|
effect3d: false,
|
|
|
// 轮播图-结束
|
|
|
|
|
|
user_id: 0, //顾问id
|
|
|
chou: {}, //抽奖结果
|
|
|
chouGui: {}, //抽奖活动规则
|
|
|
chouLog: [], //获奖名单
|
|
|
indexData: {},
|
|
|
show: false, //展示页面
|
|
|
boxCheck: false,
|
|
|
showShareAlert: false,
|
|
|
showDrawAlert: false, //抽奖次数用完提示弹框
|
|
|
//抽奖次数用完弹框
|
|
|
drawOutInfo: {
|
|
|
imgUrl: '../../static/image/tongzhi_icon.png',
|
|
|
alertTxt: '您的抽奖机会已经用完',
|
|
|
otherTxt: '下一次活动再试试',
|
|
|
share_num: 0,
|
|
|
btnMt: 22,
|
|
|
btnTxt: '好的'
|
|
|
},
|
|
|
getRequireInfo: {
|
|
|
imgUrl: '../../static/image/zhuyi_icon.png',
|
|
|
alertTxt: '请填写完整信息'
|
|
|
},
|
|
|
showActRule: false, //展示活动规则弹框
|
|
|
getSuccessInfo: {
|
|
|
imgUrl: '../../static/image/chenggong_icon.png',
|
|
|
alertTxt: '提交成功'
|
|
|
},
|
|
|
showGetSuccess: false, //展示领取成功提示弹框
|
|
|
showRequireAlert: false, //展示必填项提示弹框
|
|
|
|
|
|
showPickInfo: false, //展示填写领取信息弹框
|
|
|
|
|
|
showGetDraw: false, //抽奖获得红包弹框
|
|
|
//红包弹框
|
|
|
redPackAlert: {
|
|
|
bgImgUrl: '../../static/image/hongbaotanchuang_img.png',
|
|
|
bgPdTop: '92rpx',
|
|
|
bgImgWidth: '602rpx',
|
|
|
bgImgHeight: '825rpx',
|
|
|
infoWidth: '428rpx',
|
|
|
infoHeight: '444rpx',
|
|
|
infoPdTop: '300rpx',
|
|
|
content: [
|
|
|
'恭喜您,抽中10元红包',
|
|
|
'可在获奖记录查看'
|
|
|
],
|
|
|
time: '',
|
|
|
address: '',
|
|
|
btnList: [
|
|
|
/* {
|
|
|
btnName:'去提现',
|
|
|
btnWidth:'48%',
|
|
|
type:'navTo',
|
|
|
url:''
|
|
|
},*/
|
|
|
{
|
|
|
btnName: '去分享',
|
|
|
btnWidth: '100%',
|
|
|
type: 'share',
|
|
|
url: ''
|
|
|
}
|
|
|
]
|
|
|
|
|
|
},
|
|
|
showCouponDraw: false, //展示抵用券中奖
|
|
|
//抵扣券弹框
|
|
|
couponAlert: {
|
|
|
bgImgUrl: '../../static/image/diyongquan_img.png',
|
|
|
bgPdTop: '132rpx',
|
|
|
bgImgWidth: '602rpx',
|
|
|
bgImgHeight: '785rpx',
|
|
|
infoWidth: '424rpx',
|
|
|
infoHeight: '396rpx',
|
|
|
infoPdTop: '308rpx',
|
|
|
content: ['恭喜您,抽中1000元抵用券'],
|
|
|
time: '',
|
|
|
address: '',
|
|
|
btnList: [{
|
|
|
btnName: '去分享',
|
|
|
btnWidth: '100%',
|
|
|
type: 'share',
|
|
|
url: ''
|
|
|
/* btnName:'去领奖',
|
|
|
btnWidth:'100%',
|
|
|
type:'coupon',
|
|
|
url:'' */
|
|
|
}]
|
|
|
|
|
|
},
|
|
|
showSnackAlert: false, //展示零食大礼包
|
|
|
//零食大礼包弹框
|
|
|
snackAlert: {
|
|
|
bgImgUrl: '../../static/image/libao_img.png',
|
|
|
bgPdTop: '132rpx',
|
|
|
bgImgWidth: '602rpx',
|
|
|
bgImgHeight: '865rpx',
|
|
|
infoWidth: '424rpx',
|
|
|
infoHeight: '474rpx',
|
|
|
infoPdTop: '310rpx',
|
|
|
content: ['恭喜您,抽中零食大礼包'],
|
|
|
time: '领取时间:2020/05/05-2021/05/20',
|
|
|
address: '领取地址:天津市南开区长江道4s店',
|
|
|
btnList: [{
|
|
|
btnName: '去分享',
|
|
|
btnWidth: '100%',
|
|
|
type: 'share',
|
|
|
url: ''
|
|
|
/* btnName:'知道了',
|
|
|
btnWidth:'100%',
|
|
|
type:'close',
|
|
|
url:'' */
|
|
|
}]
|
|
|
|
|
|
},
|
|
|
showIntegralAlert: false, //展示积分
|
|
|
//积分弹框
|
|
|
integralAlert: {
|
|
|
bgImgUrl: '../../static/image/jifen_img_bg.png',
|
|
|
bgPdTop: '116rpx',
|
|
|
bgImgWidth: '602rpx',
|
|
|
bgImgHeight: '801rpx',
|
|
|
infoWidth: '424rpx',
|
|
|
infoHeight: '410rpx',
|
|
|
infoPdTop: '310rpx',
|
|
|
content: ['恭喜您,抽中10积分'],
|
|
|
time: '',
|
|
|
address: '',
|
|
|
btnList: [{
|
|
|
btnName: '去分享',
|
|
|
btnWidth: '100%',
|
|
|
type: 'share',
|
|
|
url: ''
|
|
|
/* btnName:'',
|
|
|
btnWidth:'100%',
|
|
|
type:'program',
|
|
|
url:'' */
|
|
|
}]
|
|
|
|
|
|
},
|
|
|
actPeopleList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
|
|
|
|
|
showActPeople: false, //展示活动弹框
|
|
|
avatar_arr: [],
|
|
|
colorAwardDefault: "url('../../static/image/bg_img_4.png')",
|
|
|
colorAwardSelect: "url('../../static/image/bg_img_5.png')",
|
|
|
indexSelect: 0, //被选中的奖品索引
|
|
|
isRunning: false, //是否正在抽奖
|
|
|
lun_arr: [], //奖品图片数组
|
|
|
guInfo: {},
|
|
|
// 选中的品牌和id
|
|
|
brand: '',
|
|
|
brandId: 0,
|
|
|
brand2: '',
|
|
|
brandId2: 0,
|
|
|
// 最新的抽奖次数
|
|
|
newchouNum: ''
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (e) {
|
|
|
wx.setStorageSync('drawId', e.id)
|
|
|
console.log(e, '传递的抽奖id')
|
|
|
if (e.id != undefined) {
|
|
|
this.setData({
|
|
|
id: e.id
|
|
|
})
|
|
|
this.getDrawList()
|
|
|
this.getAdvisers()
|
|
|
this.getnewchouNum()
|
|
|
this.addLiu()
|
|
|
}
|
|
|
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
this.setData({
|
|
|
brand: wx.getStorageSync('brand'),
|
|
|
brandId: wx.getStorageSync('brandId'),
|
|
|
brand2: wx.getStorageSync('brand2'),
|
|
|
brandId2: wx.getStorageSync('brandId2')
|
|
|
})
|
|
|
console.log(this.data.brand, this.data.brandId, '选中的品牌,抽奖页')
|
|
|
|
|
|
},
|
|
|
// 获取抽奖页数据
|
|
|
async getDrawList() {
|
|
|
let that = this
|
|
|
const {
|
|
|
data: {
|
|
|
data
|
|
|
}
|
|
|
} = await request({
|
|
|
url: 'api/h5/chouData',
|
|
|
data: {
|
|
|
id: that.data.id,
|
|
|
}
|
|
|
})
|
|
|
|
|
|
let countdownPer = parseFloat((data.all_time - data.sheng_time) / data.all_time).toFixed(2)
|
|
|
console.log(countdownPer, "剩余时间百分比")
|
|
|
console.log(data.all_time, data.sheng_time, '总时间和剩余时间')
|
|
|
that.setData({
|
|
|
indexData: data,
|
|
|
// 奖品列表
|
|
|
lun_arr: data.lun_arr,
|
|
|
content: data.detail,
|
|
|
countdownPer: countdownPer
|
|
|
})
|
|
|
|
|
|
WxParse.wxParse('content', 'html', that.data.content, that, 25);
|
|
|
if (that.data.lun_arr.length > 0) {
|
|
|
//奖品item设置
|
|
|
var awardList = [];
|
|
|
//间距,怎么顺眼怎么设置吧.
|
|
|
var topAward = 45;
|
|
|
var leftAward = 11;
|
|
|
for (var j = 0; j < 12; j++) {
|
|
|
if (j == 0) {
|
|
|
topAward = topAward;
|
|
|
leftAward = leftAward;
|
|
|
} else if (j < 4) {
|
|
|
topAward = topAward;
|
|
|
leftAward = leftAward + 132 + 12;
|
|
|
} else if (j < 7) {
|
|
|
leftAward = leftAward;
|
|
|
topAward = topAward + 132 + 8;
|
|
|
} else if (j < 10) {
|
|
|
leftAward = leftAward - 132 - 12;
|
|
|
topAward = topAward;
|
|
|
} else if (j < 13) {
|
|
|
leftAward = leftAward - 2;
|
|
|
topAward = topAward - 132 - 10;
|
|
|
}
|
|
|
var lun = that.data.lun_arr[j];
|
|
|
if (lun) {
|
|
|
awardList.push({
|
|
|
topAward: topAward,
|
|
|
leftAward: leftAward,
|
|
|
lun: lun
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
that.setData({
|
|
|
awardList: awardList
|
|
|
})
|
|
|
}
|
|
|
// 获取抽奖活动规则
|
|
|
request({
|
|
|
url: 'api/h5/chouGui',
|
|
|
data: {
|
|
|
id: that.data.id,
|
|
|
}
|
|
|
}).then(res => {
|
|
|
that.setData({
|
|
|
chouGui: res.data
|
|
|
})
|
|
|
})
|
|
|
// 获取抽奖活动数据
|
|
|
request({
|
|
|
url: 'api/h5/chouLog',
|
|
|
data: {
|
|
|
id: that.data.id,
|
|
|
}
|
|
|
}).then(res => {
|
|
|
that.setData({
|
|
|
chouLog: res.data.data.slice(0, 30)
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
//开始游戏
|
|
|
|
|
|
startGame: function () {
|
|
|
console.log(this.data.isRunning, this.data.sheng_time <= 0, this.data.indexData.sheng_time == -2, this.data.awardList.length != 12)
|
|
|
if (this.data.isRunning || this.data.sheng_time <= 0 || this.data.indexData.sheng_time == -2 || this.data.awardList.length != 12) return;
|
|
|
console.log('通过初始化')
|
|
|
console.log(this.data.isRunning, this.data.sheng_time <= 0, this.data.indexData.sheng_time == -2, this.data.awardList.length != 12)
|
|
|
|
|
|
if (this.data.newchouNum == 0) {
|
|
|
wx.showToast({
|
|
|
title: '非常抱歉,您本次活动抽奖机会已经用完啦',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
this.setData({
|
|
|
showDrawAlert: true
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
this.setData({
|
|
|
isRunning: true
|
|
|
})
|
|
|
console.log('启动抽奖')
|
|
|
//获取奖品
|
|
|
request({
|
|
|
url: 'api/h5/chou',
|
|
|
data: {
|
|
|
id: this.data.id,
|
|
|
}
|
|
|
}).then(res => {
|
|
|
this.setData({
|
|
|
chou: res.data.data
|
|
|
})
|
|
|
console.log(this.data.chou, '获取奖品')
|
|
|
})
|
|
|
|
|
|
var _this = this;
|
|
|
var indexSelect = 0;
|
|
|
var i = 300;
|
|
|
var rooNum = 0;
|
|
|
|
|
|
function show() {
|
|
|
rooNum++
|
|
|
indexSelect++
|
|
|
indexSelect = indexSelect % 12;
|
|
|
_this.setData({
|
|
|
indexSelect: indexSelect
|
|
|
})
|
|
|
// console.log(_this.data.indexSelect,'已选中')
|
|
|
if (rooNum == 20) {
|
|
|
i = 600
|
|
|
}
|
|
|
//这里我只是简单粗暴用y=30*x+200函数做的处理.可根据自己的需求改变转盘速度
|
|
|
if (rooNum > 20 && _this.data.lun_arr[indexSelect].id == _this.data.chou.id) {
|
|
|
console.log(_this.data.lun_arr[indexSelect].id, _this.data.chou.id, '停止条件')
|
|
|
// var contentTxt = ''
|
|
|
// var btn = {
|
|
|
// btnName: '去分享',
|
|
|
// btnWidth: '100%',
|
|
|
// type: 'share',
|
|
|
// url: ''
|
|
|
// }
|
|
|
// 分享获得抽奖次数?
|
|
|
// if (_this.data.chou.share_num > 0) {
|
|
|
// contentTxt = '分享至朋友圈可获得' + _this.chou.share_num + '次抽奖机会'
|
|
|
// } else {
|
|
|
// btn = {
|
|
|
// btnName: '去领奖',
|
|
|
// btnWidth: '100%',
|
|
|
// type: 'coupon',
|
|
|
// url: '/pages/myPrize/myPrize?id=1'
|
|
|
// }
|
|
|
// }
|
|
|
//获取最新的抽奖次数
|
|
|
// if (_this.data.chou.type_id == 1) {
|
|
|
// _this.data.indexData.chou_num--
|
|
|
// } else {
|
|
|
// request('/api/h5/chouNum', {
|
|
|
// id: _this.id
|
|
|
// }).then((res) => {
|
|
|
// _this.data.indexData.chou_num = res.data.num
|
|
|
// })
|
|
|
// }
|
|
|
//抵用券
|
|
|
if (_this.data.chou.type_id == 2) {
|
|
|
_this.setData({
|
|
|
showCouponDraw: true
|
|
|
})
|
|
|
// let cc0 = _this.data.couponAlert.content[0]
|
|
|
// let cc1 = _this.data.couponAlert.content[1]
|
|
|
// let cbtn = _this.data.couponAlert.btnList[0]
|
|
|
// _this.setData({
|
|
|
// showCouponDraw : true,
|
|
|
// cc0:'恭喜您,抽中' + _this.data.chou.name,
|
|
|
// cc1:contentTxt,
|
|
|
// cbtn:btn
|
|
|
// })
|
|
|
// console.log(_this.data.couponAlert,'抵用券获奖信息')
|
|
|
}
|
|
|
//红包
|
|
|
if (_this.data.chou.type_id == 1) {
|
|
|
_this.setData({
|
|
|
showCouponDraw: true
|
|
|
})
|
|
|
}
|
|
|
//零食大礼包
|
|
|
if (_this.data.chou.type_id == 4) {
|
|
|
_this.setData({
|
|
|
showCouponDraw: true
|
|
|
})
|
|
|
}
|
|
|
//积分
|
|
|
if (_this.data.chou.type_id == 3) {
|
|
|
_this.setData({
|
|
|
showCouponDraw: true
|
|
|
})
|
|
|
}
|
|
|
_this.setData({
|
|
|
isRunning: false
|
|
|
})
|
|
|
} else {
|
|
|
// console.log(show,i,'定时器')
|
|
|
setTimeout(show, i);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
show();
|
|
|
this.getnewchouNum()
|
|
|
},
|
|
|
// 获取顾问数据
|
|
|
async getAdvisers() {
|
|
|
let that = this
|
|
|
const {
|
|
|
data: {
|
|
|
data
|
|
|
}
|
|
|
} = await request({
|
|
|
url: 'api/h5/guInfo',
|
|
|
data: {
|
|
|
user_id: that.data.advisers_id,
|
|
|
}
|
|
|
})
|
|
|
// console.log(data);
|
|
|
// 数据为空时不显示顾问区
|
|
|
that.setData({
|
|
|
|
|
|
})
|
|
|
},
|
|
|
// 浏览量+1
|
|
|
async addLiu() {
|
|
|
let that = this
|
|
|
await request({
|
|
|
url: 'api/h5/addLiu',
|
|
|
data: {
|
|
|
id: that.data.id
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
// 获取最新的抽奖次数
|
|
|
async getnewchouNum() {
|
|
|
let that = this
|
|
|
const {
|
|
|
data: {
|
|
|
data
|
|
|
}
|
|
|
} = await request({
|
|
|
url: 'api/h5/chouNum',
|
|
|
data: {
|
|
|
id: that.data.id,
|
|
|
}
|
|
|
})
|
|
|
console.log(data, '最新抽奖次数');
|
|
|
that.setData({
|
|
|
newchouNum: data.num
|
|
|
})
|
|
|
},
|
|
|
// 返回顶部
|
|
|
returnTop() {
|
|
|
wx.pageScrollTo({
|
|
|
scrollTop: 0
|
|
|
});
|
|
|
},
|
|
|
// 弹出框--参与活动头像
|
|
|
showActpeo() {
|
|
|
this.setData({
|
|
|
showActPeople: true
|
|
|
})
|
|
|
},
|
|
|
// // 弹出框--关闭参与活动头像
|
|
|
closeActpeo() {
|
|
|
this.setData({
|
|
|
showActPeople: false
|
|
|
})
|
|
|
},
|
|
|
// 弹出--规则 介绍
|
|
|
clickActRule(e) {
|
|
|
let type = e.currentTarget.dataset.idx
|
|
|
|
|
|
if (type == 0) {
|
|
|
this.setData({
|
|
|
titleName: '关于小象',
|
|
|
showActRule: true
|
|
|
})
|
|
|
} else if (type == 1) {
|
|
|
this.setData({
|
|
|
titleName: '活动规则',
|
|
|
showActRule: true
|
|
|
})
|
|
|
} else if (type == 2) {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/myPrize/myPrize?drawid=' + this.data.id,
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
// 弹出--关闭规则介绍
|
|
|
clickCloseRule() {
|
|
|
this.setData({
|
|
|
showActRule: false
|
|
|
})
|
|
|
},
|
|
|
// 弹出--获取获奖人信息
|
|
|
bindPrize() {
|
|
|
this.setData({
|
|
|
showPickInfo: true
|
|
|
})
|
|
|
},
|
|
|
// 关闭获奖弹窗
|
|
|
f_d_a: function (e) {
|
|
|
console.log(e)
|
|
|
this.setData({
|
|
|
showCouponDraw: e.detail
|
|
|
})
|
|
|
},
|
|
|
// 关闭获取信息弹窗
|
|
|
p_z: function (e) {
|
|
|
|
|
|
this.setData({
|
|
|
showPickInfo: e.detail
|
|
|
})
|
|
|
},
|
|
|
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|