roomRecord.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. // pages/roomRecord/roomRecord.js
  2. const app = getApp()
  3. var net = require('../../utils/net.js')
  4. var url = require('../../utils/url.js')
  5. var common = require('../../utils/common.js')
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. listTipsView: true,
  12. shareUserId: '',
  13. isMineRecord: true,//是否是自己的榜单
  14. gameId:'',
  15. desc: '',//金主
  16. bottom: {
  17. action: '',
  18. button: ''
  19. },
  20. awardUser: 0,
  21. rank: 0,
  22. getNumber: 0,//已获取红包个数
  23. numOfPeople: 0,
  24. status: 0,//0是有奖金,1是没有奖金
  25. tips: '',
  26. bonus:0,
  27. avatar:'',
  28. list:[]
  29. },
  30. getResult: function () {
  31. var that = this
  32. net.connect({
  33. url: url.host + url.get_room_result,
  34. data: { gameId: this.data.gameId },
  35. success: res => {
  36. if (res.data.code == 200) {
  37. // app.globalData.user.withdrawalbleFee += res.data.data.awardFee
  38. // var bonus = Number((res.data.data.awardFee / 100).toFixed(2))
  39. // this.data.bonus = bonus
  40. // this.data.avatar = res.data.data.headImg
  41. // this.data.rank = res.data.data.rank
  42. // this.getRanking()
  43. } else if (res.data.code == 20006) {
  44. var that = this
  45. setTimeout(function () {
  46. that.getResult()
  47. }.bind(this), 1000)
  48. } else {
  49. this.backHome(res.data.msg)
  50. }
  51. }
  52. }, true)
  53. },
  54. getRanking: function () {
  55. net.connect({
  56. url: url.host + url.get_room_bonus_ranking,
  57. data: { gameId: this.data.gameId },
  58. success: res => {
  59. if (res.data.code == 200) {
  60. this.data.awardUser = res.data.data.room.awardUser
  61. this.data.desc = res.data.data.room.desc
  62. if (app.globalData.userInfo.nickName == this.data.desc) {
  63. this.data.listTipsView = false
  64. }
  65. var list = res.data.data.playUserList
  66. var num = 0
  67. var shareUser = null
  68. var user = null
  69. for (var d in list) {
  70. if (list[d].awardFee > 0) {
  71. num++
  72. } else if (user) {
  73. break;
  74. }
  75. if (list[d].userId == this.data.shareUserId) {
  76. shareUser = list[d]
  77. }
  78. if (list[d].userId == app.server.userId) {
  79. user = list[d]
  80. }
  81. }
  82. app.log(user)
  83. if (user == null) {
  84. user = shareUser
  85. this.data.isMineRecord = false
  86. }
  87. app.log(user)
  88. if (user) {
  89. // app.globalData.user.withdrawalbleFee += user.awardFee
  90. var bonus = Number((user.awardFee / 100).toFixed(2))
  91. this.data.bonus = bonus
  92. this.data.avatar = user.headImg
  93. this.data.rank = user.rank
  94. }
  95. this.data.list = list
  96. this.data.numOfPeople = list.length
  97. this.data.getNumber = num
  98. if (this.data.rank <= this.data.awardUser) {
  99. //有奖
  100. var tips = '恭喜你位列积分榜第 ' + this.data.rank + ' 名'
  101. var status = 0
  102. } else {
  103. //无奖
  104. var tips = '很遗憾你未进入前' + this.data.awardUser + '名'
  105. var status = 1
  106. }
  107. this.data.status = status
  108. this.data.tips = tips
  109. var length = list.length
  110. if (length > 0) {
  111. list[0].image = '../../resource/room_record_1.png'
  112. list[0].rank = ''
  113. }
  114. if (length > 1) {
  115. list[1].image = '../../resource/room_record_2.png'
  116. list[1].rank = ''
  117. }
  118. if (length > 2) {
  119. list[2].image = '../../resource/room_record_3.png'
  120. list[2].rank = ''
  121. }
  122. this.finishGetData()
  123. } else if (res.data.code == 20006) {
  124. var that = this
  125. setTimeout(function () {
  126. that.getRanking()
  127. }.bind(this), 1000)
  128. } else {
  129. this.backHome(res.data.msg)
  130. }
  131. }
  132. }, true)
  133. },
  134. finishGetData: function () {
  135. wx.hideLoading()
  136. // console.log('刷新了')
  137. this.setData({
  138. status: this.data.status,
  139. tips: this.data.tips,
  140. bonus: this.data.bonus,
  141. avatar: this.data.avatar,
  142. list: this.data.list,
  143. getNumber: this.data.getNumber,
  144. awardUser: this.data.awardUser,
  145. numOfPeople: this.data.numOfPeople,
  146. desc: this.data.desc,
  147. listTipsView: this.data.listTipsView
  148. })
  149. },
  150. backHome: function (tips) {
  151. wx.showToast({
  152. title: tips,
  153. icon: 'none',
  154. mask: true,
  155. duration: 2000,
  156. })
  157. setTimeout(function () {
  158. // var arr = getCurrentPages()
  159. wx.navigateBack({
  160. })
  161. }.bind(this), 2000)
  162. },
  163. toHome: function () {
  164. wx.redirectTo({
  165. url: '/pages/home/home',
  166. })
  167. },
  168. toOpenRoom: function () {
  169. wx.redirectTo({
  170. url: '/pages/open/open',
  171. })
  172. },
  173. /**
  174. * 生命周期函数--监听页面加载
  175. */
  176. onLoad: function (options) {
  177. wx.hideShareMenu({})
  178. this.data.gameId = options.gameId
  179. this.data.shareUserId = options.shareUserId
  180. wx.showLoading({
  181. title: '',
  182. })
  183. this.getRanking()
  184. var arr = getCurrentPages()
  185. if (arr.length > 1) {
  186. this.data.bottom.action = 'toOpenRoom'
  187. this.data.bottom.button = '发起趣味奖励赛'
  188. } else {
  189. this.data.bottom.action = 'toHome'
  190. this.data.bottom.button = '返回首页'
  191. }
  192. this.setData({
  193. bottom: this.data.bottom,
  194. listTipsView: this.data.listTipsView
  195. })
  196. },
  197. /**
  198. * 生命周期函数--监听页面初次渲染完成
  199. */
  200. onReady: function () {
  201. },
  202. /**
  203. * 生命周期函数--监听页面显示
  204. */
  205. onShow: function () {
  206. },
  207. /**
  208. * 生命周期函数--监听页面隐藏
  209. */
  210. onHide: function () {
  211. },
  212. /**
  213. * 生命周期函数--监听页面卸载
  214. */
  215. onUnload: function () {
  216. },
  217. /**
  218. * 页面相关事件处理函数--监听用户下拉动作
  219. */
  220. onPullDownRefresh: function () {
  221. },
  222. /**
  223. * 页面上拉触底事件的处理函数
  224. */
  225. onReachBottom: function () {
  226. },
  227. /**
  228. * 用户点击右上角分享
  229. */
  230. onShareAppMessage: function () {
  231. var id = this.data.isMineRecord ? app.server.userId : this.data.shareUserId
  232. return common.shareAction({
  233. path: '&gameId=' + this.data.gameId + '&type=2' + '&shareUserId=' + id + '&page=room',
  234. title: app.globalData.userInfo.nickName + ' 在' + this.data.desc + ' 的房间里勇夺第' + this.data.rank + '名',
  235. gameId: this.data.gameId,
  236. type: 6,
  237. success: res => {
  238. wx.hideShareMenu({})
  239. },
  240. fail: e => {
  241. wx.hideShareMenu({})
  242. }
  243. })
  244. }
  245. })