wangzhibo
2025-10-23 cad64c1de2c45856b0774933c5801b05b64984e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"use strict";
const common_vendor = require("../../common/vendor.js");
const stores_user = require("../../stores/user.js");
const apiservice_apiService = require("../../apiservice/apiService.js");
const userStore = stores_user.useUserStore();
const _sfc_main = {
  data() {
    return {
      form: {
        question: "",
        images: [],
        contactperson: userStore.username,
        contactphone: userStore.phone
      }
    };
  },
  methods: {
    chooseImage() {
      common_vendor.index.chooseImage({
        count: 3 - this.form.images.length,
        sizeType: ["original", "compressed"],
        success: (res) => {
          const files = res.tempFilePaths.filter((f, i) => i + this.form.images.length < 3);
          const maxSize = 5 * 1024 * 1024;
          const oversized = files.filter((f) => f.size > maxSize);
          if (oversized.length > 0) {
            common_vendor.index.showToast({
              title: "图片不能大于 5MB,请重新选择",
              icon: "none"
            });
            return;
          }
          this.form.images.push(...files);
        }
      });
    },
    removeImage(index) {
      this.form.images.splice(index, 1);
    },
    async uploadAllImages() {
      if (this.form.images.length === 0)
        return [];
      const uploadPromises = this.form.images.map((img) => {
        return new Promise((resolve, reject) => {
          common_vendor.index.uploadFile({
            url: apiservice_apiService.apiService.baseURL + "/advices/upload",
            // 后端上传接口
            filePath: img,
            name: "file",
            success: (res) => {
              try {
                const data = JSON.parse(res.data);
                if (data.code === 1e3 && data.data) {
                  resolve(data.data);
                } else {
                  reject(new Error("上传失败"));
                }
              } catch (err) {
                reject(err);
              }
            },
            fail: reject
          });
        });
      });
      return Promise.all(uploadPromises);
    },
    async submitForm() {
      if (this.form.question.length < 5) {
        common_vendor.index.showToast({
          title: "投诉内容至少5个字",
          icon: "none"
        });
        return;
      }
      if (this.form.question.length > 200) {
        common_vendor.index.showToast({
          title: "投诉内容最多200字",
          icon: "none"
        });
        return;
      }
      const contact = this.form.contactperson.trim();
      if (!contact) {
        common_vendor.index.showToast({
          title: "联系人不能为空",
          icon: "none"
        });
        return;
      }
      if (contact.length > 10) {
        common_vendor.index.showToast({
          title: "联系人最多10个字符",
          icon: "none"
        });
        return;
      }
      const phone = this.form.contactphone.trim();
      const phoneRegex = /^(1\d{10}|([0-9\uFF10-\uFF19\--\s,,]{5,20}))$/;
      if (!phoneRegex.test(phone)) {
        common_vendor.index.showToast({
          title: "联系电话格式不正确",
          icon: "none"
        });
        return;
      }
      try {
        common_vendor.index.showLoading({
          title: "提交中..."
        });
        const imageUrls = await this.uploadAllImages();
        const [img1, img2, img3] = imageUrls || [];
        const payload = {
          uuid: userStore.uuid,
          question: this.form.question,
          img1,
          img2,
          img3,
          contactperson: this.form.contactperson,
          contactphone: this.form.contactphone
        };
        apiservice_apiService.apiService.advicesAdd(payload).then((res) => {
          if (res.code === 1e3) {
            common_vendor.index.showToast({
              title: "提交成功,我们将在24小时内回复,请在“我的”菜单查看。",
              icon: "success"
            });
            this.form.question = "";
            this.form.images = [];
            common_vendor.index.navigateTo({
              url: "/pages/ucenter/my-advice"
            });
          } else {
            common_vendor.index.__f__("warn", "at pages/index/advice.vue:222", "游客更新失败:", res.message);
            common_vendor.index.showToast({
              title: res.message || "提交失败",
              icon: "none"
            });
          }
        }).catch((err) => {
          common_vendor.index.__f__("error", "at pages/index/advice.vue:229", "游客更新错误:", err);
          common_vendor.index.showToast({
            title: "发生错误,请联系管理员",
            icon: "none"
          });
        });
      } catch (err) {
        common_vendor.index.__f__("error", "at pages/index/advice.vue:236", "提交错误:", err);
        common_vendor.index.showToast({
          title: "网络错误",
          icon: "none"
        });
      } finally {
        common_vendor.index.hideLoading();
      }
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: $data.form.question,
    b: common_vendor.o(($event) => $data.form.question = $event.detail.value),
    c: common_vendor.t($data.form.question.length),
    d: common_vendor.f($data.form.images, (img, index, i0) => {
      return {
        a: img,
        b: common_vendor.o(($event) => $options.removeImage(index), index),
        c: index
      };
    }),
    e: $data.form.images.length < 3
  }, $data.form.images.length < 3 ? {
    f: common_vendor.o((...args) => $options.chooseImage && $options.chooseImage(...args))
  } : {}, {
    g: $data.form.contactperson,
    h: common_vendor.o(($event) => $data.form.contactperson = $event.detail.value),
    i: $data.form.contactphone,
    j: common_vendor.o(($event) => $data.form.contactphone = $event.detail.value),
    k: common_vendor.o((...args) => $options.submitForm && $options.submitForm(...args))
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/advice.js.map