fragmentsRecord.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. // pages/fragmentsRecord/fragmentsRecord.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. gameId: 0,
  12. ui: {
  13. rankingView: 'ranking-view',
  14. scrollViewBg: 'scroll-view-bg'
  15. },
  16. location: 0,//进来的标签页0世界排行,1好友排行
  17. rank: 0,
  18. isFirstLoad: true,
  19. season: {
  20. current:0,//0本赛季,1上赛季
  21. button: '回顾上赛季脑力排行榜'
  22. },
  23. switchButton: {
  24. left: 'selected',
  25. center: 'normal',
  26. right: 'normal',
  27. scrollLeft: 0
  28. },
  29. scroll: false,
  30. allList: [],
  31. friendsList: [],
  32. currentRecord: 0,//0世界排行,1好友排行,2群排行
  33. getData:0,//2表示获取完
  34. share: {
  35. t: 0, //分享0世界排行,1好友排行,2群排行
  36. },
  37. },
  38. switchAction: function(e) {
  39. this.changeAction(e.currentTarget.id)
  40. },
  41. changeAction: function (tab) {
  42. if (tab == this.data.currentRecord) {
  43. return
  44. }
  45. app.log(app.globalData.sys.windowWidth)
  46. this.setData({
  47. scroll: true
  48. })
  49. if (tab == 0) {
  50. this.data.switchButton.left = 'selected'
  51. this.data.switchButton.center = 'normal'
  52. this.data.switchButton.right = 'normal'
  53. this.data.switchButton.scrollLeft = 0
  54. } else if (tab == 1) {
  55. this.data.switchButton.left = 'normal'
  56. this.data.switchButton.center = 'selected'
  57. this.data.switchButton.right = 'normal'
  58. this.data.switchButton.scrollLeft = app.globalData.sys.windowWidth
  59. } else if (tab == 2) {
  60. this.data.switchButton.left = 'normal'
  61. this.data.switchButton.center = 'normal'
  62. this.data.switchButton.right = 'selected'
  63. this.data.switchButton.scrollLeft = app.globalData.sys.windowWidth * 2
  64. }
  65. this.data.share.t = tab
  66. this.setData({
  67. switchButton: this.data.switchButton,
  68. currentRecord: tab,
  69. scroll: false
  70. })
  71. },
  72. changeSeasonAction: function () {
  73. if (this.data.season.current == 0) {
  74. wx.navigateTo({
  75. url: '../fragmentsRecord/fragmentsRecord?currentSeason=1'
  76. })
  77. } else {
  78. wx.navigateBack({
  79. })
  80. }
  81. },
  82. handleData: function (list) {
  83. var result = []
  84. for (var i = 0; i < list.length; i ++) {
  85. var item = list[i]
  86. var f = common.starToFragment(app.server.config.rankDanList, item.starC)
  87. var fragment = app.server.config.rankDanList[f[0]].name
  88. var starNum = f[1]
  89. item['fragment'] = fragment
  90. item['starNum'] = starNum
  91. item['bg'] = item.userId == app.server.userId ? 'self' : 'all'
  92. item['row'] = i
  93. result.push(item)
  94. }
  95. return result
  96. },
  97. finishGetData: function () {
  98. wx.hideLoading()
  99. this.setData({
  100. allList: this.data.allList,
  101. friendsList: this.data.friendsList,
  102. rank: this.data.rank
  103. })
  104. this.changeAction(this.data.location)
  105. },
  106. /**
  107. * 生命周期函数--监听页面加载
  108. */
  109. onLoad: function (options) {
  110. wx.showShareMenu({
  111. withShareTicket: true
  112. })
  113. if (options.location) {
  114. this.data.location = options.location
  115. }
  116. this.data.rank = app.server.rank
  117. if (options.currentSeason == 1) {
  118. this.data.gameId = app.globalData.rankInfo.preGameId
  119. this.data.season.current = 1
  120. this.data.season.button = '回到本赛季脑力排行榜'
  121. } else {
  122. this.data.gameId = app.globalData.rankInfo.gameId
  123. if (app.globalData.rankInfo.preGameId == 0) {
  124. this.data.ui.rankingView = 'ranking-view-o'
  125. this.data.ui.scrollViewBg = 'scroll-view-bg-o'
  126. }
  127. }
  128. this.setData({
  129. season: this.data.season,
  130. rank: this.data.rank,
  131. ui: this.data.ui
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面初次渲染完成
  136. */
  137. onReady: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: function () {
  143. app.log('show' + this.data.gameId)
  144. if (!this.data.isFirstLoad) {
  145. return
  146. }
  147. wx.showLoading({
  148. title: '',
  149. })
  150. net.connect({
  151. url: url.host + url.all_fragments_record,
  152. data: { gameId: this.data.gameId },
  153. success: res => {
  154. this.data.allList = this.handleData(res.data.data)
  155. this.data.getData ++
  156. if (this.data.getData == 3) {
  157. this.finishGetData()
  158. }
  159. },
  160. })
  161. net.connect({
  162. url: url.host + url.friends_fragments_record,
  163. data: { gameId: this.data.gameId },
  164. success: res => {
  165. this.data.friendsList = this.handleData(res.data.data)
  166. this.data.getData++
  167. if (this.data.getData == 3) {
  168. this.finishGetData()
  169. }
  170. },
  171. })
  172. net.connect({
  173. url: url.host + url.get_my_ranking,
  174. data: { gameId: this.data.gameId },
  175. success: res => {
  176. this.data.rank = res.data.data.rank
  177. if (this.data.season.current == 0) {
  178. app.server.rank = res.data.data.rank
  179. }
  180. this.data.getData++
  181. if (this.data.getData == 3) {
  182. this.finishGetData()
  183. }
  184. }
  185. })
  186. this.data.isFirstLoad = false
  187. },
  188. /**
  189. * 生命周期函数--监听页面隐藏
  190. */
  191. onHide: function () {
  192. },
  193. /**
  194. * 生命周期函数--监听页面卸载
  195. */
  196. onUnload: function () {
  197. },
  198. /**
  199. * 页面相关事件处理函数--监听用户下拉动作
  200. */
  201. onPullDownRefresh: function () {
  202. },
  203. /**
  204. * 页面上拉触底事件的处理函数
  205. */
  206. onReachBottom: function () {
  207. },
  208. /**
  209. * 用户点击右上角分享
  210. */
  211. onShareAppMessage: function () {
  212. var title = '用脑力征服世界,段位排行榜,你上榜了吗?'
  213. var image = ''
  214. if (this.data.share.t == 0) {
  215. var path = '&page=fragmentsRecord&location=0'
  216. var t = 1
  217. var gameId = 0
  218. } else if (this.data.share.t == 1) {
  219. var path = '&page=fragmentsRecord&location=1'
  220. var t = 1
  221. var gameId = 0
  222. } else if (this.data.share.t == 2) {
  223. var path = '&gameId=' + app.globalData.rankInfo.gameId + '&page=groupFragmentsRecord'
  224. image = '../../resource/share_group_fragment_record.png'
  225. var t = 11
  226. var gameId = app.globalData.rankInfo.gameId
  227. }
  228. return common.shareAction({
  229. imageUrl: image,
  230. path: path,
  231. title: title,
  232. type: t,
  233. gameId: gameId,
  234. success: res => {
  235. }
  236. })
  237. }
  238. })