123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- // pages/fragmentsList/fragmentsList.js
- var net = require('../../utils/net.js')
- var url = require('../../utils/url.js')
- var common = require('../../utils/common.js')
- var lock = require('../../utils/lock.js')
- const app = getApp()
- // const fragments = [
- // { id: 0, fragment: '胎教期', star: 1, consume: '100万' },
- // { id: 1, fragment: '幼儿园', star: 4, consume: '200万' },
- // { id: 2, fragment: '小学', star: 6, consume: '500万' },
- // { id: 3, fragment: '初中', star: 3, consume: '900万' },
- // { id: 4, fragment: '高中', star: 3, consume: '1100万' },
- // { id: 5, fragment: '本科', star: 4, consume: '1500万' },
- // { id: 6, fragment: '硕士', star: 3, consume: '2000万' },
- // { id: 7, fragment: '博士', star: 3, consume: '2700万' },
- // { id: 8, fragment: '讲师', star: 5, consume: '3000万' },
- // { id: 9, fragment: '教授', star: 5, consume: '1亿' },
- // { id: 10, fragment: '院士', star: 0, consume: '3亿', top: true }]
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- isFirstLoad: true,
- currentFragment: 0,//从0开始,跟接口文档不一致
- currentStarNum:0,
- isCurrentFragment: false,//是否在当前段位pk
- fragmentsList: [],
- allFragmentsNum: 0,//一共有多少个段位
- banner: '',
- poster: '',
- rank: 0,
- scrollBottomId: '',//列表最后一个id
- dialogBrainLack: {
- hidden: true,
- title: '哎呀,你的脑力值不足',
- subtitle: '无法参加排位赛、冲刺院士荣誉并争夺至尊大奖哦',
- button: '分享到群',
- },
- dialogRank: {
- hidden: true
- },
- },
- showRankDialog: function () {
- this.setData({
- dialogRank: {
- hidden: false,
- headImg: '../../resource/head_rank.png'
- }
- })
- },
- hideRankDialog: function () {
- this.setData({
- dialogRank: { hidden: true }
- })
- },
- hideBrainLackDialog: function () {
- this.data.dialogBrainLack.hidden = true
- this.setData({
- dialogBrainLack: this.data.dialogBrainLack
- })
- },
- showBrainLackDialog: function (cell) {
- this.data.dialogBrainLack.button = '分享到群 赚取' + common.unit(cell) + '脑力值'
- this.data.dialogBrainLack.hidden = false
- this.setData({
- dialogBrainLack: this.data.dialogBrainLack
- })
- },
- goToPK: function (e) {
- if (lock.lockTapDelay()) {
- return
- }
- if (app.globalData.timeDifference + new Date().getTime() > app.globalData.rankInfo.endTime) {
- this.showRankDialog()
- return
- }
- var rankDan = Number(e.currentTarget.id.substring(1)) + 1
- var fragment = rankDan - 1
- var cell = app.server.config.rankDanList[fragment].cellRankCost
- if (app.globalData.user.cell < cell) {
- if (app.server.shareRankCellLack < app.server.config.shareRankCellLackMax) {
- var c = app.server.config.rankDanList[this.data.currentFragment].cellRankCost
- this.showBrainLackDialog(c)
- } else {
- wx.showToast({
- title: '脑力值不足',
- icon: 'none'
- })
- }
- return
- }
-
- if (rankDan - 1 == this.data.currentFragment) {
- this.data.isCurrentFragment = true
- } else {
- this.data.isCurrentFragment = false
- }
- wx.navigateTo({
- url: '/pages/pk/pk?type=1&rankDan=' + rankDan
- })
- },
- goToRecord: function () {
- wx.navigateTo({
- url: '../fragmentsRecord/fragmentsRecord',
- })
- },
- joinFragments: function () {
- net.connect({
- url: url.host + url.join_fragments,
- data: {},
- method: 'POST',
- success: res => {
- app.server.rank = res.data.data.rank
- this.data.rank = app.server.rank
- this.setData({
- rank: this.data.rank
- })
- },
- })
- },
- goToPoster: function () {
- wx.previewImage({
- urls: [this.data.poster],
- })
- },
- confirmFragmentsList: function () {
- if (this.data.currentFragment + 3 >= this.data.allFragmentsNum) {
- this.data.fragmentsList = app.server.config.rankDanList.slice(0)
- var { ...item } = this.data.fragmentsList[this.data.allFragmentsNum - 1]
- item.star = 0
- this.data.fragmentsList[this.data.allFragmentsNum - 1] = item
- } else {
- this.data.fragmentsList = app.server.config.rankDanList.slice(0, this.data.currentFragment + 3)
- }
- },
- getFragmentsResult: function (result) {
- if (this.data.isCurrentFragment) {
- if (result) {
- app.server.starC++
- var r = common.starToFragment(app.server.config.rankDanList, app.server.starC)
- this.data.currentFragment = r[0]
- this.data.currentStarNum = r[1]
- } else {
- var r = common.decreaseStar(app.server.config.rankDanList, app.server.starC)
- this.data.currentFragment = r[0]
- this.data.currentStarNum = r[1]
- app.server.starC = r[2]
- }
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- app.log(app.server)
- wx.hideShareMenu({})
- this.data.banner = app.globalData.rankInfo.banner
- this.data.poster = app.globalData.rankInfo.poster
- var f = common.starToFragment(app.server.config.rankDanList, app.server.starC)
- this.data.currentFragment = f[0]
- this.data.currentStarNum = f[1]
- this.data.allFragmentsNum = app.server.config.rankDanList.length
- this.confirmFragmentsList()
-
- this.data.scrollBottomId = 'a' + this.data.currentFragment
- app.log(this.data.scrollBottomId)
- this.setData({
- fragmentsList: this.data.fragmentsList,
- currentFragment: this.data.currentFragment,
- currentStarNum: this.data.currentStarNum,
- allFragmentsNum: this.data.allFragmentsNum,
- banner: this.data.banner,
- scrollBottomId: this.data.scrollBottomId
- })
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if (this.data.isFirstLoad) {
- this.data.rank = app.server.rank
- if (this.data.rank == 0) {
- this.joinFragments()
- }
- else {
- this.setData({
- rank: this.data.rank
- })
- }
- this.data.isFirstLoad = false
- } else {
-
- this.data.rank = app.server.rank
- this.confirmFragmentsList()
- this.setData({
- fragmentsList: this.data.fragmentsList,
- currentFragment: this.data.currentFragment,
- currentStarNum: this.data.currentStarNum,
- rank: this.data.rank
- })
- net.connect({
- url: url.host + url.get_my_ranking,
- data: { gameId: app.globalData.rankInfo.gameId },
- success: res => {
- if (app.server.starC != res.data.data.starC) {
- app.log('change')
- app.server.starC = res.data.data.starC
- app.server.rank = res.data.data.rank
- }
- this.data.rank = app.server.rank
- var r = common.starToFragment(app.server.config.rankDanList, app.server.starC)
- this.data.currentFragment = r[0]
- this.data.currentStarNum = r[1]
- this.confirmFragmentsList()
- this.setData({
- fragmentsList: this.data.fragmentsList,
- currentFragment: this.data.currentFragment,
- currentStarNum: this.data.currentStarNum,
- rank: this.data.rank
- })
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- wx.showShareMenu({
- withShareTicket: true
- })
- this.hideBrainLackDialog()
- return common.shareAction({
- title: app.globalData.userInfo.nickName + '邀请你来瓜分8万8千8百8十8元现金奖励!',
- path: '',
- type: 12,
- success: res => {
- if (res.data.data.addCell > 0) {
- wx.showToast({
- title: '分享+' + common.unit(res.data.data.addCell) + '脑力值',
- icon: 'none',
- duration: 2500
- })
- }
- this.setData({
- user: app.globalData.user
- })
- wx.hideShareMenu({})
- },
- fail: e =>{
- wx.hideShareMenu({})
- }
- })
- }
- })
|