var e = getApp(); Page({ data: { token: e.globalData.token, sourceUrl: e.baseUrls.sourceUrl, newsId: "", newsDetail: {}, reply: "", userIcon: "", userName: "", replyList: [], isCollect: "no", isGetFocus: !1, placeholder: "写评论", replyTo: "", replyUserName: "", isLoading: !1 }, getNewsDetail: function() { var t = this; e.restAjax.get(e.restAjax.path(e.apis.getNewsDetail, [ e.baseUrls.requestUrl, t.data.newsId ]), {}, { headers: { token: t.data.token } }, function(e, a) { t.setData({ newsDetail: a }); }, function(e, t) { console.log(t); }); }, doReplyNews: function() { var t = this; if (!t.data.isLoading) { if (!t.data.reply) return void wx.showToast({ title: "评论不能为空", icon: "error" }); var a = { content: t.data.reply, headPortrait: t.data.userIcon, userName: t.data.userName, newsId: t.data.newsId }; t.setData({ isLoading: !0 }), e.restAjax.post(e.restAjax.path(e.apis.submitNewsReply, [ e.baseUrls.requestUrl ]), a, { headers: { token: t.data.token } }, function(e, a) { "200" == e && (t.getReplyList(), t.setData({ reply: "", isLoading: !1 })); }, function(e, a) { console.log(a), t.setData({ isLoading: !1 }); }); } }, getReplyList: function() { var t = this; e.restAjax.get(e.restAjax.path(e.apis.getNewsReplyList, [ e.baseUrls.requestUrl ]), { newsId: t.data.newsId }, { headers: { token: t.data.token } }, function(e, a) { t.setData({ replyList: a }); }, function(e, t) { console.log(t); }); }, getIsCollect: function() { var t = this; e.restAjax.get(e.restAjax.path(e.apis.isCollectNews, [ e.baseUrls.requestUrl, t.data.newsId ]), {}, { headers: { token: t.data.token } }, function(e, a) { t.setData({ isCollect: a }); }, function(e, t) { console.log(t); }); }, toggleCollect: function() { "no" == this.data.isCollect ? this.collectNews() : this.cancelCollect(); }, collectNews: function() { var t = this; e.restAjax.post(e.restAjax.path(e.apis.doCollectNews, [ e.baseUrls.requestUrl ]), { newsId: t.data.newsId }, { headers: { token: t.data.token } }, function(e, a) { "200" == e && (wx.showToast({ title: "收藏成功!", icon: "success" }), t.getIsCollect()); }, function(e, t) { console.log(t); }); }, cancelCollect: function() { var t = this; e.restAjax.delete(e.restAjax.path(e.apis.cancelCollectNews, [ e.baseUrls.requestUrl, t.data.newsId ]), {}, { headers: { token: t.data.token } }, function(e, a) { "200" == e && (wx.showToast({ title: "已取消收藏!", icon: "success" }), t.getIsCollect()); }, function(e, t) { console.log(t); }); }, getFocus: function(e) { var t = e.currentTarget.dataset.user, a = e.currentTarget.dataset.id, s = e.currentTarget.dataset.name; this.setData({ isGetFocus: !0, placeholder: "回复" + t + ":", replyTo: a, replyUserName: s }); }, inputBlur: function() { this.data.reply || this.setData({ placeholder: "讨论一下", isGetFocus: !1 }); }, doReply: function() { this.data.replyTo ? this.doReplyReply() : this.doReplyNews(); }, doReplyReply: function() { var t = this; if (!t.data.isLoading) { var a = { content: t.data.reply, headPortrait: t.data.userIcon, userName: t.data.userName, newsId: t.data.newsId, commentId: t.data.replyTo, replyCommentId: t.data.replyTo, replyNewsCommentId: t.data.replyTo, replyUserName: t.data.replyUserName }; t.setData({ isLoading: !0 }), e.restAjax.post(e.restAjax.path(e.apis.submitNewsReply, [ e.baseUrls.requestUrl ]), a, { headers: { token: t.data.token } }, function(e, a) { "200" == e && (wx.showToast({ title: "评论成功!", icon: "success" }), t.getReplyList(), t.setData({ reply: "", replyTo: "", replyUserName: "", placeholder: "讨论一下", isLoading: !1 })); }, function(e, a) { console.log(a), t.setData({ isLoading: !1 }); }); } }, onLoad: function(t) { this.setData({ newsId: t.newsId, userIcon: wx.getStorageSync("userIcon"), userName: wx.getStorageSync("name"), token: e.globalData.token }), this.getNewsDetail(), this.getReplyList(), this.getIsCollect(); }, onReady: function() {}, onShow: function() {}, onHide: function() {}, onUnload: function() {}, onPullDownRefresh: function() {}, onReachBottom: function() {}, onShareAppMessage: function() {} });