index.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. import { addFeedback } from "../../api/api";
  2. import { apple } from "../../config/config";
  3. import { uploadImg, SendEvent } from "../../utils/util";
  4. const app = getApp();
  5. Page({
  6. data: {
  7. qsList: [
  8. { label: "重复被打扰", value: 6 },
  9. { label: "内容不喜欢", value: 1 },
  10. { label: "拒绝再次入群", value: 7 },
  11. { label: "其他问题", value: 4 },
  12. ],
  13. qsValue: "",
  14. message: "",
  15. contact: "",
  16. imageList: [], // { path, url, status, message }
  17. nickname: "",
  18. submitLoading: false,
  19. showNicknamePopup: false,
  20. nextAction: "",
  21. },
  22. onLoad(options) {
  23. if (!app.globalData.token) {
  24. app.login().then(() => {});
  25. }
  26. this.reportEntrance();
  27. },
  28. clickQs(e) {
  29. const qsValue = e.currentTarget.dataset.value;
  30. this.setData({ qsValue });
  31. this.reportSelectQuestion(qsValue);
  32. },
  33. onMessageInput(e) {
  34. this.setData({ message: e.detail.value });
  35. },
  36. onContactInput(e) {
  37. this.setData({ contact: e.detail.value });
  38. },
  39. onNickNameInput(e) {
  40. this.setData({ nickname: e.detail.value });
  41. },
  42. // 选择图片
  43. chooseImage() {
  44. const _this = this;
  45. const n = this.data.imageList.length;
  46. if (n >= 9) {
  47. wx.showToast({
  48. title: "最多上传九张图片",
  49. icon: "none",
  50. duration: 2000,
  51. });
  52. return;
  53. }
  54. let imageList = this.data.imageList;
  55. wx.chooseImage({
  56. count: 9 - n,
  57. sizeType: ["original", "compressed"],
  58. sourceType: ["album", "camera"],
  59. success: (res) => {
  60. wx.showLoading({
  61. title: "图片上传中",
  62. mask: true,
  63. });
  64. let promiseList = [];
  65. for (let i = 0; i < res.tempFiles.length; i++) {
  66. promiseList.push(uploadImg(res.tempFiles[i].path));
  67. }
  68. wx.showLoading();
  69. Promise.all(promiseList)
  70. .then((results) => {
  71. results.forEach((img) => {
  72. imageList.push(img);
  73. });
  74. _this.setData({
  75. imageList,
  76. });
  77. _this.reportSelectImage(imageList);
  78. })
  79. .catch(() => {
  80. wx.showModal({
  81. title: "友情提示",
  82. content: "您上传的照片违规,请重新上传!",
  83. showCancel: false,
  84. });
  85. })
  86. .finally(() => {
  87. wx.hideLoading();
  88. });
  89. },
  90. });
  91. },
  92. deleteImage(e) {
  93. const index = e.currentTarget.dataset.index;
  94. const list = this.data.imageList;
  95. list.splice(index, 1);
  96. this.setData({ imageList: list });
  97. },
  98. confirm() {
  99. if (!this.data.qsValue) {
  100. wx.showToast({ title: "请选择问题类型", icon: "none" });
  101. return;
  102. }
  103. if (this.data.imageList.length === 0) {
  104. wx.showToast({ title: "请上传群截图", icon: "none" });
  105. return;
  106. }
  107. this.setData({ showNicknamePopup: true, nextAction: "submit" });
  108. },
  109. async submitFeedbackWithNickname() {
  110. if (!this.data.nickname) {
  111. wx.showToast({ title: "请输入昵称", icon: "none" });
  112. return;
  113. }
  114. if (this.data.nextAction === "service") {
  115. await this.submitServiceWithNickname();
  116. return;
  117. }
  118. const param = {
  119. feedType: this.data.qsValue,
  120. images: this.data.imageList.join(","),
  121. description: this.data.message,
  122. contact: this.data.contact,
  123. type: 3,
  124. appId: apple.appid,
  125. nickname: this.data.nickname,
  126. ...app.globalData.queryData,
  127. };
  128. param.unionId = app.globalData.unionId || "";
  129. param.openId = app.globalData.openId || "";
  130. this.setData({ submitLoading: true });
  131. this.reportSubmitFeedback();
  132. addFeedback(param)
  133. .then(() => {
  134. wx.redirectTo({ url: "/pages/feedback/success" });
  135. })
  136. .catch((err) => {
  137. wx.showToast({ title: err.msg || "提交失败", icon: "none" });
  138. })
  139. .finally(() => {
  140. this.setData({ submitLoading: false });
  141. this.setData({ showNicknamePopup: false });
  142. this.setData({ nextAction: "" });
  143. });
  144. },
  145. async clickService() {
  146. this.setData({ showNicknamePopup: true, nextAction: "service" });
  147. },
  148. // ---------- 埋点 ----------
  149. getBaseEventParams() {
  150. const {
  151. employeeId = "",
  152. corpId = "",
  153. taskId = "",
  154. } = app.globalData.queryData || {};
  155. return {
  156. employee_id: employeeId,
  157. corp_id: corpId,
  158. task_id: taskId,
  159. };
  160. },
  161. reportEntrance() {
  162. SendEvent("feedback_page_entrance", {
  163. ...this.getBaseEventParams(),
  164. });
  165. },
  166. reportSelectQuestion(qsValue) {
  167. SendEvent("select_question_type", {
  168. ...this.getBaseEventParams(),
  169. question_type: qsValue,
  170. });
  171. },
  172. reportSelectImage(imageList) {
  173. SendEvent("select_image", {
  174. ...this.getBaseEventParams(),
  175. image_url: (imageList || []).join(";"),
  176. });
  177. },
  178. reportSubmitFeedback() {
  179. SendEvent("submit_feedback", {
  180. ...this.getBaseEventParams(),
  181. question_type: this.data.qsValue,
  182. image_url: (this.data.imageList || []).join(";"),
  183. description: this.data.message,
  184. contact: this.data.contact,
  185. nickname: this.data.nickname,
  186. });
  187. },
  188. reportClickOnlineCustomer() {
  189. SendEvent("click_online_customer", {
  190. ...this.getBaseEventParams(),
  191. question_type: this.data.qsValue,
  192. image_url: (this.data.imageList || []).join(";"),
  193. description: this.data.message,
  194. contact: this.data.contact,
  195. nickname: this.data.nickname,
  196. });
  197. },
  198. onCancelNickname() {
  199. this.setData({ showNicknamePopup: false, nextAction: "" });
  200. },
  201. async submitServiceWithNickname() {
  202. const param = {
  203. feedType: 99,
  204. images: this.data.imageList.join(","),
  205. description: this.data.message,
  206. contact: this.data.contact,
  207. type: 3,
  208. appId: apple.appid,
  209. nickname: this.data.nickname,
  210. ...app.globalData.queryData,
  211. };
  212. param.unionId = app.globalData.unionId || "";
  213. param.openId = app.globalData.openId || "";
  214. this.setData({ submitLoading: true });
  215. try {
  216. await addFeedback(param);
  217. this.reportClickOnlineCustomer();
  218. if (apple.appid === "wx7b6f62f800f10d3f") {
  219. wx.navigateTo({
  220. url: "/pages/feedback/service",
  221. success: (res) => {
  222. console.log("Navigate success");
  223. },
  224. fail: (err) => {
  225. console.error("Navigate failed", err);
  226. },
  227. });
  228. } else {
  229. wx.navigateToMiniProgram({
  230. appId: "wx7b6f62f800f10d3f",
  231. path: "/pages/feedback/service",
  232. success(res) {
  233. console.log("跳转成功", res);
  234. },
  235. fail(err) {
  236. console.error("跳转失败", err);
  237. wx.showToast({
  238. title: "跳转失败",
  239. icon: "none",
  240. });
  241. },
  242. });
  243. }
  244. } catch (error) {
  245. wx.showToast({ title: "提交失败", icon: "none" });
  246. } finally {
  247. this.setData({
  248. submitLoading: false,
  249. showNicknamePopup: false,
  250. nextAction: "",
  251. });
  252. }
  253. },
  254. });