123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- // pages/manage/manage.js
- const api = require('../../utils/api.js')
- const util = require('../../utils/util.js')
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- tabIndex: 1,
- is_Change: false,
- hotParams: {
- page: 1,
- offset: 10,
- rank_type: 2
- },
- hotGameCount: 99,
- hotGames: [],
- hotFloats: [],
- goldParams: {
- page: 1,
- offset: 10,
- rank_type: 4
- },
- goldGameCount: 99,
- goldGames: [],
- goldFloats: [],
- playParams: {
- page: 1,
- offset: 10
- },
- playGameCount: 99,
- playGames: [],
- playFloats: [],
- auth: {},
- mpType: app.globalData.mpType
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- auth: app.globalData.auth
- })
- if (this.data.auth.gain === 2) {
- this.getGoldGames()
- } else {
- this.setData({
- tabIndex: 2
- })
- }
- this.getHotGames()
- this.getPlayGames()
- },
- routeDetail: function (e) {
- // util.routeTo(`/pages/detail/detail?id=${e.currentTarget.dataset.id}`)
- },
- ChangeGame: function (e) {
- const _self = this
- let index = e.currentTarget.dataset.index
- if (e.currentTarget.dataset.clicktype === 'add') {
- api.addMemGame({ game_id: e.currentTarget.dataset.id }).then(res => {
- _self.statusChange(2, res, index)
- })
- } else if (e.currentTarget.dataset.clicktype === 'cancel') {
- api.delMemGame({ game_id: e.currentTarget.dataset.id }).then(res => {
- _self.statusChange(1, res, index)
- })
- }
- },
- statusChange: function (status, data, itemIndex) {
- const _self = this
- if (data.code === 200) {
- if (this.data.tabIndex === 0) {
- this.setData({
- playParams: {
- page: 1,
- offset: 10
- },
- is_Change: false
- })
- this.getPlayGames()
- }
- wx.showToast({
- title: data.msg,
- icon: 'success',
- duration: 500,
- success: function () {
- setTimeout(() => {
- let _id = '';
- if (_self.data.tabIndex === 1) {
- _id = _self.data.goldGames[itemIndex].game_id
- } else if (_self.data.tabIndex === 2) {
- _id = _self.data.hotGames[itemIndex].game_id
- } else {
- _id = _self.data.playGames[itemIndex].game_id
- }
- // 佣金
- _self.data.goldGames.forEach((item, ids) => {
- if (item.game_id === _id) {
- _self.data.goldGames[ids].is_add = status
- }
- })
- // 热度
- _self.data.hotGames.forEach((item, ids) => {
- if (item.game_id === _id) {
- _self.data.hotGames[ids].is_add = status
- }
- })
- // 玩过
- _self.data.playGames.forEach((item, ids) => {
- if (item.game_id === _id) {
- _self.data.playGames[ids].is_add = status
- }
- })
- _self.setData({
- goldGames: _self.data.goldGames,
- hotGames: _self.data.hotGames,
- playGames: _self.data.playGames,
- is_Change: true
- })
- }, 500)
- }
- })
- } else {
- wx.showToast({
- title: '请稍后再试',
- icon: 'none'
- })
- }
- },
- getHotGames: function (hdld) {
- api.getGameList(hdld ? { ...this.data.hotParams, HideLoading: true } : this.data.hotParams).then(res => {
- this.setData({
- hotGames: this.data.hotGames.concat(res.data.list),
- hotGameCount: res.data.count,
- hotFloats: this.data.hotFloats.concat(res.data.list.map((item) => {
- return this.data.mpType === 'gd' ? item.mem_agent_integral : item.mem_agent_reward.toFixed(2)
- }))
- })
- })
- },
- getGoldGames: function (hdld) {
- api.getGameList(hdld ? { ...this.data.goldParams, HideLoading: true } : this.data.goldParams).then(res => {
- this.setData({
- goldGames: this.data.goldGames.concat(res.data.list),
- goldGameCount: res.data.count,
- goldFloats: this.data.goldFloats.concat(res.data.list.map((item) => {
- return this.data.mpType === 'gd' ? item.mem_agent_integral : item.mem_agent_reward.toFixed(2)
- }))
- })
- })
- },
- getPlayGames: function (hdld) {
- api.getGamePlayList(hdld ? { ...this.data.playParams, HideLoading: true } : this.data.playParams).then(res => {
- this.setData({
- playGames: this.data.playParams.page === 1 ? res.data.list : this.data.playGames.concat(res.data.list),
- playGameCount: res.data.count,
- playFloats: this.data.playParams.page === 1 ? res.data.list.map((item) => {
- return this.data.mpType === 'gd' ? item.mem_agent_integral : (item.mem_agent_reward || 0).toFixed(2)
- }) : this.data.playFloats.concat(res.data.list.map((item) => {
- return this.data.mpType === 'gd' ? item.mem_agent_integral : (item.mem_agent_reward || 0).toFixed(2)
- }))
- })
- })
- },
- tabChange: function (e) {
- let Index = e.target.dataset.index * 1
- if (Index === 0 && this.data.is_Change) {
- this.setData({
- playParams: {
- page: 1,
- offset: 10
- },
- is_Change: false
- })
- this.getPlayGames()
- }
- this.setData({
- tabIndex: e.target.dataset.index * 1
- })
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- var pages = getCurrentPages();
- if (pages.length > 1) {
- var prePage = pages[pages.length - 2];
- prePage.getBoxGameList && prePage.getBoxGameList()
- }
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- console.log(this.data.tabIndex)
- if (this.data.tabIndex === 1) {
- if (this.data.goldGameCount <= this.data.goldGames.length) {
- return false
- }
- // 佣金
- this.setData({
- goldParams: {
- page: ++this.data.goldParams.page,
- offset: 10,
- rank_type: 4
- }
- })
- this.getGoldGames()
- } else if (this.data.tabIndex === 2) {
- if (this.data.hotGameCount <= this.data.hotGames.length) {
- return false
- }
- // 热度
- this.setData({
- hotParams: {
- page: ++this.data.hotParams.page,
- offset: 10,
- rank_type: 2
- }
- })
- this.getHotGames()
- } else {
- if (this.data.playGameCount <= this.data.playGames.length) {
- return false
- }
- // 最近
- this.setData({
- playParams: {
- page: ++this.data.playParams.page,
- offset: 10
- }
- })
- this.getPlayGames()
- }
- },
- // 页面相关事件处理函数--监听用户下拉动作
- onPullDownRefresh: function () {
- switch (this.data.tabIndex) {
- case 0:
- this.getPlayGames(true)
- break;
- case 1:
- this.getGoldGames(true)
- break;
- case 2:
- this.getHotGames(true)
- break;
- }
- wx.stopPullDownRefresh()
- },
- openGame: function (e) {
- let id = e.currentTarget.dataset.id
- api.openGame({
- game_id: id
- }).then(res => {
- console.log(res)
- }, err => {
- console.log(err)
- })
- }
- })
|