购买成功后更新列表上的游戏状态
This commit is contained in:
parent
b98a266125
commit
b465ec3f73
@ -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',
|
||||
|
@ -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'
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user