/* * 手太欠 * 愿这世界都如故事里一样 美好而动人~ */ Page({ /** * 页面的初始数据 */ data: { articleId : '', //文章id indexShow : '', //内容 mallContent : '', //简介 favoritesSee : '', //收藏状态 favoritesNumber : '', //收藏数量 subscribesSee : '', //点赞状态 subscribesNumber: '', //点赞数量 isFixedTop : 0, barHeight : getApp().globalData.barHeight, // 状态栏高度 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ articleId : options.id }) if(options.invite != undefined) { getApp().globalData.inviteText = options.invite } }, /** * 生命周期函数--监听页面显示 */ onShow() { // 获取详情数据 this.indexInfo(); }, /** * 详情数据 */ indexInfo () { wx.$api.health.healthSee(this.data.articleId).then(res => { this.setData({ indexShow : res.data, favoritesSee : res.data.isFavorite, subscribesSee : res.data.isSubscribed, favoritesNumber : res.data.favorites, subscribesNumber: res.data.subscribes, mallContent : res.data.content.replace(/\ {}) }, // 操作按钮 toolTap(e) { let newName = e.currentTarget.dataset.name if(wx.getStorageSync("token") != ''){ // 收藏 if(newName == 'favorites') { wx.$api.health.favorite(this.data.articleId).then(res => { this.setData({ favoritesSee : res.data.favorite, favoritesNumber: res.data.count }) wx.showToast({ title:'操作成功', icon:'none' }) }).catch(err => {}) return } // 点赞 wx.$api.health.subscribe(this.data.articleId).then(res => { this.setData({ subscribesSee : res.data.subscribed, subscribesNumber: res.data.count }) wx.showToast({ title:'操作成功', icon:'none' }) }).catch(err => {}) }else{ // 去登录 wx.navigateTo({ url: "/pages/login/index" }) } }, /** * 微信分享 */ onShareAppMessage(){ return { title : this.data.indexShow.title, imageUrl: this.data.indexShow.cover, path : "/pages/health/article/article?id=" + this.data.articleId + '&invite=' + wx.getStorageSync("invite") } }, /** * 返回上一页 */ returnGo() { wx.navigateBack({ delta: 1, fail: () => { wx.switchTab({ url: '/pages/index/index?invite=' + getApp().globalData.inviteText }) } }) }, /** * 回到首页 */ returnHome() { wx.switchTab({ url: '/pages/index/index?invite=' + getApp().globalData.inviteText }) }, /** * 监听页面滑动事件 */ onPageScroll(e) { this.setData({ isFixedTop: parseInt(e.scrollTop) }); }, })