message-analysis.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { Post } from "../../../../lib/request/method";
  2. interface Gallery {
  3. label?: string;
  4. src: string;
  5. }
  6. type Result = {
  7. thumbnail: Gallery[];
  8. source: (Gallery & { target: string; })[];
  9. }
  10. // module/chats/components/message-analysis/message-analysis.ts
  11. const defaultGallery = {
  12. 'tongueImgUrl': '',
  13. 'tongueBackImgUrl': '',
  14. 'faceImgUrl': '',
  15. }
  16. Component({
  17. properties: {
  18. payload: { type: Object, value: { title: '', description: '' } },
  19. active: { type: Boolean, value: false },
  20. messageType: { type: Number, value: 0 },
  21. },
  22. data: {
  23. isAnalysis: 0,
  24. start: false,
  25. examples: [
  26. { label: '舌面举例', src: '../../assets/tongue-1.png' },
  27. { label: '舌下举例', src: '../../assets/tongue-2.png' },
  28. { label: '面部举例', src: '../../assets/face-1.png' },
  29. ] as Gallery[],
  30. source: [] as Gallery[],
  31. },
  32. attached() {
  33. this.setData({
  34. isAnalysis: wx.getStorageSync("isAnalysis"),
  35. });
  36. },
  37. /**
  38. * 组件的方法列表
  39. */
  40. methods: {
  41. onConfirm() {
  42. if (this.data.source.length) return;
  43. this.setData({ start: true });
  44. // wx.navigateTo({
  45. // url: '/module/chats/pages/analysis/analysis?messageType=' + this.data.messageType,
  46. // events: { update: (data: Result) => this._update(data) }
  47. // });
  48. },
  49. onCancel() {
  50. this.triggerEvent('next', defaultGallery);
  51. },
  52. async onUpdate(event) {
  53. this.setData({ start: false });
  54. if (event.detail) {
  55. await this._followUp(event.detail);
  56. this._update(event.detail);
  57. }
  58. },
  59. // 提交随访提醒
  60. async _followUp({ source, thumbnail }: Result) {
  61. const data = {} as AnyObject;
  62. for (const item of source) { data[item.target] = item.src; }
  63. if (this.data.messageType === 2 && this.data.isAnalysis === 2) {
  64. wx.showLoading({ title: '提交中', mask: true });
  65. try {
  66. const workId = wx.getStorageSync("workId") || 0;
  67. const followObj = wx.getStorageSync("followObj");
  68. const res = await Post(
  69. `/followupTaskManage/updateFollowupTaskFillin/${workId}`,
  70. { ...followObj, upImg: data.tongueImgUrl, downImg: data.tongueBackImgUrl, faceImg: data.faceImgUrl },
  71. { transform({ data }: any) { return data; }, }
  72. );
  73. // 存储舌面象分析报告id,用于跳转页面时最后产生结果查看
  74. wx.setStorageSync("tonguefaceAnalysisReportId", res.tonguefaceAnalysisReportId);
  75. wx.hideLoading();
  76. } catch (error) {
  77. wx.hideLoading();
  78. wx.showToast({ title: error?.errMsg ?? '提交失败', icon: 'none', duration: 3000 });
  79. this.setData({ start: true });
  80. throw error;
  81. }
  82. }
  83. },
  84. _update({ source, thumbnail }: Result) {
  85. this.setData({ source: thumbnail });
  86. const data = {} as AnyObject;
  87. for (const item of source) { data[item.target] = item.src; }
  88. this.triggerEvent('next', {
  89. ...defaultGallery,
  90. ...data,
  91. });
  92. }
  93. }
  94. })