"use strict"; var common_vendor = require("../../common/vendor.js"); var api_index = require("../../api/index.js"); var config_index = require("../../config/index.js"); require("../../utils/request.js"); const _sfc_main = { setup(__props) { const userInfo = common_vendor.ref({}); const detail = common_vendor.reactive({ id: "", userId: "", images: [], title: "", text: "", time: "", isLike: false, likeCount: void 0 }); const commentList = common_vendor.ref([]); common_vendor.onLoad((e) => { const { user_info } = common_vendor.index.getStorageSync("userData"); userInfo.value = user_info; getCommunity(e.id); getComment(e.id); }); const getCommunity = (id) => { api_index.getCommunityDetail(id).then(({ status, data }) => { if (Number(status) === 200) { const { post_id, user_id, title, is_like, like_count, content, created_at } = data.post_info; const detailInfo = typeof content === "string" ? JSON.parse(content) : {}; detail.title = title || ""; detail.id = post_id; detail.userId = user_id; detail.images = detailInfo.images || []; detail.text = detailInfo.text || ""; detail.time = created_at; detail.isLike = is_like; detail.likeCount = like_count; } }); }; const getComment = (id) => { api_index.getCommentData(id).then(({ status, data }) => { if (Number(status) === 200 && Array.isArray(data.comment_list)) { commentList.value = data.comment_list; } }); }; const commentText = common_vendor.ref(""); const onSubmitComment = () => { if (commentText.value) { api_index.submitComment({ id: detail.id, content: commentText.value }).then(({ status }) => { if (Number(status) === 200) { commentText.value = ""; getComment(detail.id); } }); } else [ common_vendor.index.showToast({ title: "\u8BF7\u8F93\u5165\u8BC4\u8BBA\u5185\u5BB9", icon: "none" }) ]; }; const onDeleteComment = (item) => { api_index.deleteComment({ id: detail.id, commentId: item.comment_id }).then(() => { getComment(detail.id); }); }; const onSubmitLike = async (type) => { if (type === "like") { api_index.submitLike(detail.id).then(({ status }) => { if (Number(status) === 200) { detail.isLike = true; detail.likeCount += 1; } }); } else { api_index.cancelLike(detail.id).then(({ status }) => { if (Number(status) === 200) { detail.isLike = false; detail.likeCount -= 1; } }); } }; const commentTxt = common_vendor.ref(""); const onInputBlur = () => { if (commentTxt.value) { api_index.submitComment({ id: detail.id, content: commentTxt.value }).then(({ status }) => { if (Number(status) === 200) { commentTxt.value = ""; getComment(detail.id); } }); } }; return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.unref(detail).images.length > 0 }, common_vendor.unref(detail).images.length > 0 ? { b: common_vendor.f(common_vendor.unref(detail).images, (img, k0, i0) => { return { a: `${common_vendor.unref(config_index.filePrefix)}${img}`, b: img }; }) } : {}, { c: common_vendor.t(common_vendor.unref(detail).title), d: common_vendor.t(common_vendor.unref(detail).text), e: common_vendor.t(common_vendor.unref(detail).time), f: common_vendor.t(commentList.value.length), g: `${common_vendor.unref(config_index.filePrefix)}${userInfo.value.avatar_id}`, h: common_vendor.o(onInputBlur), i: commentTxt.value, j: common_vendor.o(($event) => commentTxt.value = $event.detail.value), k: common_vendor.f(commentList.value, (item, k0, i0) => { return common_vendor.e({ a: `${common_vendor.unref(config_index.filePrefix)}${item.avatar_id}`, b: common_vendor.t(item.username), c: item.user_id === common_vendor.unref(detail).userId }, item.user_id === common_vendor.unref(detail).userId ? {} : {}, { d: item.user_id === userInfo.value.user_id }, item.user_id === userInfo.value.user_id ? { e: common_vendor.o(($event) => onDeleteComment(item)) } : {}, { f: common_vendor.t(item.content), g: common_vendor.t(item.time), h: item.comment_id }); }), l: commentText.value, m: common_vendor.o(($event) => commentText.value = $event.detail.value), n: common_vendor.unref(detail).isLike }, common_vendor.unref(detail).isLike ? { o: common_vendor.o(($event) => onSubmitLike("cancel")) } : { p: common_vendor.o(($event) => onSubmitLike("like")) }, { q: common_vendor.t(common_vendor.unref(detail).likeCount), r: commentText.value }, commentText.value ? { s: common_vendor.o(onSubmitComment) } : {}); }; } }; var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2f2e4a30"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/community/detail.vue"]]); wx.createPage(MiniProgramPage);