123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- // pages/fragmentsRecord/fragmentsRecord.js
- const app = getApp()
- var net = require('../../utils/net.js')
- var url = require('../../utils/url.js')
- var common = require('../../utils/common.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- gameId: 0,
- ui: {
- rankingView: 'ranking-view',
- scrollViewBg: 'scroll-view-bg'
- },
- location: 0,//进来的标签页0世界排行,1好友排行
- rank: 0,
- isFirstLoad: true,
- season: {
- current:0,//0本赛季,1上赛季
- button: '回顾上赛季脑力排行榜'
- },
- switchButton: {
- left: 'selected',
- center: 'normal',
- right: 'normal',
- scrollLeft: 0
- },
- scroll: false,
- allList: [],
- friendsList: [],
- currentRecord: 0,//0世界排行,1好友排行,2群排行
- getData:0,//2表示获取完
- share: {
- t: 0, //分享0世界排行,1好友排行,2群排行
- },
- },
- switchAction: function(e) {
- this.changeAction(e.currentTarget.id)
- },
- changeAction: function (tab) {
- if (tab == this.data.currentRecord) {
- return
- }
- app.log(app.globalData.sys.windowWidth)
- this.setData({
- scroll: true
- })
- if (tab == 0) {
- this.data.switchButton.left = 'selected'
- this.data.switchButton.center = 'normal'
- this.data.switchButton.right = 'normal'
- this.data.switchButton.scrollLeft = 0
- } else if (tab == 1) {
- this.data.switchButton.left = 'normal'
- this.data.switchButton.center = 'selected'
- this.data.switchButton.right = 'normal'
- this.data.switchButton.scrollLeft = app.globalData.sys.windowWidth
- } else if (tab == 2) {
- this.data.switchButton.left = 'normal'
- this.data.switchButton.center = 'normal'
- this.data.switchButton.right = 'selected'
- this.data.switchButton.scrollLeft = app.globalData.sys.windowWidth * 2
- }
- this.data.share.t = tab
- this.setData({
- switchButton: this.data.switchButton,
- currentRecord: tab,
- scroll: false
- })
- },
- changeSeasonAction: function () {
- if (this.data.season.current == 0) {
- wx.navigateTo({
- url: '../fragmentsRecord/fragmentsRecord?currentSeason=1'
- })
- } else {
- wx.navigateBack({
- })
- }
- },
- handleData: function (list) {
- var result = []
- for (var i = 0; i < list.length; i ++) {
- var item = list[i]
- var f = common.starToFragment(app.server.config.rankDanList, item.starC)
- var fragment = app.server.config.rankDanList[f[0]].name
- var starNum = f[1]
- item['fragment'] = fragment
- item['starNum'] = starNum
- item['bg'] = item.userId == app.server.userId ? 'self' : 'all'
- item['row'] = i
- result.push(item)
- }
- return result
- },
- finishGetData: function () {
- wx.hideLoading()
- this.setData({
- allList: this.data.allList,
- friendsList: this.data.friendsList,
- rank: this.data.rank
- })
- this.changeAction(this.data.location)
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
-
- wx.showShareMenu({
- withShareTicket: true
- })
- if (options.location) {
- this.data.location = options.location
- }
- this.data.rank = app.server.rank
- if (options.currentSeason == 1) {
- this.data.gameId = app.globalData.rankInfo.preGameId
- this.data.season.current = 1
- this.data.season.button = '回到本赛季脑力排行榜'
- } else {
- this.data.gameId = app.globalData.rankInfo.gameId
- if (app.globalData.rankInfo.preGameId == 0) {
- this.data.ui.rankingView = 'ranking-view-o'
- this.data.ui.scrollViewBg = 'scroll-view-bg-o'
- }
- }
-
- this.setData({
- season: this.data.season,
- rank: this.data.rank,
- ui: this.data.ui
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- app.log('show' + this.data.gameId)
- if (!this.data.isFirstLoad) {
- return
- }
- wx.showLoading({
- title: '',
- })
- net.connect({
- url: url.host + url.all_fragments_record,
- data: { gameId: this.data.gameId },
- success: res => {
- this.data.allList = this.handleData(res.data.data)
- this.data.getData ++
- if (this.data.getData == 3) {
- this.finishGetData()
- }
- },
- })
- net.connect({
- url: url.host + url.friends_fragments_record,
- data: { gameId: this.data.gameId },
- success: res => {
- this.data.friendsList = this.handleData(res.data.data)
- this.data.getData++
- if (this.data.getData == 3) {
- this.finishGetData()
- }
- },
- })
- net.connect({
- url: url.host + url.get_my_ranking,
- data: { gameId: this.data.gameId },
- success: res => {
- this.data.rank = res.data.data.rank
- if (this.data.season.current == 0) {
- app.server.rank = res.data.data.rank
- }
- this.data.getData++
- if (this.data.getData == 3) {
- this.finishGetData()
- }
- }
- })
- this.data.isFirstLoad = false
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- var title = '用脑力征服世界,段位排行榜,你上榜了吗?'
- var image = ''
- if (this.data.share.t == 0) {
- var path = '&page=fragmentsRecord&location=0'
- var t = 1
- var gameId = 0
- } else if (this.data.share.t == 1) {
- var path = '&page=fragmentsRecord&location=1'
- var t = 1
- var gameId = 0
- } else if (this.data.share.t == 2) {
- var path = '&gameId=' + app.globalData.rankInfo.gameId + '&page=groupFragmentsRecord'
- image = '../../resource/share_group_fragment_record.png'
- var t = 11
- var gameId = app.globalData.rankInfo.gameId
- }
- return common.shareAction({
- imageUrl: image,
- path: path,
- title: title,
- type: t,
- gameId: gameId,
- success: res => {
- }
- })
- }
- })
|