|
@@ -3,7 +3,6 @@ import 'package:fis_i18n/i18n.dart';
|
|
|
import 'package:fis_jsonrpc/services/remedical.m.dart';
|
|
|
import 'package:fis_measure/interfaces/process/items/item_metas.dart';
|
|
|
import 'package:fis_measure/process/items/item_meta_convert.dart';
|
|
|
-import 'package:fis_measure/process/language/measure_language.dart';
|
|
|
import 'package:fis_measure/view/mobile_view/mobile_right_panel/mobile_measure_tool.dart';
|
|
|
import 'package:fis_ui/index.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
@@ -26,37 +25,34 @@ class _MobileMoreMeasureItemDialogState
|
|
|
final scrollController = ScrollController();
|
|
|
final searchBarController = TextEditingController();
|
|
|
|
|
|
- /// 测量语言包
|
|
|
- final measureLanguage = MeasureLanguage();
|
|
|
-
|
|
|
/// 当前模式的下标
|
|
|
int currentModeIndex = 0;
|
|
|
|
|
|
- /// 当前模式下可用的测量项
|
|
|
- List<ItemMetaDTO> currentModeMeasureItemList = [];
|
|
|
-
|
|
|
/// 当前可用的模式列表
|
|
|
List<String> currentModeNameList = [];
|
|
|
|
|
|
/// 搜索词
|
|
|
String searchWord = '';
|
|
|
|
|
|
- /// 搜索结果
|
|
|
- List<ItemMetaDTO> searchResult = [];
|
|
|
+ /// 当前模式下可用的测量项
|
|
|
+ List<MeasureItemModel> currentModeMeasureItemList = [];
|
|
|
+
|
|
|
+ /// 过滤后的展示结果
|
|
|
+ List<MeasureItemModel> filteredItems = [];
|
|
|
|
|
|
@override
|
|
|
void initState() {
|
|
|
super.initState();
|
|
|
// 遍历 measureModeList 获取到当前可用的模式列表,写入 currentModeNameList
|
|
|
for (final measureMode in widget.measureModeList) {
|
|
|
- currentModeNameList.add(measureMode.modeName);
|
|
|
+ currentModeNameList.add(measureMode.displayName);
|
|
|
}
|
|
|
if (widget.measureModeList.isEmpty) {
|
|
|
return;
|
|
|
}
|
|
|
currentModeMeasureItemList =
|
|
|
widget.measureModeList[currentModeIndex].availableItems;
|
|
|
- searchResult = currentModeMeasureItemList.toList();
|
|
|
+ filteredItems = currentModeMeasureItemList.toList();
|
|
|
}
|
|
|
|
|
|
@override
|
|
@@ -141,7 +137,7 @@ class _MobileMoreMeasureItemDialogState
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
- if (searchResult.isEmpty) {
|
|
|
+ if (filteredItems.isEmpty) {
|
|
|
return FContainer(
|
|
|
color: const Color.fromARGB(255, 36, 36, 36),
|
|
|
child: FCenter(
|
|
@@ -155,50 +151,89 @@ class _MobileMoreMeasureItemDialogState
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ final List<MeasureItemCategoryModel> categories =
|
|
|
+ _getClassifiedData(filteredItems);
|
|
|
return FContainer(
|
|
|
color: const Color.fromARGB(255, 36, 36, 36),
|
|
|
child: FScrollbar(
|
|
|
controller: scrollController,
|
|
|
isAlwaysShown: true,
|
|
|
- child: FGridView.count(
|
|
|
- padding: const EdgeInsets.all(10),
|
|
|
+ child: FListView(
|
|
|
+ shrinkWrap: true,
|
|
|
controller: scrollController,
|
|
|
+ children: [
|
|
|
+ FColumn(
|
|
|
+ children: [
|
|
|
+ ...categories.map((e) {
|
|
|
+ return _buildEachCategory(e);
|
|
|
+ }).toList(),
|
|
|
+ ],
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ FWidget _buildEachCategory(MeasureItemCategoryModel category) {
|
|
|
+ final List<MeasureItemModel> measureItemList = category.items;
|
|
|
+ final String categoryName = category.name;
|
|
|
+ return FColumn(
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
+ children: [
|
|
|
+ FContainer(
|
|
|
+ margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
|
|
+ child: FText(
|
|
|
+ categoryName,
|
|
|
+ style: const TextStyle(
|
|
|
+ color: Colors.grey,
|
|
|
+ fontSize: 14,
|
|
|
+ ),
|
|
|
+ textAlign: TextAlign.start,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ FContainer(
|
|
|
+ margin: const EdgeInsets.symmetric(horizontal: 10),
|
|
|
+ color: Colors.grey,
|
|
|
+ height: 1,
|
|
|
+ ),
|
|
|
+ FGridView.count(
|
|
|
+ physics: const NeverScrollableScrollPhysics(),
|
|
|
+ shrinkWrap: true,
|
|
|
+ padding: const EdgeInsets.all(10),
|
|
|
crossAxisCount: 6,
|
|
|
childAspectRatio: 3,
|
|
|
mainAxisSpacing: 5,
|
|
|
crossAxisSpacing: 5,
|
|
|
children: [
|
|
|
- ...searchResult.map((e) {
|
|
|
+ ...measureItemList.map((e) {
|
|
|
return _buildMeasureListItem(
|
|
|
e,
|
|
|
);
|
|
|
}).toList()
|
|
|
],
|
|
|
),
|
|
|
- ),
|
|
|
+ ],
|
|
|
);
|
|
|
}
|
|
|
|
|
|
/// 构建更多测量项列表中的测量项按钮
|
|
|
FWidget _buildMeasureListItem(
|
|
|
- ItemMetaDTO itemMeta,
|
|
|
+ MeasureItemModel item,
|
|
|
) {
|
|
|
- final bool isActive = widget.activeItemName == itemMeta.name;
|
|
|
- String displayName = itemMeta.name ?? '';
|
|
|
- if (i18nBook.isCurrentChinese) {
|
|
|
- displayName = measureLanguage.t('measure', itemMeta.description ?? '');
|
|
|
- }
|
|
|
+ final bool isActive = widget.activeItemName == item.itemMeta.name;
|
|
|
return FInkWell(
|
|
|
onTap: () {
|
|
|
if (isActive) return;
|
|
|
HapticFeedback.mediumImpact();
|
|
|
ItemMeta selectedItemMeta;
|
|
|
try {
|
|
|
- selectedItemMeta = ItemMetaConverter(itemMeta).output();
|
|
|
+ selectedItemMeta = ItemMetaConverter(item.itemMeta).output();
|
|
|
Get.back<ItemMeta>(result: selectedItemMeta);
|
|
|
} catch (e) {
|
|
|
logger.e(
|
|
|
- "Item meta -[${itemMeta.name}] convert error; JSON-Text: ${itemMeta.toJson()}",
|
|
|
+ "Item meta -[${item.displayName}] convert error; JSON-Text: ${item.itemMeta.toJson()}",
|
|
|
e,
|
|
|
);
|
|
|
}
|
|
@@ -213,7 +248,7 @@ class _MobileMoreMeasureItemDialogState
|
|
|
),
|
|
|
child: FCenter(
|
|
|
child: FText(
|
|
|
- displayName,
|
|
|
+ item.displayName,
|
|
|
textAlign: TextAlign.center,
|
|
|
style: TextStyle(
|
|
|
fontSize: 12,
|
|
@@ -300,7 +335,7 @@ class _MobileMoreMeasureItemDialogState
|
|
|
border: InputBorder.none,
|
|
|
),
|
|
|
onChanged: (value) {
|
|
|
- _searchMeasureItem(value);
|
|
|
+ _filterMeasureItems(value);
|
|
|
},
|
|
|
),
|
|
|
),
|
|
@@ -309,13 +344,13 @@ class _MobileMoreMeasureItemDialogState
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- void _searchMeasureItem(String value) {
|
|
|
+ void _filterMeasureItems(String value) {
|
|
|
searchWord = value;
|
|
|
value = value.toLowerCase();
|
|
|
- searchResult.clear(); // 清除任何现有的搜索结果
|
|
|
- for (ItemMetaDTO itemMeta in currentModeMeasureItemList) {
|
|
|
- if (itemMeta.name!.toLowerCase().contains(value)) {
|
|
|
- searchResult.add(itemMeta);
|
|
|
+ filteredItems.clear(); // 清除任何现有的搜索结果
|
|
|
+ for (MeasureItemModel itemModel in currentModeMeasureItemList) {
|
|
|
+ if (itemModel.searchKey.contains(value)) {
|
|
|
+ filteredItems.add(itemModel);
|
|
|
}
|
|
|
}
|
|
|
setState(() {});
|
|
@@ -325,6 +360,71 @@ class _MobileMoreMeasureItemDialogState
|
|
|
currentModeIndex = index;
|
|
|
currentModeMeasureItemList =
|
|
|
widget.measureModeList[currentModeIndex].availableItems;
|
|
|
- _searchMeasureItem(searchWord);
|
|
|
+ _filterMeasureItems(searchWord);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<MeasureItemCategoryModel> _getClassifiedData(
|
|
|
+ List<MeasureItemModel> items,
|
|
|
+ ) {
|
|
|
+ final Map<String, List<MeasureItemModel>> categoryMap = {};
|
|
|
+ for (MeasureItemModel item in items) {
|
|
|
+ if (categoryMap.containsKey(item.category)) {
|
|
|
+ categoryMap[item.category]!.add(item);
|
|
|
+ } else {
|
|
|
+ categoryMap[item.category] = [item];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<MeasureItemCategoryModel> classifiedData = categoryMap.entries
|
|
|
+ .map((e) => MeasureItemCategoryModel(
|
|
|
+ name: e.key,
|
|
|
+ items: e.value,
|
|
|
+ ))
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ /// 遍历 classifiedData 将 common 类别放在最前面
|
|
|
+ int commonIndex = classifiedData
|
|
|
+ .indexWhere((element) => element.name.toLowerCase().contains('common'));
|
|
|
+ if (commonIndex != -1) {
|
|
|
+ final MeasureItemCategoryModel commonCategory =
|
|
|
+ classifiedData[commonIndex];
|
|
|
+ classifiedData.removeAt(commonIndex);
|
|
|
+ classifiedData.insert(0, commonCategory);
|
|
|
+ }
|
|
|
+
|
|
|
+ return classifiedData;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+class MeasureItemModel {
|
|
|
+ /// 外显名称(中文下只显示中文、英文下只显示英文)
|
|
|
+ final String displayName;
|
|
|
+
|
|
|
+ /// 测量项DTO
|
|
|
+ final ItemMetaDTO itemMeta;
|
|
|
+
|
|
|
+ /// 类别
|
|
|
+ final String category;
|
|
|
+
|
|
|
+ /// 搜索关键字
|
|
|
+ final String searchKey;
|
|
|
+
|
|
|
+ MeasureItemModel({
|
|
|
+ required this.displayName,
|
|
|
+ required this.itemMeta,
|
|
|
+ required this.category,
|
|
|
+ required this.searchKey,
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+class MeasureItemCategoryModel {
|
|
|
+ /// 类别名称
|
|
|
+ final String name;
|
|
|
+
|
|
|
+ /// 类别下的测量项
|
|
|
+ final List<MeasureItemModel> items;
|
|
|
+
|
|
|
+ MeasureItemCategoryModel({
|
|
|
+ required this.name,
|
|
|
+ required this.items,
|
|
|
+ });
|
|
|
+}
|