base_form_value.dart 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import 'form_info.dart';
  2. import 'package:fis_common/index.dart';
  3. abstract class BaseFormValueChange {
  4. void onHeightOrWeightChange(UpdateFormArgs e) {
  5. UpdateFormType type = e.type;
  6. String height = FormInfo.instance.formValue["Height"] ?? '';
  7. String weight = FormInfo.instance.formValue["Weight"] ?? '';
  8. if (height.isNotNullOrEmpty && weight.isNotNullOrEmpty) {
  9. var doubleHeight = double.parse(height) / 100;
  10. var doubleWeight = double.parse(weight);
  11. var bmi =
  12. (doubleWeight / (doubleHeight * doubleHeight)).toStringAsFixed(2);
  13. FormInfo.instance.formValue["Bmi"] = bmi;
  14. FormInfo.instance.onChangeTargetValue.emit(
  15. this,
  16. TargetFormArgs(
  17. "Bmi",
  18. targetValue: bmi,
  19. ),
  20. );
  21. } else {
  22. if (FormInfo.instance.formValue.containsKey("Bmi")) {
  23. FormInfo.instance.formValue.remove("Bmi");
  24. }
  25. return;
  26. }
  27. }
  28. ///转诊
  29. void onReferralChange(UpdateFormArgs e) {
  30. UpdateFormType type = e.type;
  31. bool isDisabledValue = false;
  32. if ((type == UpdateFormType.Add && e.sourceValue == "referral_1")) {
  33. ///选中了无,则禁用其他选项
  34. isDisabledValue = true;
  35. } else if ((type == UpdateFormType.Remove &&
  36. e.sourceValue == "referral_1") ||
  37. (type == UpdateFormType.Add && e.sourceValue == "referral_2")) {
  38. ///取消选中无或选中有,则取消禁用其他选项
  39. isDisabledValue = false;
  40. }
  41. FormInfo.instance.onChangeTargetValue.emit(
  42. this,
  43. TargetFormArgs(
  44. "Reason_For_Referral",
  45. isDisabledValue: isDisabledValue,
  46. ),
  47. );
  48. FormInfo.instance.onChangeTargetValue.emit(
  49. this,
  50. TargetFormArgs(
  51. "Institution_And_Department",
  52. isDisabledValue: isDisabledValue,
  53. ),
  54. );
  55. if (e.sourceValue == "referral_1") {
  56. FormInfo.instance.onChangeTargetValue.emit(
  57. this,
  58. TargetFormArgs(
  59. "referral_2",
  60. isDisabledValue: false,
  61. targetValue: "cancelSelection",
  62. ),
  63. );
  64. } else if (e.sourceValue == "referral_2") {
  65. FormInfo.instance.onChangeTargetValue.emit(
  66. this,
  67. TargetFormArgs(
  68. "referral_1",
  69. isDisabledValue: false,
  70. targetValue: "cancelSelection",
  71. ),
  72. );
  73. }
  74. }
  75. void onValueChange(UpdateFormArgs e, String sourceValue, String targetKey) {
  76. UpdateFormType type = e.type;
  77. bool isDisabledValue = false;
  78. if (type == UpdateFormType.Add && e.sourceValue == sourceValue) {
  79. ///选中了无,则禁用其他选项
  80. isDisabledValue = true;
  81. } else if (type == UpdateFormType.Remove && e.sourceValue == sourceValue) {
  82. ///取消选中无,则取消禁用其他选项
  83. isDisabledValue = false;
  84. }
  85. FormInfo.instance.onChangeTargetValue.emit(
  86. this,
  87. TargetFormArgs(
  88. targetKey,
  89. isDisabledValue: isDisabledValue,
  90. ),
  91. );
  92. }
  93. }