| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- 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: "",
- });
- }
- },
- });
|