import { addFeedback } from "../../api/api"; import { apple } from "../../config/config"; import { uploadImg, SendEvent } from "../../utils/util"; const app = getApp(); Page({ data: { qsList: [ { label: "重复被打扰", value: 6 }, { label: "内容不喜欢", value: 1 }, { label: "拒绝再次入群", value: 7 }, { label: "其他问题", value: 4 }, ], qsValue: "", message: "", contact: "", imageList: [], // { path, url, status, message } nickname: "", submitLoading: false, showNicknamePopup: false, nextAction: "", }, onLoad(options) { if (!app.globalData.token) { app.login().then(() => {}); } this.reportEntrance(); }, clickQs(e) { const qsValue = e.currentTarget.dataset.value; this.setData({ qsValue }); this.reportSelectQuestion(qsValue); }, onMessageInput(e) { this.setData({ message: e.detail.value }); }, onContactInput(e) { this.setData({ contact: e.detail.value }); }, onNickNameInput(e) { this.setData({ nickname: e.detail.value }); }, // 选择图片 chooseImage() { const _this = this; const n = this.data.imageList.length; if (n >= 9) { wx.showToast({ title: "最多上传九张图片", icon: "none", duration: 2000, }); return; } let imageList = this.data.imageList; wx.chooseImage({ count: 9 - n, sizeType: ["original", "compressed"], sourceType: ["album", "camera"], success: (res) => { wx.showLoading({ title: "图片上传中", mask: true, }); let promiseList = []; for (let i = 0; i < res.tempFiles.length; i++) { promiseList.push(uploadImg(res.tempFiles[i].path)); } wx.showLoading(); Promise.all(promiseList) .then((results) => { results.forEach((img) => { imageList.push(img); }); _this.setData({ imageList, }); _this.reportSelectImage(imageList); }) .catch(() => { wx.showModal({ title: "友情提示", content: "您上传的照片违规,请重新上传!", showCancel: false, }); }) .finally(() => { wx.hideLoading(); }); }, }); }, deleteImage(e) { const index = e.currentTarget.dataset.index; const list = this.data.imageList; list.splice(index, 1); this.setData({ imageList: list }); }, confirm() { if (!this.data.qsValue) { wx.showToast({ title: "请选择问题类型", icon: "none" }); return; } if (this.data.imageList.length === 0) { wx.showToast({ title: "请上传群截图", icon: "none" }); return; } this.setData({ showNicknamePopup: true, nextAction: "submit" }); }, async submitFeedbackWithNickname() { if (!this.data.nickname) { wx.showToast({ title: "请输入昵称", icon: "none" }); return; } if (this.data.nextAction === "service") { await this.submitServiceWithNickname(); return; } const param = { feedType: this.data.qsValue, images: this.data.imageList.join(","), description: this.data.message, contact: this.data.contact, type: 3, appId: apple.appid, nickname: this.data.nickname, ...app.globalData.queryData, }; param.unionId = app.globalData.unionId || ""; param.openId = app.globalData.openId || ""; this.setData({ submitLoading: true }); this.reportSubmitFeedback(); addFeedback(param) .then(() => { wx.redirectTo({ url: "/pages/feedback/success" }); }) .catch((err) => { wx.showToast({ title: err.msg || "提交失败", icon: "none" }); }) .finally(() => { this.setData({ submitLoading: false }); this.setData({ showNicknamePopup: false }); this.setData({ nextAction: "" }); }); }, async clickService() { this.setData({ showNicknamePopup: true, nextAction: "service" }); }, // ---------- 埋点 ---------- getBaseEventParams() { const { employeeId = "", corpId = "", taskId = "", } = app.globalData.queryData || {}; return { employee_id: employeeId, corp_id: corpId, task_id: taskId, }; }, reportEntrance() { SendEvent("feedback_page_entrance", { ...this.getBaseEventParams(), }); }, reportSelectQuestion(qsValue) { SendEvent("select_question_type", { ...this.getBaseEventParams(), question_type: qsValue, }); }, reportSelectImage(imageList) { SendEvent("select_image", { ...this.getBaseEventParams(), image_url: (imageList || []).join(";"), }); }, reportSubmitFeedback() { SendEvent("submit_feedback", { ...this.getBaseEventParams(), question_type: this.data.qsValue, image_url: (this.data.imageList || []).join(";"), description: this.data.message, contact: this.data.contact, nickname: this.data.nickname, }); }, reportClickOnlineCustomer() { SendEvent("click_online_customer", { ...this.getBaseEventParams(), question_type: this.data.qsValue, image_url: (this.data.imageList || []).join(";"), description: this.data.message, contact: this.data.contact, nickname: this.data.nickname, }); }, onCancelNickname() { this.setData({ showNicknamePopup: false, nextAction: "" }); }, async submitServiceWithNickname() { const param = { feedType: 99, images: this.data.imageList.join(","), description: this.data.message, contact: this.data.contact, type: 3, appId: apple.appid, nickname: this.data.nickname, ...app.globalData.queryData, }; param.unionId = app.globalData.unionId || ""; param.openId = app.globalData.openId || ""; this.setData({ submitLoading: true }); try { await addFeedback(param); this.reportClickOnlineCustomer(); if (apple.appid === "wx7b6f62f800f10d3f") { wx.navigateTo({ url: "/pages/feedback/service", success: (res) => { console.log("Navigate success"); }, fail: (err) => { console.error("Navigate failed", err); }, }); } else { wx.navigateToMiniProgram({ appId: "wx7b6f62f800f10d3f", path: "/pages/feedback/service", success(res) { console.log("跳转成功", res); }, fail(err) { console.error("跳转失败", err); wx.showToast({ title: "跳转失败", icon: "none", }); }, }); } } catch (error) { wx.showToast({ title: "提交失败", icon: "none" }); } finally { this.setData({ submitLoading: false, showNicknamePopup: false, nextAction: "", }); } }, });