"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
|