refund-proof-popup.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Component({
  2. properties: {
  3. visible: { type: Boolean, value: false },
  4. desc: { type: String, value: "" },
  5. images: { type: Array, value: [] },
  6. },
  7. data: {
  8. inputDesc: "",
  9. inputImages: [] as string[],
  10. },
  11. observers: {
  12. visible(v: boolean) {
  13. if (v) {
  14. this.setData({
  15. inputDesc: this.data.desc || "",
  16. inputImages: [...(this.data.images as string[])],
  17. });
  18. }
  19. },
  20. },
  21. methods: {
  22. onPopupVisibleChange(e: WechatMiniprogram.CustomEvent<{ visible: boolean }>) {
  23. if (!e?.detail?.visible) this.triggerEvent("close");
  24. },
  25. onClose() {
  26. this.triggerEvent("close");
  27. },
  28. onDescInput(e: WechatMiniprogram.Input) {
  29. const value = (e.detail?.value || "").slice(0, 200);
  30. this.setData({ inputDesc: value });
  31. },
  32. onChooseImage() {
  33. const current = this.data.inputImages.length;
  34. const remain = 9 - current;
  35. if (remain <= 0) {
  36. wx.showToast({ title: "最多上传9张", icon: "none" });
  37. return;
  38. }
  39. wx.chooseImage({
  40. count: remain,
  41. sizeType: ["compressed"],
  42. sourceType: ["album", "camera"],
  43. success: (res) => {
  44. const next = [...this.data.inputImages, ...res.tempFilePaths].slice(0, 9);
  45. this.setData({ inputImages: next });
  46. },
  47. });
  48. },
  49. onRemoveImage(e: WechatMiniprogram.TouchEvent) {
  50. const index = Number((e.currentTarget.dataset as { index?: number })?.index ?? -1);
  51. if (index < 0) return;
  52. const next = [...this.data.inputImages];
  53. next.splice(index, 1);
  54. this.setData({ inputImages: next });
  55. },
  56. onConfirm() {
  57. this.triggerEvent("confirm", {
  58. desc: this.data.inputDesc,
  59. images: this.data.inputImages,
  60. });
  61. },
  62. },
  63. });