From b465ec3f7325a411373d5e3ea158fb357b2c4b0a Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 21 Feb 2019 14:21:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E6=88=90=E5=8A=9F=E5=90=8E?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=97=E8=A1=A8=E4=B8=8A=E7=9A=84=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/global.js | 3 ++- src/common/jc-event.js | 3 ++- src/pages/gameInfo.wpy | 2 ++ src/pages/index.wpy | 11 +++++++++++ src/pages/product.wpy | 32 +++++++++++++++++++++++++------- src/pages/search.wpy | 14 ++++++++++++++ 6 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/common/global.js b/src/common/global.js index fb329e2..0824e08 100644 --- a/src/common/global.js +++ b/src/common/global.js @@ -1,5 +1,6 @@ export default { - apiBase: 'http://192.168.100.232', + // apiBase: 'http://192.168.100.232', + apiBase: 'https://ghost-test.kingsome.cn', hostBase: 'https://pay.kingsome.cn', //游戏页面根路径 gameBase: 'http://192.168.100.232', diff --git a/src/common/jc-event.js b/src/common/jc-event.js index e4dd478..d6278ac 100644 --- a/src/common/jc-event.js +++ b/src/common/jc-event.js @@ -27,6 +27,7 @@ export default { events: { BUY_GAME_SUCCESS: 'buy-game-success', LOGIN_FINISHED : 'login-finished', - UPDATE_RECENT_GAMES: 'update-recent-games' + UPDATE_RECENT_GAMES: 'update-recent-games', + UPDATE_GAME_STATUS: 'update-game-status' } } diff --git a/src/pages/gameInfo.wpy b/src/pages/gameInfo.wpy index 7e571f7..b2a6190 100644 --- a/src/pages/gameInfo.wpy +++ b/src/pages/gameInfo.wpy @@ -121,6 +121,7 @@ self.bottomActionCfg.mainBtnIconClass = 'icon-merge'; self.bottomActionCfg.mainBtnTitle = '开始游戏'; self.bottomActionCfg.primary = true; + jcEvent.emit(jcEvent.events.UPDATE_GAME_STATUS, {gid: self.id}); self.$apply(); }); this.getRecord(); @@ -180,6 +181,7 @@ icon: 'none', duration: 2000 }) + jcEvent.emit(jcEvent.events.UPDATE_GAME_STATUS, {gid: this.id}); this.getRecord(); } } catch (err) { diff --git a/src/pages/index.wpy b/src/pages/index.wpy index df6a1df..3a5a30d 100644 --- a/src/pages/index.wpy +++ b/src/pages/index.wpy @@ -90,6 +90,7 @@ async onLoad(options) { let userInfo = this.$parent.getUserInfo(); + let self = this; console.log(userInfo); if (userInfo) { this.nickname = userInfo.nickName; @@ -113,6 +114,15 @@ console.log('catch update-recent-games event'); this.getRecendGames() }); + jcEvent.on(jcEvent.events.UPDATE_GAME_STATUS, this, data => { + for(let g of self.records) { + if (g.gid == data.gid) { + g.owned = true; + break; + } + } + self.$apply(); + }); } getAllData() { this.getRecords(); @@ -122,6 +132,7 @@ onUnload() { jcEvent.remove(jcEvent.events.LOGIN_FINISHED, this); jcEvent.remove(jcEvent.events.UPDATE_RECENT_GAMES, this); + jcEvent.remove(jcEvent.events.UPDATE_GAME_STATUS, this); } onShow() { let userInfo = this.$parent.getUserInfo(); diff --git a/src/pages/product.wpy b/src/pages/product.wpy index 408832e..12ef009 100644 --- a/src/pages/product.wpy +++ b/src/pages/product.wpy @@ -28,11 +28,13 @@ mainBtnTitle: '购买', secondBtnIconClass: 'icon-forbid', secondBtnTitle: '取消' - } + }, + tid: '' }; methods = { bottomMainTap(e) { console.log('bottomMainTap'); + let self = this; wepy.showLoading({ title: '支付中' }) @@ -41,6 +43,7 @@ console.log(res.data); if (res.errcode === 0) { let payResult = res.data; + self.tid = res.tid; wx.requestPayment({ 'timeStamp': payResult.timeStamp, 'nonceStr': payResult.nonceStr, @@ -51,12 +54,7 @@ wepy.hideLoading(); if (res.errMsg === 'requestPayment:ok') { console.log('支付成功') - jcEvent.emit(jcEvent.events.BUY_GAME_SUCCESS, {}); - wepy.showToast({ - title: '支付成功', - icon: 'none', - duration: 2000 - }) + self.queryOrder(); } else if (res.errMsg === 'requestPayment:fail cancel' || res.errMsg === 'requestPayment:cancel') { wepy.showToast({ title: '用户取消支付', @@ -89,5 +87,25 @@ onLoad(params) { this.gid = decodeURIComponent(params.gid); } + async queryOrder() { + try { + let res = await http.post('/api/emulated/query_order', {tid: this.tid}); + if (res.errcode === 0 && res.result === 1) { + wepy.showToast({ + title: '支付成功', + icon: 'none', + duration: 2000 + }) + jcEvent.emit(jcEvent.events.BUY_GAME_SUCCESS, {}); + } + } catch (err) { + console.log(err); + wepy.showToast({ + title: '支付失败', + icon: 'none', + duration: 2000 + }) + } + } } diff --git a/src/pages/search.wpy b/src/pages/search.wpy index 04b771d..f7f94a9 100644 --- a/src/pages/search.wpy +++ b/src/pages/search.wpy @@ -52,6 +52,7 @@ import recentGame from '../components/recent-game'; import zanLoadmore from '../components/zan-loadmore'; import g from '../common/global'; + import jcEvent from '../common/jc-event'; export default class SearchPage extends wepy.page { mixins = [base, tips]; @@ -135,6 +136,16 @@ async onLoad(options) { this.getRecords(); this.typeArr.unshift('所有类型') + let self = this; + jcEvent.on(jcEvent.events.UPDATE_GAME_STATUS, this, data => { + for(let g of self.records) { + if (g.gid == data.gid) { + g.owned = true; + break; + } + } + self.$apply(); + }); } onShow() { @@ -184,5 +195,8 @@ this.noData = false; this.noMore = true; } + onUnload() { + jcEvent.remove(jcEvent.events.UPDATE_GAME_STATUS, this); + } }