diff --git a/lib/core/redux/actions/sell_actions.dart b/lib/core/redux/actions/sell_actions.dart index 8b0619e..14727c6 100644 --- a/lib/core/redux/actions/sell_actions.dart +++ b/lib/core/redux/actions/sell_actions.dart @@ -28,6 +28,35 @@ final Logger log = getLogger('SetSellStateAction'); final DbService _dbService = locator(); +ThunkAction counterSellItem({required int transactionId, required num counter}) { + return (Store store) async { + log.i('counterSellItem'); + int? appCompanyId = store.state.userState!.auth!.companyId; + String? uuid = store.state.sellState!.transactionState!.uuid; + + Transaction? transaction; + + if (uuid != null ) { + List> set = await _dbService.queryRowsWithWhere( + TransactionTableName, + '$TransactionColumnAppCompanyId = ? and $TransactionColumnStatus = ? and ${TransactionColumnType} = ? and ${TransactionColumnId} = ?', + [appCompanyId, TransactionStatusPrepare, TransactionTypeSell, transactionId], + orderBy: '$TransactionColumnCreatedAt desc'); + if (set.isNotEmpty) { + transaction = Transaction.fromMap(set.first); + } + } + if (transaction != null) { + ProductDao item = ProductDao.fromMap(jsonDecode(transaction.data!)); + item.count = (item.count ?? 0) + counter; + transaction.data = jsonEncode(item.toMap()); + _dbService.update(TransactionTableName, transaction.toMap()); + } + // refresh from db ? after save data + await loadSellData(store); + }; +} + ThunkAction addSellItem({required Good good, String? excise}) { return (Store store) async { log.i('addSellItem'); @@ -108,20 +137,6 @@ ThunkAction removeSellItem({required int transactionId}) { int count = await _dbService.delete(TransactionTableName, transactionId); log.i('removeSellItem ${count} by transactionId:${transactionId}'); - // List> set = await _dbService.queryRowsWithWhere( - // TransactionTableName, - // '$TransactionColumnId = ? ', - // [transactionId]); - // if (set.isNotEmpty) { - // for (Map map in set) { - // Transaction _transaction = Transaction.fromMap(map); - // ProductDao _product = ProductDao.fromMap(jsonDecode(_transaction.data)); - // if (_product.id == good.id && _product.excise == excise) { - // transaction = _transaction; - // break; - // } - // } - // } // refresh from db ? after save data await loadSellData(store); diff --git a/lib/core/redux/reducers/nav_reducer.dart b/lib/core/redux/reducers/nav_reducer.dart index 1cb9b7d..6d5315e 100644 --- a/lib/core/redux/reducers/nav_reducer.dart +++ b/lib/core/redux/reducers/nav_reducer.dart @@ -4,9 +4,9 @@ import 'package:satu/core/redux/state/nav_state.dart'; import 'package:satu/core/redux/state/user_state.dart'; navReducer(NavState prevState, SetNavStateAction action) { - final payload = action.navState; + final NavState? payload = action.navState; return prevState.copyWith( - drawerViewClass: payload.drawerViewClass!, - selectedTabIndex: payload.selectedTabIndex!, + drawerViewClass: payload?.drawerViewClass!, + selectedTabIndex: payload?.selectedTabIndex!, ); } diff --git a/lib/views/work/tabs/component/product_list_item.dart b/lib/views/work/tabs/component/product_list_item.dart index 8e3217c..60362ce 100644 --- a/lib/views/work/tabs/component/product_list_item.dart +++ b/lib/views/work/tabs/component/product_list_item.dart @@ -49,6 +49,7 @@ class _ProductListItemState extends State { padding: const EdgeInsets.all(8.0), child: Text( 'Удалить', + style: TextStyle(color: whiteColor, fontWeight: FontWeight.w500), ), ), ), @@ -78,6 +79,7 @@ class _ProductListItemState extends State { key: Key(widget.name ?? ''), child: ListTile( //onTap: () => _onItemTapped(context), + onTap: () {}, contentPadding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 4.0), title: Row( crossAxisAlignment: CrossAxisAlignment.start, @@ -126,9 +128,13 @@ class _ProductListItemState extends State { color: Colors.transparent, borderRadius: BorderRadius.circular(ScreenUtil().radius(5)), child: InkWell( - onTap: () {}, + onTap: () { + Redux.store! + .dispatch(counterSellItem(transactionId: this.widget.transactionId!, counter: 1.0)); + }, child: Container( decoration: BoxDecoration( + color: whiteColor, borderRadius: BorderRadius.circular(ScreenUtil().radius(5)), border: Border.all(width: 1.0.sp, color: successColor)), child: Icon( @@ -141,8 +147,8 @@ class _ProductListItemState extends State { ), Container( width: 45.w, - margin: EdgeInsets.symmetric( horizontal: 5.w), - padding: EdgeInsets.symmetric( vertical: 6.0.w ), + margin: EdgeInsets.symmetric(horizontal: 5.w), + padding: EdgeInsets.symmetric(vertical: 6.0.w), decoration: BoxDecoration( color: whiteColor, borderRadius: BorderRadius.circular(ScreenUtil().radius(5)), @@ -151,10 +157,7 @@ class _ProductListItemState extends State { width: 45.w, child: Text( '${widget.count} шт', - style: TextStyle( - fontSize: 8.sp, - color: placeholderColor - ), + style: TextStyle(fontSize: 8.sp, color: placeholderColor), textAlign: TextAlign.center, ), ), @@ -163,11 +166,18 @@ class _ProductListItemState extends State { color: Colors.transparent, borderRadius: BorderRadius.circular(ScreenUtil().radius(5)), child: InkWell( - onTap: () {}, + onTap: () { + if (widget.count! > 1.0) { + Redux.store! + .dispatch(counterSellItem(transactionId: this.widget.transactionId!, counter: -1.0)); + } + }, child: Container( decoration: BoxDecoration( + color: whiteColor, borderRadius: BorderRadius.circular(ScreenUtil().radius(5)), - border: Border.all(width: 1.0.sp, color: widget.count! <= 1.0 ? disableColor : dangerColor)), + border: Border.all( + width: 1.0.sp, color: widget.count! <= 1.0 ? disableColor : dangerColor)), child: Icon( Icons.remove, color: widget.count! <= 1.0 ? disableColor : dangerColor, diff --git a/lib/views/work/tabs/component/products_title_bar.dart b/lib/views/work/tabs/component/products_title_bar.dart index 10dc845..46ca634 100644 --- a/lib/views/work/tabs/component/products_title_bar.dart +++ b/lib/views/work/tabs/component/products_title_bar.dart @@ -28,8 +28,25 @@ class ProductsTitleBarBar extends StatelessWidget { )), if(itemsExist) TextButton( - onPressed: () { - Redux.store!.dispatch(removeAllSellData); + onPressed: () async { + bool? result = await showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text("Внимание"), + content: Text("Удалить все товары из списка"), + actions: [ + TextButton(onPressed: () => Navigator.of(context).pop(true), child: const Text("Удалить")), + TextButton( + onPressed: () => Navigator.of(context).pop(false), + child: const Text("Отмена"), + ), + ], + ); + }, + ); + if(result == true) + Redux.store!.dispatch(removeAllSellData); }, child: Text( 'Удалить все', diff --git a/lib/views/work/tabs/sell_view.dart b/lib/views/work/tabs/sell_view.dart index fc01138..46f4264 100644 --- a/lib/views/work/tabs/sell_view.dart +++ b/lib/views/work/tabs/sell_view.dart @@ -40,8 +40,8 @@ class SellView extends StatelessWidget { ContragentSelectBar( value: 'Частное лицо', ), - ProductsTitleBarBar(itemsExist: state.items!.isNotEmpty), - ListView.builder( + Visibility(child: ProductsTitleBarBar(itemsExist: true), visible: state.items!.isNotEmpty,), + ListView.separated( shrinkWrap: true, physics: BouncingScrollPhysics(), itemCount: state.items!.length, @@ -58,6 +58,9 @@ class SellView extends StatelessWidget { transactionId: product.transactionId, ); }, + separatorBuilder: (context, index) { + return Divider(height: 1, color: disableColor,); + }, ), ], ),