|
@@ -0,0 +1,132 @@
|
|
|
+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_info.dart';
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+
|
|
|
+class ReportEditPage extends StatefulWidget {
|
|
|
+ const ReportEditPage({
|
|
|
+ Key? key,
|
|
|
+ required this.reporter,
|
|
|
+ required this.jsonStr,
|
|
|
+ required this.reportDate,
|
|
|
+ required this.onSelect,
|
|
|
+ }) : super(key: key);
|
|
|
+
|
|
|
+ final FEventHandler<String> onSelect;
|
|
|
+ final String reporter;
|
|
|
+ final String jsonStr;
|
|
|
+ final String reportDate;
|
|
|
+
|
|
|
+ @override
|
|
|
+ State<ReportEditPage> createState() => _ReportEditPageState();
|
|
|
+}
|
|
|
+
|
|
|
+class _ReportEditPageState extends State<ReportEditPage> {
|
|
|
+ ReportTemplateDocument _reportTemplate = ReportTemplateDocument();
|
|
|
+ double _height = 0;
|
|
|
+ double _width = 0;
|
|
|
+ List<IBlockElement> _blocks = [];
|
|
|
+ List<IBlockElement> _header = [];
|
|
|
+ List<IBlockElement> _footer = [];
|
|
|
+ double _baseFontSize = 9.0;
|
|
|
+ double _footerDistance = 34.0;
|
|
|
+ double _footerHeight = 0;
|
|
|
+ EdgeInsetsGeometry _padding = EdgeInsets.all(PtToPxConverter.ptToPx(56.83));
|
|
|
+ bool isInit = false;
|
|
|
+
|
|
|
+ @override
|
|
|
+ initState() {
|
|
|
+ _intitTemplate();
|
|
|
+ super.initState();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ if (widget.jsonStr.isEmpty) {
|
|
|
+ return const SizedBox();
|
|
|
+ }
|
|
|
+ if (!isInit) {
|
|
|
+ _intitTemplate();
|
|
|
+ }
|
|
|
+ return Container(
|
|
|
+ decoration: _buildDecoration(),
|
|
|
+ padding: _padding,
|
|
|
+ alignment: Alignment.center,
|
|
|
+ height: _height,
|
|
|
+ width: _width,
|
|
|
+ child: ListView(
|
|
|
+ // mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ // crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
+ // mainAxisSize: MainAxisSize.min,
|
|
|
+ children: [
|
|
|
+ ..._header.map((head) {
|
|
|
+ return BlockElementPage(element: head);
|
|
|
+ }),
|
|
|
+ ..._blocks.map((block) {
|
|
|
+ return BlockElementPage(element: block);
|
|
|
+ }),
|
|
|
+ const SizedBox(height: 10),
|
|
|
+ ..._footer.map((footer) {
|
|
|
+ return BlockElementPage(element: footer);
|
|
|
+ }),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ BoxDecoration _buildDecoration() {
|
|
|
+ return BoxDecoration(
|
|
|
+ border: Border.all(
|
|
|
+ width: 0.5,
|
|
|
+ color: const Color.fromARGB(255, 83, 83, 83),
|
|
|
+ ),
|
|
|
+ color: Colors.white);
|
|
|
+ }
|
|
|
+
|
|
|
+ void _intitTemplate() {
|
|
|
+ if (widget.jsonStr.isEmpty) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final reportMap = jsonDecode(widget.jsonStr);
|
|
|
+ final template = ReportTemplateDocument.fromJson(reportMap);
|
|
|
+ _reportTemplate = template;
|
|
|
+ ReportInfo.instance.init(_reportTemplate);
|
|
|
+ setState(() {
|
|
|
+ _initPage();
|
|
|
+ });
|
|
|
+ widget.onSelect.addListener((sender, e) {
|
|
|
+ ReportInfo.instance.selectedInputImage(e);
|
|
|
+ });
|
|
|
+ isInit = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ void _initPage() {
|
|
|
+ try {
|
|
|
+ _height = PtToPxConverter.ptToPx(_reportTemplate.pageSize!.height);
|
|
|
+ _width = PtToPxConverter.ptToPx(_reportTemplate.pageSize!.width);
|
|
|
+ _baseFontSize = PtToPxConverter.ptToPx(_reportTemplate.baseFontSize);
|
|
|
+ _footerDistance = PtToPxConverter.ptToPx(_reportTemplate.footerDistance);
|
|
|
+ _footerHeight = PtToPxConverter.ptToPx(_reportTemplate.footerHeight);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|