123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- // share/pages/activity/activity.js
- const app = getApp();
- const utils = require("../../../utils/http");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- imgUrl:app.globalData.imgUrl,
- loginFlag: false,
- canIUseGetUserProfile: false,
- showWinning: true,
- showNoWinning: true,
- showNoCount: true,
- companyobj: {},
- shareobj: {},
- turntableDetail: {},
- prizesImage: '',
- prizesText: '',
- actid: '',
- textContent: '',
- prizesContent: '',
- clientype: '',
- uploadText: '截图上传',
- lottery: 0,
- blocks: [{
- padding: '30px',
- imgs: [{
- src: 'https://o.nczyzs.com/xcx/ciecleground.png',
- width: '650rpx',
- height: '650rpx',
- rotate: false,
- top: '14rpx'
- }]
- }],
- prizes: [],
- buttons: [{
- radius: '50px',
- pointer: true,
- imgs: [{
- src: 'https://o.nczyzs.com/xcx/roundcircle.png',
- width: '100%',
- top: '-130%'
- }],
- fonts: [{
- text: '抽奖',
- top: '-20px',
- fontSize: '24px',
- fontColor: '#ffffff'
- }, {
- text: '剩余3次',
- top: '10px',
- fontSize: '12px',
- fontColor: '#ffffff'
- }]
- }
- ],
- },
- start() {
- if (!this.data.prizes.length) {
- wx.showToast({
- title: '没有奖品,无法抽奖',
- icon: 'none'
- })
- return;
- }
- if (this.data.lottery <= 0) {
- this.setData({
- showNoCount: false
- })
- return;
- }
- // 获取抽奖组件实例
- const child = this.selectComponent('#myLucky')
- // 调用play方法开始旋转
- child.$lucky.play()
- // 用定时器模拟请求接口
- setTimeout(() => {
- var that = this;
- utils.$post({
- url: app.globalData.webUrl + 'api/lottery/user_lottery',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- actid: that.data.actid
- },
- success: function (res) {
- let data = res.data.data;
- if (res.data.code == '0') {
- let lotteryCount = that.data.lottery - 1;
- that.setData({
- lottery: lotteryCount
- })
- that.setsurplusCount(that.data.lottery);
- // 3s 后得到中奖索引 (假设抽到第0个奖品)
- if (data == -1) {
- const index = 0
- // 调用stop方法然后缓慢停止
- child.$lucky.stop(index)
- } else {
- const index = that.getWinningPrizeIndex(data);
- // 调用stop方法然后缓慢停止
- child.$lucky.stop(index)
- }
- } else {
- child.$lucky.stop(0)
- }
- }
- })
- }, 3000)
- },
- end(event) {
- // 中奖奖品详情
- let data = event.detail.fonts[0];
- if (data.id == '111') {
- this.setData({
- showNoWinning: false,
- })
- } else {
- let imageData = event.detail.imgs[0];
- this.setData({
- showWinning: false,
- prizesImage: imageData.src,
- prizesText: data.text
- })
- }
- },
- againPlayTurntable() {
- this.setData({
- showWinning: true,
- showNoWinning: true,
- showNoCount: true,
- })
- this.start();
- },
- getWinningPrizeIndex(prizesId) {
- let index = 0;
- this.data.prizes.forEach((v, i) => {
- if (v.fonts[0].id == prizesId) {
- index = i;
- }
- })
- return index;
- },
- copyTextContent(e) {
- wx.setClipboardData({
- data: e.currentTarget.dataset.text,
- success: function (res) {
- console.log(res)
- },
- fail: function (err) {
- console.log(err)
- }
- })
- },
- cutUpload() {
- let that = this;
- if (this.data.uploadText == '已截图上传') {
- wx.showToast({
- title: '只能截图上传一次',
- icon: 'none'
- })
- return;
- }
- wx.chooseMedia({
- count: 1,
- mediaType: ['image'],
- sourceType: ['album'],
- success: function (res) {
- console.log(res)
- let tempFilePath = res.tempFiles[0].tempFilePath;
- that.uploadImage(tempFilePath)
- }
- })
- },
- uploadImage(filePath) {
- let that = this;
- wx.uploadFile({
- url: app.globalData.webUrl + 'api/lottery/user_upimg',
- filePath: filePath,
- name: 'img',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- formData: {
- actid: this.data.actid
- },
- success: function (res) {
- let data = JSON.parse(res.data);
- if (data.code == 0) {
- that.setData({
- uploadText: '已截图上传'
- })
- that.addActivityUser();
- } else {
- wx.showToast({
- title: data.msg,
- icon: 'none'
- })
- }
- },
- fail: function (res) {
- console.log(res, '>>>')
- }
- })
- },
- closeMask(e) {
- this.setData({
- showWinning: true,
- showNoWinning: true,
- showNoCount: true
- })
- },
- preventEvent(e) { },
- setsurplusCount(count) {
- this.setData({
- buttons: [{
- radius: '50px',
- pointer: true,
- imgs: [{
- src: 'https://o.nczyzs.com/xcx/roundcircle.png',
- width: '100%',
- top: '-130%'
- }],
- fonts: [{
- text: '抽奖',
- top: '-20px',
- fontSize: '24px',
- fontColor: '#ffffff'
- }, {
- text: `剩余${count}次`,
- top: '10px',
- fontSize: '12px',
- fontColor: '#ffffff'
- }]
- }
- ]
- })
- },
- /**
- * 客户授权登录
- */
- login: function () {
- var that = this;
- wx.login({
- success: function (data) {
- if (data.errMsg == 'login:ok') {
- utils.$post({
- method: "POST", //TESTAPIURL APIURL/users/auth
- url: app.globalData.webUrl + 'api/users/code2session',
- data: {
- client_type: that.clientype,
- code: data.code,
- share: app.globalData.shareuserid
- },
- success: function (r) {
- if (r.data.code == '0') {
- app.globalData.sharepersonobj = r.data.share;
- app.globalData.token = r.data.token;
- that.setData({
- shareobj: app.globalData.sharepersonobj
- })
- if (r.data.user != null && (!!r.data.user.headimgurl && r.data.user.headimgurl != "" || !!r.data.user.nickname && r.data.user.nickname != "" && r.data.user.nickname != '游客')) {
- that.setData({
- datashow: true,
- loginFlag: false,
- employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
- })
- app.globalData.personMsg = r.data.user;
- app.globalData.userflag = false; //有个人信息
- var nickname = r.data.user.nickname;
- var phone = r.data.user.phone;
- app.globalData.phone = false; //没有手机号
- if (r.data.user.phone == '') {
- wx.hideLoading();
- app.globalData.phone = false; //没有手机号
- that.loginbox = that.selectComponent("#loginbox");
- that.loginbox.loginfun();
- } else {
- app.globalData.phone = true; //有手机号
- }
- that.unreadMsg();
- } else {
- wx.hideLoading();
- that.setData({
- loginFlag: true
- })
- }
- } else {
- setTimeout(function () {
- wx.hideLoading()
- }, 500)
- }
- }
- })
- }
- }
- })
- },
- unreadMsg: function () {
- this.addActivityUser();
- },
- addActivityUser() {
- var that = this;
- console.log(that.data.actid,app.globalData.currentUserId,app.globalData.shareuserid,'<<<活动ID')
- utils.$post({
- url: app.globalData.webUrl + 'api/lottery/add_user',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- actid: that.data.actid,
- empid: app.globalData.currentUserId
- },
- success: function (res) {
- let data = res.data.data;
- console.log(data,'>>>活动信息')
- if (res.data.code == '0') {
- that.setsurplusCount(data.user_data.lottery);
- that.setData({
- turntableDetail: data.act_data,
- lottery: data.user_data.lottery,
- prizes: data.act_data ? that.handleGoods(data.act_data.good) : [],
- prizesContent: data.act_data ? data.act_data.good.map(v => v.good_name).join('/') : '',
- uploadText: data.user_data.share_status == 1 ? '截图上传' : '已截图上传'
- })
- wx.setNavigationBarTitle({
- title: data.act_data.title,
- })
- that.getActivityInfo();
- } else {
- let msg = res.data.msg;
- wx.showModal({
- title: '大转盘提示',
- content: msg,
- showCancel: false,
- confirmText: '退出应用',
- success: () => {
- wx.exitMiniProgram();
- }
- })
- }
- }
- })
- },
- getActivityInfo() {
- var that = this;
- utils.$post({
- url: app.globalData.webUrl + 'api/lottery/user_detail_lukus',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- actid: that.data.actid
- },
- success: function (res) {
- let data = res.data.data;
- if (res.data.code == '0') {
- let str = that.setWinningString(data);
- that.setData({
- textContent: '中奖客户:' + str
- })
- }
- }
- })
- },
- setWinningString(data) {
- if (data.length > 3) {
- let client = data.slice(0, 3);
- return client.map(v => v.user.nickname).join(',');
- } else {
- return data.map(v => v.user.nickname).join(',');
- }
- },
- handleGoods(goodList) {
- let goods = goodList.map((v, i) => {
- return {
- fonts: [{
- text: v.good_name,
- top: '10%',
- id: v.id,
- 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: '#f0f0f0'
- })
- return goods;
- },
- sharecompany: function () {
- const that = this;
- utils.$post({
- url: app.globalData.webUrl + 'client/index/content_belong_company',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- client_type: app.globalData.clientype,
- uid: app.globalData.shareuserid
- },
- success: function (res) {
- if (res.data.code == '0') {
- app.globalData.companyobj=res.data.data;
- that.setData({
- companyobj: res.data.data
- })
- }
- },
- complete(res) {
- wx.hideLoading()
- }
- })
- },
- myWinning() {
- wx.navigateTo({
- url: '/pages/other/other?type=63&actid=' + this.data.actid,
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- if (options.actid) {
- this.setData({
- actid: options.actid
- })
- }
- if (options.empid) {
- app.globalData.currentUserId = options.empid
- }
- if (options.uid) {
- app.globalData.shareuserid = options.uid;
- }
- if (options.clientype) {
- this.setData({
- clientype: options.clientype
- })
- app.globalData.clientype = options.clientype;
- }
- if (wx.getUserProfile) {
- this.setData({
- canIUseGetUserProfile: true
- })
- }
- this.setData({
- imgUrl:app.globalData.imgUrl,
- })
- this.login();
- wx.hideHomeButton()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- })
|