// customer/pages/activitydetail/activitydetail.js const app = getApp(); const utils = require("../../../utils/http"); let page = 1; Page({ /** * 页面的初始数据 */ data: { turntableDetail: {}, imgUrl:app.globalData.imgUrl, prizesText: '', blocks: [{ padding: '30px', imgs: [{ src: 'https://o.nczyzs.com/xcx/ciecleground.png', width: '650rpx', height: '650rpx', rotate: true, top: '14rpx' }] }], prizes: [{ fonts: [{ text: '0', top: '15%' }], background: '#FFFFFF' }, { fonts: [{ text: '1', top: '15%' }], background: '#FFD6B1' }, { fonts: [{ text: '2', top: '15%' }], background: '#FFFFFF' }, { fonts: [{ text: '3', top: '15%' }], background: '#FFD6B1' }, { fonts: [{ text: '4', top: '15%' }], background: '#FFFFFF' }, { fonts: [{ text: '5', top: '15%' }], background: '#FFD6B1' }, ], buttons: [{ radius: '50px', pointer: true, imgs: [{ src: 'https://o.nczyzs.com/xcx/roundcircle.png', width: '90%', top: '-115%' }], fonts: [{ text: '抽奖', top: '-38rpx', fontSize: '38rpx', fontColor: '#ffffff' }, { text: '剩余3次', top: '18rpx', fontSize: '24rpx', fontColor: '#ffffff' }] } ], }, start() { wx.showToast({ title: '只有客户才能参与', icon: 'none' }) return false; // 获取抽奖组件实例 const child = this.selectComponent('#myLucky') // 调用play方法开始旋转 child.$lucky.play() // 用定时器模拟请求接口 setTimeout(() => { // 3s 后得到中奖索引 (假设抽到第0个奖品) const index = 0 // 调用stop方法然后缓慢停止 child.$lucky.stop(index) }, 3000) }, end(event) { // 中奖奖品详情 console.log(event.detail) }, getTurntableDetail() { var that = this; utils.$post({ url: app.globalData.webUrl + 'api/lottery/act_detail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == '0') { that.setsurplusCount(res.data.data.lottery_num); that.setData({ turntableDetail: res.data.data, prizes: that.handleGoods(res.data.data.good), prizesText: res.data.data.good.map(v => v.good_name).join('/') }) } } }) }, handleGoods(goodList) { let goods = goodList.map((v, i) => { return { fonts: [{ text: v.good_name, top: '10%', id: v.actid, fontSize: '24rpx' }], imgs: [{ src: v.good_img || 'https://o.nczyzs.com/xcx/circlegift.png', width: '50rpx', height: '50rpx', top: '50%' }], background: i % 2 == 0 ? '#FFFFFF' : '#FFD6B1', } }); goods.splice(0, '', { fonts: [{ text: '谢谢参与', top: '10%', id: '111', fontSize: '24rpx', }], imgs: [{ src: 'https://o.nczyzs.com/xcx/circlegift.png', width: '50rpx', height: '50rpx', top: '50%' }], background: '#FFD6B1' }) return goods; }, /** * 设置抽奖次数 * @param {*} count */ setsurplusCount(count) { this.setData({ buttons: [{ radius: '50px', pointer: true, imgs: [{ src: 'https://o.nczyzs.com/xcx/roundcircle.png', width: '90%', top: '-115%' }], fonts: [{ text: '抽奖', top: '-38rpx', fontSize: '38rpx', fontColor: '#ffffff' }, { text: `剩余${count}次`, top: '18rpx', fontSize: '24rpx', fontColor: '#ffffff' }] } ], }) }, /** * 抽奖客户 */ lotteryClient() { wx.navigateTo({ url: '/pages/other/other?type=29&actid=' + this.data.turntableDetail.id, }) }, /** * 我的中奖客户 */ winningClient() { wx.showToast({ title: '只有客户才能查看', icon: 'none' }) }, /** * 员工转发活动记录 */ shareCountRecord() { var that = this; utils.$post({ url: app.globalData.webUrl + 'api/lottery/act_forward_log', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { actid: that.data.turntableDetail.id }, success: function (res) { if (res.data.code == '0') { console.log('成功') } } }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ imgUrl:app.globalData.imgUrl }) this.getTurntableDetail(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { this.shareCountRecord(); let uid = app.globalData.currentUserId ? app.globalData.currentUserId : app.globalData.personMsg.id; return { title: this.data.turntableDetail.title, imageUrl: '', path: '/share/pages/activity/activity?uid=' + uid + '&clientype=' + app.globalData.clientype + '&actid=' + this.data.turntableDetail.id, }; } })