status.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. } catch (error) {
  31. getTickleContext.call(this).showErrorMessage(error.errMsg, 0)
  32. }
  33. wx.hideLoading()
  34. },
  35. async onSubmit(event: WechatMiniprogram.FormSubmit) {
  36. let submitBtn = this.selectComponent('#submitBtn');
  37. const values = event.detail.value;
  38. const model = Object
  39. .entries(values)
  40. .filter(([, value]) => value)
  41. .map(([quotaId, quotaVal]) => ({ quotaId, quotaVal }));
  42. if (model.length) {
  43. wx.showLoading({ title: `提交中` });
  44. try {
  45. const health = this.data.health;
  46. const result = await Post(`/patientQuota/updateCurQuoval`, model, {
  47. transform() {
  48. return health
  49. .map(h => {
  50. const value = h.options.map(option => {
  51. const value = values[option.id];
  52. return value && value != option.value ? `${value}${option.unit}` : '';
  53. }).filter(Boolean).join(' / ');
  54. return value ? `${h.name}: ${value}` : '';
  55. })
  56. .filter(Boolean);
  57. }
  58. });
  59. this.getOpenerEventChannel().emit('update', result);
  60. wx.navigateBack();
  61. } catch (error) {
  62. submitBtn?.resetState();
  63. getTickleContext.call(this).showErrorMessage(error.errMsg);
  64. }
  65. wx.hideLoading();
  66. } else {
  67. submitBtn?.resetState();
  68. wx.showToast({ title: '请至少填写一项', icon: 'error' });
  69. }
  70. }
  71. }
  72. })