status.ts 2.5 KB

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