Authored by bevishuang

更换抽奖接口

... ... @@ -3,14 +3,14 @@ import api from '../../../common/api';
export default {
signAward(param) {
return api.get({
url: '/AwardController/signAward',
url: '/NewAwardController/luckyDraw',//wechat /AwardController/signAward
data: param,
api: 'store'
});
},
getBrandPicInfos(param) {
return api.get({
url: '/AwardController/getBrandPicInfos',
url: '/NewAwardController/getBrandPicInfo',
data:param,
api: 'store'
});
... ...
... ... @@ -12,8 +12,7 @@ let app = getApp();
let yas;
let startBlock = {
path: '/static/images/activity/start_h@3x.png',
picPath: '/static/images/activity/start_h@3x.png'
path: '/static/images/activity/start_h@3x.png'
};
//请求返回后延迟时间
... ... @@ -43,7 +42,7 @@ Page({
userPrize: {
id: 0,
name: `未中奖`,
picPath: '很遗憾未中奖'
path: ''
}, // 签到后用户中奖信息
indexs: [0, 1, 2, 5, 8, 7, 6, 3],
... ... @@ -61,8 +60,6 @@ Page({
hasLocationSetting: res.authSetting['scope.userLocation'] || false
});
});
this.getLuckPostion();
},
onReady: function() {
return this.clockLoginEvent().then(res => {
... ... @@ -71,10 +68,10 @@ Page({
});
},
onShareAppMessage: function() {
return {
title: '我在有货MKT打卡签到居然领到了这个!快来试试你的运气!',
imageUrl: '/static/images/activity/banner-clock.jpg'
};
return {
title: '我在有货MKT打卡签到居然领到了这个!快来试试你的运气!',
imageUrl: '/static/images/activity/banner-clock.jpg'
};
},
//进入页面时缓慢切换
... ... @@ -86,7 +83,7 @@ Page({
if (index > 7) {
index = 0;
that.data.prizesList[3].color = COLORS[1];
that.data.prizesList[index].color = COLORS[1];
} else if (index != 0) {
let lastRealIndex = that.data.indexs[index - 1];
that.data.prizesList[lastRealIndex].color = COLORS[1];
... ... @@ -105,29 +102,27 @@ Page({
}
},
//点击抽奖按钮
clockLuck: function() {
clockLuck: function(position) {
var that = this;
//判断中奖位置格式
// if (that.data.luckPosition == null || isNaN(that.data.luckPosition) || that.data.luckPosition > 8) {
// wx.showModal({
// title: '提示',
// content: '请填写正确数值',
// showCancel: false,
// })
// return;
// }
//设置按钮不可点击
// that.setData({
// clickLuck: '',
// })
if (position == null || isNaN(position) || position > 7) {
wx.showModal({
title: '提示',
content: '请稍后再试!',
showCancel: false,
})
return;
}
//清空计时器
clearInterval(interval);
interval = null;
if(interval !== null){
clearInterval(interval);
interval = null;
}
var index = defaultIndex;;
// console.log(that.data.prizesList[0].color);
//循环设置每一项的透明度
interval = setInterval(function() {
... ... @@ -146,27 +141,18 @@ Page({
prizesList
})
index++;
}, intime);
}, intime);
setTimeout(function () {
return that.stop(that.data.luckPosition, index);
}, STOPTIME);
},
stop: function(which) {
stop: function (which, index) {
var that = this;
//清空计数器
clearInterval(interval);
//初始化当前位置
var current = -1;
var prizesList = that.data.prizesList; //that.data.color;
var colorIndexs = that.data.indexs;
for (var i = 0; i < colorIndexs.length; i++) {
let colorIndex = colorIndexs[i];
if (prizesList[colorIndex].color == 1) {
//实际viewID
current = i;
}
}
//下标从1开始
var index = current + 1;
interval = null;
console.log(which + "====" + index);
that.stopLuck(which, index, intime, 10);
},
/**
... ... @@ -189,10 +175,11 @@ Page({
that.data.prizesList[3].color = COLORS[1];
} else if (index != 0) {
let lastRealIndex = that.data.indexs[index - 1];
// console.log("lastRealIndex:" + lastRealIndex);
that.data.prizesList[lastRealIndex].color = COLORS[1];
// that.data.color[lastRealIndex] = COLORS[1]
}
let currentRealIndex = that.data.indexs[index];
// console.log("currentRealIndex:" + currentRealIndex);
that.data.prizesList[currentRealIndex].color = COLORS[0];
let prizesList = that.data.prizesList;
... ... @@ -239,39 +226,23 @@ Page({
if (res.code === 200) {
let prizesList = [];
let isSign = util.get(res, 'data.isSign', 'N') === 'Y';
if (isSign) {
let luckDrawRspBOList = res.data && res.data.luckDrawRspBOList || [];
luckDrawRspBOList.map(item => {
item.awardInfoBo = item.awardInfoBo || {};
prizesList.push({
name: item.awardInfoBo.name,
picPath: item.awardInfoBo.picPath,
path: item.awardInfoBo.picPath,
animationData: '',
color: COLORS[1]
});
return item;
});
} else {
let awardBrandPicInfos = res.data && res.data.awardBrandPicInfos || [];
let awardPicInfos = res.data && res.data.awardPicInfos || [];
awardPicInfos.map((item, index) => {
prizesList.push({
name: item.name,
picPath: item.path,
path: item.path,
color: COLORS[1]
});
return item;
let awardInfo = res.data && res.data.awardInfo || {}
let awardPicInfos = res.data && res.data.awardPicInfos || [];
awardPicInfos.map((item, index) => {
prizesList.push({
name: item.name,
id: item.id,
path: item.path,
color: COLORS[1]
});
}
return item;
});
prizesList.length && prizesList.splice(4, 0, startBlock);
this.setData({
awardInfo,
prizesList,
isBegin: isSign ? false : this.data.isBegin, // 如果已签到,则开始按钮不可单击
isSign: isSign
... ... @@ -337,7 +308,9 @@ Page({
// return Promise.resolve(false);
this.setData({ isUnderway: true });
this.setData({
isUnderway: true
});
// 签到之前再次查询是否已经签到过,防止登录接口延迟出现多次签到情况
return this.clockLoginEvent().then(res => {
if (util.get(res, 'data.isSign', 'N') === 'Y') {
... ... @@ -351,48 +324,35 @@ Page({
}).then(lres => {
//请求问题,此处提示,可以提示未中奖
if (lres.code !== 200) {
// 模拟网络请求时间 设为两秒
// setTimeout(function() {
// return that.stop(that.data.luckPosition);
// }, STOPTIME);
return this._showToast(lres);
}
//去签到,现在应该获取中奖位置
return clockModel.signAward({
longitude: lres.data.longitude,
latitude: lres.data.latitude,
position: this.data.luckPosition,
// position: this.data.luckPosition,
}).then(sres => {
//执行提示,是否中奖
if (sres.code !== 200) {
// setTimeout(function() {
// return that.stop(that.data.luckPosition);
// }, STOPTIME);
return this._showToast(sres);
}
this.clockLuck();
let userPrize = sres.data;
let luckID = userPrize.id;
yas.report('YB_SIGN_SUCCESS_L'); // 签到成功上报
let prizesList = this.data.prizesList;
let sdata = sres.data.luckDrawRspBOList || [];
let zindex = -1;
let userPrize = {};
sdata.length && sdata.splice(4, 0, startBlock);
sdata.map((item, index) => {
if (item.isLucky === 'Y') { // 从接口读取返回来的位置
prizesList.map((item, index) => {
if (item.id === luckID) { // 从接口读取返回来的位置
zindex = index;
Object.assign(prizesList[zindex], {
id: item.position,
name: item.awardInfoBo.name,
picPath: item.awardInfoBo.picPath,
// animationData: item.isLucky === 'Y' ? animationData : ''
this.setData({
luckPosition: index
});
userPrize = {
id: item.position,
name: `恭喜您获得${item.awardInfoBo.name}`,
picPath: item.awardInfoBo.picPath
};
this.clockLuck();
}
return item;
});
... ... @@ -419,11 +379,7 @@ Page({
return util.sleep(1000);
}).then(() => {
if (userPrize.id) {
// setTimeout(function() {
// return that.stop(that.data.luckPosition);
// }, STOPTIME);
this.setData({
// isResultDialog: true,
userPrize: userPrize
});
}
... ... @@ -446,14 +402,5 @@ Page({
this.setData({
isResultDialog: false
});
},
getLuckPostion: function() {
let index = Math.floor(Math.random() * 7);
let positiion = this.data.indexs[index];
console.log("index:" + index + "//postion:" + positiion);
this.setData({
luckPosition: positiion
});
}
});
\ No newline at end of file
... ...
... ... @@ -11,7 +11,7 @@
<view class="area-item z-index10" animation="{{item.animationData}}">
<view class="flip-block {{item.name ? 'flip-poker': ''}} {{isBegin || item.activity ? 'active': ''}} {{isRotatey? 'rotate-y' : ''}}">
<view class="overflow-hidden-block-start">
<image mode="widthFix" wx:if="{{item.picPath}}" src="{{helper.imgView(item.picPath, 100, 100)}}"></image>
<image mode="widthFix" wx:if="{{item.path}}" src="{{helper.imgView(item.path, 100, 100)}}"></image>
</view>
<my-login-page bindloginSuccessCallback="clockLoginEvent"></my-login-page>
<button wx:if="{{hasLocationSetting}}" class="form-sub" formType="submit" type="default" hover-class="none"></button>
... ... @@ -58,7 +58,7 @@
<view class="clock-result-content">
<view class="clock-result-icon">
<view class="overflow-hidden-block">
<image mode="widthFix" src="{{helper.image(userPrize.picPath, 180, 180)}}"></image>
<image mode="widthFix" src="{{helper.image(userPrize.path, 180, 180)}}"></image>
</view>
</view>
<text class="clock-result-p1 ellipsis">{{userPrize.name}}</text>
... ...