Initial commit
This commit is contained in:
@@ -3,12 +3,20 @@ const app = getApp()
|
||||
Page({
|
||||
data: {
|
||||
coupons: [],
|
||||
user: {}
|
||||
user: {},
|
||||
loading: true
|
||||
},
|
||||
onLoad() {
|
||||
this.fetchCoupons();
|
||||
},
|
||||
onShow() {
|
||||
// Optimistically update from global data
|
||||
if (app.globalData.userInfo && app.globalData.userInfo.phone) {
|
||||
this.setData({
|
||||
user: app.globalData.userInfo,
|
||||
loading: false
|
||||
});
|
||||
}
|
||||
this.getUserInfo();
|
||||
this.fetchCoupons();
|
||||
},
|
||||
@@ -19,12 +27,14 @@ Page({
|
||||
// Fetch latest user info from backend to check if phone exists in DB
|
||||
request({ url: '/user/' }).then(user => {
|
||||
app.globalData.userInfo = user; // Sync global data
|
||||
this.setData({ user: user });
|
||||
this.setData({ user: user, loading: false });
|
||||
}).catch(err => {
|
||||
console.error('Failed to fetch user info', err)
|
||||
// Fallback to global data if fetch fails
|
||||
if (app.globalData.userInfo) {
|
||||
this.setData({ user: app.globalData.userInfo });
|
||||
this.setData({ user: app.globalData.userInfo, loading: false });
|
||||
} else {
|
||||
this.setData({ loading: false });
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user