import { Get } from "../../../../lib/request/method"; Component({ properties: { visible: { type: Boolean, value: false }, goodsName: { type: String, value: "" }, goodsImage: { type: String, value: "" }, goodsPrice: { type: String, value: "" }, goodsMeta1: { type: String, value: "" }, goodsMeta2: { type: String, value: "" }, refundReason: { type: String, value: "" }, refundStatus: { type: String, value: "" }, refundAmount: { type: Number, value: 0 }, maxAmount: { type: Number, value: 0 }, proofImages: { type: Array, value: [] }, showReceiptStatus: { type: Boolean, value: true }, }, data: { statusPickerVisible: false, statusPickerOptions: [] as Array<{ label: string; value: string }>, statusPickerValue: [] as string[], statusLabel: "", // 退款金额编辑器(整屏弹窗) amountEditorVisible: false, amountInput: "", }, observers: { refundStatus(v: string) { const options = (this as any).data?.statusPickerOptions || []; const matched = options.find((item: any) => item.value === v); if (matched) { (this as any).setData({ statusPickerValue: [v], statusLabel: matched.label, }); } }, visible(v: boolean) { if (v && (this as any).data?.statusPickerOptions?.length) { const currentValue = (this as any).data?.statusPickerValue?.[0]; if (currentValue) { (this as any).triggerEvent("changeStatus", { status: currentValue }); } } }, }, lifetimes: { attached() { (this as any).fetchStatusOptions(); }, }, methods: { getStatusLabel(value: string): string { const options = (this as any).data?.statusPickerOptions || []; return options.find((item: any) => item.value === value)?.label || ""; }, async fetchStatusOptions() { try { const res = await Get("/dict/getDicts"); const dict = (res as any)?.data?.find( (item: any) => item.dictType === "aftersale_receipt_status" ); if (dict?.items?.length) { const options = dict.items.map((item: any) => ({ label: item.dictLabel, value: item.dictValue, })); // 默认选中最后一个(未收到货) const lastOption = options[options.length - 1]; const current = (this as any).data?.refundStatus; const matched = options.find((item: any) => item.value === current); const value = matched ? current : lastOption.value; const label = matched ? matched.label : lastOption.label; (this as any).setData({ statusPickerOptions: options, statusPickerValue: [value], statusLabel: label, }); // 回传默认值给父页面 (this as any).triggerEvent("changeStatus", { status: value }); } } catch { wx.showToast({ title: "获取商品状态失败", icon: "none" }); } }, 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 status = String(valueArr?.[0] ?? ""); (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"); }, }, });