status.ts 2.5 KB

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