ui render
parent
8a7e606be1
commit
c7ce34407e
|
|
@ -8,6 +8,7 @@ class ProductDao {
|
|||
String eanCode;
|
||||
int article;
|
||||
String excise;
|
||||
int transactionId;
|
||||
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
|
|
@ -21,6 +22,7 @@ class ProductDao {
|
|||
'eanCode': eanCode,
|
||||
'article': article,
|
||||
'excise': excise,
|
||||
'transactionId' : transactionId,
|
||||
};
|
||||
return map;
|
||||
}
|
||||
|
|
@ -37,6 +39,7 @@ class ProductDao {
|
|||
eanCode = map['eanCode'];
|
||||
article = map['article'];
|
||||
excise = map['excise'];
|
||||
transactionId = map['transactionId'];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -76,6 +76,7 @@ ThunkAction<AppState> addSellItem({Good good, String excise}) {
|
|||
if (set.isNotEmpty) {
|
||||
Category category = Category.fromMap(set.first);
|
||||
item.categoryId = category.id;
|
||||
item.categoryName = category.name;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,8 +100,55 @@ ThunkAction<AppState> addSellItem({Good good, String excise}) {
|
|||
};
|
||||
}
|
||||
|
||||
ThunkAction<AppState> removeSellItem({int transactionId}) {
|
||||
return (Store<AppState> store) async {
|
||||
|
||||
int appCompanyId = store.state.userState.auth.companyId;
|
||||
String uuid = store.state.sellState.transactionState.uuid;
|
||||
|
||||
int count = await _dbService.delete(TransactionTableName, 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
|
||||
await loadSellData(store);
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> removeAllSellData(Store<AppState> store) async {
|
||||
try {
|
||||
log.i('removeAllSellData');
|
||||
int appCompanyId = store.state.userState.auth.companyId;
|
||||
String uuid = store.state.sellState.transactionState.uuid;
|
||||
await _dbService.deleteByWhere(
|
||||
TransactionTableName,
|
||||
'$TransactionColumnAppCompanyId = ? '
|
||||
' and $TransactionColumnStatus = ? '
|
||||
' and ${TransactionColumnType} = ?'
|
||||
' and ${TransactionColumnUuid} = ?',
|
||||
[appCompanyId, TransactionStatusPrepare, TransactionTypeSell, uuid]);
|
||||
await loadSellData(store);
|
||||
} catch (e, stack) {
|
||||
log.e('removeAllSellData', e, stack);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadSellData(Store<AppState> store) async {
|
||||
try {
|
||||
log.i('loadSellData');
|
||||
int appCompanyId = store.state.userState.auth.companyId;
|
||||
List<Map<String, dynamic>> set = await _dbService.queryRowsWithWhere(
|
||||
TransactionTableName,
|
||||
|
|
@ -112,7 +160,9 @@ Future<void> loadSellData(Store<AppState> store) async {
|
|||
for (Map<String, dynamic> map in set) {
|
||||
Transaction transaction = Transaction.fromMap(map);
|
||||
uuid = transaction.uuid;
|
||||
list.add(ProductDao.fromMap(jsonDecode(transaction.data)));
|
||||
ProductDao productDao = ProductDao.fromMap(jsonDecode(transaction.data));
|
||||
productDao.transactionId = transaction.id;
|
||||
list.add(productDao);
|
||||
}
|
||||
store.dispatch(SetSellStateAction(SellState(items: list, transactionState: TransactionState()..uuid = uuid)));
|
||||
} catch (e, stack) {
|
||||
|
|
|
|||
|
|
@ -144,5 +144,10 @@ class DbService extends BaseService {
|
|||
return await db.delete(table);
|
||||
}
|
||||
|
||||
Future<int> deleteByWhere(String table, String where, List<dynamic> args) async {
|
||||
Database db = await instance.database;
|
||||
return await db.delete(table, where: where, whereArgs: args);
|
||||
}
|
||||
|
||||
Future close() async => instance.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:satu/core/redux/actions/sell_actions.dart';
|
||||
import 'package:satu/core/redux/store.dart';
|
||||
import 'package:satu/shared/app_colors.dart';
|
||||
import 'package:satu/shared/shared_styles.dart';
|
||||
import 'package:satu/shared/ui_helpers.dart';
|
||||
|
|
@ -11,8 +13,9 @@ class ProductListItem extends StatelessWidget {
|
|||
final num price;
|
||||
final num count;
|
||||
final bool isOdd;
|
||||
final int transactionId;
|
||||
|
||||
const ProductListItem({Key key, this.name, this.ean, this.categoryName, this.price, this.count, this.isOdd}) : super(key: key);
|
||||
const ProductListItem({Key key, this.name, this.ean, this.categoryName, this.price, this.count, this.isOdd, this.transactionId}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -27,16 +30,16 @@ class ProductListItem extends StatelessWidget {
|
|||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Confirm"),
|
||||
content: const Text("Are you sure you wish to delete this item?"),
|
||||
title: const Text("Внимание"),
|
||||
content: Text("Удалить товар \"${this.name}\" - ${count} ед. ?"),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text("DELETE")
|
||||
child: const Text("Удалить")
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text("CANCEL"),
|
||||
child: const Text("Отмена"),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
@ -45,6 +48,7 @@ class ProductListItem extends StatelessWidget {
|
|||
},
|
||||
onDismissed: (direction) {
|
||||
print(direction);
|
||||
Redux.store.dispatch(removeSellItem( transactionId: this.transactionId ));
|
||||
},
|
||||
key: Key(name),
|
||||
child: ListTile(
|
||||
|
|
@ -63,7 +67,7 @@ class ProductListItem extends StatelessWidget {
|
|||
Text(name , style: const TextStyle( fontWeight: FontWeight.w500 ), overflow: TextOverflow.ellipsis, maxLines: 2,),
|
||||
verticalSpaceTiny,
|
||||
Text('Штрих-код: $ean' , style: productSubTextStyle,),
|
||||
Text(categoryName, style: productSubTextStyle,)
|
||||
Text(categoryName ?? '', style: productSubTextStyle,)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:satu/core/models/flow/product_dao.dart';
|
||||
import 'package:satu/core/redux/actions/sell_actions.dart';
|
||||
import 'package:satu/core/redux/state/sell_state.dart';
|
||||
import 'package:satu/core/redux/store.dart';
|
||||
import 'package:satu/core/services/navigator_service.dart';
|
||||
import 'package:satu/core/utils/locator.dart';
|
||||
import 'package:satu/routes/route_names.dart';
|
||||
import 'package:satu/shared/app_colors.dart';
|
||||
import 'package:satu/shared/ui_helpers.dart';
|
||||
import 'package:satu/views/work/tabs/component/product_list_item.dart';
|
||||
import 'package:satu/views/work/tabs/component/products_app_bar.dart';
|
||||
import 'package:satu/views/work/tabs/component/products_header_bar.dart';
|
||||
|
|
@ -30,31 +34,71 @@ class SellView extends StatelessWidget {
|
|||
backgroundColor: backgroundColor,
|
||||
childHeight: 80,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
//ProductHeaderBar(count: 14, sum: 25000,),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
body: ListView.builder(
|
||||
physics: BouncingScrollPhysics(),
|
||||
itemCount: state.items.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
ProductDao product = state.items.elementAt(index);
|
||||
return ProductListItem(
|
||||
key: UniqueKey(),
|
||||
ean: product.eanCode,
|
||||
isOdd: index % 2 == 0,
|
||||
name: product.productName,
|
||||
price: product.price,
|
||||
count: product.count,
|
||||
categoryName: product.productName,
|
||||
categoryName: product.categoryName,
|
||||
transactionId: product.transactionId,
|
||||
);
|
||||
},
|
||||
),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
||||
floatingActionButton: floatingActionButtonRender(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget floatingActionButtonRender() {
|
||||
return StoreConnector<AppState, SellState>(
|
||||
converter: (store) => store.state.sellState,
|
||||
builder: (_, snapshot) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 16.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
Visibility(
|
||||
visible: snapshot.items.isNotEmpty,
|
||||
child: FloatingActionButton(
|
||||
elevation: 2,
|
||||
backgroundColor: greenColor,
|
||||
onPressed: () => print('check'),
|
||||
child: Icon(
|
||||
Icons.check,
|
||||
color: whiteColor,
|
||||
size: 30.sp
|
||||
),
|
||||
)),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
FloatingActionButton(
|
||||
elevation: 2,
|
||||
onPressed: () => locator<NavigatorService>().push(AddProductViewRoute),
|
||||
child: Icon(Icons.add, size: 30.sp,),
|
||||
),
|
||||
verticalSpaceMedium,
|
||||
FloatingActionButton(
|
||||
elevation: 2,
|
||||
onPressed: () => locator<NavigatorService>().push(AddByBarcodeViewRoute),
|
||||
child: Icon(Icons.qr_code_rounded, size: 30.sp),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
List<Widget> actions() {
|
||||
|
|
@ -62,17 +106,9 @@ class SellView extends StatelessWidget {
|
|||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.add_box, size: 30.0, color: yellowColor),
|
||||
icon: Icon(Icons.delete, size: 30.0, color: yellowColor),
|
||||
onPressed: () {
|
||||
locator<NavigatorService>().push(AddProductViewRoute);
|
||||
}),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.camera_enhance_rounded, size: 30.0, color: yellowColor),
|
||||
onPressed: () {
|
||||
locator<NavigatorService>().push(AddByBarcodeViewRoute);
|
||||
Redux.store.dispatch(removeAllSellData);
|
||||
}),
|
||||
)
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||
import 'package:satu/core/redux/actions/sell_actions.dart';
|
||||
import 'package:satu/core/redux/store.dart';
|
||||
import 'package:satu/shared/app_colors.dart';
|
||||
import 'package:satu/views/work/tabs/buy_view.dart';
|
||||
import 'package:satu/views/work/tabs/journal_view.dart';
|
||||
|
|
@ -24,6 +26,13 @@ class _WorkViewState extends State<WorkView> {
|
|||
];
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// state sell view
|
||||
Redux.store.dispatch(loadSellData);
|
||||
}
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
|
|
|
|||
Loading…
Reference in New Issue