city_card/packagecard/moments/momentsdetail/momentsdetail.js
2023-07-15 14:25:28 +08:00

606 lines
22 KiB
JavaScript
Executable File

var t = getApp(), a = wx.createInnerAudioContext();
Page({
data: {
actions: [ {
className: "dialog-content"
} ],
dataList: [],
isShowCommentInput: !1,
collectSwitch: "1",
likeSwitch: "1",
commentSwitch: "1",
shareSwitch: "1",
speedStep: 5,
waitFlag: !1,
avatarUrl: t.globalData.userInfo.avatarUrl,
imgUrl: t.baseUrls.baseCardUrl,
uId: "",
columnId: "",
publishTime: "",
isShowComment: !1,
maxVideo: 1,
maxPhoto: 1,
commentValue: "",
mediaBean: null,
uploadCount: 0,
uploadVideoCount: 0,
maxDuration: 60,
dataId: "",
commentList: [],
commentCount: 0,
currentPage: 1,
curUserId: t.globalData.currentUserId,
isShowRestore: !1,
restoreList: [],
currentCommentItem: void 0,
currentType: 2,
restorePage: 1,
restoreCount: 0,
likeStatus: !1,
collectStatus: !1,
restoreLikeStatus: !1,
contentHeight: t.globalData.windowHeight
},
onLoad: function(t) {
this.setData({
uId: t.uId,
columnId: t.cId,
dataId: t.uId,
collectSwitch: t.collectSwitch,
likeSwitch: t.likeSwitch,
commentSwitch: t.commentSwitch,
shareSwitch: t.shareSwitch
}), wx.setNavigationBarTitle({
title: "详情"
}), "3" == t.collectSwitch || "4" == t.collectSwitch || "3" == t.likeSwitch && "4" == t.likeSwitch || "3" == t.shareSwitch || "4" == t.shareSwitch || "3" == t.commentSwitch || "4" == t.commentSwitch ? this.setData({
isShowCommentInput: !0
}) : this.setData({
isShowCommentInput: !1
}), this.getMainMoment(), this.getCommentList(), this.getColumnContentHandle(this.data.uId, 2);
},
getMainMoment: function() {
wx.showLoading({
title: "加载中..."
});
var a = this;
t.http.get(t.urls.getMomentsContent.format({
configColumnId: a.data.columnId,
uid: a.data.uId
}), {
header: {
token: t.globalData.token
}
}).then(function(t) {
wx.hideLoading({}), a.buildDetail(t.data);
}).catch(function(t) {
wx.hideLoading({}), console.log(t);
});
},
getColumnContentHandle: function(a, e) {
var n = this;
wx.showLoading({
title: "加载中..."
}), t.http.get(t.urls.getColumnContentHandle.format({
projectId: "column",
businessIds: a
}), {
header: {
token: t.globalData.token
}
}).then(function(t) {
wx.hideLoading({}), t.data.length > 0 && (2 == e ? n.setData({
likeStatus: t.data[0].likeStatus,
collectStatus: t.data[0].collectStatus
}) : 2 == n.data.currentType ? (n.data.commentList.forEach(function(a) {
t.data.forEach(function(t) {
a.contentCommentId == t.businessId && (a.likeStatus = t.likeStatus, a.contentCommentLike = t.likeCount,
a.contentCommentSubCount = t.commentCount);
});
}), n.setData({
commentList: n.data.commentList
})) : (n.data.restoreList.forEach(function(a) {
t.data.forEach(function(t) {
a.contentCommentId == t.businessId && (a.likeStatus = t.likeStatus, a.contentCommentLike = t.likeCount,
a.contentCommentSubCount = t.commentCount);
});
}), n.setData({
restoreList: n.data.restoreList
})));
}).catch(function(t) {});
},
buildDetail: function(a) {
this.setData({
publishTime: a.gmtCreate
}), a.list.forEach(function(a) {
switch (a.dataType) {
case "2":
var e = a.value.split("@");
e.length > 1 ? a.dataMode = e[1] : a.dataMode = "1";
var n = e[0].split(","), o = [];
n.forEach(function(a) {
if (a.length > 0) {
var e = {
id: a,
path: t.baseUrls.baseCardUrl + a
};
o.push(e);
}
}), a.valueList = o;
break;
case "4":
n = a.value.split(","), o = [];
for (var i = 0; i < n.length; i++) if (n[i].length > 0) {
var s = n[i].split("&"), r = {
path: t.baseUrls.baseCardUrl + s[0],
imgPath: t.baseUrls.baseCardUrl + s[1]
};
o.push(r);
}
a.valueList = o;
break;
case "3":
n = a.value.split(","), o = [];
n.forEach(function(a) {
if (a.length > 0) {
var e = a.split("&"), n = "00:00";
if (e.length > 1) {
var i = e[1], s = parseInt(i / 60), r = parseInt(i % 60);
n = (s > 9 ? s : "0" + s) + ":" + (+r > 9 ? r : "0" + r);
}
var d = {
id: e[0],
path: t.baseUrls.baseCardUrl + e[0],
isPlay: !1,
duration: 100,
curDuation: 0,
curDurationStr: "00:00",
totalDurationStr: n
};
o.push(d);
}
}), a.valueList = o;
break;
case "6":
n = a.value.split("-"), o = [];
n.forEach(function(t) {
if (t.length > 0) {
var a = t.split(","), e = {
name: "",
address: "",
latitude: a[0],
longitude: a[1]
};
o.push(e);
}
}), a.valueList = o;
break;
case "8":
a.dictionariesList.forEach(function(t) {
-1 != a.value.indexOf(t.dataId) && (a.selValue = t.dataName);
});
break;
case "9":
var d = "";
a.dictionariesList.forEach(function(t) {
-1 != a.value.indexOf(t.dataId) ? (d += t.dataName + ",", t.isSel = !0) : t.isSel = !1;
}), d = d.substr(0, d.length - 1), a.selValue = d;
}
}), this.setData({
dataList: a.list
});
},
getCommentList: function() {
var a = this;
t.http.get(t.urls.getCommentList.format({
projectId: "column",
businessId: a.data.dataId
}), {
header: {
token: t.globalData.token
},
data: {
page: a.data.currentPage
}
}).then(function(t) {
wx.hideLoading({});
var e = "";
t.data.rows.forEach(function(t) {
t.likeStatus = !1, e += t.contentCommentId + ",";
}), a.data.commentList = a.data.commentList.concat(t.data.rows), a.setData({
commentList: a.data.commentList,
commentCount: t.data.total
}), e.length > 0 && a.getColumnContentHandle(e, 3);
}).catch(function(t) {
console.log(res);
});
},
getRestoreList: function() {
var a = this;
t.http.get(t.urls.getCommentList.format({
projectId: "column",
businessId: a.data.dataId
}), {
header: {
token: t.globalData.token
},
data: {
page: a.data.restorePage
}
}).then(function(t) {
wx.hideLoading({});
var e = "";
t.data.rows.forEach(function(t) {
t.likeStatus = !1, e += t.contentCommentId + ",";
}), a.data.restoreList = a.data.restoreList.concat(t.data.rows), a.setData({
restoreList: a.data.restoreList,
restoreCount: t.data.total,
isShowRestore: !0
}), e.length > 0 && a.getColumnContentHandle(e, 3);
}).catch(function(t) {
console.log(res);
});
},
viewImg: function(t) {
var a = [];
t.currentTarget.dataset.values.forEach(function(t) {
a.push(t.path);
}), wx.previewImage({
urls: a,
current: t.currentTarget.dataset.cur
});
},
viewVideo: function(t) {
var a = t.currentTarget.dataset.url;
wx.previewMedia({
sources: [ {
url: a,
type: "video"
} ]
});
},
play: function(t) {
var e = this, n = t.currentTarget.dataset.index, o = t.currentTarget.dataset.i, i = t.currentTarget.dataset.a, s = t.currentTarget.dataset.item;
e.data.dataList.forEach(function(t) {
t.list.forEach(function(t) {
"3" == t.dataType && t.valueList && t.valueList.forEach(function(t) {
t.isPlay && a.stop(), t.isPlay = !1, t.curDuration = 0, t.curDuationStr = "00:00";
});
});
}), s.isPlay ? a.stop() : ((a = wx.createInnerAudioContext()).src = e.data.dataList[n].list[o].valueList[i].path + ".mp3",
a.autoplay = !0, console.log(e.data.dataList[n].list[o].valueList[i].path)), a.onPlay(function() {
console.log("onPlay"), e.data.dataList[n].list[o].valueList[i].isPlay = !0, e.setData({
dataList: e.data.dataList
});
}), a.onCanplay(function(t) {}), a.onStop(function(t) {
console.log("停止播放"), e.data.dataList[n].list[o].valueList[i].isPlay = !1, e.data.dataList[n].list[o].valueList[i].curDuration = 0,
e.data.dataList[n].list[o].valueList[i].curDurationStr = "00:00", e.setData({
dataList: e.data.dataList
}), a.destroy();
}), a.onEnded(function(t) {
console.log(t), console.log("播放完毕"), e.data.dataList[n].list[o].valueList[i].isPlay = !1,
e.data.dataList[n].list[o].valueList[i].curDuration = 0, e.data.dataList[n].list[o].valueList[i].curDurationStr = "00:00",
e.setData({
dataList: e.data.dataList
}), a.destroy();
}), a.onError(function(t) {
console.log("播放错误"), console.log(t), e.data.dataList[n].list[o].valueList[i].isPlay = !1,
e.data.dataList[n].list[o].valueList[i].curDuration = 0, e.data.dataList[n].list[o].valueList[i].curDurationStr = "00:00",
e.setData({
dataList: e.data.dataList
}), a.destroy();
}), a.onSeeking(function() {}), a.onWaiting(function() {}), a.onTimeUpdate(function() {
if (a.duration != 1 / 0) {
e.data.dataList[n].list[o].valueList[i].curDuration = parseInt(a.currentTime), e.data.dataList[n].list[o].valueList[i].duration = parseInt(a.duration);
var t = parseInt(a.currentTime / 60), s = parseInt(a.currentTime % 60), r = parseInt(a.duration / 60), d = parseInt(a.duration % 60), c = t > 9 ? t : "0" + t, u = s > 9 ? s : "0" + s, l = r > 9 ? r : "0" + r, m = +d > 9 ? d : "0" + d;
e.data.dataList[n].list[o].valueList[i].curDurationStr = c + ":" + u, e.data.dataList[n].list[o].valueList[i].totalDurationStr = l + ":" + m,
e.setData({
dataList: e.data.dataList
});
}
});
},
rewind: function(t) {
var e = t.currentTarget.dataset.index, n = t.currentTarget.dataset.item, o = (t.currentTarget.dataset.idx,
t.currentTarget.dataset.a), i = t.currentTarget.dataset.i;
n.isPlay && (this.data.dataList[e].list[i].valueList[o].curDuration = this.data.dataList[e].list[i].valueList[o].curDuration - this.data.speedStep,
a.seek(this.data.dataList[e].list[i].valueList[o].curDuration), this.setData({
dataList: this.data.dataList
}));
},
speed: function(t) {
var e = t.currentTarget.dataset.index, n = t.currentTarget.dataset.item, o = (t.currentTarget.dataset.idx,
t.currentTarget.dataset.a), i = t.currentTarget.dataset.i;
n.isPlay && (this.data.dataList[e].list[i].valueList[o].curDuration = this.data.dataList[e].list[i].valueList[o].curDuration + this.data.speedStep,
a.seek(this.data.dataList[e].list[i].valueList[o].curDuration), this.setData({
dataList: this.data.dataList
}));
},
slider4change: function(t) {
t.currentTarget.dataset.index;
t.currentTarget.dataset.item.isPlay && a.seek(t.detail.value);
},
shareRecord: function(a) {
var e = this;
t.http.post(t.urls.shareRecord, {
header: {
token: t.globalData.token
},
data: {
cardTemplateUseId: e.data.cardInfo.cardTemplateUseId,
cardTemplateDispatchParentId: "",
cardTemplateDispatchId: a
}
}).then(function(t) {
console.log(t.data), e.setData({
shareRecordId: t.data.data
});
});
},
inputWatch: function(t) {
this.setData({
commentValue: t.detail.value
});
},
delMedia: function() {
var t = this;
wx.showModal({
title: "警告",
content: "确定要删除该数据吗?",
success: function(a) {
a.confirm && t.setData({
mediaBean: null
});
}
});
},
delComment: function(t) {
var a = this, e = t.currentTarget.dataset.id, n = t.currentTarget.dataset.idx;
wx.showModal({
title: "提示",
content: "确定要删除该评论吗?",
success: function(t) {
t.confirm && a.doDelComment(e, n);
}
});
},
doDelComment: function(a, e) {
var n = this;
wx.showLoading({
title: "删除中..."
}), t.http.delete(t.urls.doDelComment.format({
ids: a
}), {
header: {
token: t.globalData.token
}
}).then(function(t) {
wx.hideLoading({}), wx.showToast({
title: "删除成功"
}), 2 == n.data.currentType ? (n.data.commentList.splice(e, 1), n.setData({
commentList: n.data.commentList
})) : (n.data.restoreList.splice(e, 1), n.data.commentList.forEach(function(t) {
t.contentCommentId == n.data.dataId && t.contentCommentSubCount--;
}), n.setData({
restoreList: n.data.restoreList,
commentList: n.data.commentList
}));
}).catch(function(t) {});
},
doCommentToComment: function(t) {
var a = t.currentTarget.dataset.id, e = t.currentTarget.dataset.item;
this.setData({
dataId: a,
currentPage: 1,
restoreList: [],
currentCommentItem: e,
currentType: 3
}), this.getRestoreList();
},
showComment: function() {
this.setData({
isShowComment: !0
});
},
onCloseDialog: function(t) {
this.setData({
isShowComment: !1
});
},
onCloseRestore: function(t) {
this.setData({
isShowRestore: !1,
currentType: 2,
dataId: this.data.uId,
restoreList: [],
currentCommentItem: void 0
});
},
chooseImg: function() {
var t = this;
wx.chooseImage({
count: t.data.maxPhoto,
sourceType: [ "album", "camera" ],
success: function(a) {
a.tempFilePaths.length > 0 && t.doUploadImg(a.tempFilePaths);
},
fail: function(t) {}
});
},
doUploadImg: function(a) {
wx.showLoading({
title: "上传中..."
});
var e = this;
t.http.upload(t.urls.doUploadImg, {
path: a[0],
name: "image",
header: {
token: t.globalData.token
}
}).then(function(a) {
wx.hideLoading({});
var n = JSON.parse(a).data, o = t.baseUrls.baseCardUrl + n, i = {
id: n,
type: "image",
coverPath: o,
path: o
};
e.setData({
mediaBean: i
});
}).catch(function(t) {
wx.hideLoading({}), e.setData({
mediaBean: null
});
});
},
chooseVideo: function() {
var t = this;
wx.chooseMedia({
count: t.data.maxVideo,
mediaType: [ "video" ],
sourceType: [ "camera", "album" ],
maxDuration: 60,
success: function(a) {
console.log(a), a.tempFiles.length > 0 && (a.tempFiles[0].duration <= t.data.maxDuration ? t.doUploadVideo(a.tempFiles) : wx.showToast({
title: "视频最长60秒",
icon: "none"
}));
},
fail: function(t) {}
});
},
doUploadVideo: function(a) {
wx.showLoading({
title: "上传中..."
});
var e = this;
t.http.upload(t.urls.doUploadVideo, {
path: a[0].tempFilePath,
name: "video",
header: {
token: t.globalData.token
}
}).then(function(n) {
wx.hideLoading({});
var o = JSON.parse(n).data, i = t.baseUrls.baseCardUrl + o, s = {
id: o,
type: "video",
coverPath: a[0].thumbTempFilePath,
path: i
};
e.setData({
mediaBean: s
});
}).catch(function(t) {
wx.hideLoading({}), e.setData({
mediaBean: null
});
});
},
doSubmitComment: function(t) {
console.log(t);
var a = t.currentTarget.dataset.id;
this.data.commentValue.length > 0 ? this.doSaveComment(a) : wx.showToast({
title: "请输入要发布的内容",
icon: "none"
});
},
doSaveComment: function(a) {
var e = this;
wx.showLoading({
title: "保存中..."
}), t.http.post(t.urls.doSaveComment, {
header: {
token: t.globalData.token
},
data: {
businessId: a,
projectId: "column",
contentCommentContent: e.data.commentValue
}
}).then(function(t) {
wx.hideLoading({}), wx.showToast({
title: "评论成功"
}), 2 == e.data.currentType ? (e.setData({
commentValue: "",
isShowComment: !1,
currentPage: 1,
commentList: [],
commentCount: 0
}), e.getCommentList()) : (e.data.commentList.forEach(function(t) {
t.contentCommentId == a && t.contentCommentSubCount++;
}), e.setData({
commentValue: "",
isShowComment: !1,
restorePage: 1,
restoreList: [],
restoreCount: 0,
commentList: e.data.commentList
}), e.getRestoreList());
}).catch(function(t) {
wx.hideLoading({}), e.setData({
isShowComment: !1
});
});
},
doLike: function(a) {
var e = this, n = a.currentTarget.dataset.type, o = "2" == n ? e.data.uId : a.currentTarget.dataset.id, i = -1;
"4" == n ? e.data.commentList.forEach(function(t, a) {
t.contentCommentId == o && (i = a);
}) : i = a.currentTarget.dataset.idx;
var s = "2" == n ? e.data.likeStatus : a.currentTarget.dataset.like, r = "";
r = s ? "取消中..." : "保存中...", wx.showLoading({
title: r
}), t.http.post(t.urls.doSaveLike, {
header: {
token: t.globalData.token
},
data: {
businessId: o,
projectId: "column"
}
}).then(function(t) {
wx.hideLoading({}), "2" == n ? e.setData({
likeStatus: !s
}) : 2 == e.data.currentType ? (s ? (e.data.commentList[i].contentCommentLike--,
e.data.commentList[i].likeStatus = !1) : (e.data.commentList[i].contentCommentLike++,
e.data.commentList[i].likeStatus = !0), e.setData({
commentList: e.data.commentList
})) : "4" == n ? (s ? (e.data.commentList[i].contentCommentLike--, e.data.commentList[i].likeStatus = !1,
e.data.currentCommentItem.likeStatus = !1) : (e.data.commentList[i].contentCommentLike++,
e.data.commentList[i].likeStatus = !0, e.data.currentCommentItem.likeStatus = !0),
e.setData({
commentList: e.data.commentList,
currentCommentItem: e.data.currentCommentItem
})) : (s ? (e.data.restoreList[i].contentCommentLike--, e.data.restoreList[i].likeStatus = !1) : (e.data.restoreList[i].contentCommentLike++,
e.data.restoreList[i].likeStatus = !0), e.setData({
restoreList: e.data.restoreList
}));
}).catch(function(t) {});
},
doCollect: function(a) {
var e = this, n = "";
n = e.data.collectStatus ? "取消收藏..." : "收藏中...", wx.showLoading({
title: n
}), t.http.post(t.urls.doSaveCollect, {
header: {
token: t.globalData.token
},
data: {
businessId: e.data.uId,
projectId: "column"
}
}).then(function(t) {
wx.hideLoading({}), e.data.collectStatus = !e.data.collectStatus, e.setData({
collectStatus: e.data.collectStatus
});
}).catch(function(t) {});
}
});