Component({ properties: { visible: { type: Boolean, value: false }, desc: { type: String, value: "" }, images: { type: Array, value: [] }, }, data: { inputDesc: "", inputImages: [] as string[], }, observers: { visible(v: boolean) { if (v) { this.setData({ inputDesc: this.data.desc || "", inputImages: [...(this.data.images as string[])], }); } }, }, methods: { onPopupVisibleChange(e: WechatMiniprogram.CustomEvent<{ visible: boolean }>) { if (!e?.detail?.visible) this.triggerEvent("close"); }, onClose() { this.triggerEvent("close"); }, onDescInput(e: WechatMiniprogram.Input) { const value = (e.detail?.value || "").slice(0, 200); this.setData({ inputDesc: value }); }, onChooseImage() { const current = this.data.inputImages.length; const remain = 9 - current; if (remain <= 0) { wx.showToast({ title: "最多上传9张", icon: "none" }); return; } wx.chooseImage({ count: remain, sizeType: ["compressed"], sourceType: ["album", "camera"], success: (res) => { const next = [...this.data.inputImages, ...res.tempFilePaths].slice(0, 9); this.setData({ inputImages: next }); }, }); }, onRemoveImage(e: WechatMiniprogram.TouchEvent) { const index = Number((e.currentTarget.dataset as { index?: number })?.index ?? -1); if (index < 0) return; const next = [...this.data.inputImages]; next.splice(index, 1); this.setData({ inputImages: next }); }, onConfirm() { this.triggerEvent("confirm", { desc: this.data.inputDesc, images: this.data.inputImages, }); }, }, });