city_card/pages/neighbor/help/helpDetail.js

164 lines
5.2 KiB
JavaScript
Raw Normal View History

2023-07-15 14:25:28 +08:00
var e = getApp();
Page({
data: {
sourceUrl: e.baseUrls.sourceUrl,
token: e.globalData.token,
neighborId: "",
helpDetail: {},
reply: "",
userIcon: "",
userName: "",
replyList: [],
serviceUrl: e.baseUrls.serviceUrl,
baseImgUrl: e.baseUrls.baseImgUrl,
isGetFocus: !1,
placeholder: "写评论",
replyTo: "",
replyUserName: "",
childNeighborId: "",
isLoading: !1
},
getHelpDetail: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getHelpDetail, [ e.baseUrls.requestUrl, t.data.neighborId ]), {}, {
headers: {
token: t.data.token
}
}, function(e, a) {
a.photo && (a.photo = a.photo.split(",")), t.setData({
helpDetail: a
});
}, function(e, t) {
console.log(t);
});
},
doReplyHelp: function() {
var t = this;
if (!t.data.isLoading) {
var a = {
content: t.data.reply,
headPortrait: t.data.userIcon,
neighborId: t.data.neighborId,
userName: t.data.userName
};
t.setData({
isLoading: !0
}), e.restAjax.post(e.restAjax.path(e.apis.doReplyHelp, [ e.baseUrls.requestUrl ]), a, {
headers: {
token: t.data.token
}
}, function(e, a) {
"200" == e && (t.setData({
isLoading: !1
}), wx.showToast({
title: "回复成功!",
icon: "success"
}), t.getRelyList(), t.setData({
reply: ""
}));
}, function(e, a) {
console.log(a), t.setData({
isLoading: !1
});
});
}
},
getRelyList: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getReplyList, [ e.baseUrls.requestUrl ]), {
neighborId: t.data.neighborId
}, {
headers: {
token: t.data.token
}
}, function(e, a) {
t.setData({
replyList: a
}), console.log(a);
}, function(e, t) {
console.log(t);
});
},
viewImg: function(e) {
for (var t = this.data.serviceUrl + this.data.baseImgUrl + e.currentTarget.dataset.id, a = [], o = 0; o < this.data.helpDetail.photo.length; o++) {
var s = this.data.serviceUrl + this.data.baseImgUrl + this.data.helpDetail.photo[o];
a.push(s);
}
wx.previewImage({
current: t,
urls: a
});
},
getFocus: function(e) {
var t = e.currentTarget.dataset.user, a = e.currentTarget.dataset.id, o = e.currentTarget.dataset.name, s = e.currentTarget.dataset.neighbor;
console.log(s), this.setData({
isGetFocus: !0,
placeholder: "回复" + t + ":",
replyTo: a,
replyUserName: o,
childNeighborId: s
});
},
inputBlur: function() {
this.data.reply || this.setData({
placeholder: "讨论一下",
isGetFocus: !1
});
},
doReply: function() {
this.data.replyTo ? this.doReplyReply() : this.doReplyHelp();
},
doReplyReply: function() {
var t = this;
if (!t.data.isLoading) {
var a = {
content: t.data.reply,
headPortrait: t.data.userIcon,
userName: t.data.userName,
replyCommentId: t.data.replyTo,
replyUserName: t.data.replyUserName,
neighborId: t.data.childNeighborId,
replyNeighborCommentId: t.data.replyTo
};
t.setData({
isLoading: !0
}), e.restAjax.post(e.restAjax.path(e.apis.doReplyHelp, [ e.baseUrls.requestUrl ]), a, {
headers: {
token: t.data.token
}
}, function(e, a) {
"200" == e && (t.setData({
isLoading: !1
}), wx.showToast({
title: "评论成功!",
icon: "success"
}), t.getRelyList(), t.setData({
reply: "",
replyTo: "",
replyUserName: "",
placeholder: "讨论一下"
}));
}, function(e, a) {
console.log(a), t.setData({
isLoading: !1
});
});
}
},
onLoad: function(t) {
this.setData({
neighborId: t.neighborId,
userIcon: wx.getStorageSync("userIcon"),
userName: wx.getStorageSync("name"),
token: e.globalData.token
}), this.getHelpDetail(), this.getRelyList();
},
onReady: function() {},
onShow: function() {},
onHide: function() {},
onUnload: function() {},
onPullDownRefresh: function() {},
onReachBottom: function() {},
onShareAppMessage: function() {}
});