index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const api_system_complaint = require("../../../api/system/complaint.js");
  4. const api_system_dict = require("../../../api/system/dict.js");
  5. const api_resource_oss = require("../../../api/resource/oss.js");
  6. const ErpNavBar = () => "../../../components/erp-nav-bar.js";
  7. const _sfc_main = {
  8. components: { ErpNavBar },
  9. data() {
  10. return {
  11. types: [],
  12. uploading: false,
  13. imageOssMap: [],
  14. formData: {
  15. type: "",
  16. content: "",
  17. images: []
  18. }
  19. };
  20. },
  21. computed: {
  22. isFormValid() {
  23. return !this.uploading && this.formData.type && this.formData.content && this.formData.content.trim().length >= 5;
  24. }
  25. },
  26. onLoad() {
  27. this.loadTypes();
  28. },
  29. methods: {
  30. async loadTypes() {
  31. try {
  32. const res = await api_system_dict.getDictByType("sys_complaint_type");
  33. if (res && res.data) {
  34. this.types = res.data.map((d) => ({ label: d.dictLabel, value: d.dictValue }));
  35. if (this.types.length)
  36. this.formData.type = this.types[0].value;
  37. }
  38. } catch (e) {
  39. this.types = [
  40. { label: "系统投诉", value: "complaint" },
  41. { label: "改进建议", value: "suggestion" },
  42. { label: "其他反馈", value: "other" }
  43. ];
  44. this.formData.type = "complaint";
  45. }
  46. },
  47. goBack() {
  48. common_vendor.index.navigateBack();
  49. },
  50. chooseImage() {
  51. const count = 6 - this.formData.images.length;
  52. common_vendor.index.chooseImage({
  53. count,
  54. sizeType: ["compressed"],
  55. success: async (res) => {
  56. const paths = res.tempFilePaths;
  57. this.uploading = true;
  58. try {
  59. for (const path of paths) {
  60. const preview = path;
  61. const placeholderIndex = this.formData.images.length;
  62. this.formData.images.push(preview);
  63. this.imageOssMap.push(null);
  64. try {
  65. const uploadRes = await api_resource_oss.uploadFile(path);
  66. this.formData.images.splice(placeholderIndex, 1, uploadRes.url);
  67. this.imageOssMap.splice(placeholderIndex, 1, uploadRes.ossId);
  68. } catch (err) {
  69. this.formData.images.splice(placeholderIndex, 1);
  70. this.imageOssMap.splice(placeholderIndex, 1);
  71. common_vendor.index.showToast({ title: "图片上传失败", icon: "none" });
  72. }
  73. }
  74. } finally {
  75. this.uploading = false;
  76. }
  77. }
  78. });
  79. },
  80. removeImage(index) {
  81. this.formData.images.splice(index, 1);
  82. this.imageOssMap.splice(index, 1);
  83. },
  84. previewImage(index) {
  85. common_vendor.index.previewImage({
  86. urls: this.formData.images,
  87. current: index
  88. });
  89. },
  90. async handleSubmit() {
  91. if (!this.isFormValid)
  92. return;
  93. try {
  94. common_vendor.index.showLoading({ title: "提交中" });
  95. const payload = {
  96. feedbackType: this.formData.type,
  97. content: this.formData.content,
  98. images: this.imageOssMap.filter((id) => id !== null).join(",")
  99. };
  100. await api_system_complaint.submitComplaint(payload);
  101. common_vendor.index.hideLoading();
  102. common_vendor.index.showToast({ title: "反馈成功", icon: "success" });
  103. setTimeout(() => {
  104. common_vendor.index.navigateBack();
  105. }, 1500);
  106. } catch (e) {
  107. common_vendor.index.hideLoading();
  108. common_vendor.index.showToast({ title: e.message || "提交失败", icon: "none" });
  109. }
  110. }
  111. }
  112. };
  113. if (!Array) {
  114. const _component_erp_nav_bar = common_vendor.resolveComponent("erp-nav-bar");
  115. _component_erp_nav_bar();
  116. }
  117. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  118. return common_vendor.e({
  119. a: common_vendor.p({
  120. title: "投诉与建议"
  121. }),
  122. b: common_vendor.f($data.types, (item, k0, i0) => {
  123. return {
  124. a: common_vendor.t(item.label),
  125. b: item.value,
  126. c: $data.formData.type === item.value ? 1 : "",
  127. d: common_vendor.o(($event) => $data.formData.type = item.value, item.value)
  128. };
  129. }),
  130. c: $data.formData.content,
  131. d: common_vendor.o(($event) => $data.formData.content = $event.detail.value, "71"),
  132. e: common_vendor.t($data.formData.content.length),
  133. f: common_vendor.f($data.formData.images, (img, index, i0) => {
  134. return {
  135. a: img,
  136. b: common_vendor.o(($event) => $options.previewImage(index), index),
  137. c: common_vendor.o(($event) => $options.removeImage(index), index),
  138. d: index
  139. };
  140. }),
  141. g: $data.formData.images.length < 6
  142. }, $data.formData.images.length < 6 ? {
  143. h: common_vendor.o((...args) => $options.chooseImage && $options.chooseImage(...args), "2e")
  144. } : {}, {
  145. i: !$options.isFormValid,
  146. j: common_vendor.o((...args) => $options.handleSubmit && $options.handleSubmit(...args), "5f")
  147. });
  148. }
  149. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-6497fc4f"]]);
  150. wx.createPage(MiniProgramPage);
  151. //# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/mine/complaint/index.js.map