diff --git a/packageB/miniprogram_npm/mini-luck-draw/lucky-wheel/index.js b/packageB/miniprogram_npm/mini-luck-draw/lucky-wheel/index.js
index bbe9457..8621c98 100644
--- a/packageB/miniprogram_npm/mini-luck-draw/lucky-wheel/index.js
+++ b/packageB/miniprogram_npm/mini-luck-draw/lucky-wheel/index.js
@@ -181,6 +181,7 @@ var _utils = __webpack_require__(1);
Component({
properties: {
+ hiddenCanvas: { type: Boolean, value: false},
width: { type: String, value: '600rpx' },
height: { type: String, value: '600rpx' },
blocks: { type: Array, value: [] },
diff --git a/packageB/miniprogram_npm/mini-luck-draw/lucky-wheel/index.wxml b/packageB/miniprogram_npm/mini-luck-draw/lucky-wheel/index.wxml
index 2a1d7a6..4fce5a5 100644
--- a/packageB/miniprogram_npm/mini-luck-draw/lucky-wheel/index.wxml
+++ b/packageB/miniprogram_npm/mini-luck-draw/lucky-wheel/index.wxml
@@ -1,6 +1,7 @@
diff --git a/packageB/pages/luckactivity/index/index.wxss b/packageB/pages/luckactivity/index/index.wxss
index 4b424b8..0c76dbb 100644
--- a/packageB/pages/luckactivity/index/index.wxss
+++ b/packageB/pages/luckactivity/index/index.wxss
@@ -155,7 +155,7 @@ page {
}
.btn {
- font-size: 24rpx;
+ font-size: 28rpx;
padding: 12rpx 30rpx;
border-radius: 8rpx;
text-align: center;
diff --git a/packageB/pages/luckactivity/luckinfo/luckinfo.js b/packageB/pages/luckactivity/luckinfo/luckinfo.js
index 9a0bedf..331100a 100644
--- a/packageB/pages/luckactivity/luckinfo/luckinfo.js
+++ b/packageB/pages/luckactivity/luckinfo/luckinfo.js
@@ -3,6 +3,12 @@ let self = null;
Page({
data: {
+ start: false,
+ list: null,
+ isLoading: false, // 检测是否已经发送请求,防止重复发送请求
+ noMore: false, // 检测是否有更多数据,true为没有更多数据,false为还有数据
+ pageNum: 1, // 当前页数
+
prizes: [
{ fonts: [{ text: '积分', top: '18%', wordWrap:false, fontColor: 'transparent'}],
imgs: [
@@ -97,8 +103,8 @@ Page({
// }
{
radius: '60rpx',
- background: 'black',
- pointer: true,
+ // background: 'black',
+ // pointer: true,
imgs: [{
src: 'http://201442.image.myqcloud.com/201442/0/b29290ec-aeb3-40e9-9444-8f15fd9acda3/original',
width: '188rpx',
@@ -110,12 +116,15 @@ Page({
},
onLoad(options) {
- console.log('options', options);
self = this;
this.data.options = options;
+ wx.setNavigationBarTitle({
+ title: options.title,
+ });
app.isLogin().then(function(data) {//进入页面前已经授权登录成功
self.setData({
userInfo: data,
+ imghost: app.globalData.setting.imghost,
});
});
},
@@ -124,44 +133,51 @@ Page({
if(app.globalData.userInfo) {
if(!this.data.isLogin) {
- console.log('gl', app.globalData);
-
this.setData({
userInfo: app.globalData.userInfo,
imghost: app.globalData.setting.imghost,
isLogin: true,
});
+ console.log('imghost', this.data.imghost);
let user_id = app.globalData.userInfo.user_id;
let store_id = app.globalData.setting.stoid;
let id = this.data.options.id;
let url = `/api/weshop/marketing/marketingLuckForm/getLuckInfo/${store_id}/${id}/${user_id}`;
- console.log('url', url);
+
+
app.request.get(url, {
success: function(res) {
- // self.setData({
- // details: res.data.data
- // });
- console.log('res****', res.data.data);
- // let basic = res.data.data;
-
- // self.setData({
- // basic,
- // });
+ if(res.data.code == 0) {
+ self.setData({
+ luckInfo: res.data.data,
+ });
+ } else {
+ wx.showToast({
+ title: res.data.msg,
+ icon: 'none',
+ });
+ self.data.msg = res.data.msg;
+ };
- // if(basic.template_type == 1) { //获取模板
- // let url = `/api/weshop/marketing/marketingLuckTemplate/get/${store_id}/${basic.template_id}`;
- // app.request.get(url, {
-
- // success: function(res) {
- // // console.log('prizes//////', res.data.data);
- // // self.setData({
- // // prizes: res.data.data.pageData
- // // });
- // },
-
- // });
- // };
+ console.log('luckInfo', res.data.data);
+ let luckInfo = res.data.data;
+ let imghost = self.data.imghost;
+ if(luckInfo.template_type == 1) { //获取模板
+ let url = `/api/weshop/marketing/marketingLuckTemplate/get/${store_id}/${luckInfo.template_id}`;
+ app.request.get(url, {
+ success: function(res) {
+ console.log('prizes//////', res.data.data);
+ self.setData({
+ template: res.data.data,
+ bannerUrl: imghost + res.data.data.bannerUrl, //背景图
+ 'blocks[0].imgs[0].src': imghost + res.data.data.wheelBaseUrl, //转盘
+ 'buttons[0].imgs[0].src': imghost + res.data.data.wheelPointerUrl, //指针
+ });
+ },
+ });
+ };
+
},
});
@@ -172,10 +188,14 @@ Page({
luck_formid: id,
},
success: function(res) {
- // console.log('res//////', res.data.data.pageData);
+
+ let award = res.data.data.pageData;
self.setData({
- prizes: res.data.data.pageData
+ award,
});
+ console.log('award', award);
+ self.prizeLayout(award);
+
},
});
@@ -183,33 +203,552 @@ Page({
};
},
+ // 设置转盘奖品布局
+ prizeLayout(award) {
+ let prizes = [];
+ let length = award.length;
+ let thx = {fonts: [{ text: '谢谢\n参与', top: '18%', wordWrap:false, fontColor: 'rgba(0,0,0,.5)'}]};
+
+ if(length == 1) {
+ [0,2,4,6].map(function(item, index) {
+ prizes[item] = {
+ id: award[0].id,
+ fonts: [{ text: award[0].luck_goods_name, top: '18%', wordWrap:false, fontColor: 'transparent'}],
+ imgs: [
+ {
+ src: self.prizeSrc(award[0].lbtype),
+ width: '135rpx',
+ height: '107rpx',
+ top: '12%',
+ }
+ ],
+ };
+ });
+
+ [1,3,5,7].map(function(item, index) {
+ prizes[item] = thx;
+ });
+
+ this.data.thxIndexArr = [1,3,5,7];
+ };
+
+ if(length == 2) {
+ [0,4].map(function(item, index) {
+ prizes[item] = {
+ id: award[0].id,
+ fonts: [{ text: award[0].luck_goods_name, top: '18%', wordWrap:false, fontColor: 'transparent'}],
+ imgs: [
+ {
+ src: self.prizeSrc(award[0].lbtype),
+ width: '135rpx',
+ height: '107rpx',
+ top: '12%',
+ }
+ ],
+ };
+ });
+
+ [2,6].map(function(item, index) {
+ prizes[item] = {
+ id: award[1].id,
+ fonts: [{ text: award[1].luck_goods_name, top: '18%', wordWrap:false, fontColor: 'transparent'}],
+ imgs: [
+ {
+ src: self.prizeSrc(award[1].lbtype),
+ width: '135rpx',
+ height: '107rpx',
+ top: '12%',
+ }
+ ],
+ };
+ });
+
+ [1,3,5,7].map(function(item, index) {
+ prizes[item] = thx;
+ });
+ this.data.thxIndexArr = [1,3,5,7];
+ };
+
+
+ if(length == 3) {
+ [0,4].map(function(item, index) {
+ prizes[item] = {
+ id: award[0].id,
+ fonts: [{ text: award[0].luck_goods_name, top: '18%', wordWrap:false, fontColor: 'transparent'}],
+ imgs: [
+ {
+ src: self.prizeSrc(award[0].lbtype),
+ width: '135rpx',
+ height: '107rpx',
+ top: '12%',
+ }
+ ],
+ };
+ });
+
+ [1,5].map(function(item, index) {
+ prizes[item] = {
+ id: award[1].id,
+ fonts: [{ text: award[1].luck_goods_name, top: '18%', wordWrap:false, fontColor: 'transparent'}],
+ imgs: [
+ {
+ src: self.prizeSrc(award[1].lbtype),
+ width: '135rpx',
+ height: '107rpx',
+ top: '12%',
+ }
+ ],
+ };
+ });
+
+ [2,6].map(function(item, index) {
+ prizes[item] = {
+ id: award[2].id,
+ fonts: [{ text: award[2].luck_goods_name, top: '18%', wordWrap:false, fontColor: 'transparent'}],
+ imgs: [
+ {
+ src: self.prizeSrc(award[2].lbtype),
+ width: '135rpx',
+ height: '107rpx',
+ top: '12%',
+ }
+ ],
+ };
+ });
+
+ [3,7].map(function(item, index) {
+ prizes[item] = thx;
+ });
+
+ this.data.thxIndexArr = [3,7];
+ };
+
+
+ if(length == 4) {
+ [0,2,4,6].map(function(item, index) {
+ prizes[item] = {
+ id: award[index].id,
+ fonts: [{ text: award[index].luck_goods_name, top: '18%', wordWrap:false, fontColor: 'transparent'}],
+ imgs: [
+ {
+ src: self.prizeSrc(award[index].lbtype),
+ width: '135rpx',
+ height: '107rpx',
+ top: '12%',
+ }
+ ],
+ };
+ });
+
+ [1,3,5,7].map(function(item, index) {
+ prizes[item] = thx;
+ });
+
+ this.data.thxIndexArr = [1,3,5,7];
+ };
+
+ if(length == 5) {
+ [0,2,3,5,6].map(function(item, index) {
+ prizes[item] = {
+ id: award[index].id,
+ fonts: [{ text: award[index].luck_goods_name, top: '18%', wordWrap:false, fontColor: 'transparent'}],
+ imgs: [
+ {
+ src: self.prizeSrc(award[index].lbtype),
+ width: '135rpx',
+ height: '107rpx',
+ top: '12%',
+ }
+ ],
+ };
+ });
+
+ [1,4,7].map(function(item, index) {
+ prizes[item] = thx;
+ });
+
+ this.data.thxIndexArr = [1,4,7];
+ };
+
+ if(length == 6) {
+ prizes = award.map(function(item, index) {
+ return {
+ id: item.id,
+ fonts: [{ text: item.luck_goods_name, top: '18%', wordWrap:false, fontColor: 'transparent'}],
+ imgs: [
+ {
+ src: self.prizeSrc(item.lbtype),
+ width: '135rpx',
+ height: '107rpx',
+ top: '12%',
+ }
+ ],
+ };
+ });
+
+ prizes.push(thx);
+ prizes.splice(3, 0, thx);
+
+ this.data.thxIndexArr = [3,7];
+ };
+
+ console.log('prizes', prizes);
+
+ this.setData({
+ prizes,
+ });
+ },
+
+ // 根据lbtype指定奖品类别图标
+ prizeSrc(lbtype) {
+ let src = '';
+ let imghost = this.data.imghost;
+ switch(lbtype) {
+ case 1: { //积分
+ src = imghost + 'miniapp/images/luckDraw/jf.png';
+ break;
+ };
+ case 2: { //成长值
+ src = imghost + 'miniapp/images/luckDraw/czz.png';
+ break;
+ };
+ case 3: { //优惠券
+ src = imghost + 'miniapp/images/luckDraw/yhq.png';
+ break;
+ };
+ case 4: { //服务项目
+ src = imghost + 'miniapp/images/luckDraw/fw.png';
+ break;
+ };
+ case 5: { //赠品
+ src = imghost + 'miniapp/images/luckDraw/zp.png';
+ break;
+ };
+ case 6: { //礼包
+ src = imghost + 'miniapp/images/luckDraw/lb.png';
+ break;
+ };
+ };
+ return src;
+ },
+
+ // 获取抽奖结果匹配对应奖品在奖品列表里的所有索引号
+ luckyIndex(arr, target) {
+ var results=[],
+ len = arr.length,
+ pos = 0;
+ while(pos < len){
+ // pos = arr[pos].indexOf(target, pos);
+ if(arr[pos].id == target) {
+ results.push(pos);//找到就存储索引
+
+ };
+ pos+=1;//并从下个位置开始搜索
+ // if(pos === -1){//未找到就退出循环完成搜索
+ // break;
+ // };
+
+ }
+ // console.log('当前奖品列表', this.data.prizes);
+ // console.log('中奖结果在当前奖品列表中的索引', results);
+
+ return results;
+ },
+
start () {
- // 获取抽奖组件实例
- const $lucky = this.selectComponent('#myLucky')
- // 调用play方法开始旋转
- $lucky.play()
- // 用定时器模拟请求接口
- setTimeout(() => {
- // 3s 后得到中奖索引
- const index = Math.random() * 6 >> 0
- // 调用stop方法然后缓慢停止
- $lucky.stop(index)
- }, 3000)
+ if(!this.data.luckInfo) {
+ wx.showToast({
+ title: this.data.msg,
+ icon: 'none',
+ });
+ return;
+ };
+
+ if(this.data.luckInfo.user_LuckNumDay != 0) {
+ // console.log('start choujiang');
+ // let start = false;
+ if(!this.data.start) {
+ this.data.start = true;
+ // 获取抽奖组件实例
+ const $lucky = this.selectComponent('#myLucky');
+ // 调用play方法开始旋转
+ $lucky.play();
+
+ // 获取抽奖结果
+ app.request.post('/api/weshop/marketing/marketingLuckForm/startLuck', {
+ isShowLoading: false,
+ data: {
+ storeId: app.globalData.setting.stoid,
+ userId: app.globalData.userInfo.user_id,
+ LuckId: this.data.options.id,
+ },
+ success: function(res) {
+
+ // console.log('开始摇奖', res.data.data.id, res.data.data);
+ if(res.data.code == 0) {
+ self.setData({
+ 'luckInfo.user_LuckNumDay': self.data.luckInfo.user_LuckNumDay - 1
+ });
+ // console.log('请求成功', res.data.data);
+ let luckyId = res.data.data.id;
+ let indexArr = self.luckyIndex(self.data.prizes, luckyId);
+ // console.log('抽奖奖品id', luckyId);
+ // console.log('奖品列表', self.data.prizes);
+ // console.log('奖品对应的索引数组', indexArr);
+ let random = Math.random() * indexArr.length >> 0;
+ // console.log('random', random);
+ let index = indexArr[random];
+ setTimeout(() => {
+ $lucky.stop(index);
+ self.data.start = false;
+ }, 3000);
+
+
+ } else {
+ console.log('请求出错');
+ let thxIndexArr = self.data.thxIndexArr;
+ const random = Math.random() * thxIndexArr.length >> 0;
+ const index = thxIndexArr[random];
+ // console.log('谢谢参与数组', thxIndexArr);
+ // console.log('请求出错产生谢谢参与的随机数', index);
+ setTimeout(() => {
+ $lucky.stop(index);
+ self.data.start = false;
+ }, 3000);
+ };
+ },
+
+ fail: function() {
+
+ console.log('出错');
+ let thxIndexArr = self.data.thxIndexArr;
+ const random = Math.random() * thxIndexArr.length >> 0;
+ const index = thxIndexArr[random];
+ setTimeout(() => {
+ $lucky.stop(index);
+ self.data.start = false;
+ }, 3000);
+ },
+
+ });
+
+ }
+
+
+ } else {
+ wx.showToast({
+ title: '你今天的抽奖次数已用完啦!~',
+ icon: 'none',
+ });
+ };
+
},
end (event) {
// 中奖奖品详情
- console.log(event.detail)
+ // console.log('zjiangla~~',event.detail.fonts[0].text.replace('\n',''));
+ let resultTitle = event.detail.fonts[0].text.replace('\n','');
+ this.setData({
+ hiddenCanvas: true,
+ showResult: true,
+ showMask: true,
+ resultTitle,
+ });
},
showPopup() {
this.setData({
- showPopup: true,
+ list: null,
+ pageNum: 1,
+ noMore: false,
+ });
+ this.getData(true, '/api/weshop/marketing/marketingLuckRecord/page', {
+ store_id: app.globalData.setting.stoid,
+ user_id: app.globalData.userInfo.user_id,
+ luck_formid: this.data.options.id,
+ luck_state: 1,
+ pageSize: 50,
+ }).then(function(res) {
+ self.setData({
+ showPopup: true,
+ showMask: true,
+ hiddenCanvas: true,
+ // record: self.data.list.pageData,
+ });
});
+ // app.request.get('/api/weshop/marketing/marketingLuckRecord/page', {
+ // // isShowLoading: false,
+ // data: {
+ // store_id: app.globalData.setting.stoid,
+ // user_id: app.globalData.userInfo.user_id,
+ // luck_formid: this.data.options.id,
+ // luck_state: 1
+ // },
+ // success: function(res) {
+ // // console.log('中奖记录', res.data.data);
+ // if(res.data.code == 0) {
+ // self.setData({
+ // showPopup: true,
+ // showMask: true,
+ // hiddenCanvas: true,
+ // record: self.data.list.pageData,
+ // });
+
+
+ // };
+ // },
+
+ // });
+
},
closePopup() {
this.setData({
showPopup: false,
+ showMask: false,
+ hiddenCanvas: false,
+ });
+ },
+
+ closeResult() {
+ this.setData({
+ showResult: false,
+ showMask: false,
+ hiddenCanvas: false,
+ });
+ },
+
+ loadmore() {
+ this.scrollToLower('/api/weshop/marketing/marketingLuckRecord/page', {
+ store_id: app.globalData.setting.stoid,
+ user_id: app.globalData.userInfo.user_id,
+ luck_formid: this.data.options.id,
+ luck_state: 1,
+ pageSize: 50,
+ });
+ },
+
+
+ /**
+ * 请求数据
+ */
+ getData: function(isInit, url, data) {
+ let p = app.request.promiseGet(url, {
+ data: data,
+ isShowLoading: true,
+ })
+ .then(function(res) {
+ if(res.data.code == 0) {
+
+ self.setData({
+ isLoading: false
+ });
+
+ if(isInit) {// 第一次加载
+ self.setData({
+ list: res.data.data
+ });
+ } else {
+ self.setData({
+ 'list.pageData': self.data.list.pageData.concat(res.data.data.pageData)
+ });
+ };
+
+ if((res.data.data.pageData.length == 0) || (res.data.data.pageSize * res.data.data.page >= res.data.data.total)) {
+ self.setData({
+ noMore: true
+ });
+ };
+
+ } else {
+ self.setData({
+ 'list.pageData': []
+ });
+ };
+
+ });
+
+ return p;
+ },
+
+
+ /**
+ * 上拉加载
+ */
+ scrollToLower(url, requestData) {
+ // 数据总量
+ let total = this.data.list.total;
+ // 单页最大数据量
+ let pageSize = this.data.list.pageSize;
+ // 如果数据总量不为0且小于或等于单页最大数据量,说明数据已全部加载,显示‘没有更多了’
+ if((total != 0)&&(total <= pageSize)) {
+ this.setData({
+ noMore: true
+ });
+ };
+
+ if(!this.data.isLoading && !this.data.noMore) {
+ this.setData({
+ isLoading: true,
+ pageNum: this.data.pageNum + 1
+ });
+ requestData.page = this.data.pageNum;
+ this.getData(false, url, requestData);
+ };
+ },
+
+
+ goto(e) {
+ let url = '';
+ let type = e.currentTarget.dataset.type;
+ switch(type) {
+ case 1: {
+ url = '/pages/user/integral/integral';
+ break;
+ };
+ case 2: {
+ url = '/pages/user/grow_value/grow_value';
+ break;
+ };
+ case 3: {
+ url = '/pages/user/coupons/coupons';
+ break;
+ };
+ case 4: {
+ url = '/pages/user/my_service/i_service';
+ break;
+ };
+ case 6: {
+ url = '/packageA/pages/myGift/myGift';
+ break;
+ };
+ };
+ app.goto(url);
+ },
+
+ showQr(e) {
+ let store_id = app.globalData.setting.stoid;
+ let id = e.currentTarget.dataset.id;
+ let url = `/api/weshop/marketing/marketingLuckList/updateGoodsVerifyCode/${store_id}/${id}`;
+ app.request.put(url, {
+ success: function(res) {
+ if(res.data.code == 0) {
+ let data = res.data.data;
+ let barcode = self.selectComponent("#qrcode");
+ barcode.open({val: data});
+ self.setData({
+ hiddenCanvas: true,
+ showPopup: false,
+ });
+ };
+ },
+
+ });
+ },
+
+ closeCode() {
+ this.setData({
+ hiddenCanvas: false,
+ showMask: false,
});
},
})
\ No newline at end of file
diff --git a/packageB/pages/luckactivity/luckinfo/luckinfo.json b/packageB/pages/luckactivity/luckinfo/luckinfo.json
index 1999b3f..18c1e3f 100644
--- a/packageB/pages/luckactivity/luckinfo/luckinfo.json
+++ b/packageB/pages/luckactivity/luckinfo/luckinfo.json
@@ -1,6 +1,8 @@
{
"usingComponents": {
- "lucky-wheel":"/packageB/miniprogram_npm/mini-luck-draw/lucky-wheel/index"
+ "lucky-wheel":"/packageB/miniprogram_npm/mini-luck-draw/lucky-wheel/index",
+ "qrcode": "/components/qr_code/qr_code",
+ "nodata": "/components/nodata/nodata"
},
"enablePullDownRefresh": false,
"navigationBarTitleText": "幸运大转盘"
diff --git a/packageB/pages/luckactivity/luckinfo/luckinfo.wxml b/packageB/pages/luckactivity/luckinfo/luckinfo.wxml
index 6a0939f..07e1285 100644
--- a/packageB/pages/luckactivity/luckinfo/luckinfo.wxml
+++ b/packageB/pages/luckactivity/luckinfo/luckinfo.wxml
@@ -1,37 +1,44 @@
+
+
+
-
- 今天你还有 3 次抽奖机会
+
+
+
+
+ 今天你还有 {{filter.show_default(luckInfo.user_LuckNumDay, '0')}} 次抽奖机会
-
-
+
+
-
+
-
+
- {{item.luck_goods_name}}
-
+ {{item.luck_goods_name}}
+
价值:{{item.luck_goods_price}}
数量:{{item.luck_goods_qty}}
@@ -41,7 +48,7 @@
-
+
{{basic.remark}}
@@ -98,7 +105,7 @@
- 提供技术支持
+ 提供技术支持
@@ -107,40 +114,52 @@