123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- // share/pages/eggsactivity/eggsactivity.js
- const app = getApp();
- const utils = require("../../../utils/http");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- loginFlag: false,
- canIUseGetUserProfile: false,
- phoneFlag:false,
- showWinning: true,
- showNoCount: true,
- showNoWinning: true,
- active: '',
- activeEggs: '',
- prizesContent: '',
- textContent: '',
- clientype: '',
- companyobj: {},
- activityDetail: {},
- egg_status_log: [],
- prizesObject: {},
- uploadText: '截图上传',
- lottery: 0,
- },
- handleClick(e) {
- let currentData = e.currentTarget.dataset;
- var that = this;
- if (currentData.status == true) {
- wx.showToast({
- title: '金蛋已砸开',
- icon: 'none'
- })
- return;
- }
- if (this.data.lottery == 0) {
- this.setData({
- showNoCount: false,
- })
- return;
- }
- this.setData({
- active: currentData.id,
- })
- utils.$post({
- url: app.globalData.webUrl + 'api/lottery/user_lottery',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- actid: that.data.actid,
- eggid: that.data.active
- },
- success: function (res) {
- let data = res.data.data;
- console.log(res,'<<<砸金蛋')
- if (res.data.code == '0') {
- //抽奖次数减1
- that.setData({
- lottery: that.data.lottery - 1
- })
- if (data == -1) {
- setTimeout(() => {
- that.setData({
- showNoWinning: false,
- })
- }, 500)
- that.changeGoldenEggStatus(currentData, '空空如也')
- } else {
- let prizesObj = that.getWinningPrizes(data);
- setTimeout(() => {
- that.setData({
- prizesObject: prizesObj,
- showWinning: false,
- })
- }, 500)
- that.changeGoldenEggStatus(currentData, prizesObj.good_name)
- }
- }
- }
- })
- },
- getWinningPrizes(prizesId) {
- let data = {};
- if (this.data.activityDetail && this.data.activityDetail.good.length) {
- this.data.activityDetail.good.forEach(v => {
- if (v.id == prizesId) {
- data = v;
- }
- });
- return data;
- } else {
- return {};
- }
- },
- changeGoldenEggStatus(currentData, name) {
- //更改金蛋状态
- let arrData = JSON.parse(JSON.stringify(this.data.egg_status_log))
- arrData[parseInt(currentData.index)].status = true;
- arrData[parseInt(currentData.index)].good_name = name;
- this.setData({
- egg_status_log: arrData
- })
- },
- closeMask() {
- this.setData({
- showWinning: true,
- showNoCount: true,
- showNoWinning: true,
- })
- },
- preventHandle() { },
- /**
- * 客户授权登录
- */
- 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/code2sessionmini',
- 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.phone) {
- that.setData({
- datashow: true,
- loginFlag: false,
- phoneFlag:false,
- employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
- })
- app.globalData.personMsg = r.data.user;
- app.globalData.userflag = false; //有个人信息
- } else {
- wx.hideLoading();
- that.setData({
- loginFlag: false,
- phoneFlag: true
- })
- }
- that.addActivityUser();
- } else {
- setTimeout(function () {
- wx.hideLoading()
- }, 500)
- }
- }
- })
- }
- }
- })
- },
- unreadMsg: function () {
- this.addActivityUser();
- },
- addActivityUser() {
- var that = this;
- utils.$post({
- url: app.globalData.webUrl + 'api/lottery/add_user',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- empid: app.globalData.currentUserId,
- actid: that.data.actid
- },
- success: function (res) {
- let data = res.data.data;
- if (res.data.code == '0') {
- that.setData({
- egg_status_log: JSON.parse(data.user_data.egg_status_log),
- activityDetail: data.act_data ? data.act_data : {},
- lottery: data.user_data.lottery,
- companyobj: data.act_data ? data.act_data.company : {},
- 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 ? `中奖客户:${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(',');
- }
- },
- myWinning() {
- wx.navigateTo({
- url: '/pages/other/other?type=63&actid=' + this.data.actid,
- })
- },
- 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, '>>>')
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- if (!!options.uid) {
- app.globalData.shareuserid = options.uid;
- }
- if (!!options.empid) {
- app.globalData.currentUserId = options.empid;
- }
- if (!!options.actid) {
- this.setData({
- actid: options.actid
- })
- }
- if (!!options.clientype) {
- this.setData({
- clientype: options.clientype
- })
- app.globalData.clientype = options.clientype;
- }
- if (wx.getUserProfile) {
- this.setData({
- canIUseGetUserProfile: true
- })
- }
- this.login();
- wx.hideHomeButton()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- })
|