From e1340ead5f424e660a9c8262ff193ed59b103bf1 Mon Sep 17 00:00:00 2001 From: louis <869322496@qq.com> Date: Tue, 26 Mar 2024 17:10:14 +0800 Subject: [PATCH] feat: inventory loading --- .../components/inventory_search.dart | 214 +++++++++--------- lib/services/dio.service.dart | 1 + lib/widgets/empty.dart | 2 +- 3 files changed, 112 insertions(+), 105 deletions(-) diff --git a/lib/screens/new_inventory_inout/components/inventory_search.dart b/lib/screens/new_inventory_inout/components/inventory_search.dart index 413091b..abe5fea 100644 --- a/lib/screens/new_inventory_inout/components/inventory_search.dart +++ b/lib/screens/new_inventory_inout/components/inventory_search.dart @@ -10,6 +10,7 @@ import 'package:sk_base_mobile/models/index.dart'; import 'package:sk_base_mobile/models/inventory.model.dart'; import 'package:sk_base_mobile/util/debouncer.dart'; import 'package:sk_base_mobile/util/screen_adaper_util.dart'; +import 'package:sk_base_mobile/widgets/empty.dart'; class InventorySearch extends StatelessWidget { Function(InventoryModel)? onInventorySelected; @@ -103,7 +104,7 @@ class InventorySearch extends StatelessWidget { ], onChanged: (value) { controller.hasInventoryStatus.value = value!; - controller.onRefresh(); + controller.refreshController.requestRefresh(); }, decoration: InputDecoration( contentPadding: EdgeInsets.symmetric( @@ -124,112 +125,117 @@ class InventorySearch extends StatelessWidget { controller: controller.refreshController, onLoading: controller.onLoading, onRefresh: controller.onRefresh, - child: Table(columnWidths: { - 0: FixedColumnWidth(100), - 1: FlexColumnWidth(2), - 2: MinColumnWidth(FixedColumnWidth(200), FixedColumnWidth(200)), - 3: MinColumnWidth(FixedColumnWidth(100), FixedColumnWidth(100)), - 4: MinColumnWidth(FixedColumnWidth(80), FixedColumnWidth(80)), - }, children: [ - // table header - TableRow( - decoration: 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, + child: controller.inventories.isEmpty + ? Center( + child: Empty(text: '暂无库存'), + ) + : Table(columnWidths: { + 0: FixedColumnWidth(100), + 1: FlexColumnWidth(2), + 2: MinColumnWidth(FixedColumnWidth(200), FixedColumnWidth(200)), + 3: MinColumnWidth(FixedColumnWidth(100), FixedColumnWidth(100)), + 4: MinColumnWidth(FixedColumnWidth(80), FixedColumnWidth(80)), + }, children: [ + // table header + TableRow( + decoration: 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: BoxDecoration( - border: Border( - bottom: BorderSide(color: AppTheme.dividerColor))), - children: [ - buildTableCell( - Text( - itemData.inventoryNumber!, - style: textStyle, + TableCell( + verticalAlignment: TableCellVerticalAlignment.middle, + child: Text( + '单价', + style: listTitleTextStyle, + ), ), - 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.sp(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 ?? ''}', + TableCell( + verticalAlignment: TableCellVerticalAlignment.middle, + child: Text( + '数量', textAlign: TextAlign.right, - style: textStyle), - itemData: itemData, - alignment: Alignment.centerRight), - ]); - }).toList() - ]))); + style: listTitleTextStyle, + ), + ), + ]), + ...controller.inventories.map((itemData) { + return TableRow( + decoration: BoxDecoration( + border: Border( + bottom: + BorderSide(color: AppTheme.dividerColor))), + children: [ + buildTableCell( + Text( + itemData.inventoryNumber!, + 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.sp(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), + ]); + }).toList() + ]))); } Widget buildInventoryList1() { diff --git a/lib/services/dio.service.dart b/lib/services/dio.service.dart index bcd0db7..7126600 100644 --- a/lib/services/dio.service.dart +++ b/lib/services/dio.service.dart @@ -137,6 +137,7 @@ class DioService extends Get.GetxService { response.data = response.data['data']; // 分页数据处理 if (response.data != null && + response.data is Map && response.data['meta'] != null && response.data['items'] != null) { response.data = PaginationData.fromJson(response.data); diff --git a/lib/widgets/empty.dart b/lib/widgets/empty.dart index a159054..00d1848 100644 --- a/lib/widgets/empty.dart +++ b/lib/widgets/empty.dart @@ -17,7 +17,7 @@ class Empty extends StatelessWidget { Text( text ?? '', textAlign: TextAlign.center, - style: TextStyle(fontSize: ScreenAdaper.sp(18)), + style: TextStyle(fontSize: ScreenAdaper.sp(30)), ), ]), );