123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import 'dart:convert';
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/managers/interfaces/exam.dart';
- import 'package:vitalapp/pages/medical/controller.dart';
- import 'package:vitalapp/store/store.dart';
- class TableInputDialogController extends GetxController {
- TableInputDialogController({
- required this.tableDataConfig,
- });
- final _examManager = Get.find<IExamManager>();
- final List<TableElementConfig> tableDataConfig;
- final List<TableElementData> tableData = [];
- Future<void> onConfirm(
- String? physicalExamNumber,
- String? keyValue,
- ) async {
- final result = <String, String>{};
- tableData.forEach((element) {
- String vlaue = element.textController.text;
- if (vlaue.isEmpty) {
- vlaue = '-';
- }
- result[element.config.id] = vlaue;
- });
- await createCheckup(physicalExamNumber, keyValue, result);
- Get.find<MedicalController>().onSelectExam.emit(this, true);
- // Get.back(result: TableInputResult(data: result));
- }
- /// 体检 检查提交
- Future<void> createCheckup(
- String? physicalExamNumber,
- String? keyValue,
- Map<String, dynamic> diagnosisDataValue,
- ) async {
- // Map<String, dynamic> input = diagnosisDataValue;
- // Map<String, dynamic> output = {};
- // input.forEach((key, value) {
- // value.forEach((innerKey, innerValue) {
- // output[innerKey] = innerValue;
- // });
- // });
- var result = await _examManager.createExam(CreateExamRequest(
- key: keyValue ?? "HEIBasic",
- examData: jsonEncode(diagnosisDataValue),
- physicalExamNumber:
- Store.user.currentSelectRegisterPersonInfo?.physicalExamNumber,
- ));
- if (result == true) {
- Get.back();
- }
- print(result);
- }
- void focusPre() {
- int index = getCurrFocusIndex();
- if (index != -1) {
- if (index > 0) {
- moveFocus(index - 1);
- }
- if (index == 0) {
- moveFocus(tableData.length - 1);
- }
- }
- }
- void focusNext() {
- int index = getCurrFocusIndex();
- if (index != -1) {
- if (index < tableData.length - 1) {
- moveFocus(index + 1);
- }
- if (index == tableData.length - 1) {
- moveFocus(0);
- }
- }
- }
- int getCurrFocusIndex() {
- for (int i = 0; i < tableData.length; i++) {
- final FocusNode focusNode = tableData[i].focusNode;
- if (focusNode.hasFocus) {
- return i;
- }
- }
- return -1;
- }
- void moveFocus(int index) {
- print('moveFocus: $index');
- if (index >= 0 && index < tableData.length) {
- tableData[index].focusNode.requestFocus();
- // 如果该行有值,下一帧执行,选择全部
- if (tableData[index].textController.text.isNotEmpty) {
- WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
- Future.delayed(Duration(milliseconds: 30), () {
- tableData[index].textController.selection = TextSelection(
- baseOffset: 0,
- extentOffset: tableData[index].textController.text.length,
- );
- });
- });
- }
- }
- }
- @override
- void onInit() {
- super.onInit();
- // 根据 tableDataConfig 初始化 tableData
- tableDataConfig.forEach((element) {
- tableData.add(TableElementData(element));
- });
- }
- @override
- void onReady() {
- super.onReady();
- }
- @override
- void onClose() {
- super.onClose();
- }
- }
- /// 表格配置项 (入参)
- class TableElementConfig {
- final String id;
- final String name;
- final String unit;
- final String? initValue;
- TableElementConfig(
- {required this.id,
- required this.name,
- required this.unit,
- this.initValue});
- }
- /// 表格输入结果 (出参)
- class TableInputResult {
- Map<String, String> data;
- TableInputResult({required this.data});
- }
- /// 表格元素数据(UI数据)
- class TableElementData {
- final TableElementConfig config;
- final TextEditingController textController;
- FocusNode focusNode = FocusNode();
- TableElementData(this.config)
- : textController = TextEditingController(text: config.initValue);
- }
|