From 49ddf6275158cfc7b167059fe59ccec69c454dd4 Mon Sep 17 00:00:00 2001 From: louis <869322496@qq.com> Date: Tue, 2 Apr 2024 16:22:21 +0800 Subject: [PATCH] fix: bug --- lib/models/sale_quotation.model.dart | 2 +- .../components/inventory_search.dart | 309 +++++++++--------- .../sale_quotation_group_search.dart | 16 +- .../sale_quotation.controller.dart | 47 ++- .../sale_quotation/sale_quotation.dart | 48 +-- lib/widgets/core/sk_number_input.dart | 2 +- lib/widgets/core/sk_single_search_more.dart | 50 +-- pubspec.lock | 8 + pubspec.yaml | 1 + 9 files changed, 249 insertions(+), 234 deletions(-) diff --git a/lib/models/sale_quotation.model.dart b/lib/models/sale_quotation.model.dart index 54eef6b..13add1f 100644 --- a/lib/models/sale_quotation.model.dart +++ b/lib/models/sale_quotation.model.dart @@ -3,7 +3,7 @@ import 'package:get/get_rx/src/rx_types/rx_types.dart'; class SaleQuotationModel { final String name; RxBool isExpanded = true.obs; - List items; + RxList items; SaleQuotationModel({required this.name, required this.items}); } diff --git a/lib/screens/new_inventory_inout/components/inventory_search.dart b/lib/screens/new_inventory_inout/components/inventory_search.dart index b0ce48d..07570b9 100644 --- a/lib/screens/new_inventory_inout/components/inventory_search.dart +++ b/lib/screens/new_inventory_inout/components/inventory_search.dart @@ -199,173 +199,170 @@ class InventorySearch extends StatelessWidget { controller: controller.refreshController, onLoading: controller.onLoading, onRefresh: controller.onRefresh, - child: controller.refreshController.isLoading - ? const SizedBox() - : controller.inventories.isEmpty - ? const Center( - child: Empty(text: '暂无库存'), - ) - : !ScreenAdaper.isLandspace() - ? buildPortraitList() - : Table(columnWidths: { - 0: const MinColumnWidth( - FixedColumnWidth(80), FixedColumnWidth(80)), - 1: MinColumnWidth( - FixedColumnWidth( - ScreenAdaper.screenShortDistance() / 5), - FixedColumnWidth( - ScreenAdaper.screenShortDistance() / 5)), - 2: FlexColumnWidth( - ScreenAdaper.screenShortDistance() / 4), - 3: FlexColumnWidth( - ScreenAdaper.screenShortDistance() / 4), - 4: MinColumnWidth( - FixedColumnWidth( - ScreenAdaper.screenShortDistance() / 5), - FixedColumnWidth( - ScreenAdaper.screenShortDistance() / 5)), - 5: MinColumnWidth( - FixedColumnWidth( - ScreenAdaper.screenShortDistance() / 6), - FixedColumnWidth( - ScreenAdaper.screenShortDistance() / 6)), - }, children: [ - // table header - TableRow( - decoration: const BoxDecoration( - border: Border( - bottom: BorderSide( - color: AppTheme.dividerColor))), - children: [ - TableCell( - verticalAlignment: - TableCellVerticalAlignment.middle, - child: Container( - alignment: Alignment.centerLeft, - height: ScreenAdaper.height(60), - child: Text( - '库存编号', - style: listTitleTextStyle, - ), - )), - TableCell( - verticalAlignment: - TableCellVerticalAlignment.middle, - child: Text( - '所属项目', - style: listTitleTextStyle, - )), - TableCell( - verticalAlignment: - TableCellVerticalAlignment.middle, - child: Text( - '产品名称', - style: listTitleTextStyle, - )), - TableCell( - verticalAlignment: - TableCellVerticalAlignment.middle, + child: controller.inventories.isEmpty + ? const Center( + child: Empty(text: '暂无库存'), + ) + : !ScreenAdaper.isLandspace() + ? buildPortraitList() + : Table(columnWidths: { + 0: const MinColumnWidth( + FixedColumnWidth(80), FixedColumnWidth(80)), + 1: MinColumnWidth( + FixedColumnWidth( + ScreenAdaper.screenShortDistance() / 5), + FixedColumnWidth( + ScreenAdaper.screenShortDistance() / 5)), + 2: FlexColumnWidth( + ScreenAdaper.screenShortDistance() / 4), + 3: FlexColumnWidth( + ScreenAdaper.screenShortDistance() / 4), + 4: MinColumnWidth( + FixedColumnWidth( + ScreenAdaper.screenShortDistance() / 5), + FixedColumnWidth( + ScreenAdaper.screenShortDistance() / 5)), + 5: MinColumnWidth( + FixedColumnWidth( + ScreenAdaper.screenShortDistance() / 6), + FixedColumnWidth( + ScreenAdaper.screenShortDistance() / 6)), + }, children: [ + // table header + TableRow( + decoration: const BoxDecoration( + border: Border( + bottom: BorderSide( + color: AppTheme.dividerColor))), + children: [ + TableCell( + verticalAlignment: + TableCellVerticalAlignment.middle, + child: Container( + alignment: Alignment.centerLeft, + height: ScreenAdaper.height(60), child: Text( - '规格', + '库存编号', style: listTitleTextStyle, ), - ), - TableCell( - verticalAlignment: - TableCellVerticalAlignment.middle, - child: Text( - '单价', - style: listTitleTextStyle, + )), + TableCell( + verticalAlignment: + TableCellVerticalAlignment.middle, + child: Text( + '所属项目', + style: listTitleTextStyle, + )), + TableCell( + verticalAlignment: + TableCellVerticalAlignment.middle, + child: Text( + '产品名称', + style: listTitleTextStyle, + )), + TableCell( + verticalAlignment: + TableCellVerticalAlignment.middle, + child: Text( + '规格', + style: listTitleTextStyle, + ), + ), + TableCell( + verticalAlignment: + TableCellVerticalAlignment.middle, + child: Text( + '单价', + style: listTitleTextStyle, + ), + ), + TableCell( + verticalAlignment: + TableCellVerticalAlignment.middle, + child: Text( + '数量', + textAlign: TextAlign.right, + style: listTitleTextStyle, + ), + ), + ]), + ...controller.inventories.map((itemData) { + return TableRow( + decoration: const BoxDecoration( + border: Border( + bottom: BorderSide( + color: AppTheme.dividerColor))), + children: [ + buildTableCell( + Text( + itemData.inventoryNumber!, + style: textStyle, ), - ), - TableCell( - verticalAlignment: - TableCellVerticalAlignment.middle, - child: Text( - '数量', - textAlign: TextAlign.right, - style: listTitleTextStyle, - ), - ), - ]), - ...controller.inventories.map((itemData) { - return TableRow( - decoration: const BoxDecoration( - border: Border( - bottom: BorderSide( - color: AppTheme.dividerColor))), - children: [ - buildTableCell( + itemData: itemData), + + // 入库时所属项目 + buildTableCell( + Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ Text( - itemData.inventoryNumber!, + '${itemData.project?.name}', style: textStyle, ), - itemData: itemData), - - // 入库时所属项目 - buildTableCell( - Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - '${itemData.project?.name}', - style: textStyle, - ), - ], - ), - itemData: itemData), - // 产品 - buildTableCell( - Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - '${itemData.product?.name}', - style: textStyle, - ), - Text( - '${itemData.product?.company?.name}', - style: TextStyle( - fontSize: - ScreenAdaper.height(15), - color: AppTheme.grey), - ) - ], - ), - itemData: itemData), - // 规格 - buildTableCell( + ], + ), + itemData: itemData), + // 产品 + buildTableCell( + Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ Text( - itemData.product - ?.productSpecification ?? - '', - style: textStyle), - itemData: itemData), - // 单价 - buildTableCell( - Text( - '¥${double.parse('${itemData.unitPrice}')}', + '${itemData.product?.name}', style: textStyle, ), - itemData: itemData), - - // 库存数量 - buildTableCell( Text( - '${itemData.quantity}${itemData.product?.unit?.label ?? ''}', - textAlign: TextAlign.right, - style: textStyle), - itemData: itemData, - alignment: Alignment.centerRight), - ]); - }) - ])))); + '${itemData.product?.company?.name}', + style: TextStyle( + fontSize: ScreenAdaper.height(15), + color: AppTheme.grey), + ) + ], + ), + itemData: itemData), + // 规格 + buildTableCell( + Text( + itemData.product + ?.productSpecification ?? + '', + style: textStyle), + itemData: itemData), + // 单价 + buildTableCell( + Text( + '¥${double.parse('${itemData.unitPrice}')}', + style: textStyle, + ), + itemData: itemData), + + // 库存数量 + buildTableCell( + Text( + '${itemData.quantity}${itemData.product?.unit?.label ?? ''}', + textAlign: TextAlign.right, + style: textStyle), + itemData: itemData, + alignment: Alignment.centerRight), + ]); + }) + ])))); } Widget buildTableCell(Widget child, diff --git a/lib/screens/sale_quotation/components/sale_quotation_group_search.dart b/lib/screens/sale_quotation/components/sale_quotation_group_search.dart index 101f054..3e17990 100644 --- a/lib/screens/sale_quotation/components/sale_quotation_group_search.dart +++ b/lib/screens/sale_quotation/components/sale_quotation_group_search.dart @@ -175,14 +175,14 @@ class GroupSearchController extends GetxController { // isRefresh == true ? list.assignAll(newList) : list.addAll(newList); List newList = [ - SaleQuotationModel(name: '中间过渡架电控部分', items: []), - SaleQuotationModel(name: '端头架电控部分', items: []), - SaleQuotationModel(name: '主阀部分', items: []), - SaleQuotationModel(name: '自动反冲洗过滤器部分', items: []), - SaleQuotationModel(name: '位移测量部分', items: []), - SaleQuotationModel(name: '压力检测部分', items: []), - SaleQuotationModel(name: '煤机定位部分', items: []), - SaleQuotationModel(name: '姿态检测部分', items: []), + SaleQuotationModel(name: '中间过渡架电控部分', items: RxList([])), + SaleQuotationModel(name: '端头架电控部分', items: RxList([])), + SaleQuotationModel(name: '主阀部分', items: RxList([])), + SaleQuotationModel(name: '自动反冲洗过滤器部分', items: RxList([])), + SaleQuotationModel(name: '位移测量部分', items: RxList([])), + SaleQuotationModel(name: '压力检测部分', items: RxList([])), + SaleQuotationModel(name: '煤机定位部分', items: RxList([])), + SaleQuotationModel(name: '姿态检测部分', items: RxList([])), ]; list.assignAll(newList); return newList; diff --git a/lib/screens/sale_quotation/sale_quotation.controller.dart b/lib/screens/sale_quotation/sale_quotation.controller.dart index ad9a4d7..33dd30a 100644 --- a/lib/screens/sale_quotation/sale_quotation.controller.dart +++ b/lib/screens/sale_quotation/sale_quotation.controller.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:sk_base_mobile/models/base_search_more.dart'; import 'package:sk_base_mobile/models/sale_quotation.model.dart'; import 'package:sk_base_mobile/screens/sale_quotation/components/sale_quotation_group_search.dart'; import 'package:sk_base_mobile/widgets/core/sk_single_search_more.dart'; import 'package:sk_base_mobile/util/modal.util.dart'; import 'package:sk_base_mobile/util/screen_adaper_util.dart'; +import 'package:pinyin/pinyin.dart'; class SaleQuotationController extends GetxController { static SaleQuotationController get to => Get.find(); @@ -37,15 +37,6 @@ class SaleQuotationController extends GetxController { @override void onReady() { - // groups.assignAll(); - // SaleQuotationModel(name: '中间过渡架电控部分', items: products), - // SaleQuotationModel(name: '端头架电控部分', items: products), - // SaleQuotationModel(name: '主阀部分', items: products), - // SaleQuotationModel(name: '自动反冲洗过滤器部分', items: products), - // SaleQuotationModel(name: '位移测量部分', items: products), - // SaleQuotationModel(name: '压力检测部分', items: products), - // SaleQuotationModel(name: '煤机定位部分', items: products), - // SaleQuotationModel(name: '姿态检测部分', items: products), super.onReady(); } @@ -86,7 +77,7 @@ class SaleQuotationController extends GetxController { groups.removeAt(index); } - Future addItems() async { + Future addItems(int groupIndex) async { final controller = Get.put(ItemSearchMoreController()); // 选择产品 ModalUtil.showGeneralDialog( @@ -99,13 +90,7 @@ class SaleQuotationController extends GetxController { return InkWell( onTap: () { Get.back(); - // if (beforeSelectedCheck != null) - // { - // if (beforeSelectedCheck!(controller.list[index])) - // {onSelected!(controller.list[index])} - // } - // else - // {onSelected!(controller.list[index])} + groups[groupIndex].items.add(controller.list[index]); }, child: Container( padding: EdgeInsets.symmetric( @@ -136,16 +121,19 @@ class GroupSearchMoreController extends GetxController @override Future> getData({bool isRefresh = false}) async { List newList = [ - SaleQuotationModel(name: '中间过渡架电控部分', items: []), - SaleQuotationModel(name: '端头架电控部分', items: []), - SaleQuotationModel(name: '主阀部分', items: []), - SaleQuotationModel(name: '自动反冲洗过滤器部分', items: []), - SaleQuotationModel(name: '位移测量部分', items: []), - SaleQuotationModel(name: '压力检测部分', items: []), - SaleQuotationModel(name: '煤机定位部分', items: []), - SaleQuotationModel(name: '姿态检测部分', items: []), + SaleQuotationModel(name: '中间过渡架电控部分', items: RxList([])), + SaleQuotationModel(name: '端头架电控部分', items: RxList([])), + SaleQuotationModel(name: '主阀部分', items: RxList([])), + SaleQuotationModel(name: '自动反冲洗过滤器部分', items: RxList([])), + SaleQuotationModel(name: '位移测量部分', items: RxList([])), + SaleQuotationModel(name: '压力检测部分', items: RxList([])), + SaleQuotationModel(name: '煤机定位部分', items: RxList([])), + SaleQuotationModel(name: '姿态检测部分', items: RxList([])), ]; - list.assignAll(newList); + list.assignAll(newList + .where((element) => PinyinHelper.getPinyin(element.name, separator: '') + .contains(searchKey.value)) + .toList()); return newList; } } @@ -176,7 +164,10 @@ class ItemSearchMoreController extends GetxController SaleQuotationItemModel(name: '倾角传感器'), SaleQuotationItemModel(name: '各类安装附件'), ]; - list.assignAll(newList); + list.assignAll(newList + .where((element) => PinyinHelper.getPinyin(element.name, separator: '') + .contains(searchKey.value)) + .toList()); return newList; } } diff --git a/lib/screens/sale_quotation/sale_quotation.dart b/lib/screens/sale_quotation/sale_quotation.dart index da3a4ee..cf0e97d 100644 --- a/lib/screens/sale_quotation/sale_quotation.dart +++ b/lib/screens/sale_quotation/sale_quotation.dart @@ -128,7 +128,7 @@ class SaleQuotationPage extends StatelessWidget { )); } - Widget buildBody(SaleQuotationModel group, int index) { + Widget buildBody(SaleQuotationModel group, int groupIndex) { final titleStyle = TextStyle( fontSize: ScreenAdaper.height(30), color: AppTheme.nearlyBlack, @@ -143,16 +143,17 @@ class SaleQuotationPage extends StatelessWidget { alignment: Alignment.centerLeft, child: InkWell( onTap: () { - controller.groups[index].isExpanded.value = - !controller.groups[index].isExpanded.value; + controller.groups[groupIndex].isExpanded.value = + !controller.groups[groupIndex].isExpanded.value; }, child: Row( children: [ - Obx(() => controller.groups[index].isExpanded.value + Obx(() => controller.groups[groupIndex].isExpanded.value ? IconButton( padding: EdgeInsets.zero, onPressed: () { - controller.groups[index].isExpanded.value = false; + controller.groups[groupIndex].isExpanded.value = + false; }, icon: const Icon( Icons.expand_more, @@ -162,7 +163,8 @@ class SaleQuotationPage extends StatelessWidget { : IconButton( padding: EdgeInsets.zero, onPressed: () { - controller.groups[index].isExpanded.value = true; + controller.groups[groupIndex].isExpanded.value = + true; }, icon: const Icon( Icons.chevron_right, @@ -179,7 +181,7 @@ class SaleQuotationPage extends StatelessWidget { ModalUtil.confirm( title: '确定要删除此组吗?', onConfirm: () { - controller.removeGroup(index); + controller.removeGroup(groupIndex); }); }, icon: const Icon( @@ -188,7 +190,7 @@ class SaleQuotationPage extends StatelessWidget { )), IconButton( onPressed: () { - controller.addItems(); + controller.addItems(groupIndex); }, icon: const Icon( Icons.add_circle_outline, @@ -196,7 +198,7 @@ class SaleQuotationPage extends StatelessWidget { )), ], ))), - sliver: Obx(() => !controller.groups[index].isExpanded.value + sliver: Obx(() => !controller.groups[groupIndex].isExpanded.value ? SliverList( delegate: SliverChildBuilderDelegate( (context, i) => SizedBox(), @@ -212,11 +214,13 @@ class SaleQuotationPage extends StatelessWidget { children: [ SlidableAction( padding: EdgeInsets.zero, - onPressed: (_) {}, + onPressed: (_) { + controller.groups[groupIndex].items.removeAt(i); + }, backgroundColor: AppTheme.dangerColor, foregroundColor: Colors.white, icon: Icons.delete, - label: 'Delete', + label: '删除', ), ], ), @@ -304,51 +308,53 @@ class SaleQuotationPage extends StatelessWidget { alignment: Alignment.center, width: quantityWidth, child: Text( - '${controller.groups[index].items[i].quantity}', + '${controller.groups[groupIndex].items[i].quantity}', style: TextStyle( fontSize: ScreenAdaper.height(25)), ), ), - groupIndex: index, + groupIndex: groupIndex, rowIndex: i, field: 'quantity', inputWidth: quantityWidth, - value: controller.groups[index].items[i].quantity), + value: controller + .groups[groupIndex].items[i].quantity), buildEditCell( Container( alignment: Alignment.center, width: unitPriceWidth, child: Text( - '${controller.groups[index].items[i].cost}', + '${controller.groups[groupIndex].items[i].cost}', style: TextStyle( fontSize: ScreenAdaper.height(25)), ), ), - groupIndex: index, + groupIndex: groupIndex, rowIndex: i, field: 'cost', inputWidth: unitPriceWidth, - value: controller.groups[index].items[i].cost), + value: controller.groups[groupIndex].items[i].cost), buildEditCell( Container( alignment: Alignment.center, width: amountWidth, child: Text( - '${controller.groups[index].items[i].amount}', + '${controller.groups[groupIndex].items[i].amount}', style: TextStyle( fontSize: ScreenAdaper.height(25)), ), ), - groupIndex: index, + groupIndex: groupIndex, rowIndex: i, field: 'amount', inputWidth: amountWidth, - value: controller.groups[index].items[i].amount), + value: + controller.groups[groupIndex].items[i].amount), ], ), ), ), - childCount: !controller.groups[index].isExpanded.value + childCount: !controller.groups[groupIndex].isExpanded.value ? 0 : group.items.length, ), diff --git a/lib/widgets/core/sk_number_input.dart b/lib/widgets/core/sk_number_input.dart index 2cd7c8e..f37daad 100644 --- a/lib/widgets/core/sk_number_input.dart +++ b/lib/widgets/core/sk_number_input.dart @@ -48,7 +48,7 @@ class _SkNumberInputState extends State { return TextFormField( focusNode: focusNode, onTap: () { - if (widget.onTap == null) { + if (widget.onTap != null) { widget.onTap!(focusNode); } }, diff --git a/lib/widgets/core/sk_single_search_more.dart b/lib/widgets/core/sk_single_search_more.dart index 2a7e059..49976bd 100644 --- a/lib/widgets/core/sk_single_search_more.dart +++ b/lib/widgets/core/sk_single_search_more.dart @@ -37,25 +37,9 @@ class SkSingleSearchMore extends StatelessWidget { vertical: ScreenAdaper.height(20)), child: Column( children: [ - Container( - height: ScreenAdaper.height(60), - padding: EdgeInsets.only(bottom: ScreenAdaper.height(15)), - child: Stack( - children: [ - Center( - child: Text( - '请选择', - style: TextStyle( - fontSize: ScreenAdaper.height(30), - fontWeight: FontWeight.w600), - ), - ), - Positioned( - right: 0, - child: - GestureDetector(onTap: () {}, child: Icon(Icons.close))) - ], - ), + buildDialogHeader(), + SizedBox( + height: ScreenAdaper.height(defaultPadding) / 2, ), buildSearchBar(), SizedBox( @@ -67,6 +51,34 @@ class SkSingleSearchMore extends StatelessWidget { ); } + Widget buildDialogHeader() { + return Container( + height: ScreenAdaper.height(60), + child: Stack( + children: [ + Center( + child: Text( + '请选择', + style: TextStyle( + fontSize: ScreenAdaper.height(30), + fontWeight: FontWeight.w600), + ), + ), + Positioned( + right: 0, + child: GestureDetector( + onTap: () { + Get.back(); + }, + child: Icon( + Icons.close, + size: ScreenAdaper.height(40), + ))) + ], + ), + ); + } + Widget buildSearchBar() { final doSearch = debouncer((String value) { controller.searchKey.value = value; diff --git a/pubspec.lock b/pubspec.lock index e413b1d..4824d3a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -736,6 +736,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.14.0" + pinyin: + dependency: "direct main" + description: + name: pinyin + sha256: "509a51abec754d8b69cc94074b2bdb9f4a407bc4daf5723ec6d995b7682a048a" + url: "https://pub.dev" + source: hosted + version: "3.2.0" platform: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 06ce37c..6dab595 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -64,6 +64,7 @@ dependencies: flutter_svg: ^2.0.10+1 flutter_sticky_header: ^0.6.5 flutter_slidable: ^3.1.0 + pinyin: ^3.2.0 dev_dependencies: flutter_test: sdk: flutter