"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_api = require("../../utils/api.js"); const _sfc_main = { data() { return { bookInfo: { id: null, title: "" }, selectedRating: "recommend", // recommend, general, bad ratingOptions: [ { label: "推荐", value: "recommend" }, { label: "一般", value: "general" }, { label: "不好", value: "bad" } ], reviewContent: "", userInfo: null, isSubmitting: false }; }, computed: { canPublish() { return this.reviewContent.trim().length > 0 && !this.isSubmitting; } }, onLoad(options) { try { const userInfo = common_vendor.index.getStorageSync("userInfo"); if (userInfo && userInfo.id) { this.userInfo = userInfo; } } catch (e) { common_vendor.index.__f__("error", "at pages/write-review/write-review.vue:82", "获取用户信息失败", e); } if (options.bookId) { this.bookInfo.id = parseInt(options.bookId); } if (options.title) { this.bookInfo.title = decodeURIComponent(options.title); } }, methods: { selectRating(value) { this.selectedRating = value; }, handleInput(e) { this.reviewContent = e.detail.value; }, handleCancel() { common_vendor.index.showModal({ title: "提示", content: "确定要取消吗?未保存的内容将丢失。", success: (res) => { if (res.confirm) { common_vendor.index.navigateBack(); } } }); }, async handlePublish() { if (!this.canPublish) { common_vendor.index.showToast({ title: "请输入书评内容", icon: "none" }); return; } if (!this.userInfo || !this.userInfo.id) { common_vendor.index.showModal({ title: "提示", content: "请先登录", showCancel: true, cancelText: "取消", confirmText: "去登录", success: (res) => { if (res.confirm) { common_vendor.index.navigateTo({ url: "/pages/login/login" }); } } }); return; } if (!this.bookInfo.id) { common_vendor.index.showToast({ title: "书籍信息不完整", icon: "none" }); return; } try { this.isSubmitting = true; common_vendor.index.showLoading({ title: "发表中...", mask: true }); const res = await utils_api.addComment( this.userInfo.id, this.bookInfo.id, this.reviewContent.trim() ); common_vendor.index.hideLoading(); this.isSubmitting = false; if (res && res.code === 200) { common_vendor.index.showToast({ title: "发表成功", icon: "success", duration: 2e3 }); setTimeout(() => { common_vendor.index.navigateBack(); }, 2e3); } else { common_vendor.index.showToast({ title: res.message || "发表失败", icon: "none" }); } } catch (e) { common_vendor.index.hideLoading(); this.isSubmitting = false; common_vendor.index.__f__("error", "at pages/write-review/write-review.vue:182", "发表评论失败", e); common_vendor.index.showToast({ title: e.message || "发表失败,请重试", icon: "none" }); } } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return { a: common_vendor.f($data.ratingOptions, (rating, index, i0) => { return { a: common_vendor.t(rating.label), b: index, c: $data.selectedRating === rating.value ? 1 : "", d: common_vendor.o(($event) => $options.selectRating(rating.value), index) }; }), b: common_vendor.o([($event) => $data.reviewContent = $event.detail.value, (...args) => $options.handleInput && $options.handleInput(...args)]), c: $data.reviewContent, d: common_vendor.t($data.reviewContent.length), e: common_vendor.o((...args) => $options.handleCancel && $options.handleCancel(...args)), f: !$options.canPublish ? 1 : "", g: common_vendor.o((...args) => $options.handlePublish && $options.handlePublish(...args)) }; } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-d8ce6122"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/write-review/write-review.js.map