analysis.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import { upload } from "../../../../lib/request/upload";
  3. import { Post } from "../../../../lib/request/method";
  4. // module/chats/pages/analysis/analysis.ts
  5. Component({
  6. behaviors: [PageContainerBehavior],
  7. options: {},
  8. properties: {
  9. messageType: { type: Number, value: 0 },
  10. },
  11. data: {
  12. uploadList: [
  13. {
  14. target: "tongueImgUrl",
  15. required: true,
  16. label: "舌面图",
  17. src: "../../assets/tongue-1.png",
  18. },
  19. {
  20. target: "tongueBackImgUrl",
  21. required: true,
  22. label: "舌下图",
  23. src: "../../assets/tongue-2.png",
  24. },
  25. {
  26. target: "faceImgUrl",
  27. required: false,
  28. label: "面部图",
  29. src: "../../assets/face-1.png",
  30. },
  31. ],
  32. thumbnail: [] as string[],
  33. original: [] as string[],
  34. status: [false, false, false],
  35. _queue: {} as AnyObject,
  36. // 随访上传参数
  37. activeObj: {},
  38. followObj: {},
  39. workId: 0,
  40. },
  41. attached() {
  42. // 从存储中拿到之前的对话信息
  43. this.setData({
  44. followObj: wx.getStorageSync("followObj"),
  45. workId: wx.getStorageSync("workId"),
  46. });
  47. },
  48. methods: {
  49. handle(event: WechatMiniprogram.TouchEvent) {
  50. const { handle, index } = event.mark as AnyObject;
  51. console.log(handle, index, handle === "upload:delete", event.mark);
  52. switch (handle) {
  53. case "preview":
  54. break;
  55. case "upload":
  56. this._chooseMedia(index).then(
  57. (src) => src && this._uploadMedia(index, src)
  58. );
  59. break;
  60. case "upload:delete":
  61. this._deleteMedia(index);
  62. break;
  63. }
  64. },
  65. _chooseMedia(index: number) {
  66. return wx
  67. .chooseMedia({
  68. count: 1,
  69. mediaType: ["image"],
  70. sourceType: ["album", "camera"],
  71. camera: "front",
  72. })
  73. .then((res) => {
  74. const src = res.tempFiles[0].tempFilePath;
  75. this.setData({ [`thumbnail.${index}`]: src });
  76. return src;
  77. })
  78. .catch(() => null);
  79. },
  80. _deleteMedia(index: number) {
  81. this.setData({
  82. [`thumbnail.${index}`]: "",
  83. [`original.${index}`]: "",
  84. });
  85. },
  86. _uploadMedia(index: number, src?: string) {
  87. this.setData({ [`_queue.${index}`]: true });
  88. src ??= this.data.thumbnail[index];
  89. upload({
  90. params: { name: "file", file: src! },
  91. transform({ data }) {
  92. return (<any>data).url;
  93. },
  94. })
  95. .then(
  96. (src) => {
  97. this.setData({ [`original.${index}`]: src });
  98. },
  99. (error) => {
  100. wx.showToast({ title: error?.errMsg ?? "上传失败", icon: "error" });
  101. this.setData({
  102. [`thumbnail.${index}`]: "",
  103. [`original.${index}`]: "",
  104. });
  105. }
  106. )
  107. .then(() => {
  108. this.setData({ [`_queue.${index}`]: false });
  109. });
  110. },
  111. async onSubmit() {
  112. const data = {
  113. thumbnail: [] as any,
  114. source: [] as any,
  115. };
  116. for (let index = 0; index < this.data.uploadList.length; index++) {
  117. const item = this.data.uploadList[index];
  118. if (this.data._queue[index]) {
  119. wx.showToast({ title: `请等待图片上传完毕`, icon: "none" });
  120. return;
  121. } else if (item.required && !this.data.original[index]) {
  122. wx.showToast({ title: `请上传${item.label}`, icon: "none" });
  123. return;
  124. }
  125. if (this.data.original[index])
  126. data.source.push({
  127. target: item.target,
  128. src: this.data.original[index],
  129. });
  130. if (this.data.thumbnail[index])
  131. data.thumbnail.push({
  132. target: item.target,
  133. src: this.data.thumbnail[index],
  134. });
  135. }
  136. let imageObj: any = {
  137. upImg: this.data.thumbnail[0],
  138. downImg: this.data.thumbnail[1],
  139. faceImg: this.data.thumbnail[2],
  140. };
  141. this.setData({
  142. activeObj: { ...imageObj, ...this.data.followObj },
  143. });
  144. console.log({ ...this.data.activeObj }, "activeObj");
  145. let isAnalysis: number;
  146. if (this.data.messageType === 2) {
  147. isAnalysis = wx.getStorageSync("isAnalysis");
  148. }
  149. console.log(this.data.messageType, "messageType", isAnalysis);
  150. if (isAnalysis === 2) {
  151. // 提交随访提醒
  152. try {
  153. const res = await Post(
  154. `/followupTaskManage/updateFollowupTaskFillin/${this.data?.workId}`,
  155. { ...this.data.activeObj },
  156. {
  157. transform({ data }: any) {
  158. return data;
  159. },
  160. }
  161. );
  162. // 存储舌面象分析报告id,用于跳转页面时最后产生结果查看
  163. wx.setStorageSync(
  164. "tonguefaceAnalysisReportId",
  165. res.tonguefaceAnalysisReportId
  166. );
  167. this.getOpenerEventChannel().emit("update", data);
  168. wx.navigateBack();
  169. } catch (error) {
  170. wx.showToast({ title: error.errMsg, icon: "error" });
  171. }
  172. } else {
  173. // 对话管家
  174. this.getOpenerEventChannel().emit("update", data);
  175. wx.navigateBack();
  176. }
  177. },
  178. },
  179. });