report_edit.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import 'dart:convert';
  2. import 'package:fis_lib_report/converts/event_type.dart';
  3. import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
  4. import 'package:fis_lib_report/pages/block_element_page.dart';
  5. import 'package:fis_lib_report/report/interfaces/block_element.dart';
  6. import 'package:fis_lib_report/report/report_template_document.dart';
  7. import 'package:fis_lib_report/report/rt_thickness.dart';
  8. import 'package:fis_lib_report/report_info/report_event_args.dart';
  9. import 'package:fis_lib_report/report_info/report_info.dart';
  10. import 'package:fis_ui/index.dart';
  11. import 'package:flutter/material.dart';
  12. class FReportEditPage extends StatefulWidget implements FWidget {
  13. const FReportEditPage({
  14. Key? key,
  15. required this.reporter,
  16. required this.jsonStr,
  17. required this.reportDate,
  18. required this.onSelect,
  19. required this.selectEntry,
  20. required this.revoke,
  21. required this.selectImageHint,
  22. this.patinentAge,
  23. this.patinentName,
  24. this.patinentSex,
  25. this.patinentId,
  26. this.isReload = true,
  27. }) : super(key: key);
  28. final FEventHandler<String> onSelect;
  29. final String jsonStr;
  30. final String reporter;
  31. final String? patinentName;
  32. final String? patinentId;
  33. final String? patinentSex;
  34. final String? patinentAge;
  35. final String selectEntry;
  36. final String revoke;
  37. final String selectImageHint;
  38. final DateTime reportDate;
  39. final bool isReload;
  40. @override
  41. State<FReportEditPage> createState() {
  42. return _FReportEditPageState();
  43. }
  44. }
  45. class _FReportEditPageState extends State<FReportEditPage> {
  46. bool isInit = false;
  47. ReportTemplateDocument _reportTemplate = ReportTemplateDocument();
  48. double _height = 0;
  49. double _width = 0;
  50. List<IBlockElement> _blocks = [];
  51. List<IBlockElement> _header = [];
  52. List<IBlockElement> _footer = [];
  53. EdgeInsetsGeometry _padding = EdgeInsets.all(PtToPxConverter.ptToPx(56.83));
  54. bool _isReload = true;
  55. @override
  56. initState() {
  57. _isReload = widget.isReload;
  58. super.initState();
  59. }
  60. @override
  61. FWidget build(BuildContext context) {
  62. if (widget.jsonStr.isEmpty) {
  63. return const FSizedBox();
  64. }
  65. if (_isReload) {
  66. _intitTemplate();
  67. _initListentener();
  68. _isReload = false;
  69. }
  70. var margin = const EdgeInsets.symmetric(vertical: 2);
  71. return FCenter(
  72. widthFactor: 810,
  73. child: FContainer(
  74. alignment: Alignment.center,
  75. padding: _padding,
  76. width: _width,
  77. child: FColumn(
  78. mainAxisAlignment: MainAxisAlignment.center,
  79. children: [
  80. ..._header.map((head) {
  81. return FContainer(
  82. margin: margin,
  83. child: FBlockElementPage(element: head),
  84. );
  85. }),
  86. ..._blocks.map((block) {
  87. return FContainer(
  88. margin: margin,
  89. child: FBlockElementPage(element: block),
  90. );
  91. }),
  92. const FSizedBox(height: 10),
  93. ..._footer.map((footer) {
  94. return FContainer(
  95. margin: margin,
  96. constraints: const BoxConstraints(minHeight: 24),
  97. child: FBlockElementPage(element: footer),
  98. );
  99. }),
  100. ],
  101. ),
  102. ),
  103. );
  104. }
  105. void _intitTemplate({ReportEventArgs? args}) {
  106. String jsonStr = widget.jsonStr;
  107. DateTime reportDate = widget.reportDate;
  108. String reporter = widget.reporter;
  109. if (args != null) {
  110. jsonStr = args.jsonStr;
  111. reporter = args.reporter;
  112. reportDate = args.reportDate;
  113. FReportInfo.instance.onReload.addListener((sender, e) {
  114. _header.clear();
  115. _blocks.clear();
  116. _footer.clear();
  117. widget.onSelect.dispose();
  118. _intitTemplate(args: e);
  119. FReportInfo.instance.onReloadFinsh.emit(this, '');
  120. });
  121. }
  122. if (jsonStr.isEmpty) {
  123. return;
  124. }
  125. final reportMap = jsonDecode(jsonStr);
  126. setState(() {
  127. _reportTemplate = ReportTemplateDocument.fromJson(reportMap);
  128. FReportInfo.instance.init(
  129. _reportTemplate,
  130. reportDate,
  131. reporter,
  132. patientName: widget.patinentName,
  133. patientAge: widget.patinentAge,
  134. patientSex: widget.patinentSex,
  135. patinentId: widget.patinentId,
  136. revoke: widget.revoke,
  137. selectEntry: widget.selectEntry,
  138. selectImageHint: widget.selectImageHint,
  139. );
  140. if (args != null) {
  141. FReportInfo.instance.isASROn = args.isASROn;
  142. }
  143. _initPage();
  144. });
  145. if (args != null) {
  146. args.onSelect.dispose();
  147. args.onSelect.addListener((sender, e) {
  148. FReportInfo.instance.selectedInputImage(e);
  149. });
  150. FReportInfo.instance.onClose.addListener((sender, e) {
  151. if (mounted) {
  152. setState(() {
  153. _header.clear();
  154. _blocks.clear();
  155. _footer.clear();
  156. widget.onSelect.dispose();
  157. });
  158. }
  159. });
  160. } else {
  161. widget.onSelect.dispose();
  162. widget.onSelect.addListener((sender, e) {
  163. FReportInfo.instance.selectedInputImage(e);
  164. });
  165. }
  166. isInit = true;
  167. }
  168. void _initListentener() {
  169. FReportInfo.instance.onReload.addListener((sender, e) {
  170. _header.clear();
  171. _blocks.clear();
  172. _footer.clear();
  173. widget.onSelect.dispose();
  174. _intitTemplate(args: e);
  175. FReportInfo.instance.onReloadFinsh.emit(this, '');
  176. });
  177. FReportInfo.instance.onClose.addListener((sender, e) {
  178. if (mounted) {
  179. setState(() {
  180. _header.clear();
  181. _blocks.clear();
  182. _footer.clear();
  183. widget.onSelect.dispose();
  184. });
  185. }
  186. });
  187. }
  188. void _initPage() {
  189. try {
  190. _height = PtToPxConverter.ptToPx(_reportTemplate.pageSize!.height);
  191. _width = PtToPxConverter.ptToPx(_reportTemplate.pageSize!.width);
  192. final pagePadding =
  193. _reportTemplate.pagePadding ?? RTThickness.uniform(56);
  194. _padding = EdgeInsets.only(
  195. left: PtToPxConverter.ptToPx(pagePadding.left),
  196. right: PtToPxConverter.ptToPx(pagePadding.right),
  197. top: PtToPxConverter.ptToPx(pagePadding.top),
  198. bottom: PtToPxConverter.ptToPx(pagePadding.bottom),
  199. );
  200. _footer = _reportTemplate.footer ?? [];
  201. _blocks = _reportTemplate.blocks ?? [];
  202. _header = _reportTemplate.header ?? [];
  203. } catch (e) {
  204. _height = 841.8897637795275;
  205. _width = 595.275590551181;
  206. }
  207. }
  208. @override
  209. void dispose() {
  210. FReportInfo.instance.onReload.dispose();
  211. super.dispose();
  212. }
  213. }