roomRecord.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. this.setData({
  137. status: this.data.status,
  138. tips: this.data.tips,
  139. bonus: this.data.bonus,
  140. avatar: this.data.avatar,
  141. list: this.data.list,
  142. getNumber: this.data.getNumber,
  143. awardUser: this.data.awardUser,
  144. numOfPeople: this.data.numOfPeople,
  145. desc: this.data.desc,
  146. listTipsView: this.data.listTipsView
  147. })
  148. },
  149. backHome: function (tips) {
  150. wx.showToast({
  151. title: tips,
  152. icon: 'none',
  153. mask: true,
  154. duration: 2000,
  155. })
  156. setTimeout(function () {
  157. // var arr = getCurrentPages()
  158. wx.navigateBack({
  159. })
  160. }.bind(this), 2000)
  161. },
  162. toHome: function () {
  163. wx.redirectTo({
  164. url: '/pages/home/home',
  165. })
  166. },
  167. toOpenRoom: function () {
  168. wx.redirectTo({
  169. url: '/pages/open/open',
  170. })
  171. },
  172. /**
  173. * 生命周期函数--监听页面加载
  174. */
  175. onLoad: function (options) {
  176. wx.hideShareMenu({})
  177. this.data.gameId = options.gameId
  178. this.data.shareUserId = options.shareUserId
  179. wx.showLoading({
  180. title: '',
  181. })
  182. this.getRanking()
  183. var arr = getCurrentPages()
  184. if (arr.length > 1) {
  185. this.data.bottom.action = 'toOpenRoom'
  186. this.data.bottom.button = '发起趣味奖励赛'
  187. } else {
  188. this.data.bottom.action = 'toHome'
  189. this.data.bottom.button = '返回首页'
  190. }
  191. this.setData({
  192. bottom: this.data.bottom,
  193. listTipsView: this.data.listTipsView
  194. })
  195. },
  196. /**
  197. * 生命周期函数--监听页面初次渲染完成
  198. */
  199. onReady: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面显示
  203. */
  204. onShow: function () {
  205. },
  206. /**
  207. * 生命周期函数--监听页面隐藏
  208. */
  209. onHide: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面卸载
  213. */
  214. onUnload: function () {
  215. },
  216. /**
  217. * 页面相关事件处理函数--监听用户下拉动作
  218. */
  219. onPullDownRefresh: function () {
  220. },
  221. /**
  222. * 页面上拉触底事件的处理函数
  223. */
  224. onReachBottom: function () {
  225. },
  226. /**
  227. * 用户点击右上角分享
  228. */
  229. onShareAppMessage: function () {
  230. var id = this.data.isMineRecord ? app.server.userId : this.data.shareUserId
  231. return common.shareAction({
  232. path: '&gameId=' + this.data.gameId + '&type=2' + '&shareUserId=' + id + '&page=room',
  233. title: app.globalData.userInfo.nickName + ' 在' + this.data.desc + ' 的房间里勇夺第' + this.data.rank + '名',
  234. gameId: this.data.gameId,
  235. type: 6,
  236. success: res => {
  237. wx.hideShareMenu({})
  238. },
  239. fail: e => {
  240. wx.hideShareMenu({})
  241. }
  242. })
  243. }
  244. })