status.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import I18nBehavior from "../../../../i18n/behavior";
  2. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  3. import TickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
  4. import { Post } from "../../../../lib/request/method";
  5. import { transformHealthIndex2Ruler } from "../../tools/health-index";
  6. // module/health/pages/status/status.ts
  7. type ResponseData = { id: string, name: string, options: App.Health.Index.Ruler[] }[];
  8. Component({
  9. behaviors: [I18nBehavior, PageContainerBehavior, TickleBehavior],
  10. lifetimes: {
  11. attached() {
  12. this.getData()
  13. }
  14. },
  15. properties: {},
  16. data: {
  17. i18n: { healthIndex: { title: '数据信息', tips: '', __show__: false } },
  18. health: [] as ResponseData,
  19. },
  20. methods: {
  21. async getData() {
  22. wx.showLoading({ title: '加载中' });
  23. try {
  24. const health = await Post<ResponseData, App.Health.Index.Data[]>(`/patientQuota/getCurQuoval`, {}, {
  25. transform({ data }) {
  26. return transformHealthIndex2Ruler(data.map(item => ({ ...item, patientQuotaRecordDTOS: [] })))
  27. }
  28. });
  29. this.setData({ health })
  30. console.log(health, '指标数据health');
  31. } catch (error) {
  32. getTickleContext.call(this).showErrorMessage(error.errMsg, 0)
  33. }
  34. wx.hideLoading()
  35. },
  36. async onSubmit(event: WechatMiniprogram.FormSubmit) {
  37. let submitBtn = this.selectComponent('#submitBtn');
  38. const values = event.detail.value;
  39. const model = Object
  40. .entries(values)
  41. .filter(([, value]) => value)
  42. .map(([quotaId, quotaVal]) => ({ quotaId, quotaVal }));
  43. if (model.length) {
  44. wx.showLoading({ title: `提交中` });
  45. try {
  46. const health = this.data.health;
  47. const result = await Post(`/patientQuota/updateCurQuoval`, model, {
  48. transform() {
  49. return health
  50. .map(h => {
  51. const value = h.options.map(option => {
  52. const value = values[option.id];
  53. return value && value != option.value ? `${value}${option.unit}` : '';
  54. }).filter(Boolean).join(' / ');
  55. return value ? `${h.name}: ${value}` : '';
  56. })
  57. .filter(Boolean);
  58. }
  59. });
  60. this.getOpenerEventChannel().emit('update', result);
  61. wx.navigateBack();
  62. } catch (error) {
  63. submitBtn?.resetState();
  64. getTickleContext.call(this).showErrorMessage(error.errMsg);
  65. }
  66. wx.hideLoading();
  67. } else {
  68. submitBtn?.resetState();
  69. wx.showToast({ title: '请至少填写一项', icon: 'error' });
  70. }
  71. }
  72. }
  73. })