city_card/pages/talk/talkDetail.js
2023-07-15 14:25:28 +08:00

226 lines
7.0 KiB
JavaScript

var e = getApp();
Page({
data: {
sourceUrl: e.baseUrls.sourceUrl,
trifleMyselfId: "",
token: e.globalData.token,
talkDetail: {},
serviceUrl: e.baseUrls.serviceUrl,
baseImgUrl: e.baseUrls.baseImgUrl,
reply: "",
userIcon: "",
userName: "",
replyList: [],
goodCount: 0,
isClickGood: "no",
clickGoodPeople: [],
isGetFocus: !1,
placeholder: "讨论一下",
replyTo: "",
replyUserName: ""
},
getTalkDetail: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getTalkDetail, [ e.baseUrls.requestUrl, t.data.trifleMyselfId ]), {}, {
headers: {
token: t.data.token
}
}, function(e, a) {
a.photo && (a.photo = a.photo.split(",")), t.setData({
talkDetail: a
});
}, function(e, t) {
console.log(t);
});
},
doReplyTalk: function() {
var t = this, a = {
content: t.data.reply,
headPortrait: t.data.userIcon,
userName: t.data.userName,
trifleMyselfId: t.data.trifleMyselfId
};
e.restAjax.post(e.restAjax.path(e.apis.replyTalk, [ e.baseUrls.requestUrl ]), a, {
headers: {
token: t.data.token
}
}, function(e, a) {
"200" == e && (wx.showToast({
title: "评论成功!",
icon: "success"
}), t.setData({
reply: ""
}), t.getReplyList());
}, function(e, t) {
console.log(t);
});
},
getReplyList: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getTalkReplyList, [ e.baseUrls.requestUrl ]), {
trifleMyselfId: t.data.trifleMyselfId
}, {
headers: {
token: t.data.token
}
}, function(e, a) {
t.setData({
replyList: a
});
}, function(e, t) {
console.log(t);
});
},
getGoodCount: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.getTalkGoodCount, [ e.baseUrls.requestUrl ]), {
trifleMyselfId: t.data.trifleMyselfId
}, {
headers: {
token: t.data.token
}
}, function(e, a) {
t.setData({
goodCount: a.data
});
}, function(e, t) {
console.log(t);
});
},
getIsClickGood: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.talkIsClicked, [ e.baseUrls.requestUrl, t.data.trifleMyselfId ]), {}, {
headers: {
token: t.data.token
}
}, function(e, a) {
t.setData({
isClickGood: a
});
}, function(e, t) {
console.log(t);
});
},
toggleGood: function() {
"no" == this.data.isClickGood ? this.clickGood() : this.cancelGood();
},
getClickedPeople: function() {
var t = this;
e.restAjax.get(e.restAjax.path(e.apis.talkClickPeople, [ e.baseUrls.requestUrl ]), {
page: 1,
rows: 10,
trifleMyselfId: t.data.trifleMyselfId
}, {
headers: {
token: t.data.token
}
}, function(e, a) {
console.log(a), t.setData({
clickGoodPeople: a.rows
});
}, function(e, t) {
console.log(t);
});
},
clickGood: function() {
var t = this, a = {
trifleMyselfId: t.data.trifleMyselfId,
userName: t.data.userName,
headPortrait: t.data.userIcon
};
e.restAjax.post(e.restAjax.path(e.apis.talkClickGood, [ e.baseUrls.requestUrl ]), a, {
headers: {
token: t.data.token
}
}, function(e, a) {
"200" == e && (t.getGoodCount(), t.getClickedPeople(), t.getIsClickGood());
}, function(e, t) {
console.log(t);
});
},
cancelGood: function() {
var t = this;
e.restAjax.delete(e.restAjax.path(e.apis.talkCancelGood, [ e.baseUrls.requestUrl, t.data.trifleMyselfId ]), {}, {
headers: {
token: t.data.token
}
}, function(e, a) {
"200" == e && (t.getGoodCount(), t.getClickedPeople(), t.getIsClickGood());
}, function(e, t) {
console.log(t);
});
},
getFocus: function(e) {
var t = e.currentTarget.dataset.user, a = e.currentTarget.dataset.id, o = e.currentTarget.dataset.name;
this.setData({
isGetFocus: !0,
placeholder: "回复" + t + ":",
replyTo: a,
replyUserName: o
});
},
inputBlur: function() {
this.data.reply || this.setData({
placeholder: "讨论一下",
isGetFocus: !1
});
},
doReply: function() {
this.data.replyTo ? this.doReplyReply() : this.doReplyTalk();
},
doReplyReply: function() {
var t = this, a = {
content: t.data.reply,
headPortrait: t.data.userIcon,
userName: t.data.userName,
trifleMyselfId: t.data.trifleMyselfId,
commentId: t.data.replyTo,
replyCommentId: t.data.replyTo,
replyUserName: t.data.replyUserName
};
e.restAjax.post(e.restAjax.path(e.apis.replyTalk, [ 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: "讨论一下"
}));
}, 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.talkDetail.photo.length; o++) {
var s = this.data.serviceUrl + this.data.baseImgUrl + this.data.talkDetail.photo[o];
a.push(s);
}
wx.previewImage({
current: t,
urls: a
});
},
onLoad: function(t) {
this.setData({
trifleMyselfId: t.trifleMyselfId,
userIcon: wx.getStorageSync("userIcon"),
userName: wx.getStorageSync("name"),
token: e.globalData.token
}), this.getTalkDetail(), this.getReplyList(), this.getGoodCount(), this.getIsClickGood(),
this.getClickedPeople();
},
onReady: function() {},
onShow: function() {},
onHide: function() {},
onUnload: function() {},
onPullDownRefresh: function() {},
onReachBottom: function() {},
onShareAppMessage: function() {}
});