diff --git a/littleApp_child/pages/home/home.js b/littleApp_child/pages/home/home.js index f19bfaf..acd153e 100644 --- a/littleApp_child/pages/home/home.js +++ b/littleApp_child/pages/home/home.js @@ -17,6 +17,11 @@ var timeCount = 60; var timer; var phone; var name; +// 用户信息的缓存 +var babyCache = ['',''] + // 文章的缓存 +var artCache = ['',''] + Page({ /*---------属性变量--------*/ data: { @@ -29,41 +34,36 @@ Page({ list:[], userInfo:'', inputFocus: { nameInput: false, phoneInput: false, codeInput: false }, - currentBabyIndex:0 + currentBabyIndex:0, + babys:[] }, /*---------生命周期--------*/ onLoad: function () { this.calculatePageSize() - var isFirst = wx.getStorageSync('isFirst') - // 网络监听 - this.networkStatusChange() - if (!isFirst) { - wx.setStorageSync('isFirst', 'isFirst') - this.welcomePage() - } else { - if (app.globalData.token == null || app.globalData.token == '') { - this.toLogin() + // 网络监听 + this.networkStatusChange() + if (app.globalData.token == null || app.globalData.token == '') { + this.welcomePage() + } else { + + this.homePage() + // 监听事件 + event.on('likeChanged', this, function (data) { + if (data.categoryIndex == -1) { + var artList = this.data.crisisCategorie + artList[data.articleIdIndex].likeCount++ + this.setData({ + crisisCategorie: artList + }); } else { - - this.homePage() - // 监听事件 - event.on('likeChanged', this, function (data) { - if (data.categoryIndex == -1) { - var artList = this.data.crisisCategorie - artList[data.articleIdIndex].likeCount++ - this.setData({ - crisisCategorie: artList - }); - } else { - var artList = this.data.articleList - artList[data.categoryIndex].article[data.articleIdIndex].likeCount++ - this.setData({ - articleList: artList - }); - } - }) + var artList = this.data.articleList + artList[data.categoryIndex].article[data.articleIdIndex].likeCount++ + this.setData({ + articleList: artList + }); } - } + }) + } }, onUnload: function () { // 移除监听 @@ -142,17 +142,20 @@ Page({ }, // 改变baby changeBaby(e){ - this.setData({ currentBabyIndex: e.currentTarget.dataset.index }) + this.setUserInfo(babyCache[e.currentTarget.dataset.index]) + this.setArtInfo(artCache[e.currentTarget.dataset.index]) }, /*---------自定义函数--------*/ homePage() { var that = this this.requestHomeInfo() that.setData({ - pageType: 2 + pageType: 2, + // babys: [1,2] + babys: app.globalData.userId }) }, toLogin() { @@ -195,12 +198,9 @@ Page({ var param = { 'token': app.globalData.token } networkUtil._get(api.userInfo + app.globalData.currentId, {}, function (res) { console.log('获取用户信息',res) - app.globalData.days = res.data.data.days - app.globalData.userInfo = res.data.data self.getArticleInfo(res.data.data.days) - self.setData({ - userData: res.data.data - }) + self.setUserInfo(res.data.data) + babyCache[self.data.currentBabyIndex] = res.data.data }, function (res) { networkUtil.showErrorToast(res.errormsg) }) @@ -210,14 +210,29 @@ Page({ // 文章列表 networkUtil._get(api.homeArtList, { page: 0, limit: 100, days: days }, function (res) { console.log('获取文章信息', res.data.list) - app.globalData.artList = res.data.list - self.setData({ - list: res.data.list - }) + artCache[self.data.currentBabyIndex] = res.data.list + self.setArtInfo(res.data.list) }, function (res) { wx.stopPullDownRefresh() }) }, + // 设置UI 用户信息 + setUserInfo(data){ + var self = this + app.globalData.days = data.days + app.globalData.userInfo = data + self.setData({ + userData: data + }) + }, + // 设置UI 文章信息 + setArtInfo(list) { + var self = this + app.globalData.artList = list + self.setData({ + list: list + }) + }, // 文章点赞 articleLike(e) { console.log(e) @@ -271,7 +286,23 @@ Page({ that.setData({ time: '0s' }) - networkUtil.showErrorToast(res.errormsg) + if (res.errorcode == 4003) { + wx.showModal({ + title: '提示', + content: '您还没有在医院建档,是否立即使用游客身份注册', + success: function (res) { + if (res.confirm) { + wx.navigateTo({ + url: '../Register/Register', + }) + } else if (res.cancel) { + console.log('用户点击取消') + } + } + }) + } else { + networkUtil.showErrorToast(res.errormsg) + } }) if (timeCount == 60) { this.keepTime() diff --git a/littleApp_child/pages/home/home.wxml b/littleApp_child/pages/home/home.wxml index 7594648..d6de116 100644 --- a/littleApp_child/pages/home/home.wxml +++ b/littleApp_child/pages/home/home.wxml @@ -11,13 +11,16 @@ - + {{userData.username}} - {{userData.username}} + 儿童2 + + + {{userData.username}} - + 出生日期 {{userData.birth}} @@ -135,7 +138,7 @@ - + 游客注册 @@ -162,7 +165,6 @@ - 游客注册 \ No newline at end of file