refund-reason-popup.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { Get } from "../../../../lib/request/method";
  2. Component({
  3. properties: {
  4. visible: { type: Boolean, value: false },
  5. initialReason: { type: String, value: "" },
  6. },
  7. data: {
  8. selectedReason: "",
  9. reasons: [] as Array<{ label: string; value: string }>,
  10. },
  11. observers: {
  12. visible(v: boolean) {
  13. if (v) {
  14. this.setData({ selectedReason: this.data.initialReason || "" });
  15. }
  16. },
  17. },
  18. lifetimes: {
  19. attached() {
  20. this.fetchReasons();
  21. },
  22. },
  23. methods: {
  24. async fetchReasons() {
  25. try {
  26. const res = await Get<any[]>("/dict/getDicts");
  27. const dict = (res as any)?.data?.find(
  28. (item: any) => item.dictType === "aftersale_reason"
  29. );
  30. if (dict?.items?.length) {
  31. this.setData({
  32. reasons: dict.items.map((item: any) => ({
  33. label: item.dictLabel,
  34. value: item.dictValue,
  35. })),
  36. });
  37. }
  38. } catch {
  39. wx.showToast({ title: "获取退款原因失败", icon: "none" });
  40. }
  41. },
  42. onPopupVisibleChange(e: WechatMiniprogram.CustomEvent<{ visible: boolean }>) {
  43. if (!e?.detail?.visible) {
  44. this.triggerEvent("close");
  45. }
  46. },
  47. onClose() {
  48. this.triggerEvent("close");
  49. },
  50. onSelectReason(e: any) {
  51. const reason = e.detail?.value;
  52. if (reason) {
  53. this.setData({ selectedReason: reason });
  54. }
  55. },
  56. onNext() {
  57. const reason = this.data.selectedReason;
  58. if (!reason) {
  59. wx.showToast({ title: "请选择退款原因", icon: "none" });
  60. return;
  61. }
  62. this.triggerEvent("next", { reason });
  63. },
  64. },
  65. });