refund-confirm-popup.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. Component({
  2. properties: {
  3. visible: { type: Boolean, value: false },
  4. goodsName: { type: String, value: "" },
  5. goodsImage: { type: String, value: "" },
  6. goodsPrice: { type: String, value: "" },
  7. goodsMeta1: { type: String, value: "" },
  8. goodsMeta2: { type: String, value: "" },
  9. refundReason: { type: String, value: "" },
  10. refundStatus: { type: String, value: "received" },
  11. refundAmount: { type: Number, value: 0 },
  12. maxAmount: { type: Number, value: 0 },
  13. proofImages: { type: Array, value: [] },
  14. },
  15. data: {
  16. statusPickerVisible: false,
  17. statusPickerOptions: [
  18. { label: "已收到货", value: "received" },
  19. { label: "未收到货", value: "not-received" },
  20. ],
  21. statusPickerValue: ["received"],
  22. // 退款金额编辑器(整屏弹窗)
  23. amountEditorVisible: false,
  24. amountInput: "",
  25. },
  26. observers: {
  27. refundStatus(v: string) {
  28. (this as any).setData({
  29. statusPickerValue: [v === "not-received" ? "not-received" : "received"],
  30. });
  31. },
  32. },
  33. methods: {
  34. onPopupVisibleChange(e: WechatMiniprogram.CustomEvent<{ visible: boolean }>) {
  35. if (!e?.detail?.visible) {
  36. (this as any).triggerEvent("close");
  37. }
  38. },
  39. onAmountPopupVisibleChange(e: WechatMiniprogram.CustomEvent<{ visible: boolean }>) {
  40. if (!e?.detail?.visible) {
  41. (this as any).setData({ amountEditorVisible: false });
  42. }
  43. },
  44. onClose() {
  45. (this as any).triggerEvent("close");
  46. },
  47. onOpenStatusPicker() {
  48. (this as any).setData({ statusPickerVisible: true });
  49. },
  50. onStatusPickerChange(e: any) {
  51. const valueArr = e?.detail?.value as Array<string | number> | undefined;
  52. const value0 = valueArr?.[0];
  53. const status = value0 === "not-received" ? "not-received" : "received";
  54. (this as any).triggerEvent("changeStatus", { status });
  55. (this as any).setData({ statusPickerVisible: false });
  56. },
  57. onStatusPickerClose() {
  58. (this as any).setData({ statusPickerVisible: false });
  59. },
  60. onEditReason() {
  61. (this as any).triggerEvent("editReason");
  62. },
  63. onEditAmount() {
  64. const cur = Number((this as any).data?.refundAmount ?? 0);
  65. (this as any).setData({ amountInput: cur ? String(cur) : "0", amountEditorVisible: true });
  66. },
  67. onEditProof() {
  68. (this as any).triggerEvent("editProof");
  69. },
  70. onAmountInput(e: WechatMiniprogram.Input) {
  71. const raw = e.detail?.value || "";
  72. // 保留数字与小数点
  73. const cleaned = raw.replace(/[^\d.]/g, "");
  74. (this as any).setData({ amountInput: cleaned });
  75. },
  76. onAmountClose() {
  77. (this as any).setData({ amountEditorVisible: false });
  78. },
  79. onAmountConfirm() {
  80. const maxAmount = Number((this as any).data?.maxAmount ?? 0);
  81. const amount = Number((this as any).data?.amountInput ?? 0);
  82. if (!amount || Number.isNaN(amount)) {
  83. wx.showToast({ title: "请输入退款金额", icon: "none" });
  84. return;
  85. }
  86. if (maxAmount && amount > maxAmount) {
  87. wx.showToast({ title: "不能超过最高可退金额", icon: "none" });
  88. return;
  89. }
  90. const fixed = Number(amount.toFixed(2));
  91. (this as any).triggerEvent("amountConfirm", { amount: fixed });
  92. (this as any).setData({ amountEditorVisible: false });
  93. },
  94. onSubmit() {
  95. (this as any).triggerEvent("submit");
  96. },
  97. },
  98. });