123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- 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 oldT = 1514736000000
- Page({
- /**
- * 页面的初始数据
- */
- //ty: 1签到,2邀请,3领取,4已领取,5绑定
- data: {
- formId: 0,
- currentFragment: 0,//从0开始,跟接口文档不一致
- cellSplitSpeed: 0,
- cellSplitMax: 0,
- currentSplitCell: 0,//当前分裂数值
- phone: 0,
- data: [
- { id: '1', t: '时时签到', d: '24小时内,时时可领取', b: 0, ty: 1, p: '0/0', w: 0 },
- { id: '2', t: '好友对战', d: '完成一场好友对战,每天可领1次', b: 0, ty: 2 },
- { id: '3', t: '邀请好友', d: '每邀请1位新用户加入即享', b: 0, ty: 2 },
- { id: '4', t: '绑定手机', d: '不怕微信账号故障而导致脑力值丢失', b: 0, ty: 5 }
- ],
- getCellResult: {
- hidden: true,
- c: '0',
- u: ''
- }
- },
- goToAdd: function (sender) {
- wx.navigateTo({
- url: '../add/add'
- })
- },
- getCell: function (sender) {
- if (sender.currentTarget.id == '2') {
- this.getPKCell()
- } else if (sender.currentTarget.id == '3') {
- this.getInvitationCell()
- }
- },
- getPhoneNumber: function (e) {
- if (e.detail.errMsg == 'getPhoneNumber:ok') {
- wx.showLoading({
- title: '',
- })
- net.connect({
- url: url.host + url.bind_phone,
- data: {
- encryptedData: e.detail.encryptedData,
- iv: e.detail.iv
- },
- method: 'POST',
- success: res => {
- wx.hideLoading()
- app.server.phone = res.data.data.phone
- this.data.phone = app.server.phone
- this.getCellResult(res.data.data.addCell)
- }
- })
- }
- // app.log(e.detail.errMsg)
- // app.log(e.detail.iv)
- // app.log(e.detail.encryptedData)
- },
- itemAction: function (sender) {
- if (sender.currentTarget.id == '1') {
- if (this.data.currentSplitCell <= 0) {
- return
- }
- this.signIn()
- }
- },
- getCellResult: function (cell) {
- app.globalData.user.cell += cell
- var c
- var u
- if (cell >= 10000) {
- var c = cell / 10000
- var u = '亿'
- } else {
- var c = cell
- var u = '万'
- }
- this.data.getCellResult = {
- hidden: false,
- c: c,
- u: u
- }
- this.setData({
- data: this.data.data,
- getCellResult: this.data.getCellResult,
- phone: this.data.phone
- })
- setTimeout(function () {
- this.data.getCellResult.hidden = true
- this.setData({
- getCellResult: this.data.getCellResult
- })
- }.bind(this), 2000)
- },
- getInvitationCell: function () {
- if (lock.lockTapDelay(1000)) {
- return
- }
- net.connect({
- url: url.host + url.recom_receive_cell,
- method: 'POST',
- data: {},
- success: res => {
- app.log(res.data)
- this.data.data[2].ty = 2
- this.getCellResult(res.data.data)
- }
- })
- },
- getPKCell: function () {
- if (lock.lockTapDelay(1000)) {
- return
- }
- net.connect({
- url: url.host + url.pk_receive_cell,
- method: 'POST',
- data: {},
- success: res => {
- app.log(res.data)
- this.data.data[1].ty = 4
- this.getCellResult(res.data.data)
- }
- })
- },
- signIn: function () {
- //点击金币,获取脑力值
- if (lock.lockTapDelay(1000)) {
- return
- }
- net.connect({
- url: url.host + url.receive_cell,
- method: 'POST',
- data: {
- formId: this.data.formId,
- },
- success: res => {
- this.data.currentSplitCell = 0
- this.refreshUI(0)
- this.getCellResult(res.data.data)
-
- //重新启动计时器
- if (this.interval) {
- clearInterval(this.interval)
- }
- this.interval = setInterval(function (data) {
- this.refreshUI(this.data.cellSplitSpeed / 2)
- }.bind(this), 1000 * 60)
- }
- })
- },
- refreshUI: function (add) {
- this.data.currentSplitCell = this.data.currentSplitCell + add
- if (this.data.currentSplitCell > this.data.cellSplitMax) {
- this.data.currentSplitCell = this.data.cellSplitMax
- if (this.interval) {
- clearInterval(this.interval)
- }
- }
- app.log(this.data.currentSplitCell)
- this.data.data[0].w = this.data.currentSplitCell / this.data.cellSplitMax * 100
- this.data.data[0].p = Math.floor(this.data.currentSplitCell) + '/' + this.data.cellSplitMax
- app.log(this.data.data[0].w)
- this.setData({
- data: this.data.data
- })
- },
- //ty: 1签到,2邀请,3领取,4已领取,5绑定
- refreshData: function () {
- //启动计时器计算分裂数值
- this.interval = setInterval(function (data) {
- this.refreshUI(this.data.cellSplitSpeed / 2)
- }.bind(this), 1000 * 60)
- //当前签到数值
- var nc = Math.floor((app.globalData.user.nowTime - app.globalData.user.splitTime) / 1000 / 60 / 2) * this.data.cellSplitSpeed
-
- var curT = new Date(app.globalData.user.nowTime).format("yyyy-MM-dd")
- app.log(curT)
- //判断好友对战
- var pkTime = app.globalData.user.pkTime || oldT
- var pkT = new Date(pkTime).format("yyyy-MM-dd")
- app.log(pkT)
- if (pkT == curT) {
- this.data.data[1].ty = 4
- } else if (app.globalData.user.pkTodayC > 0) {
- this.data.data[1].ty = 3
- } else {
- this.data.data[1].ty = 2
- }
- //判断邀请好友
- var recomTime = app.globalData.user.recomTime || oldT
- var recomT = new Date(recomTime).format("yyyy-MM-dd")
- app.log(recomT)
- if (recomT == curT) {
- if (app.globalData.user.recomTodayC <= app.globalData.user.recomC) {
- this.data.data[2].ty = 2
- } else {
- this.data.data[2].ty = 3
- }
- } else if (app.globalData.user.recomTodayC > 0) {
- this.data.data[2].ty = 3
- } else {
- this.data.data[2].ty = 2
- }
- this.refreshUI(nc)
- },
- getUserData: function () {
- net.connect({
- url: url.host + url.get_user_info,
- success: res => {
- app.globalData.user = res.data.data
- this.refreshData()
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- wx.hideShareMenu({
- })
- app.log(app.server)
- app.log(app.globalData)
- this.data.formId = options.formId || 0
- //计算段位
- if (app.server.rankStarMap.topic.starC > app.server.rankStarMap.main.starC) {
- var star = app.server.rankStarMap.topic.starC
- } else {
- var star = app.server.rankStarMap.main.starC
- }
- var f = common.starToFragment(app.server.config.rankDanList, star)
- this.data.currentFragment = f[0]
- //记录分裂数值
- this.data.cellSplitMax = app.server.config.rankDanList[this.data.currentFragment].cellSplitMax
- this.data.cellSplitSpeed = app.server.config.rankDanList[this.data.currentFragment].cellSplitSpeed
- //记录页面各项脑力值
- this.data.data[0].b = this.data.cellSplitMax
- this.data.data[0].p = '0/' + this.data.cellSplitMax
- this.data.data[1].b = app.server.config.rankDanList[this.data.currentFragment].cellPk
- this.data.data[2].b = app.server.config.rankDanList[this.data.currentFragment].cellRecom
- this.data.data[3].b = app.server.config.rankDanList[this.data.currentFragment].cellBindPhone
- //phone
- this.data.phone = app.server.phone || 0
- this.setData({
- data: this.data.data,
- phone: this.data.phone
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getUserData()
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- if (this.interval) {
- clearInterval(this.interval)
- }
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- if (this.interval) {
- clearInterval(this.interval)
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (e) {
- app.log(e)
- if (e.target.id === '2') {
- return common.shareAction({
- title: app.server.nickName + '向你发起脑力挑战,输的罚XXX!',
- path: '&page=pk&type=2&uid=' + app.server.userId,
- imageUrl: '../../resource/share_friend_pk.png',
- type: 8,
- success: res => {
- wx.navigateTo({
- url: '/pages/pk/pk?type=2'
- })
- }
- })
- } else if (e.target.id === '3') {
- return common.shareAction({
- title: app.server.nickName + '在显摆脑力,邀请你一起瓜分888元现金大奖',
- path: '',
- imageUrl: '../../resource/share_invite.png',
- type: 1,
- success: res => {
- }
- })
- }
- }
- })
- Date.prototype.format = function (fmt) {
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- }
- for (var k in o) {
- if (new RegExp("(" + k + ")").test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- }
- }
- return fmt;
- }
|