Исправления, автоклуб

This commit is contained in:
Ivan Murashov
2017-07-28 18:36:51 +03:00
parent e53ceb9ef0
commit 7207c6e247
16 changed files with 203 additions and 171 deletions

View File

@@ -24,12 +24,11 @@ class PurchaseScreen extends StatefulWidget {
class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
RegExp exp;
RegExp moneyRegexp = new RegExp(r'''^(?!0\.00)\d{1,11}(\.\d{0,2})?$''');
PurchaseScreenState(String userString, String card) {
this.user = JSON.decode(userString);
this.card = card;
exp = new RegExp(r'''^(?!0\.00)\d{1,11}(\.\d{0,2})?$''');
getLoyality(user['loyalty_url']);
}
@@ -40,15 +39,15 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
@override Widget getScreenContent() {
return new Column(
children: <Widget>[new Expanded(child: new ListView(children: <Widget>[
getValueWithTitle('ФИО', user['first_name'] == null ? '' : user['first_name']),
getValueWithTitle('Карта', card),
getValueWithTitle('Вознаграждение', loyality),
getHintLabel(),
getDecoratedTextWidget(),
buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildRaisedButton(context, 'ЗАВЕРШИТЬ ПОКУПКУ', () => onPurchaseClick(context))),
buildButton(new EdgeInsets.only(top: 24.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor))
]))]);
children: <Widget>[new Expanded(child: new ListView(children: <Widget>[
getValueWithTitle('ФИО', user['first_name'] == null ? '' : user['first_name']),
getValueWithTitle('Карта', card),
getValueWithTitle('Вознаграждение', loyality),
getHintLabel(),
getDecoratedTextWidget(),
buildButton(new EdgeInsets.only(top: 36.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildRaisedButton(context, 'ЗАВЕРШИТЬ ПОКУПКУ', () => onPurchaseClick(context))),
buildButton(new EdgeInsets.only(top: 24.0, left: buttonVerticalMargin, right: buttonVerticalMargin), buildFlatButton(context, 'СКАНИРОВАТЬ', primaryColor))
]))]);
}
@override String getTitle() {
@@ -72,7 +71,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
setState(() {
if (tmpString.length == 0 || exp.hasMatch(tmpString)) {
if (tmpString.length == 0 || moneyRegexp.hasMatch(tmpString)) {
if (tmpString.contains('.')) {
int dotIndex = tmpString.indexOf('.');
integerPart = tmpString.substring(0, dotIndex);
@@ -102,15 +101,14 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
onChanged: (text) => handleUserInput(text));
}
getLoyality(String url) {
getLoyality(String url) async {
print(url);
print(token);
if (await platform.invokeMethod('isOnline')) {
var headers = {
'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08',
'Authorization': 'dmtoken ${token}'
};
var headers = {
'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08',
'Authorization': 'dmtoken ${token}'
};
httpClient.get(url, headers: headers).then((response) {
@@ -118,24 +116,18 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
Map bonuses = JSON.decode(response.body);
String type = bonuses['type'];
setState(() {
if (type == 'amount') {
this.loyality = '${user['discount']}%';
} else {
List amountToBonus = bonuses['amount_to_bonus'];
// print(amountToBonus[0]);
// print(amountToBonus[1]);
this.loyality = '${(amountToBonus[0] / double.parse(amountToBonus[1])).toStringAsFixed(0)}%';
}
});
}).catchError((error) {
print(error.toString());
});
}
}
_buildSum() {
@@ -175,33 +167,36 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
]));
}
purchase(String sum_total) {
purchase(String sum_total) async {
platform.invokeMethod('getDocID').then((result) {
if (await platform.invokeMethod('isOnline')) {
String url = user['purchases_url'];
platform.invokeMethod('getDocID').then((result) {
var body = {
'doc_id': result,
'curr_iso_code': '643',
'commit': 'true',
'sum_total': sum_total
};
String url = user['purchases_url'];
var headers = {
'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08',
'Authorization': 'dmtoken ${token}'
};
var body = {
'doc_id': result,
'curr_iso_code': '643',
'commit': 'true',
'sum_total': sum_total
};
httpClient.post(url, body: body, headers: headers).then((response) {
print(response.body);
Navigator.of(context).pop();
pushRoute(context, new PurchaseSuccessScreen(sum_total, user['first_name'] == null ? '' : user['first_name']));
var headers = {
'DM-Authorization': 'dmapptoken 9fec83cdca38c357e6b65dbb17514cdd36bf2a08',
'Authorization': 'dmtoken ${token}'
};
}).catchError((error) {
print(error.toString());
});
});
httpClient.post(url, body: body, headers: headers).then((response) {
print(response.body);
Navigator.of(context).pop();
pushRoute(context, new PurchaseSuccessScreen(sum_total, user['first_name'] == null ? '' : user['first_name']));
}).catchError((error) {
print(error.toString());
});
});
}
}
}