diff --git a/lib/common/api/product_api.dart b/lib/common/api/product_api.dart index 0da0bce..ff483db 100644 --- a/lib/common/api/product_api.dart +++ b/lib/common/api/product_api.dart @@ -43,15 +43,25 @@ abstract class ProductApi { .toList(); } - /// 超市商品 - static Future?> supermarketProduct(dynamic pa) async { - final res = await HttpManage().dio.get( + /// 超市 spu + static Future?> supermarketSpu( + dynamic pa) async { + final res = await HttpManage().dio.post( "supermarket/supermarketSpu/ad/selectListAll", queryParameters: pa, ); if (res.data == null) return null; - return res.data - ?.map((e) => ServiceProduct.fromJson(e)) - .toList(); + return res.data?.map((e) => ServiceSupermarketSpuPage.fromJson(e)).toList(); + } + + /// 超市 spu 详情 + static Future?> supermarketSupDetial( + dynamic pa) async { + final res = await HttpManage().dio.get( + "supermarket/supermarketSpu/ad/SpuDetails", + queryParameters: pa, + ); + if (res.data == null) return null; + return res.data?.map((e) => ServiceSupermarketSkuPage.fromJson(e)).toList(); } } diff --git a/lib/common/models/api/product_api_models.dart b/lib/common/models/api/product_api_models.dart index 518b8e7..0185656 100644 --- a/lib/common/models/api/product_api_models.dart +++ b/lib/common/models/api/product_api_models.dart @@ -92,3 +92,251 @@ class ServiceProduct { Map toJson() => _$ServiceProductToJson(this); } + +// ************************************************************************** +// 超市 spu start +// ************************************************************************** +@JsonSerializable() +class ServiceSupermarketSpu { + /// id + String? id; + + /// 货号 + String? productCode; + + /// 商品名称 + String? productName; + + /// 单位 + String? unit; + + /// 规格 + String? spec; + + /// 商品分类编号 + String? categoryId; + + /// 商品封面图 + String? picUrl; + + /// 剩余库存 + String? stock; + + /// 商品性质(字典) + String? productNature; + + /// 零售价 + String? retailPrice; + + /// 促销价 + int? promotionPrice; + + /// 销量 + int? salesCount; + + ServiceSupermarketSpu({ + this.id, + this.productCode, + this.productName, + this.unit, + this.spec, + this.categoryId, + this.picUrl, + this.stock, + this.productNature, + this.retailPrice, + this.promotionPrice, + this.salesCount, + }); + + factory ServiceSupermarketSpu.fromJson(Map json) => + _$ServiceSupermarketSpuFromJson(json); + + Map toJson() => _$ServiceSupermarketSpuToJson(this); +} + +@JsonSerializable() +class ServiceSupermarketSpuPage extends ServicePageBase { + List? records; + + ServiceSupermarketSpuPage({ + this.records, + }); + + factory ServiceSupermarketSpuPage.fromJson(Map json) => + _$ServiceSupermarketSpuPageFromJson(json); + + Map toJson() => _$ServiceSupermarketSpuPageToJson(this); +} + +// ************************************************************************** +// 超市 spu end +// ************************************************************************** + +// ************************************************************************** +// 超市 sku start +// ************************************************************************** +@JsonSerializable() +class ServiceSupermarketSku { + /// 商品 SPU 编号,自增 + String? id; + + /// 货号 + String? productCode; + + /// 商品名称 + String? productName; + + /// 商品分类编号 + String? categoryId; + + /// 商品封面图 + String? picUrl; + + /// 剩余库存 + double? stock; + + /// 商户编号 + String? merchantId; + + /// 产地 + String? origin; + + /// 商品性质(字典) + String? productNature; + + /// 品牌id + String? brandId; + + /// 货商id + String? supplierId; + + /// 销量 + int? salesCount; + + /// 辅助条码集合 + List? supermarketAuxiliaryCodeEntityList; + + /// 包装对象集合 + List? supermarketUnitEntityList; + + ServiceSupermarketSku({ + this.id, + this.productCode, + this.productName, + this.categoryId, + this.picUrl, + this.stock, + this.merchantId, + this.origin, + this.productNature, + this.brandId, + this.supplierId, + this.salesCount, + this.supermarketAuxiliaryCodeEntityList, + this.supermarketUnitEntityList, + }); + + factory ServiceSupermarketSku.fromJson(Map json) => + _$ServiceSupermarketSkuFromJson(json); + + Map toJson() => _$ServiceSupermarketSkuToJson(this); +} + +// 辅助条码 +@JsonSerializable() +class ServiceSupermarketSkuCode { + /// 辅助条码id + String? id; + + /// spu Id + String? spuId; + + /// 包装单位id + String? unitId; + + /// 条码 + String? barCode; + + ServiceSupermarketSkuCode({ + this.id, + this.spuId, + this.unitId, + this.barCode, + }); + + factory ServiceSupermarketSkuCode.fromJson(Map json) => + _$ServiceSupermarketSkuCodeFromJson(json); + + Map toJson() => _$ServiceSupermarketSkuCodeToJson(this); +} + +// 包装单位 +@JsonSerializable() +class ServiceSupermarketSkuPackage { + /// 包装单位id + String? id; + + /// spu id + String? spuId; + + /// 条码 + String? barCode; + + /// 规格 + String? spec; + + /// 单位 + String? unit; + + /// 状态(0正常,1停销) + int? status; + + /// 内装数量 + int? packageNum; + + /// 进价/单位分 + int? purchasePrice; + + /// 零售价/单位分 + int? retailPrice; + + /// 促销价 + int? promotionPrice; + + ServiceSupermarketSkuPackage({ + this.id, + this.spuId, + this.barCode, + this.spec, + this.unit, + this.status, + this.packageNum, + this.purchasePrice, + this.retailPrice, + this.promotionPrice, + }); + + factory ServiceSupermarketSkuPackage.fromJson(Map json) => + _$ServiceSupermarketSkuPackageFromJson(json); + + Map toJson() => _$ServiceSupermarketSkuPackageToJson(this); +} + +@JsonSerializable() +class ServiceSupermarketSkuPage extends ServicePageBase { + List? records; + + ServiceSupermarketSkuPage({ + this.records, + }); + + factory ServiceSupermarketSkuPage.fromJson(Map json) => + _$ServiceSupermarketSkuPageFromJson(json); + + Map toJson() => _$ServiceSupermarketSkuPageToJson(this); +} + +// ************************************************************************** +// 超市 sku end +// ************************************************************************** diff --git a/lib/common/models/api/product_api_models.g.dart b/lib/common/models/api/product_api_models.g.dart index fcfd933..e14fd57 100644 --- a/lib/common/models/api/product_api_models.g.dart +++ b/lib/common/models/api/product_api_models.g.dart @@ -56,3 +56,178 @@ Map _$ServiceProductToJson(ServiceProduct instance) => 'categoryType': instance.categoryType, 'saleDate': instance.saleDate?.toIso8601String(), }; + +ServiceSupermarketSpu _$ServiceSupermarketSpuFromJson( + Map json) => + ServiceSupermarketSpu( + id: json['id'] as String?, + productCode: json['productCode'] as String?, + productName: json['productName'] as String?, + unit: json['unit'] as String?, + spec: json['spec'] as String?, + categoryId: json['categoryId'] as String?, + picUrl: json['picUrl'] as String?, + stock: json['stock'] as String?, + productNature: json['productNature'] as String?, + retailPrice: json['retailPrice'] as String?, + promotionPrice: (json['promotionPrice'] as num?)?.toInt(), + salesCount: (json['salesCount'] as num?)?.toInt(), + ); + +Map _$ServiceSupermarketSpuToJson( + ServiceSupermarketSpu instance) => + { + 'id': instance.id, + 'productCode': instance.productCode, + 'productName': instance.productName, + 'unit': instance.unit, + 'spec': instance.spec, + 'categoryId': instance.categoryId, + 'picUrl': instance.picUrl, + 'stock': instance.stock, + 'productNature': instance.productNature, + 'retailPrice': instance.retailPrice, + 'promotionPrice': instance.promotionPrice, + 'salesCount': instance.salesCount, + }; + +ServiceSupermarketSpuPage _$ServiceSupermarketSpuPageFromJson( + Map json) => + ServiceSupermarketSpuPage( + records: (json['records'] as List?) + ?.map( + (e) => ServiceSupermarketSpu.fromJson(e as Map)) + .toList(), + ) + ..current = (json['current'] as num).toInt() + ..pages = (json['pages'] as num).toInt() + ..size = (json['size'] as num).toInt() + ..total = (json['total'] as num).toInt(); + +Map _$ServiceSupermarketSpuPageToJson( + ServiceSupermarketSpuPage instance) => + { + 'current': instance.current, + 'pages': instance.pages, + 'size': instance.size, + 'total': instance.total, + 'records': instance.records, + }; + +ServiceSupermarketSku _$ServiceSupermarketSkuFromJson( + Map json) => + ServiceSupermarketSku( + id: json['id'] as String?, + productCode: json['productCode'] as String?, + productName: json['productName'] as String?, + categoryId: json['categoryId'] as String?, + picUrl: json['picUrl'] as String?, + stock: (json['stock'] as num?)?.toDouble(), + merchantId: json['merchantId'] as String?, + origin: json['origin'] as String?, + productNature: json['productNature'] as String?, + brandId: json['brandId'] as String?, + supplierId: json['supplierId'] as String?, + salesCount: (json['salesCount'] as num?)?.toInt(), + supermarketAuxiliaryCodeEntityList: + (json['supermarketAuxiliaryCodeEntityList'] as List?) + ?.map((e) => + ServiceSupermarketSkuCode.fromJson(e as Map)) + .toList(), + supermarketUnitEntityList: (json['supermarketUnitEntityList'] + as List?) + ?.map((e) => + ServiceSupermarketSkuPackage.fromJson(e as Map)) + .toList(), + ); + +Map _$ServiceSupermarketSkuToJson( + ServiceSupermarketSku instance) => + { + 'id': instance.id, + 'productCode': instance.productCode, + 'productName': instance.productName, + 'categoryId': instance.categoryId, + 'picUrl': instance.picUrl, + 'stock': instance.stock, + 'merchantId': instance.merchantId, + 'origin': instance.origin, + 'productNature': instance.productNature, + 'brandId': instance.brandId, + 'supplierId': instance.supplierId, + 'salesCount': instance.salesCount, + 'supermarketAuxiliaryCodeEntityList': + instance.supermarketAuxiliaryCodeEntityList, + 'supermarketUnitEntityList': instance.supermarketUnitEntityList, + }; + +ServiceSupermarketSkuCode _$ServiceSupermarketSkuCodeFromJson( + Map json) => + ServiceSupermarketSkuCode( + id: json['id'] as String?, + spuId: json['spuId'] as String?, + unitId: json['unitId'] as String?, + barCode: json['barCode'] as String?, + ); + +Map _$ServiceSupermarketSkuCodeToJson( + ServiceSupermarketSkuCode instance) => + { + 'id': instance.id, + 'spuId': instance.spuId, + 'unitId': instance.unitId, + 'barCode': instance.barCode, + }; + +ServiceSupermarketSkuPackage _$ServiceSupermarketSkuPackageFromJson( + Map json) => + ServiceSupermarketSkuPackage( + id: json['id'] as String?, + spuId: json['spuId'] as String?, + barCode: json['barCode'] as String?, + spec: json['spec'] as String?, + unit: json['unit'] as String?, + status: (json['status'] as num?)?.toInt(), + packageNum: (json['packageNum'] as num?)?.toInt(), + purchasePrice: (json['purchasePrice'] as num?)?.toInt(), + retailPrice: (json['retailPrice'] as num?)?.toInt(), + promotionPrice: (json['promotionPrice'] as num?)?.toInt(), + ); + +Map _$ServiceSupermarketSkuPackageToJson( + ServiceSupermarketSkuPackage instance) => + { + 'id': instance.id, + 'spuId': instance.spuId, + 'barCode': instance.barCode, + 'spec': instance.spec, + 'unit': instance.unit, + 'status': instance.status, + 'packageNum': instance.packageNum, + 'purchasePrice': instance.purchasePrice, + 'retailPrice': instance.retailPrice, + 'promotionPrice': instance.promotionPrice, + }; + +ServiceSupermarketSkuPage _$ServiceSupermarketSkuPageFromJson( + Map json) => + ServiceSupermarketSkuPage( + records: (json['records'] as List?) + ?.map( + (e) => ServiceSupermarketSku.fromJson(e as Map)) + .toList(), + ) + ..current = (json['current'] as num).toInt() + ..pages = (json['pages'] as num).toInt() + ..size = (json['size'] as num).toInt() + ..total = (json['total'] as num).toInt(); + +Map _$ServiceSupermarketSkuPageToJson( + ServiceSupermarketSkuPage instance) => + { + 'current': instance.current, + 'pages': instance.pages, + 'size': instance.size, + 'total': instance.total, + 'records': instance.records, + }; diff --git a/lib/common/services/database/dao/supermarket_spu_dao.dart b/lib/common/services/database/dao/supermarket_spu_dao.dart index 7369027..26efb8c 100644 --- a/lib/common/services/database/dao/supermarket_spu_dao.dart +++ b/lib/common/services/database/dao/supermarket_spu_dao.dart @@ -15,4 +15,27 @@ abstract class SupermarketSpuDao { ORDER BY classify.sort, supermarket_spu.price ''') Future> getAll(String classifyServiceUniqueCode); + + @Query(""" + SELECT DISTINCT COUNT(0) FROM canteen_spu + WHERE + delFlag = 0 + """) + Future getCount(); + + @Query(''' + SELECT supermarket_spu.* + FROM supermarket_spu + LEFT JOIN classify ON supermarket_spu.classifyServiceUniqueCode = classify.serviceUniqueCode + WHERE + supermarket_spu.delFlag = 0 + AND (:classifyServiceUniqueCode = '-1' OR supermarket_spu.classifyServiceUniqueCode = :classifyServiceUniqueCode) + ORDER BY classify.sort, supermarket_spu.price + LIMIT :pageSize OFFSET :offset + ''') + Future> getAllPage( + String classifyServiceUniqueCode, + int pageSize, + int offset, + ); } diff --git a/lib/common/services/database/database.g.dart b/lib/common/services/database/database.g.dart index 836ebf6..294e38f 100644 --- a/lib/common/services/database/database.g.dart +++ b/lib/common/services/database/database.g.dart @@ -120,7 +120,7 @@ class _$AppDatabase extends AppDatabase { await database.execute( 'CREATE TABLE IF NOT EXISTS `supermarket_sku` (`id` INTEGER PRIMARY KEY AUTOINCREMENT)'); await database.execute( - 'CREATE TABLE IF NOT EXISTS `supermarket_spu` (`id` INTEGER PRIMARY KEY AUTOINCREMENT)'); + 'CREATE TABLE IF NOT EXISTS `supermarket_spu` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `serviceUniqueCode` TEXT NOT NULL, `classifyServiceUniqueCode` TEXT NOT NULL, `price` INTEGER NOT NULL, `sort` INTEGER NOT NULL, `createTime` TEXT NOT NULL, `updateTime` TEXT NOT NULL, `delFlag` INTEGER NOT NULL)'); await database.execute( 'CREATE TABLE IF NOT EXISTS `shop_card` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `orderId` INTEGER NOT NULL, `productServiceUniqueCode` TEXT NOT NULL, `productName` TEXT NOT NULL, `productPic` TEXT NOT NULL, `productPrice` INTEGER NOT NULL, `productNumber` INTEGER NOT NULL, `productWidget` REAL NOT NULL, `totalPrice` INTEGER NOT NULL)'); await database.execute( @@ -652,9 +652,28 @@ class _$SupermarketSpuDao extends SupermarketSpuDao { String classifyServiceUniqueCode) async { return _queryAdapter.queryList( 'SELECT supermarket_spu.* FROM supermarket_spu LEFT JOIN classify ON supermarket_spu.classifyServiceUniqueCode = classify.serviceUniqueCode WHERE supermarket_spu.delFlag = 0 AND (?1 = \'-1\' OR supermarket_spu.classifyServiceUniqueCode = ?1) ORDER BY classify.sort, supermarket_spu.price', - mapper: (Map row) => SupermarketSpuEntity(id: row['id'] as int?), + mapper: (Map row) => SupermarketSpuEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, price: row['price'] as int, sort: row['sort'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String), updateTime: _dateTimeConverter.decode(row['updateTime'] as String), delFlag: _boolConverter.decode(row['delFlag'] as int)), arguments: [classifyServiceUniqueCode]); } + + @override + Future getCount() async { + return _queryAdapter.query( + 'SELECT DISTINCT COUNT(0) FROM canteen_spu WHERE delFlag = 0', + mapper: (Map row) => row.values.first as int); + } + + @override + Future> getAllPage( + String classifyServiceUniqueCode, + int pageSize, + int offset, + ) async { + return _queryAdapter.queryList( + 'SELECT supermarket_spu.* FROM supermarket_spu LEFT JOIN classify ON supermarket_spu.classifyServiceUniqueCode = classify.serviceUniqueCode WHERE supermarket_spu.delFlag = 0 AND (?1 = \'-1\' OR supermarket_spu.classifyServiceUniqueCode = ?1) ORDER BY classify.sort, supermarket_spu.price LIMIT ?2 OFFSET ?3', + mapper: (Map row) => SupermarketSpuEntity(id: row['id'] as int?, serviceUniqueCode: row['serviceUniqueCode'] as String, classifyServiceUniqueCode: row['classifyServiceUniqueCode'] as String, price: row['price'] as int, sort: row['sort'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String), updateTime: _dateTimeConverter.decode(row['updateTime'] as String), delFlag: _boolConverter.decode(row['delFlag'] as int)), + arguments: [classifyServiceUniqueCode, pageSize, offset]); + } } class _$ShopCardDao extends ShopCardDao { diff --git a/lib/common/services/database/entity/supermarket_spu_entity.dart b/lib/common/services/database/entity/supermarket_spu_entity.dart index 662cb9e..6850bda 100644 --- a/lib/common/services/database/entity/supermarket_spu_entity.dart +++ b/lib/common/services/database/entity/supermarket_spu_entity.dart @@ -10,8 +10,36 @@ class SupermarketSpuEntity { @PrimaryKey(autoGenerate: true) int? id; + /// 服务端唯一标识 + String serviceUniqueCode; + + /// 分类 serviceID + String classifyServiceUniqueCode; + + /// 商品价格(分) + int price; + + /// 排序 倒序排列 + int sort; + + /// 创建时间 + DateTime createTime; + + /// 同步时间 + DateTime updateTime; + + /// 是否删除 + bool delFlag; + SupermarketSpuEntity({ this.id, + required this.serviceUniqueCode, + required this.classifyServiceUniqueCode, + required this.price, + required this.sort, + required this.createTime, + required this.updateTime, + required this.delFlag, }); factory SupermarketSpuEntity.fromJson(Map json) => diff --git a/lib/common/services/database/entity/supermarket_spu_entity.g.dart b/lib/common/services/database/entity/supermarket_spu_entity.g.dart index ad3329e..5e414d1 100644 --- a/lib/common/services/database/entity/supermarket_spu_entity.g.dart +++ b/lib/common/services/database/entity/supermarket_spu_entity.g.dart @@ -10,10 +10,24 @@ SupermarketSpuEntity _$SupermarketSpuEntityFromJson( Map json) => SupermarketSpuEntity( id: (json['id'] as num?)?.toInt(), + serviceUniqueCode: json['serviceUniqueCode'] as String, + classifyServiceUniqueCode: json['classifyServiceUniqueCode'] as String, + price: (json['price'] as num).toInt(), + sort: (json['sort'] as num).toInt(), + createTime: DateTime.parse(json['createTime'] as String), + updateTime: DateTime.parse(json['updateTime'] as String), + delFlag: json['delFlag'] as bool, ); Map _$SupermarketSpuEntityToJson( SupermarketSpuEntity instance) => { 'id': instance.id, + 'serviceUniqueCode': instance.serviceUniqueCode, + 'classifyServiceUniqueCode': instance.classifyServiceUniqueCode, + 'price': instance.price, + 'sort': instance.sort, + 'createTime': instance.createTime.toIso8601String(), + 'updateTime': instance.updateTime.toIso8601String(), + 'delFlag': instance.delFlag, }; diff --git a/lib/common/utils/app/app_setting_tool.dart b/lib/common/utils/app/app_setting_tool.dart index 3c7992d..a1ab8b9 100644 --- a/lib/common/utils/app/app_setting_tool.dart +++ b/lib/common/utils/app/app_setting_tool.dart @@ -1,14 +1,33 @@ import 'dart:convert'; +import 'dart:typed_data'; import 'package:common_utils/common_utils.dart'; import 'package:get/get.dart'; +import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:pj_supermarket_cloud/common/index.dart'; abstract class AppSettingTool { static const String _tag = "app配置工具"; + static const String _settingKey = "setting"; + + // 自定义缓存管理器 + static final CacheManager _settingCache = CacheManager( + Config( + 'setting_cache', + stalePeriod: const Duration(days: 7), + maxNrOfCacheObjects: 10, + ), + ); + static Future _getSetting() async { + // 尝试从缓存获取 + final fileInfo = await _settingCache.getFileFromCache(_settingKey); + if (fileInfo != null) { + final content = await fileInfo.file.readAsString(); + return SettingEntity.fromJson(json.decode(content)); + } final app = Get.find(); final settingDao = app.dataBase.getSettingDao; final setting = await settingDao.get(); @@ -64,9 +83,12 @@ abstract class AppSettingTool { canteenExtraPriceConfig.toJson(), ); } - if (ObjectUtil.isNotEmpty(userJson)) {} - if (ObjectUtil.isNotEmpty(canteenExtraPriceConfig)) {} await settingDao.edit(setting); + await _settingCache.putFile( + 'setting', + Uint8List.fromList(utf8.encode(json.encode(setting.toJson()))), + fileExtension: 'json', + ); return true; } diff --git a/lib/common/utils/sync/sync_product_tool.dart b/lib/common/utils/sync/sync_product_tool.dart index 8c8c6d9..32509dd 100644 --- a/lib/common/utils/sync/sync_product_tool.dart +++ b/lib/common/utils/sync/sync_product_tool.dart @@ -152,7 +152,7 @@ abstract class SyncProductTool { apiList?.forEach((v) => v.saleDate = dayStr); } } else if (sysType == SysType.SUPERMARKET) { - apiList = await ProductApi.supermarketProduct(null); + apiList = await ProductApi.supermarketSpu(null); } if (apiList == null) return; if (ObjectUtil.isEmptyList(apiList)) { diff --git a/lib/common/widgets/order/order_common.dart b/lib/common/widgets/order/order_common.dart index 90500ee..63038de 100644 --- a/lib/common/widgets/order/order_common.dart +++ b/lib/common/widgets/order/order_common.dart @@ -193,5 +193,5 @@ Widget orderRowClassify( ); }) .toList() - .toRowSpace(space: 20.w); + .toRowSpace(space: 10.w); } diff --git a/lib/pages/canteen_product/view.dart b/lib/pages/canteen_product/view.dart index 3c58a46..7a78f3d 100644 --- a/lib/pages/canteen_product/view.dart +++ b/lib/pages/canteen_product/view.dart @@ -17,28 +17,21 @@ class CanteenProductPage extends GetView { final context = Get.context!; final theme = FTheme.of(context); return [ - [ - appBack( - context, - height: headerHeight, - onTap: () => Get.offAndToNamed(RouteNames.panel), - ), - Obx( - () => orderRowClassify( - context, - classifyList: controller.classifyList, - currentTabIndex: controller.currentTabIndex, - onChange: (tabIndex) => controller.doTab(tabIndex), - ), - ).scrollable(scrollDirection: Axis.horizontal).expanded(), - appRadioHourTypeDialog(context, controller.hourTypeC).width(300.w), - ].toRow(), - FDivider( - style: theme.dividerStyles.horizontalStyle.copyWith( - padding: EdgeInsets.zero, - ), + appBack( + context, + height: headerHeight, + onTap: () => Get.offAndToNamed(RouteNames.panel), ), - ].toColumn().decorated( + Obx( + () => orderRowClassify( + context, + classifyList: controller.classifyList, + currentTabIndex: controller.currentTabIndex, + onChange: (tabIndex) => controller.doTab(tabIndex), + ), + ).scrollable(scrollDirection: Axis.horizontal).expanded(), + appRadioHourTypeDialog(context, controller.hourTypeC).width(300.w), + ].toRow().decorated( color: theme.colorScheme.background, boxShadow: [ BoxShadow( @@ -49,7 +42,6 @@ class CanteenProductPage extends GetView { ), ], ); - ; } // 商品 diff --git a/lib/pages/setting/view.dart b/lib/pages/setting/view.dart index b90b5a8..8ca1b85 100644 --- a/lib/pages/setting/view.dart +++ b/lib/pages/setting/view.dart @@ -118,8 +118,6 @@ class SettingPage extends GetView { return const SizedBox.shrink(); } return settingProduct(context); - default: - return SizedBox.shrink(); } }, ); diff --git a/lib/pages/setting/widgets/setting_face.dart b/lib/pages/setting/widgets/setting_face.dart index 8fb7302..6154f19 100644 --- a/lib/pages/setting/widgets/setting_face.dart +++ b/lib/pages/setting/widgets/setting_face.dart @@ -101,12 +101,12 @@ class FaceManageController extends GetxController { getFaceList(); }, ); - } finally { - currentPage.value = 1; getFaceList(); // 重新生成人脸模型 await AppFaceTool.removeFace(sampleId: "-1"); await AppFaceTool.faceRegister(forceRegister: true); + } finally { + currentPage.value = 1; Toast.success(msg: "同步成功"); EasyLoading.dismiss(); } diff --git a/lib/pages/setting/widgets/setting_product.dart b/lib/pages/setting/widgets/setting_product.dart index 26d7672..c615d94 100644 --- a/lib/pages/setting/widgets/setting_product.dart +++ b/lib/pages/setting/widgets/setting_product.dart @@ -1,4 +1,3 @@ -import 'package:common_utils/common_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:forui/forui.dart'; @@ -10,14 +9,22 @@ import 'package:pj_supermarket_cloud/common/index.dart'; class ProductManageController extends GetxController { static const _tag = "商品管理 Controller"; - RxList productList = [].obs; + AppControl appC = Get.find(); + + late SysSetting sysSetting; + + Rx sysType = SysType.CANTEEN.obs; + + // 食堂商品 + RxList canteenSpuList = [].obs; + + // 超市商品 + final supermarketSpuList = [].obs; ProductHourType hourType = ProductHourType.MORNING; RxInt currentPage = RxInt(1); - RxInt totalPage = RxInt(0); - RxInt pageSize = RxInt(24); final hourTypeC = FRadioSelectGroupController( @@ -26,8 +33,10 @@ class ProductManageController extends GetxController { @override void onInit() async { - await initData(); super.onInit(); + sysSetting = await AppSettingTool.getSysSetting(); + sysType.value = sysSetting.sysType; + await getProductList(); hourTypeC.addValueListener((v) async { final currentHourType = ProductHourType.values.fromCode( v.first, @@ -44,13 +53,6 @@ class ProductManageController extends GetxController { hourTypeC.dispose(); } - Future initData() async { - await getProductList(); - if (ObjectUtil.isEmptyList(productList)) { - getProductList(); - } - } - // 更新商品和分类 Future updateProductAndClassify() async { EasyLoading.show( @@ -76,22 +78,35 @@ class ProductManageController extends GetxController { ); } try { - final app = Get.find(); - final sysSetting = await AppSettingTool.getSysSetting(); - final productDao = app.dataBase.getCanteenSpuDao; final currnetHourType = hourType.code; - String sysType = sysSetting.sysType.name; - final findCount = await productDao.getCount( - currnetHourType, - ); - if (findCount != null) totalPage.value = findCount; - final list = await productDao.getAllPage( - "-1", - currnetHourType, - pageSize.value, - (currentPage.value - 1) * pageSize.value, - ); - productList.value = list; + SysType sysType = sysSetting.sysType; + + if (sysType == SysType.SUPERMARKET) { + // 超市 + final supermarketSpuDao = appC.dataBase.getSupermarketSpuDao; + final findCount = await supermarketSpuDao.getCount(); + totalPage.value = findCount ?? 0; + final list = await supermarketSpuDao.getAllPage( + "-1", + pageSize.value, + (currentPage.value - 1) * pageSize.value, + ); + supermarketSpuList.value = list; + } else if (sysType == SysType.CANTEEN) { + // 食堂 + final productDao = appC.dataBase.getCanteenSpuDao; + final findCount = await productDao.getCount( + currnetHourType, + ); + totalPage.value = findCount ?? 0; + final list = await productDao.getAllPage( + "-1", + currnetHourType, + pageSize.value, + (currentPage.value - 1) * pageSize.value, + ); + canteenSpuList.value = list; + } } finally { if (isLoading) { Future.delayed(const Duration(seconds: 1), () { @@ -119,8 +134,7 @@ class ProductManageController extends GetxController { status: '设置中...', maskType: EasyLoadingMaskType.black, ); - final app = Get.find(); - final productDao = app.dataBase.getCanteenSpuDao; + final productDao = appC.dataBase.getCanteenSpuDao; final editObj = CanteenSpuEntity.fromJson(v.toJson()); editObj.isDefault = !editObj.isDefault; await productDao.edit( @@ -135,16 +149,20 @@ class ProductManageController extends GetxController { } } -/// 搜索条件 -Widget buildSearch(BuildContext context) { +// 搜索条件 +Widget _buildSearch(BuildContext context) { final theme = FTheme.of(context); final productC = Get.find(); return [ [ - appRadioHourTypeDialog( - context, - productC.hourTypeC, - ).width(300.w), + Obx( + () => appRadioHourTypeDialog( + context, + productC.hourTypeC, + ).offstage( + offstage: productC.sysType.value != SysType.CANTEEN, + ), + ).width(300.w) ].toRow().expanded(), FButton( prefix: FIcon( @@ -172,8 +190,8 @@ Widget buildSearch(BuildContext context) { ].toRow(); } -/// 列表 -Widget buildList(BuildContext context) { +// 食堂列表 +Widget _buildCanteenList(BuildContext context) { final theme = FTheme.of(context); final productC = Get.find(); return Obx( @@ -184,9 +202,9 @@ Widget buildList(BuildContext context) { crossAxisSpacing: 10.w, childAspectRatio: 0.7, ), - itemCount: productC.productList.length, + itemCount: productC.canteenSpuList.length, itemBuilder: (BuildContext context, int index) { - final v = productC.productList[index]; + final v = productC.canteenSpuList[index]; return FCard( style: theme.cardStyle.copyWith( contentStyle: theme.cardStyle.contentStyle.copyWith( @@ -212,13 +230,24 @@ Widget buildList(BuildContext context) { ); } +// 超市列表 +Widget _buildSupermarketList(BuildContext context) { + return SizedBox.shrink(); +} + Widget settingProduct(BuildContext context) { final productC = Get.put( ProductManageController(), ); return [ - buildSearch(context), - buildList(context).expanded(), + _buildSearch(context), + Obx( + () => Visibility( + visible: productC.sysType.value == SysType.CANTEEN, + replacement: _buildSupermarketList(context), + child: _buildCanteenList(context), + ), + ).expanded(), Obx( () => appPage( context, diff --git a/pubspec.lock b/pubspec.lock index 2e57d5f..519adbc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -436,7 +436,7 @@ packages: source: sdk version: "0.0.0" flutter_cache_manager: - dependency: transitive + dependency: "direct main" description: name: flutter_cache_manager sha256: "400b6592f16a4409a7f2bb929a9a7e38c72cceb8ffb99ee57bbf2cb2cecf8386" diff --git a/pubspec.yaml b/pubspec.yaml index f33ac34..2127c6d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -48,6 +48,8 @@ dependencies: # 数据库 sqflite: 2.4.1 floor: 1.4.2 + # 缓存 + flutter_cache_manager: ^3.4.1 # json序列化 json_annotation: ^4.9.0 # 外部路径获取