groupFragmentsRecord.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // pages/groupFragmentsRecord/groupFragmentsRecord.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. rankType: '1',
  12. isFirstLoad: true,
  13. gameId: '',
  14. code: '',
  15. list: []
  16. },
  17. backHome: function () {
  18. wx.redirectTo({
  19. url: '../home/home',
  20. })
  21. },
  22. handleData: function (list) {
  23. var result = []
  24. for (var i = 0; i < list.length; i++) {
  25. var item = list[i]
  26. var f = common.starToFragment(app.server.config.rankDanList, item.starC)
  27. var fragment = app.server.config.rankDanList[f[0]].name
  28. var starNum = f[1]
  29. item['fragment'] = fragment
  30. item['starNum'] = starNum
  31. item['bg'] = item.userId == app.server.userId ? 'self' : 'all'
  32. item['row'] = i
  33. result.push(item)
  34. }
  35. return result
  36. },
  37. joinGroupRecord: function () {
  38. wx.showLoading({
  39. title: '',
  40. })
  41. net.connect({
  42. url: url.host + url.join_group_record,
  43. data: { code: this.data.code },
  44. method: 'POST',
  45. success: res => {
  46. this.queryGroupRecord()
  47. },
  48. })
  49. },
  50. queryGroupRecord: function () {
  51. net.connect({
  52. url: url.host + url.group_record,
  53. data: { code: this.data.code },
  54. success: res => {
  55. this.data.list = this.handleData(res.data.data)
  56. this.setData({
  57. list: this.data.list
  58. })
  59. wx.hideLoading()
  60. },
  61. })
  62. },
  63. /**
  64. * 生命周期函数--监听页面加载
  65. */
  66. onLoad: function (options) {
  67. app.log(options)
  68. this.data.gameId = options.gameId
  69. this.data.code = app.globalData.identify.shareIdentify
  70. app.log(this.data.code)
  71. if (options.rankType) {
  72. this.data.rankType = options.rankType
  73. }
  74. var title
  75. switch (this.data.rankType) {
  76. case '1': {
  77. title = '脑力排行榜'
  78. break
  79. }
  80. case '2': {
  81. title = '专场脑力排行榜'
  82. break
  83. }
  84. default: break
  85. }
  86. wx.setNavigationBarTitle({
  87. title: title,
  88. })
  89. },
  90. /**
  91. * 生命周期函数--监听页面初次渲染完成
  92. */
  93. onReady: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow: function () {
  99. if (!this.data.isFirstLoad) {
  100. return
  101. }
  102. this.joinGroupRecord()
  103. this.data.isFirstLoad = false
  104. },
  105. /**
  106. * 生命周期函数--监听页面隐藏
  107. */
  108. onHide: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面卸载
  112. */
  113. onUnload: function () {
  114. },
  115. /**
  116. * 页面相关事件处理函数--监听用户下拉动作
  117. */
  118. onPullDownRefresh: function () {
  119. },
  120. /**
  121. * 页面上拉触底事件的处理函数
  122. */
  123. onReachBottom: function () {
  124. },
  125. /**
  126. * 用户点击右上角分享
  127. */
  128. onShareAppMessage: function () {
  129. var title = '用脑力征服世界,段位排行榜,你上榜了吗?'
  130. var path = '&gameId=' + this.data.gameId + '&page=groupFragmentsRecord'
  131. var t = 11
  132. var gameId = this.data.gameId
  133. return common.shareAction({
  134. path: path,
  135. title: title,
  136. type: t,
  137. gameId: gameId,
  138. success: res => {
  139. }
  140. }, this.data.code)
  141. }
  142. })