refund-confirm-popup.ts 3.3 KB

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