home.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import PageContainerBehavior from "../../core/behavior/page-container.behavior";
  2. import { DraggableSheetBehavior, getDraggableSheetContext } from "../../core/behavior/draggableSheet.behavior";
  3. import { login } from "../../lib/logic";
  4. import { Post } from "../../lib/request/method";
  5. const { shared, Easing, timing } = wx.worklet
  6. const offset = shared(0);
  7. const styleIds = [];
  8. // pages/home/home.ts
  9. import { getPatients, healthReportMethod, healthIndexMethod } from "./request";
  10. import { toCertificationPage } from "./router";
  11. Component({
  12. behaviors: [
  13. PageContainerBehavior,
  14. DraggableSheetBehavior('.draggable-sheet-wrapper'),
  15. ],
  16. lifetimes: {
  17. attached() { this.initFabAnimated(); }
  18. },
  19. pageLifetimes: {
  20. show() { this.load(); }
  21. },
  22. properties: {
  23. patientId: { type: String, value: '' },
  24. next: { type: String, value: '' },
  25. },
  26. data: {
  27. patients: [] as (App.Patient.Model & { isDefault: 'Y' | 'N' })[],
  28. patient: null as App.Patient.Model | null,
  29. healthId: '',
  30. healthReport: { data: null, message: '' },
  31. healthIndex: { data: [], message: '' },
  32. position: {} as AnyObject,
  33. },
  34. observers: {
  35. 'patient'(model: { patientId: string }) {
  36. wx.setStorageSync('patientId', model.patientId);
  37. this._getHealthReport();
  38. this._getAbnormalHealthIndex();
  39. }
  40. },
  41. methods: {
  42. async load() {
  43. await login();
  44. wx.showLoading({ title: '加载中' });
  45. const { patient } = await getPatients(this.data.patientId);
  46. if (!patient) await toCertificationPage();
  47. else this.setData({ patient });
  48. wx.hideLoading();
  49. },
  50. async _getHealthReport() {
  51. wx.showLoading({ title: '加载中' });
  52. this.setData({ 'healthReport.loading': true, })
  53. try {
  54. const data = await healthReportMethod();
  55. this.setData({
  56. 'healthReport.data': data,
  57. 'healthReport.loading': false,
  58. healthId: data?.healthAnalysisReportId,
  59. });
  60. } catch (error) {
  61. this.setData({
  62. 'healthReport.data': [],
  63. 'healthReport.loading': false,
  64. 'healthReport.message': error.errMsg,
  65. healthId: '',
  66. });
  67. }
  68. wx.hideLoading();
  69. },
  70. async _getAbnormalHealthIndex() {
  71. this.setData({ 'healthIndex.loading': true, })
  72. try {
  73. const data = await healthIndexMethod();
  74. this.setData({
  75. 'healthIndex.data': data.map((item: AnyObject) => item.abnormalDesc).filter(Boolean),
  76. 'healthIndex.loading': false,
  77. });
  78. } catch (error) {
  79. this.setData({
  80. 'healthIndex.data': [],
  81. 'healthIndex.loading': false,
  82. 'healthIndex.message': error.errMsg,
  83. });
  84. }
  85. },
  86. onBodyModel(event: WechatMiniprogram.TouchEvent) {
  87. if (event.detail?.position === 'LB') { this.toReportPage(); }
  88. else if (event.detail?.position === 'LT') {
  89. const report = this.data.healthReport.data as unknown as AnyObject;
  90. this.setData({
  91. position: {
  92. LT: ['willillState', 'willillDegree', 'willillSocial', 'willillFunction'].map(key => {
  93. const title = report[`${key}Name`]
  94. const description = report[`${key}Description`]
  95. return title || description ? { title, description } : null
  96. }).filter(Boolean)
  97. },
  98. });
  99. this.showDraggableSheet();
  100. }
  101. else if (event.detail?.position === 'RT') {
  102. const report = this.data.healthReport.data as unknown as AnyObject;
  103. const get = (key: string) => ({ [key]: report[key] })
  104. this.setData({
  105. position: {
  106. RT: {
  107. ...get('constitutionGroupName'),
  108. ...get('constitutionGroupDefinition'),
  109. ...get('faceImg'),
  110. ...get('faceAnalysisResult'),
  111. ...get('tongueAnalysisResult'),
  112. ...get('upImg'),
  113. ...get('downImg'),
  114. }
  115. },
  116. });
  117. this.showDraggableSheet();
  118. }
  119. else if (event.detail?.position === 'RB') {
  120. const report = this.data.healthReport.data as unknown as AnyObject;
  121. const get = (key: string) => ({ [key]: report[key] })
  122. this.setData({
  123. position: {
  124. RB: {
  125. ...get('diagnoseSyndromeSummary'),
  126. ...get('diagnoseSyndromes'),
  127. ...get('factorItemSummary'),
  128. ...get('factorItems'),
  129. }
  130. },
  131. });
  132. this.showDraggableSheet();
  133. }
  134. else if (event.detail?.position === 'CT') {
  135. wx.showModal({
  136. title: '预警信息',
  137. content: this.data.healthIndex.data.map((item, index) => `${index + 1}、${item}`).join(''),
  138. showCancel: false,
  139. })
  140. }
  141. },
  142. initFabAnimated() {
  143. (<any>this).applyAnimatedStyle('.fab-1', () => {
  144. 'worklet'
  145. return { transform: `translateY(${-offset.value}px)` };
  146. });
  147. (<any>this).applyAnimatedStyle('.fab-2', () => {
  148. 'worklet'
  149. return { transform: `translateX(${-offset.value}px) translateY(${-offset.value / 2}px)` };
  150. });
  151. (<any>this).applyAnimatedStyle('.fab-3', () => {
  152. 'worklet'
  153. return { transform: `translateX(${-offset.value}px) translateY(${offset.value / 2}px)` };
  154. });
  155. (<any>this).applyAnimatedStyle('.fab-4', () => {
  156. 'worklet'
  157. return { transform: `translateY(${offset.value}px)` };
  158. });
  159. },
  160. onFabTap() {
  161. const value = Math.abs(offset.value - 72);
  162. offset.value = timing(value, { duration: 300, easing: (<any>Easing).linear }, () => {
  163. 'worklet'
  164. if (offset.value > 0) offset.value = 72
  165. })
  166. },
  167. toChatsPage() {
  168. wx.navigateTo({ url: `/module/chats/pages/index/index` })
  169. },
  170. toHealthPage() {
  171. wx.navigateTo({ url: `/module/health/pages/home/home` })
  172. },
  173. toSchemePage() {
  174. const id = this.data.healthId;
  175. if (id) wx.navigateTo({ url: `/module/health/pages/scheme/scheme?id=${id}` })
  176. else wx.showToast({ title: '暂无调理方案', icon: 'none' });
  177. },
  178. toReportPage() {
  179. const id = this.data.healthId;
  180. if (id) wx.navigateTo({ url: `/module/health/pages/report/report?id=${id}` })
  181. else wx.showToast({ title: '暂无分析报告', icon: 'none' });
  182. },
  183. showDraggableSheet() {
  184. getDraggableSheetContext.call(this).scrollTo({
  185. size: 0.5,
  186. pixels: 600,
  187. animated: true,
  188. duration: 300,
  189. easingFunction: 'ease'
  190. });
  191. },
  192. hideDraggableSheet() {
  193. getDraggableSheetContext.call(this).scrollTo({
  194. size: 0,
  195. pixels: 600,
  196. animated: true,
  197. duration: 300,
  198. easingFunction: 'ease'
  199. });
  200. this.setData({ position: {} })
  201. }
  202. },
  203. })