Component({ properties: { visible: { type: Boolean, value: false }, goodsName: { type: String, value: "" }, goodsPrice: { type: String, value: "" }, goodsMeta1: { type: String, value: "" }, goodsMeta2: { type: String, value: "" }, refundReason: { type: String, value: "" }, refundStatus: { type: String, value: "received" }, refundAmount: { type: Number, value: 0 }, maxAmount: { type: Number, value: 0 }, proofImages: { type: Array, value: [] }, }, data: { statusPickerVisible: false, statusPickerOptions: [ { label: "已收到货", value: "received" }, { label: "未收到货", value: "not-received" }, ], statusPickerValue: ["received"], // 退款金额编辑器(整屏弹窗) amountEditorVisible: false, amountInput: "", }, observers: { refundStatus(v: string) { (this as any).setData({ statusPickerValue: [v === "not-received" ? "not-received" : "received"], }); }, }, methods: { onPopupVisibleChange(e: WechatMiniprogram.CustomEvent<{ visible: boolean }>) { if (!e?.detail?.visible) { (this as any).triggerEvent("close"); } }, onAmountPopupVisibleChange(e: WechatMiniprogram.CustomEvent<{ visible: boolean }>) { if (!e?.detail?.visible) { (this as any).setData({ amountEditorVisible: false }); } }, onClose() { (this as any).triggerEvent("close"); }, onOpenStatusPicker() { (this as any).setData({ statusPickerVisible: true }); }, onStatusPickerChange(e: any) { const valueArr = e?.detail?.value as Array | undefined; const value0 = valueArr?.[0]; const status = value0 === "not-received" ? "not-received" : "received"; (this as any).triggerEvent("changeStatus", { status }); (this as any).setData({ statusPickerVisible: false }); }, onStatusPickerClose() { (this as any).setData({ statusPickerVisible: false }); }, onEditReason() { (this as any).triggerEvent("editReason"); }, onEditAmount() { const cur = Number((this as any).data?.refundAmount ?? 0); (this as any).setData({ amountInput: cur ? String(cur) : "0", amountEditorVisible: true }); }, onEditProof() { (this as any).triggerEvent("editProof"); }, onAmountInput(e: WechatMiniprogram.Input) { const raw = e.detail?.value || ""; // 保留数字与小数点 const cleaned = raw.replace(/[^\d.]/g, ""); (this as any).setData({ amountInput: cleaned }); }, onAmountClose() { (this as any).setData({ amountEditorVisible: false }); }, onAmountConfirm() { const maxAmount = Number((this as any).data?.maxAmount ?? 0); const amount = Number((this as any).data?.amountInput ?? 0); if (!amount || Number.isNaN(amount)) { wx.showToast({ title: "请输入退款金额", icon: "none" }); return; } if (maxAmount && amount > maxAmount) { wx.showToast({ title: "不能超过最高可退金额", icon: "none" }); return; } const fixed = Number(amount.toFixed(2)); (this as any).triggerEvent("amountConfirm", { amount: fixed }); (this as any).setData({ amountEditorVisible: false }); }, onSubmit() { (this as any).triggerEvent("submit"); }, }, });