measure_configuation_page.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. import 'dart:convert';
  2. import 'package:fis_i18n/i18n.dart';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:fis_measure/interfaces/process/items/item_metas.dart';
  5. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  6. import 'package:fis_measure/process/items/item_meta_convert.dart';
  7. import 'package:fis_measure/process/workspace/measure_data_controller.dart';
  8. import 'package:fis_measure/process/workspace/measure_handler.dart';
  9. import 'package:fis_measure/view/measure/measure_config/widgets/measurement_tool_selection.dart';
  10. import 'package:fis_theme/theme.dart';
  11. import 'package:fis_ui/index.dart';
  12. import 'package:flutter/material.dart';
  13. import 'package:get/get.dart';
  14. ///条目元数据组
  15. class ItemMetaGroup {
  16. ItemMetaGroup(
  17. this.itemMetaGroupTitle,
  18. this.itemMeta,
  19. this.isExpend,
  20. );
  21. /// 当前测量组的名称
  22. final String itemMetaGroupTitle;
  23. /// 当前测量组的测量数组
  24. final List<ItemMeta> itemMeta;
  25. /// 是否展开
  26. bool? isExpend;
  27. }
  28. /// 测量工具配置
  29. class MeasureConfigurationPage extends StatelessWidget {
  30. const MeasureConfigurationPage({Key? key}) : super(key: key);
  31. @override
  32. FWidget build(BuildContext context) {
  33. return const _MeasureConfigurationDialog();
  34. }
  35. }
  36. ///测量配置对话框
  37. class _MeasureConfigurationDialog extends StatefulWidget implements FWidget {
  38. const _MeasureConfigurationDialog({
  39. Key? key,
  40. }) : super(key: key);
  41. @override
  42. State<_MeasureConfigurationDialog> createState() =>
  43. _MeasureConfigurationDialogState();
  44. }
  45. class _MeasureConfigurationDialogState
  46. extends State<_MeasureConfigurationDialog> {
  47. int measureToolsTab = 0;
  48. /// 切换标签栏
  49. void changeTab(int index) {
  50. measureToolsTab = index;
  51. setState(() {});
  52. }
  53. late final application = Get.find<IApplication>();
  54. late final measureHandler = Get.find<MeasureHandler>();
  55. /// 数据
  56. final measureData = Get.find<MeasureDataController>();
  57. /// 选中的测量项
  58. List<String> chooseMeasureList = [];
  59. List<ItemMetaGroup> itemMetaListGroup = [];
  60. String activeName = '';
  61. /// 跟超声机端保持一致,配置 项目写死
  62. List<ItemMetaGroup> getMeasureConfigurationGroupName() {
  63. return [
  64. ItemMetaGroup('Common', [], true),
  65. ItemMetaGroup('ABD', [], true),
  66. ItemMetaGroup('CARD', [], true),
  67. ItemMetaGroup('GYN', [], true),
  68. ItemMetaGroup('OB', [], true),
  69. ItemMetaGroup('VAS', [], true),
  70. ];
  71. }
  72. /// 打开已选测量工具设置
  73. ///
  74. /// [name] 测量的名字 后期改版后应该是一个测量对象
  75. void openHasSelectedSettingDialog(String name) {
  76. // state.childItemMeta = state.allItemMeta.firstWhere(
  77. // (element) => element.name == name,
  78. // );
  79. // router.dialog(() => HasSelectedSettingDialog(name: name));
  80. }
  81. Future<void> getName() async {
  82. var measureModeSelection = MeasureModeSelection(
  83. application.applicationName,
  84. application.categoryName,
  85. application.isThirdPart ? ['TPPTissue'] : ['Tissue'],
  86. );
  87. measureHandler.measureModeChanged = measureModeSelection;
  88. measureData.getMeasureApplicationList = [];
  89. var measureApplicationDTO =
  90. await measureData.getMeasureApplication.call(measureModeSelection);
  91. if (measureApplicationDTO != null) {
  92. /// 模式版本
  93. measureData.measureApplicationVersion =
  94. measureApplicationDTO.version ?? '';
  95. ///模式列表
  96. var models = measureApplicationDTO.availableModes;
  97. if (models != null && models.isNotEmpty) {
  98. ///群组列表
  99. var groups = models[0].availableGroups;
  100. if (groups != null && groups.isNotEmpty) {
  101. ///项目列表
  102. var folders = groups[0].availableFolders;
  103. if (folders != null && folders.isNotEmpty) {
  104. measureData.getMeasureApplicationList =
  105. folders[0].workingItemNames ?? [];
  106. if (folders[0].availableItems != null) {
  107. measureData.itemMetaList =
  108. folders[0].availableItems!.map((element) {
  109. return ItemMetaConverter(element).output();
  110. }).toList();
  111. }
  112. if (measureData.getMeasureApplicationList.isNotEmpty) {
  113. changeItem(measureData.getMeasureApplicationList[0]);
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }
  120. void changeItem(String? name) {
  121. activeName = name ?? '';
  122. application.switchItemByName(activeName);
  123. if (mounted) {
  124. setState(() {});
  125. }
  126. }
  127. void submit() async {
  128. var measureModeSubmitChanged = MeasureModeSubmit(
  129. measureData.measureApplicationVersion,
  130. application.applicationName,
  131. application.categoryName,
  132. UserDefinedMeasureModeDTO(
  133. modeName: 'Tissue',
  134. workingGroups: [
  135. UserDefinedMeasureGroupDTO(
  136. name: 'General',
  137. folders: [
  138. UserDefinedMeasureFolderDTO(
  139. name: 'General',
  140. workingItemNames: chooseMeasureList,
  141. ),
  142. ],
  143. ),
  144. ],
  145. ),
  146. );
  147. measureHandler.measureModeSubmitChanged = measureModeSubmitChanged;
  148. var saveUserDefinedMeasureApplication = await measureData
  149. .saveUserDefinedMeasureApplicationAsync
  150. .call(measureModeSubmitChanged);
  151. getName();
  152. setState(() {});
  153. }
  154. @override
  155. void initState() {
  156. super.initState();
  157. List<ItemMetaGroup> _itemMetaConfigurationList = [];
  158. List<String> chooseMeasure = [];
  159. Map<String, List<ItemMeta>> _group = {};
  160. getMeasureConfigurationGroupName().forEach(
  161. ((element) {
  162. List<ItemMeta> itemMetaListGroupItem = [];
  163. (measureData.itemMetaList).toList().forEach(
  164. (e) {
  165. // if (e.categories!.contains(element.itemMetaGroupTitle)) {
  166. // itemMetaListGroupItem.add(e);
  167. // }
  168. _group[element.itemMetaGroupTitle] = itemMetaListGroupItem;
  169. },
  170. );
  171. }),
  172. );
  173. _group.forEach(
  174. (key, value) {
  175. _itemMetaConfigurationList.add(
  176. ItemMetaGroup(key, value, true),
  177. );
  178. },
  179. );
  180. itemMetaListGroup = _itemMetaConfigurationList;
  181. chooseMeasure = measureData.getMeasureApplicationList;
  182. chooseMeasureList = chooseMeasure.toSet().toList();
  183. }
  184. @override
  185. void dispose() {
  186. super.dispose();
  187. }
  188. @override
  189. FWidget build(BuildContext context) {
  190. return FSimpleDialog(
  191. title: FText(
  192. i18nBook.measure.measureToolConfig.t,
  193. style: const TextStyle(
  194. color: Colors.white,
  195. fontSize: 18,
  196. ),
  197. ),
  198. isDefault: true,
  199. onOk: () {
  200. submit();
  201. },
  202. onCancel: () {
  203. chooseMeasureList = measureData.getMeasureApplicationList;
  204. Get.back();
  205. setState(() {});
  206. },
  207. children: [
  208. FContainer(
  209. width: 850,
  210. height: 500,
  211. child: _buildMeasureconfiguration(),
  212. ),
  213. ],
  214. );
  215. }
  216. FWidget _buildMeasureconfiguration() {
  217. return FContainer(
  218. padding: const EdgeInsets.symmetric(horizontal: 15),
  219. child: FRow(
  220. crossAxisAlignment: CrossAxisAlignment.start,
  221. children: [
  222. FContainer(
  223. width: 170,
  224. decoration: const BoxDecoration(
  225. border: Border(
  226. right: BorderSide(
  227. color: Color.fromRGBO(235, 235, 235, 1),
  228. width: 1,
  229. ),
  230. ),
  231. ),
  232. child: FColumn(
  233. crossAxisAlignment: CrossAxisAlignment.end,
  234. children: [
  235. const FSizedBox(
  236. height: 10,
  237. ),
  238. FContainer(
  239. width: 160,
  240. child: FInkWell(
  241. onTap: () {
  242. changeTab(0);
  243. },
  244. child: FContainer(
  245. padding: const EdgeInsets.symmetric(
  246. vertical: 10,
  247. horizontal: 5,
  248. ),
  249. child: FText(
  250. i18nBook.measure.measureToolSelect.t,
  251. style: measureToolsTab == 0
  252. ? TextStyle(
  253. color: FTheme.ins.colorScheme.primary,
  254. )
  255. : const TextStyle(),
  256. textAlign: TextAlign.end,
  257. ),
  258. ),
  259. ),
  260. ),
  261. FContainer(
  262. width: 160,
  263. child: FInkWell(
  264. onTap: () {
  265. changeTab(1);
  266. },
  267. child: FContainer(
  268. padding: const EdgeInsets.symmetric(
  269. vertical: 10,
  270. horizontal: 5,
  271. ),
  272. child: FText(
  273. i18nBook.measure.selectedMeasureTool.t,
  274. style: measureToolsTab == 1
  275. ? TextStyle(
  276. color: FTheme.ins.colorScheme.primary,
  277. )
  278. : const TextStyle(),
  279. textAlign: TextAlign.end,
  280. ),
  281. ),
  282. ),
  283. ),
  284. ],
  285. ),
  286. ),
  287. measureToolsTab == 0
  288. ? FExpanded(
  289. child: SelectModulePage(
  290. itemMetaListGroup: itemMetaListGroup,
  291. chooseMeasureList: chooseMeasureList,
  292. ),
  293. )
  294. : FExpanded(
  295. child: _HasSelectedModulePage(
  296. chooseMeasureList: chooseMeasureList,
  297. ),
  298. ),
  299. ],
  300. ),
  301. );
  302. }
  303. }
  304. class _HasSelectedModulePage extends StatelessWidget implements FWidget {
  305. final List<String> chooseMeasureList;
  306. /// 数据
  307. final measureData = Get.find<MeasureDataController>();
  308. _HasSelectedModulePage({
  309. required this.chooseMeasureList,
  310. });
  311. /// 根据语言包翻译
  312. ///
  313. /// [code] 翻译编码
  314. String getValues(String code) {
  315. final value = jsonDecode(measureData.measureLanguage)["Language"][code];
  316. return value ?? code;
  317. }
  318. @override
  319. FWidget build(BuildContext context) {
  320. return FListView(
  321. shrinkWrap: true,
  322. children: [
  323. FColumn(
  324. crossAxisAlignment: CrossAxisAlignment.start,
  325. children: [
  326. FContainer(
  327. padding: const EdgeInsets.only(left: 15, top: 15, bottom: 15),
  328. child: FWrap(
  329. spacing: 16.0, // 主轴(水平)方向间距
  330. runSpacing: 8.0, // 纵轴(垂直)方向间距
  331. direction: Axis.horizontal,
  332. crossAlignment: WrapCrossAlignment.center,
  333. alignment: WrapAlignment.start,
  334. children: List<FWidget>.generate(
  335. chooseMeasureList.length,
  336. (index) {
  337. return FElevatedButton(
  338. onPressed: () {
  339. // controller.openHasSelectedSettingDialog(
  340. // controller.state.chooseMeasureList[index],
  341. // );
  342. },
  343. style: ButtonStyle(
  344. backgroundColor: MaterialStateProperty.all(
  345. Colors.white,
  346. ),
  347. ),
  348. child: FContainer(
  349. width: 180,
  350. height: 60,
  351. child: FColumn(
  352. mainAxisAlignment: MainAxisAlignment.center,
  353. children: [
  354. FText(
  355. chooseMeasureList[index].toString(),
  356. style: const TextStyle(
  357. color: Colors.black,
  358. ),
  359. ),
  360. FText(
  361. getValues(
  362. chooseMeasureList[index].toString(),
  363. ),
  364. style: const TextStyle(
  365. color: Colors.black,
  366. ),
  367. ),
  368. ],
  369. ),
  370. ),
  371. );
  372. },
  373. ),
  374. ),
  375. ),
  376. ],
  377. ),
  378. ],
  379. );
  380. }
  381. }