product list
parent
05cf3f4284
commit
d500e4daf7
|
|
@ -28,6 +28,35 @@ final Logger log = getLogger('SetSellStateAction');
|
||||||
|
|
||||||
final DbService _dbService = locator<DbService>();
|
final DbService _dbService = locator<DbService>();
|
||||||
|
|
||||||
|
ThunkAction<AppState> counterSellItem({required int transactionId, required num counter}) {
|
||||||
|
return (Store<AppState> 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<Map<String, dynamic>> 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<AppState> addSellItem({required Good good, String? excise}) {
|
ThunkAction<AppState> addSellItem({required Good good, String? excise}) {
|
||||||
return (Store<AppState> store) async {
|
return (Store<AppState> store) async {
|
||||||
log.i('addSellItem');
|
log.i('addSellItem');
|
||||||
|
|
@ -108,20 +137,6 @@ ThunkAction<AppState> removeSellItem({required int transactionId}) {
|
||||||
|
|
||||||
int count = await _dbService.delete(TransactionTableName, transactionId);
|
int count = await _dbService.delete(TransactionTableName, transactionId);
|
||||||
log.i('removeSellItem ${count} by transactionId:${transactionId}');
|
log.i('removeSellItem ${count} by transactionId:${transactionId}');
|
||||||
// List<Map<String, dynamic>> set = await _dbService.queryRowsWithWhere(
|
|
||||||
// TransactionTableName,
|
|
||||||
// '$TransactionColumnId = ? ',
|
|
||||||
// [transactionId]);
|
|
||||||
// if (set.isNotEmpty) {
|
|
||||||
// for (Map<String, dynamic> 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
|
// refresh from db ? after save data
|
||||||
await loadSellData(store);
|
await loadSellData(store);
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ import 'package:satu/core/redux/state/nav_state.dart';
|
||||||
import 'package:satu/core/redux/state/user_state.dart';
|
import 'package:satu/core/redux/state/user_state.dart';
|
||||||
|
|
||||||
navReducer(NavState prevState, SetNavStateAction action) {
|
navReducer(NavState prevState, SetNavStateAction action) {
|
||||||
final payload = action.navState;
|
final NavState? payload = action.navState;
|
||||||
return prevState.copyWith(
|
return prevState.copyWith(
|
||||||
drawerViewClass: payload.drawerViewClass!,
|
drawerViewClass: payload?.drawerViewClass!,
|
||||||
selectedTabIndex: payload.selectedTabIndex!,
|
selectedTabIndex: payload?.selectedTabIndex!,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ class _ProductListItemState extends State<ProductListItem> {
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Удалить',
|
'Удалить',
|
||||||
|
style: TextStyle(color: whiteColor, fontWeight: FontWeight.w500),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -78,6 +79,7 @@ class _ProductListItemState extends State<ProductListItem> {
|
||||||
key: Key(widget.name ?? ''),
|
key: Key(widget.name ?? ''),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
//onTap: () => _onItemTapped(context),
|
//onTap: () => _onItemTapped(context),
|
||||||
|
onTap: () {},
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 4.0),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 4.0),
|
||||||
title: Row(
|
title: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
|
@ -126,9 +128,13 @@ class _ProductListItemState extends State<ProductListItem> {
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
|
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {},
|
onTap: () {
|
||||||
|
Redux.store!
|
||||||
|
.dispatch(counterSellItem(transactionId: this.widget.transactionId!, counter: 1.0));
|
||||||
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
|
color: whiteColor,
|
||||||
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
|
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
|
||||||
border: Border.all(width: 1.0.sp, color: successColor)),
|
border: Border.all(width: 1.0.sp, color: successColor)),
|
||||||
child: Icon(
|
child: Icon(
|
||||||
|
|
@ -141,8 +147,8 @@ class _ProductListItemState extends State<ProductListItem> {
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
width: 45.w,
|
width: 45.w,
|
||||||
margin: EdgeInsets.symmetric( horizontal: 5.w),
|
margin: EdgeInsets.symmetric(horizontal: 5.w),
|
||||||
padding: EdgeInsets.symmetric( vertical: 6.0.w ),
|
padding: EdgeInsets.symmetric(vertical: 6.0.w),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: whiteColor,
|
color: whiteColor,
|
||||||
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
|
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
|
||||||
|
|
@ -151,10 +157,7 @@ class _ProductListItemState extends State<ProductListItem> {
|
||||||
width: 45.w,
|
width: 45.w,
|
||||||
child: Text(
|
child: Text(
|
||||||
'${widget.count} шт',
|
'${widget.count} шт',
|
||||||
style: TextStyle(
|
style: TextStyle(fontSize: 8.sp, color: placeholderColor),
|
||||||
fontSize: 8.sp,
|
|
||||||
color: placeholderColor
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -163,11 +166,18 @@ class _ProductListItemState extends State<ProductListItem> {
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
|
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {},
|
onTap: () {
|
||||||
|
if (widget.count! > 1.0) {
|
||||||
|
Redux.store!
|
||||||
|
.dispatch(counterSellItem(transactionId: this.widget.transactionId!, counter: -1.0));
|
||||||
|
}
|
||||||
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
|
color: whiteColor,
|
||||||
borderRadius: BorderRadius.circular(ScreenUtil().radius(5)),
|
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(
|
child: Icon(
|
||||||
Icons.remove,
|
Icons.remove,
|
||||||
color: widget.count! <= 1.0 ? disableColor : dangerColor,
|
color: widget.count! <= 1.0 ? disableColor : dangerColor,
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,25 @@ class ProductsTitleBarBar extends StatelessWidget {
|
||||||
)),
|
)),
|
||||||
if(itemsExist)
|
if(itemsExist)
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
Redux.store!.dispatch(removeAllSellData);
|
bool? result = await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text("Внимание"),
|
||||||
|
content: Text("Удалить все товары из списка"),
|
||||||
|
actions: <Widget>[
|
||||||
|
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(
|
child: Text(
|
||||||
'Удалить все',
|
'Удалить все',
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ class SellView extends StatelessWidget {
|
||||||
ContragentSelectBar(
|
ContragentSelectBar(
|
||||||
value: 'Частное лицо',
|
value: 'Частное лицо',
|
||||||
),
|
),
|
||||||
ProductsTitleBarBar(itemsExist: state.items!.isNotEmpty),
|
Visibility(child: ProductsTitleBarBar(itemsExist: true), visible: state.items!.isNotEmpty,),
|
||||||
ListView.builder(
|
ListView.separated(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: BouncingScrollPhysics(),
|
physics: BouncingScrollPhysics(),
|
||||||
itemCount: state.items!.length,
|
itemCount: state.items!.length,
|
||||||
|
|
@ -58,6 +58,9 @@ class SellView extends StatelessWidget {
|
||||||
transactionId: product.transactionId,
|
transactionId: product.transactionId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
separatorBuilder: (context, index) {
|
||||||
|
return Divider(height: 1, color: disableColor,);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue