123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- import 'dart:convert';
- import 'package:fis_lib_report/converts/event_type.dart';
- import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
- import 'package:fis_lib_report/pages/block_element_page.dart';
- import 'package:fis_lib_report/report/interfaces/block_element.dart';
- import 'package:fis_lib_report/report/report_template_document.dart';
- import 'package:fis_lib_report/report/rt_thickness.dart';
- import 'package:fis_lib_report/report_info/report_event_args.dart';
- import 'package:fis_lib_report/report_info/report_info.dart';
- import 'package:fis_ui/index.dart';
- import 'package:flutter/material.dart';
- class FReportEditPage extends StatefulWidget implements FWidget {
- const FReportEditPage({
- Key? key,
- required this.reporter,
- required this.jsonStr,
- required this.reportDate,
- required this.onSelect,
- required this.selectEntry,
- required this.revoke,
- required this.selectImageHint,
- this.patinentAge,
- this.patinentName,
- this.patinentSex,
- this.patinentId,
- this.isReload = true,
- }) : super(key: key);
- final FEventHandler<String> onSelect;
- final String jsonStr;
- final String reporter;
- final String? patinentName;
- final String? patinentId;
- final String? patinentSex;
- final String? patinentAge;
- final String selectEntry;
- final String revoke;
- final String selectImageHint;
- final DateTime reportDate;
- final bool isReload;
- @override
- State<FReportEditPage> createState() {
- return _FReportEditPageState();
- }
- }
- class _FReportEditPageState extends State<FReportEditPage> {
- bool isInit = false;
- ReportTemplateDocument _reportTemplate = ReportTemplateDocument();
- double _height = 0;
- double _width = 0;
- List<IBlockElement> _blocks = [];
- List<IBlockElement> _header = [];
- List<IBlockElement> _footer = [];
- EdgeInsetsGeometry _padding = EdgeInsets.all(PtToPxConverter.ptToPx(56.83));
- bool _isReload = true;
- @override
- initState() {
- _isReload = widget.isReload;
- super.initState();
- }
- @override
- FWidget build(BuildContext context) {
- if (widget.jsonStr.isEmpty) {
- return const FSizedBox();
- }
- if (_isReload) {
- _intitTemplate();
- _initListentener();
- _isReload = false;
- }
- var margin = const EdgeInsets.symmetric(vertical: 2);
- return FCenter(
- widthFactor: 810,
- child: FContainer(
- alignment: Alignment.center,
- padding: _padding,
- width: _width,
- child: FColumn(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- ..._header.map((head) {
- return FContainer(
- margin: margin,
- child: FBlockElementPage(element: head),
- );
- }),
- ..._blocks.map((block) {
- return FContainer(
- margin: margin,
- child: FBlockElementPage(element: block),
- );
- }),
- const FSizedBox(height: 10),
- ..._footer.map((footer) {
- return FContainer(
- margin: margin,
- constraints: const BoxConstraints(minHeight: 24),
- child: FBlockElementPage(element: footer),
- );
- }),
- ],
- ),
- ),
- );
- }
- void _intitTemplate({ReportEventArgs? args}) {
- String jsonStr = widget.jsonStr;
- DateTime reportDate = widget.reportDate;
- String reporter = widget.reporter;
- if (args != null) {
- jsonStr = args.jsonStr;
- reporter = args.reporter;
- reportDate = args.reportDate;
- FReportInfo.instance.onReload.addListener((sender, e) {
- _header.clear();
- _blocks.clear();
- _footer.clear();
- widget.onSelect.dispose();
- _intitTemplate(args: e);
- FReportInfo.instance.onReloadFinsh.emit(this, '');
- });
- }
- if (jsonStr.isEmpty) {
- return;
- }
- final reportMap = jsonDecode(jsonStr);
- setState(() {
- _reportTemplate = ReportTemplateDocument.fromJson(reportMap);
- FReportInfo.instance.init(
- _reportTemplate,
- reportDate,
- reporter,
- patientName: widget.patinentName,
- patientAge: widget.patinentAge,
- patientSex: widget.patinentSex,
- patinentId: widget.patinentId,
- revoke: widget.revoke,
- selectEntry: widget.selectEntry,
- selectImageHint: widget.selectImageHint,
- );
- if (args != null) {
- FReportInfo.instance.isASROn = args.isASROn;
- }
- _initPage();
- });
- if (args != null) {
- args.onSelect.dispose();
- args.onSelect.addListener((sender, e) {
- FReportInfo.instance.selectedInputImage(e);
- });
- FReportInfo.instance.onClose.addListener((sender, e) {
- if (mounted) {
- setState(() {
- _header.clear();
- _blocks.clear();
- _footer.clear();
- widget.onSelect.dispose();
- });
- }
- });
- } else {
- widget.onSelect.dispose();
- widget.onSelect.addListener((sender, e) {
- FReportInfo.instance.selectedInputImage(e);
- });
- }
- isInit = true;
- }
- void _initListentener() {
- FReportInfo.instance.onReload.addListener((sender, e) {
- _header.clear();
- _blocks.clear();
- _footer.clear();
- widget.onSelect.dispose();
- _intitTemplate(args: e);
- FReportInfo.instance.onReloadFinsh.emit(this, '');
- });
- FReportInfo.instance.onClose.addListener((sender, e) {
- if (mounted) {
- setState(() {
- _header.clear();
- _blocks.clear();
- _footer.clear();
- widget.onSelect.dispose();
- });
- }
- });
- }
- void _initPage() {
- try {
- _height = PtToPxConverter.ptToPx(_reportTemplate.pageSize!.height);
- _width = PtToPxConverter.ptToPx(_reportTemplate.pageSize!.width);
- final pagePadding =
- _reportTemplate.pagePadding ?? RTThickness.uniform(56);
- _padding = EdgeInsets.only(
- left: PtToPxConverter.ptToPx(pagePadding.left),
- right: PtToPxConverter.ptToPx(pagePadding.right),
- top: PtToPxConverter.ptToPx(pagePadding.top),
- bottom: PtToPxConverter.ptToPx(pagePadding.bottom),
- );
- _footer = _reportTemplate.footer ?? [];
- _blocks = _reportTemplate.blocks ?? [];
- _header = _reportTemplate.header ?? [];
- } catch (e) {
- _height = 841.8897637795275;
- _width = 595.275590551181;
- }
- }
- @override
- void dispose() {
- FReportInfo.instance.onReload.dispose();
- super.dispose();
- }
- }
|