123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- // 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({})
- }
- })
- }
- })
|