diff --git a/lib/common/services/database/dao/broadcast_dao.dart b/lib/common/services/database/dao/broadcast_dao.dart index e77a6d0..1ef8fc1 100644 --- a/lib/common/services/database/dao/broadcast_dao.dart +++ b/lib/common/services/database/dao/broadcast_dao.dart @@ -1,10 +1,23 @@ import 'package:floor/floor.dart'; +import 'package:get/get.dart'; import 'package:pj_supermarket_cloud/common/index.dart'; // broadcast @dao abstract class BroadcastDao { + Future toggleEnable(bool enable) async { + final app = Get.find(); + final database = app.dataBase.database; + final sql = ''' + UPDATE broadcast SET enable = ${enable ? 1 : 0} + WHERE + isDone = 0 + AND strftime('%Y-%m-%d', createTime) = strftime('%Y-%m-%d', 'now', 'localtime') + '''; + return await database.rawUpdate(sql, []); + } + @insert Future save(BroadcastEntity entity); diff --git a/lib/pages/canteen_reserve/controller.dart b/lib/pages/canteen_reserve/controller.dart index ebe26df..727b7b3 100644 --- a/lib/pages/canteen_reserve/controller.dart +++ b/lib/pages/canteen_reserve/controller.dart @@ -1,3 +1,4 @@ +import 'package:flutter/src/widgets/framework.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:forui/forui.dart'; import 'package:get/get.dart'; @@ -109,9 +110,43 @@ class CanteenReserveController extends GetxController { maskType: EasyLoadingMaskType.black, ); final broadcastDao = appC.dataBase.getBroadcastDao; - v.broadcastCount = 10; + v.broadcastCount = 0; await broadcastDao.edit(v); await _getReservePage(); EasyLoading.dismiss(); } + + /// 立即广播 + Future startBroadcast() async { + EasyLoading.show( + status: '广播中...', + maskType: EasyLoadingMaskType.black, + ); + await _getReservePage(); + EasyLoading.dismiss(); + } + + /// 关闭全部广播 + Future closeBroadcast() async { + EasyLoading.show( + status: '关闭中...', + maskType: EasyLoadingMaskType.black, + ); + final broadcastDao = appC.dataBase.getBroadcastDao; + await broadcastDao.toggleEnable(false); + await _getReservePage(); + EasyLoading.dismiss(); + } + + /// 打开全部广播 + Future openBroadcast() async { + EasyLoading.show( + status: '打开中...', + maskType: EasyLoadingMaskType.black, + ); + final broadcastDao = appC.dataBase.getBroadcastDao; + await broadcastDao.toggleEnable(true); + await _getReservePage(); + EasyLoading.dismiss(); + } } diff --git a/lib/pages/canteen_reserve/view.dart b/lib/pages/canteen_reserve/view.dart index b44f202..32e6ba3 100644 --- a/lib/pages/canteen_reserve/view.dart +++ b/lib/pages/canteen_reserve/view.dart @@ -17,7 +17,7 @@ class CanteenReservePage extends GetView { final height = context.height; final headerHeight = height * 0.08; return [ - _buildCondition(context, headerHeight), + _buildCondition(context, headerHeight).marginSymmetric(horizontal: 30.w), SizedBox(height: 20.h), _buildTable(context).center().expanded(), Obx( @@ -37,9 +37,47 @@ class CanteenReservePage extends GetView { final theme = FTheme.of(context); return [ const Spacer(), - appRadioHourTypeDialog(context, controller.hourTypeC) - .width(300.w) - .marginOnly(right: 15.w), + appRadioHourTypeDialog(context, controller.hourTypeC).width(300.w), + FButton( + prefix: FIcon( + FAssets.icons.rocket, + size: theme.typography.base.fontSize, + ), + label: Text( + '立即广播', + style: theme.typography.base.copyWith( + color: theme.colorScheme.secondary, + ), + ), + onPress: () => controller.startBroadcast(), + ), + FButton( + prefix: FIcon( + FAssets.icons.rocket, + size: theme.typography.base.fontSize, + ), + label: Text( + '开启全部广播', + style: theme.typography.base.copyWith( + color: theme.colorScheme.secondary, + ), + ), + onPress: () => controller.openBroadcast(), + ), + FButton( + style: FButtonStyle.destructive, + prefix: FIcon( + FAssets.icons.ban, + size: theme.typography.base.fontSize, + ), + label: Text( + '关闭全部广播', + style: theme.typography.base.copyWith( + color: theme.colorScheme.secondary, + ), + ), + onPress: () => controller.closeBroadcast(), + ), ].toRowSpace(space: 15.w, mainAxisAlignment: MainAxisAlignment.center); } @@ -117,8 +155,8 @@ class CanteenReservePage extends GetView { ), DataCell( Text( - "${v.broadcastCount}", - textAlign: TextAlign.center, + "已播报${v.broadcastCount}次,最多播报${v.broadcastMaxCount}次", + textAlign: TextAlign.start, ).center(), ), DataCell( @@ -137,8 +175,7 @@ class CanteenReservePage extends GetView { [ FButton( label: Text( - // v.enable ? "关闭播报" : '开启播报', - "${v.enable}", + v.enable ? "关闭播报" : '开启播报', style: theme.typography.sm.copyWith( color: theme.colorScheme.primary, ),