index.js 5.3 KB

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