// pages/roomRecord/roomRecord.js const app = getApp() var net = require('../../utils/net.js') var url = require('../../utils/url.js') var common = require('../../utils/common.js') Page({ /** * 页面的初始数据 */ data: { listTipsView: true, shareUserId: '', isMineRecord: true,//是否是自己的榜单 gameId:'', desc: '',//金主 bottom: { action: '', button: '' }, awardUser: 0, rank: 0, getNumber: 0,//已获取红包个数 numOfPeople: 0, status: 0,//0是有奖金,1是没有奖金 tips: '', bonus:0, avatar:'', list:[] }, getResult: function () { var that = this net.connect({ url: url.host + url.get_room_result, data: { gameId: this.data.gameId }, success: res => { if (res.data.code == 200) { // app.globalData.user.withdrawalbleFee += res.data.data.awardFee // var bonus = Number((res.data.data.awardFee / 100).toFixed(2)) // this.data.bonus = bonus // this.data.avatar = res.data.data.headImg // this.data.rank = res.data.data.rank // this.getRanking() } else if (res.data.code == 20006) { var that = this setTimeout(function () { that.getResult() }.bind(this), 1000) } else { this.backHome(res.data.msg) } } }, true) }, getRanking: function () { net.connect({ url: url.host + url.get_room_bonus_ranking, data: { gameId: this.data.gameId }, success: res => { if (res.data.code == 200) { this.data.awardUser = res.data.data.room.awardUser this.data.desc = res.data.data.room.desc if (app.globalData.userInfo.nickName == this.data.desc) { this.data.listTipsView = false } var list = res.data.data.playUserList var num = 0 var shareUser = null var user = null for (var d in list) { if (list[d].awardFee > 0) { num++ } else if (user) { break; } if (list[d].userId == this.data.shareUserId) { shareUser = list[d] } if (list[d].userId == app.server.userId) { user = list[d] } } app.log(user) if (user == null) { user = shareUser this.data.isMineRecord = false } app.log(user) if (user) { // app.globalData.user.withdrawalbleFee += user.awardFee var bonus = Number((user.awardFee / 100).toFixed(2)) this.data.bonus = bonus this.data.avatar = user.headImg this.data.rank = user.rank } this.data.list = list this.data.numOfPeople = list.length this.data.getNumber = num if (this.data.rank <= this.data.awardUser) { //有奖 var tips = '恭喜你位列积分榜第 ' + this.data.rank + ' 名' var status = 0 } else { //无奖 var tips = '很遗憾你未进入前' + this.data.awardUser + '名' var status = 1 } this.data.status = status this.data.tips = tips var length = list.length if (length > 0) { list[0].image = '../../resource/room_record_1.png' list[0].rank = '' } if (length > 1) { list[1].image = '../../resource/room_record_2.png' list[1].rank = '' } if (length > 2) { list[2].image = '../../resource/room_record_3.png' list[2].rank = '' } this.finishGetData() } else if (res.data.code == 20006) { var that = this setTimeout(function () { that.getRanking() }.bind(this), 1000) } else { this.backHome(res.data.msg) } } }, true) }, finishGetData: function () { wx.hideLoading() // console.log('刷新了') this.setData({ status: this.data.status, tips: this.data.tips, bonus: this.data.bonus, avatar: this.data.avatar, list: this.data.list, getNumber: this.data.getNumber, awardUser: this.data.awardUser, numOfPeople: this.data.numOfPeople, desc: this.data.desc, listTipsView: this.data.listTipsView }) }, backHome: function (tips) { wx.showToast({ title: tips, icon: 'none', mask: true, duration: 2000, }) setTimeout(function () { // var arr = getCurrentPages() wx.navigateBack({ }) }.bind(this), 2000) }, toHome: function () { wx.redirectTo({ url: '/pages/home/home', }) }, toOpenRoom: function () { wx.redirectTo({ url: '/pages/open/open', }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.hideShareMenu({}) this.data.gameId = options.gameId this.data.shareUserId = options.shareUserId wx.showLoading({ title: '', }) this.getRanking() var arr = getCurrentPages() if (arr.length > 1) { this.data.bottom.action = 'toOpenRoom' this.data.bottom.button = '发起趣味奖励赛' } else { this.data.bottom.action = 'toHome' this.data.bottom.button = '返回首页' } this.setData({ bottom: this.data.bottom, listTipsView: this.data.listTipsView }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { var id = this.data.isMineRecord ? app.server.userId : this.data.shareUserId return common.shareAction({ path: '&gameId=' + this.data.gameId + '&type=2' + '&shareUserId=' + id + '&page=room', title: app.globalData.userInfo.nickName + ' 在' + this.data.desc + ' 的房间里勇夺第' + this.data.rank + '名', gameId: this.data.gameId, type: 6, success: res => { wx.hideShareMenu({}) }, fail: e => { wx.hideShareMenu({}) } }) } })