购买成功后更新列表上的游戏状态

This commit is contained in:
zhl 2019-02-21 14:21:28 +08:00
parent b98a266125
commit b465ec3f73
6 changed files with 56 additions and 9 deletions

View File

@ -1,5 +1,6 @@
export default { 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', hostBase: 'https://pay.kingsome.cn',
//游戏页面根路径 //游戏页面根路径
gameBase: 'http://192.168.100.232', gameBase: 'http://192.168.100.232',

View File

@ -27,6 +27,7 @@ export default {
events: { events: {
BUY_GAME_SUCCESS: 'buy-game-success', BUY_GAME_SUCCESS: 'buy-game-success',
LOGIN_FINISHED : 'login-finished', LOGIN_FINISHED : 'login-finished',
UPDATE_RECENT_GAMES: 'update-recent-games' UPDATE_RECENT_GAMES: 'update-recent-games',
UPDATE_GAME_STATUS: 'update-game-status'
} }
} }

View File

@ -121,6 +121,7 @@
self.bottomActionCfg.mainBtnIconClass = 'icon-merge'; self.bottomActionCfg.mainBtnIconClass = 'icon-merge';
self.bottomActionCfg.mainBtnTitle = '开始游戏'; self.bottomActionCfg.mainBtnTitle = '开始游戏';
self.bottomActionCfg.primary = true; self.bottomActionCfg.primary = true;
jcEvent.emit(jcEvent.events.UPDATE_GAME_STATUS, {gid: self.id});
self.$apply(); self.$apply();
}); });
this.getRecord(); this.getRecord();
@ -180,6 +181,7 @@
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}) })
jcEvent.emit(jcEvent.events.UPDATE_GAME_STATUS, {gid: this.id});
this.getRecord(); this.getRecord();
} }
} catch (err) { } catch (err) {

View File

@ -90,6 +90,7 @@
async onLoad(options) { async onLoad(options) {
let userInfo = this.$parent.getUserInfo(); let userInfo = this.$parent.getUserInfo();
let self = this;
console.log(userInfo); console.log(userInfo);
if (userInfo) { if (userInfo) {
this.nickname = userInfo.nickName; this.nickname = userInfo.nickName;
@ -113,6 +114,15 @@
console.log('catch update-recent-games event'); console.log('catch update-recent-games event');
this.getRecendGames() 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() { getAllData() {
this.getRecords(); this.getRecords();
@ -122,6 +132,7 @@
onUnload() { onUnload() {
jcEvent.remove(jcEvent.events.LOGIN_FINISHED, this); jcEvent.remove(jcEvent.events.LOGIN_FINISHED, this);
jcEvent.remove(jcEvent.events.UPDATE_RECENT_GAMES, this); jcEvent.remove(jcEvent.events.UPDATE_RECENT_GAMES, this);
jcEvent.remove(jcEvent.events.UPDATE_GAME_STATUS, this);
} }
onShow() { onShow() {
let userInfo = this.$parent.getUserInfo(); let userInfo = this.$parent.getUserInfo();

View File

@ -28,11 +28,13 @@
mainBtnTitle: '购买', mainBtnTitle: '购买',
secondBtnIconClass: 'icon-forbid', secondBtnIconClass: 'icon-forbid',
secondBtnTitle: '取消' secondBtnTitle: '取消'
} },
tid: ''
}; };
methods = { methods = {
bottomMainTap(e) { bottomMainTap(e) {
console.log('bottomMainTap'); console.log('bottomMainTap');
let self = this;
wepy.showLoading({ wepy.showLoading({
title: '支付中' title: '支付中'
}) })
@ -41,6 +43,7 @@
console.log(res.data); console.log(res.data);
if (res.errcode === 0) { if (res.errcode === 0) {
let payResult = res.data; let payResult = res.data;
self.tid = res.tid;
wx.requestPayment({ wx.requestPayment({
'timeStamp': payResult.timeStamp, 'timeStamp': payResult.timeStamp,
'nonceStr': payResult.nonceStr, 'nonceStr': payResult.nonceStr,
@ -51,12 +54,7 @@
wepy.hideLoading(); wepy.hideLoading();
if (res.errMsg === 'requestPayment:ok') { if (res.errMsg === 'requestPayment:ok') {
console.log('支付成功') console.log('支付成功')
jcEvent.emit(jcEvent.events.BUY_GAME_SUCCESS, {}); self.queryOrder();
wepy.showToast({
title: '支付成功',
icon: 'none',
duration: 2000
})
} else if (res.errMsg === 'requestPayment:fail cancel' || res.errMsg === 'requestPayment:cancel') { } else if (res.errMsg === 'requestPayment:fail cancel' || res.errMsg === 'requestPayment:cancel') {
wepy.showToast({ wepy.showToast({
title: '用户取消支付', title: '用户取消支付',
@ -89,5 +87,25 @@
onLoad(params) { onLoad(params) {
this.gid = decodeURIComponent(params.gid); 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
})
}
}
} }
</script> </script>

View File

@ -52,6 +52,7 @@
import recentGame from '../components/recent-game'; import recentGame from '../components/recent-game';
import zanLoadmore from '../components/zan-loadmore'; import zanLoadmore from '../components/zan-loadmore';
import g from '../common/global'; import g from '../common/global';
import jcEvent from '../common/jc-event';
export default class SearchPage extends wepy.page { export default class SearchPage extends wepy.page {
mixins = [base, tips]; mixins = [base, tips];
@ -135,6 +136,16 @@
async onLoad(options) { async onLoad(options) {
this.getRecords(); this.getRecords();
this.typeArr.unshift('所有类型') 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() { onShow() {
@ -184,5 +195,8 @@
this.noData = false; this.noData = false;
this.noMore = true; this.noMore = true;
} }
onUnload() {
jcEvent.remove(jcEvent.events.UPDATE_GAME_STATUS, this);
}
} }
</script> </script>