From 5ce8e595b059296a0a3846178a744701266c05d2 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Fri, 9 May 2025 15:11:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=8F=9C=E5=93=81=E6=8E=92=E5=88=97?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../database/dao/canteen_spu_dao.dart | 2 +- lib/common/services/database/database.g.dart | 2 +- lib/common/utils/sync/sync_product_tool.dart | 4 +- lib/pages/canteen_product/view.dart | 42 +++++++++++++++++-- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/lib/common/services/database/dao/canteen_spu_dao.dart b/lib/common/services/database/dao/canteen_spu_dao.dart index a790cf1..5ae5062 100644 --- a/lib/common/services/database/dao/canteen_spu_dao.dart +++ b/lib/common/services/database/dao/canteen_spu_dao.dart @@ -62,7 +62,7 @@ abstract class CanteenSpuDao { (:classifyServiceUniqueCode = '-1' OR canteen_spu.classifyServiceUniqueCode = :classifyServiceUniqueCode) AND (:hourType = '-1' OR INSTR(',' || hourType || ',', ',' || :hourType || ',') > 0) AND (:saleDate = '-1' OR strftime('%Y-%m-%d', saleDate) = strftime('%Y-%m-%d', :saleDate)) - ORDER BY classify.sort, canteen_spu.price + ORDER BY classify.sort,canteen_spu.sort desc,canteen_spu.price ''') Future> getAll( String classifyServiceUniqueCode, diff --git a/lib/common/services/database/database.g.dart b/lib/common/services/database/database.g.dart index 9906865..9d14e56 100644 --- a/lib/common/services/database/database.g.dart +++ b/lib/common/services/database/database.g.dart @@ -715,7 +715,7 @@ class _$CanteenSpuDao extends CanteenSpuDao { String saleDate, ) async { return _queryAdapter.queryList( - 'SELECT canteen_spu.* FROM canteen_spu LEFT JOIN classify ON canteen_spu.classifyServiceUniqueCode = classify.serviceUniqueCode AND classify.delFlag = 0 WHERE (?1 = \'-1\' OR canteen_spu.classifyServiceUniqueCode = ?1) AND (?2 = \'-1\' OR INSTR(\',\' || hourType || \',\', \',\' || ?2 || \',\') > 0) AND (?3 = \'-1\' OR strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', ?3)) ORDER BY classify.sort, canteen_spu.price', + 'SELECT canteen_spu.* FROM canteen_spu LEFT JOIN classify ON canteen_spu.classifyServiceUniqueCode = classify.serviceUniqueCode AND classify.delFlag = 0 WHERE (?1 = \'-1\' OR canteen_spu.classifyServiceUniqueCode = ?1) AND (?2 = \'-1\' OR INSTR(\',\' || hourType || \',\', \',\' || ?2 || \',\') > 0) AND (?3 = \'-1\' OR strftime(\'%Y-%m-%d\', saleDate) = strftime(\'%Y-%m-%d\', ?3)) ORDER BY classify.sort,canteen_spu.sort desc,canteen_spu.price', mapper: (Map row) => CanteenSpuEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, hourType: row['hourType'] == null ? null : ProductHourType.values[row['hourType'] as int], saleDate: _dateTimeConverter.decode(row['saleDate'] as String), name: row['name'] as String, price: row['price'] as int, image: row['image'] as String?, isDefault: _boolConverter.decode(row['isDefault'] as int), status: row['status'] as int, sort: row['sort'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String), updateTime: _dateTimeConverter.decode(row['updateTime'] as String)), arguments: [classifyServiceUniqueCode, hourType, saleDate]); } diff --git a/lib/common/utils/sync/sync_product_tool.dart b/lib/common/utils/sync/sync_product_tool.dart index fb0b834..f15a12d 100644 --- a/lib/common/utils/sync/sync_product_tool.dart +++ b/lib/common/utils/sync/sync_product_tool.dart @@ -133,7 +133,7 @@ abstract class SyncProductTool { sysType: sysType, name: v.name!, categoryType: v.categoryType ?? "-1", - sort: v.sort ?? 999, + sort: v.sort ?? 0, createTime: DateTime.now(), updateTime: DateTime.now(), delFlag: false, @@ -281,7 +281,7 @@ abstract class SyncProductTool { price: v.price ?? 0, image: v.picUrl, status: 1, - sort: v.sort ?? 999, + sort: v.sort ?? 0, createTime: DateTime.now(), updateTime: DateTime.now(), hourType: ProductHourType.values.fromCode(v.hourType), diff --git a/lib/pages/canteen_product/view.dart b/lib/pages/canteen_product/view.dart index 79fda21..f6d346e 100644 --- a/lib/pages/canteen_product/view.dart +++ b/lib/pages/canteen_product/view.dart @@ -45,8 +45,8 @@ class CanteenProductPage extends GetView { ); } - // 商品 - Widget _buildProduct() { + // 商品(带标题) + Widget _buildTitleProduct() { return LayoutBuilder( builder: (BuildContext _, BoxConstraints constraints) { const spacing = 10; @@ -87,6 +87,42 @@ class CanteenProductPage extends GetView { ); } + Widget _buildSortProduct() { + return LayoutBuilder( + builder: (BuildContext _, BoxConstraints constraints) { + const spacing = 10; + const runSpacing = 10; + double maxHeight = constraints.maxHeight; + double maxWidth = constraints.maxWidth; + double itemWidth = (maxWidth - spacing * 6) / 7; + double itemHeight = (maxHeight - (runSpacing + 30) * 3) / 3; + return Obx( + () => GridView.builder( + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 7, + mainAxisSpacing: 10.w, + crossAxisSpacing: 10.w, + childAspectRatio: 0.8, + ), + itemCount: controller.canteenSpuList.length, + itemBuilder: (context, index) { + final product = controller.canteenSpuList[index]; + return orderCaneenSpuCard( + context, + image: product.image, + name: product.name, + price: product.price, + ) + .width(itemWidth) + .height(itemHeight) + .onTap(() => controller.doProduct(product)); + }, + ), + ); + }, + ); + } + /// 商品项 Widget _buildProductItem( BuildContext context, { @@ -224,7 +260,7 @@ class CanteenProductPage extends GetView { final theme = FTheme.of(context); return [ SizedBox(width: 15.w), - _buildProduct().expanded(), + _buildSortProduct().expanded(), SizedBox(width: 15.w), _buildUser().width(width * 0.25).decorated( border: Border.all(