issue 10360, реализация выбора купонов к гашению в покупке
This commit is contained in:
@@ -137,7 +137,7 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
|||||||
EditText manualInput = (EditText) findViewById(R.id.manual_input);
|
EditText manualInput = (EditText) findViewById(R.id.manual_input);
|
||||||
|
|
||||||
// для удобства, чтоб не вводить постоянно руками при разработке
|
// для удобства, чтоб не вводить постоянно руками при разработке
|
||||||
//manualInput.setText("4620011139016317023320337");
|
manualInput.setText("4620011139016317023320337");
|
||||||
|
|
||||||
manualInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
manualInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -143,6 +143,70 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getItemToggle(String title, String description) {
|
||||||
|
if (title.length == 0) {
|
||||||
|
title = description.substring(0,30) + " ...";
|
||||||
|
}
|
||||||
|
return new Container(
|
||||||
|
margin: new EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0),
|
||||||
|
child: new Card(
|
||||||
|
child: new ExpansionTile(
|
||||||
|
title: new Text(
|
||||||
|
title,
|
||||||
|
style: Theme.of(context).textTheme.button.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: faqTitlesColor
|
||||||
|
)
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
new Container(
|
||||||
|
margin: new EdgeInsets.only(left: 20.0, right: 20.0),
|
||||||
|
padding: new EdgeInsets.only(top: 0.0, bottom: 10.0),
|
||||||
|
child: new Text(description),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Возвращает контейнер с раскрывающимся элементом и переключателем
|
||||||
|
// title - название, description - описание, isSet - состояние переключаиеля
|
||||||
|
// handler - обработчик события переключения
|
||||||
|
|
||||||
|
getItemToggleSwitch(String title, String description, bool isSet, handler) {
|
||||||
|
|
||||||
|
if (title.length == 0) {
|
||||||
|
title = description.substring(0,25) + " ...";
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Container(
|
||||||
|
margin: new EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0),
|
||||||
|
child: new Card(
|
||||||
|
child: new ExpansionTile(
|
||||||
|
title: new SwitchListTile(
|
||||||
|
title: new Text(
|
||||||
|
title,
|
||||||
|
style: Theme.of(context).textTheme.button.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: faqTitlesColor
|
||||||
|
)
|
||||||
|
),
|
||||||
|
value: isSet,
|
||||||
|
onChanged: handler
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
new Container(
|
||||||
|
margin: new EdgeInsets.only(left: 20.0, right: 20.0),
|
||||||
|
padding: new EdgeInsets.only(top: 0.0, bottom: 10.0),
|
||||||
|
child: new Text(description),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Метод возвращает контейнер только с названием элемента
|
/// Метод возвращает контейнер только с названием элемента
|
||||||
Widget getItemTitle(String title) {
|
Widget getItemTitle(String title) {
|
||||||
return new Container(
|
return new Container(
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
|||||||
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Bonus was charged"),
|
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Bonus was charged"),
|
||||||
"bonus_hint" : MessageLookupByLibrary.simpleMessage("Points to charge"),
|
"bonus_hint" : MessageLookupByLibrary.simpleMessage("Points to charge"),
|
||||||
"coupons_used" : MessageLookupByLibrary.simpleMessage("Coupons were used"),
|
"coupons_used" : MessageLookupByLibrary.simpleMessage("Coupons were used"),
|
||||||
|
"select_coupons" : MessageLookupByLibrary.simpleMessage("Select coupons for using in purchase"),
|
||||||
"bonus_explanation" : MessageLookupByLibrary.simpleMessage("If not set, points will be added"),
|
"bonus_explanation" : MessageLookupByLibrary.simpleMessage("If not set, points will be added"),
|
||||||
"scan" : MessageLookupByLibrary.simpleMessage("Scan"),
|
"scan" : MessageLookupByLibrary.simpleMessage("Scan"),
|
||||||
"sign_up" : MessageLookupByLibrary.simpleMessage("Sign Up"),
|
"sign_up" : MessageLookupByLibrary.simpleMessage("Sign Up"),
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
|||||||
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Бонусов списано"),
|
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Бонусов списано"),
|
||||||
"bonus_hint" : MessageLookupByLibrary.simpleMessage("Сколько баллов списать?"),
|
"bonus_hint" : MessageLookupByLibrary.simpleMessage("Сколько баллов списать?"),
|
||||||
"coupons_used" : MessageLookupByLibrary.simpleMessage("Были погашены купоны"),
|
"coupons_used" : MessageLookupByLibrary.simpleMessage("Были погашены купоны"),
|
||||||
|
"select_coupons" : MessageLookupByLibrary.simpleMessage("Выберите купоны для гашения"),
|
||||||
"bonus_explanation" : MessageLookupByLibrary.simpleMessage("Если не указано сколько баллов списать, баллы будут начислены"),
|
"bonus_explanation" : MessageLookupByLibrary.simpleMessage("Если не указано сколько баллов списать, баллы будут начислены"),
|
||||||
"scan" : MessageLookupByLibrary.simpleMessage("Сканировать"),
|
"scan" : MessageLookupByLibrary.simpleMessage("Сканировать"),
|
||||||
"sign_up" : MessageLookupByLibrary.simpleMessage("Зарегистрироваться"),
|
"sign_up" : MessageLookupByLibrary.simpleMessage("Зарегистрироваться"),
|
||||||
|
|||||||
@@ -35,9 +35,7 @@ getDeleteTokenRequest(String token) async {
|
|||||||
await getToken(), headers: {'Accept-Language': Intl.defaultLocale});
|
await getToken(), headers: {'Accept-Language': Intl.defaultLocale});
|
||||||
}
|
}
|
||||||
|
|
||||||
getLoyaltyRequest(String endpoint, SqliteHelper helper) async {
|
getLoyaltyRequest(String endpoint, String token) async {
|
||||||
String token = await helper.getToken();
|
|
||||||
|
|
||||||
var headers = {
|
var headers = {
|
||||||
'DM-Authorization': 'dmapptoken ${await getToken()}',
|
'DM-Authorization': 'dmapptoken ${await getToken()}',
|
||||||
'Authorization': 'dmtoken ${token}',
|
'Authorization': 'dmtoken ${token}',
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext ctx) {
|
Widget build(BuildContext ctx) {
|
||||||
setState(() {
|
setState(() {
|
||||||
requestLoyalty(user['loyalty_url']);
|
requestAsyncData(user);
|
||||||
});
|
});
|
||||||
return getMainWidget();
|
return getMainWidget();
|
||||||
}
|
}
|
||||||
@@ -55,33 +55,51 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
String loyalityType = '';
|
String loyalityType = '';
|
||||||
String loyalty = '';
|
String loyalty = '';
|
||||||
String bonus = '';
|
String bonus = '';
|
||||||
bool dataLoaded = false;
|
List<Map> coupons = [];
|
||||||
|
bool dataRequested = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget getScreenContent() {
|
Widget getScreenContent() {
|
||||||
List<Widget> widgets = [];
|
List<Widget> widgetList = [];
|
||||||
widgets.add(getValueWithDescription(
|
widgetList.add(getValueWithDescription(
|
||||||
StringsLocalization.buyer(),
|
StringsLocalization.buyer(),
|
||||||
user['first_name'] == null ? '' : user['first_name']
|
user['first_name'] == null ? '' : user['first_name']
|
||||||
));
|
));
|
||||||
widgets.add(getValueWithDescription(StringsLocalization.card(), card));
|
widgetList.add(getValueWithDescription(StringsLocalization.card(), card));
|
||||||
|
|
||||||
widgets.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
|
widgetList.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
|
||||||
|
|
||||||
if (bonus.length > 0) {
|
if (bonus.length > 0) {
|
||||||
widgets.add(getValueWithDescription(StringsLocalization.bonus(), bonus));
|
widgetList.add(getValueWithDescription(StringsLocalization.bonus(), bonus));
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets.add(getHintLabel());
|
widgetList.add(getHintLabel());
|
||||||
|
|
||||||
widgets.add(getInputField()); // Нельзя добавить еще одно поле таким же способом
|
widgetList.add(getInputField()); // Нельзя добавить еще одно поле таким же способом
|
||||||
|
|
||||||
if (this.loyalityType == 'bonus') {
|
if (this.loyalityType == 'bonus') {
|
||||||
widgets.add(getBonusInputField());
|
widgetList.add(getBonusInputField());
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets.add(wrapButton(getScreenMargins(36.0), getCompleteButton()));
|
if (this.coupons.length > 0) {
|
||||||
widgets.add(wrapButton(
|
widgetList.add(getItemTitle(StringsLocalization.selectCoupons()));
|
||||||
|
this.coupons.forEach((couponItem) {
|
||||||
|
widgetList.add(getItemToggleSwitch(
|
||||||
|
couponItem['offer_name'],
|
||||||
|
couponItem['coupon_condition'],
|
||||||
|
couponItem['isSet'],
|
||||||
|
(val) {
|
||||||
|
setState(() {
|
||||||
|
couponItem['isSet'] = val;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
widgetList.add(wrapButton(getScreenMargins(36.0), getCompleteButton()));
|
||||||
|
|
||||||
|
widgetList.add(wrapButton(
|
||||||
getScreenMargins(24.0),
|
getScreenMargins(24.0),
|
||||||
getScanButton(
|
getScanButton(
|
||||||
context,
|
context,
|
||||||
@@ -91,7 +109,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
));
|
));
|
||||||
return new Column(children: <Widget>[
|
return new Column(children: <Widget>[
|
||||||
new Expanded(
|
new Expanded(
|
||||||
child: new ListView(children: widgets))
|
child: new ListView(children: widgetList))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,22 +207,37 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestLoyalty(String url) async {
|
requestAsyncData(Map user) async {
|
||||||
bool showBonus = await platform.invokeMethod('showBonus');
|
bool showBonus = await platform.invokeMethod('showBonus');
|
||||||
String flavor = await platform.invokeMethod('getFlavor');
|
String flavor = await platform.invokeMethod('getFlavor');
|
||||||
if (await platform.invokeMethod('isOnline') && !this.dataLoaded) {
|
if (await platform.invokeMethod('isOnline') && !this.dataRequested) {
|
||||||
getLoyaltyRequest(url, helper).then((response) {
|
this.dataRequested = true;
|
||||||
print(response);
|
var response, couponResponse;
|
||||||
this.dataLoaded = true;
|
print(user['coupons_url']);
|
||||||
|
try {
|
||||||
|
var token = await helper.getToken();
|
||||||
|
response = await getLoyaltyRequest(user['loyalty_url'], token);
|
||||||
|
couponResponse = await getCouponsRequest(
|
||||||
|
user['coupons_url'] + '?status=active',
|
||||||
|
token
|
||||||
|
);
|
||||||
|
} catch(error) {
|
||||||
|
print(error.toString());
|
||||||
|
}
|
||||||
Map loyality = JSON.decode(response.body);
|
Map loyality = JSON.decode(response.body);
|
||||||
|
Map coupons = JSON.decode(couponResponse.body);
|
||||||
|
|
||||||
|
coupons['results'].forEach((couponItem) {
|
||||||
|
couponItem['isSet'] = false;
|
||||||
|
});
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
this.flavor = flavor;
|
this.flavor = flavor;
|
||||||
|
this.coupons = coupons['results'];
|
||||||
this.loyalityType = loyality['type'];
|
this.loyalityType = loyality['type'];
|
||||||
setBonuses(loyality, showBonus);
|
setBonuses(loyality, showBonus);
|
||||||
});
|
});
|
||||||
}).catchError((error) {
|
|
||||||
print(error.toString());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,18 +335,30 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
String token = await helper.getToken();
|
String token = await helper.getToken();
|
||||||
var result = await helper.getMerchantID();
|
var result = await helper.getMerchantID();
|
||||||
var currency = await helper.getCurrency();
|
var currency = await helper.getCurrency();
|
||||||
|
var couponIds = [];
|
||||||
|
|
||||||
|
this.coupons.forEach((item) {
|
||||||
|
if (item['isSet'] == true) couponIds.add(item['id']);
|
||||||
|
});
|
||||||
|
|
||||||
|
print(couponIds);
|
||||||
|
|
||||||
var body = {
|
var body = {
|
||||||
'doc_id': result,
|
'doc_id': result,
|
||||||
'curr_iso_code': currency.toString(),
|
'curr_iso_code': currency.toString(),
|
||||||
'commit': 'true',
|
'commit': 'true',
|
||||||
'sum_total': sumTotal
|
'sum_total': sumTotal,
|
||||||
|
// 'coupons': []
|
||||||
};
|
};
|
||||||
|
|
||||||
if (bonusController.text.length > 0) {
|
if (bonusController.text.length > 0) {
|
||||||
body['bonus_payment'] = bonusController.text;
|
body['bonus_payment'] = bonusController.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (couponIds.length > 0) {
|
||||||
|
body['coupons'] = couponIds.join(",");
|
||||||
|
}
|
||||||
|
|
||||||
var purchaseResponse;
|
var purchaseResponse;
|
||||||
Map purchase;
|
Map purchase;
|
||||||
|
|
||||||
|
|||||||
@@ -108,12 +108,13 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
|
|||||||
if (this.coupons.length > 0) {
|
if (this.coupons.length > 0) {
|
||||||
widgetList.add(getItemTitle(StringsLocalization.couponsUsed()));
|
widgetList.add(getItemTitle(StringsLocalization.couponsUsed()));
|
||||||
this.coupons.forEach((couponItem) {
|
this.coupons.forEach((couponItem) {
|
||||||
widgetList.add(getCoupons(couponItem));
|
widgetList.add(getItemToggle(
|
||||||
|
couponItem['offer_name'],
|
||||||
|
couponItem['coupon_condition']
|
||||||
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
widgetList.add(wrapButton(getScreenMargins(174.0), getScanButton()));
|
widgetList.add(wrapButton(getScreenMargins(174.0), getScanButton()));
|
||||||
|
|
||||||
return new ListView.builder(
|
return new ListView.builder(
|
||||||
@@ -140,33 +141,7 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getCoupons(couponItem) {
|
|
||||||
String title = couponItem['offer_name'];
|
|
||||||
if (title.length == 0) {
|
|
||||||
title = couponItem['coupon_condition'].substring(0,30) + " ...";
|
|
||||||
}
|
|
||||||
return new Container(
|
|
||||||
margin: new EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0),
|
|
||||||
child: new Card(
|
|
||||||
child: new ExpansionTile(
|
|
||||||
title: new Text(
|
|
||||||
title,
|
|
||||||
style: Theme.of(context).textTheme.button.copyWith(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: faqTitlesColor
|
|
||||||
)
|
|
||||||
),
|
|
||||||
children: [
|
|
||||||
new Container(
|
|
||||||
margin: new EdgeInsets.only(left: 20.0, right: 20.0),
|
|
||||||
padding: new EdgeInsets.only(top: 0.0, bottom: 10.0),
|
|
||||||
child: new Text(couponItem['coupon_condition']),
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
getSuccessMessage() {
|
getSuccessMessage() {
|
||||||
return new Row(
|
return new Row(
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ class StringsLocalization {
|
|||||||
static String sum() => Intl.message('sum', name: 'sum', locale: Intl.defaultLocale);
|
static String sum() => Intl.message('sum', name: 'sum', locale: Intl.defaultLocale);
|
||||||
static String bonus() => Intl.message('bonus', name: 'bonus', locale: Intl.defaultLocale);
|
static String bonus() => Intl.message('bonus', name: 'bonus', locale: Intl.defaultLocale);
|
||||||
static String couponsUsed() => Intl.message('coupons_used', name: 'coupons_used', locale: Intl.defaultLocale);
|
static String couponsUsed() => Intl.message('coupons_used', name: 'coupons_used', locale: Intl.defaultLocale);
|
||||||
|
static String selectCoupons() => Intl.message('select_coupons', name: 'select_coupons', locale: Intl.defaultLocale);
|
||||||
static String carryingPurchase() => Intl.message('carry_purchase', name: 'carry_purchase', locale: Intl.defaultLocale);
|
static String carryingPurchase() => Intl.message('carry_purchase', name: 'carry_purchase', locale: Intl.defaultLocale);
|
||||||
static String completePurchase() => Intl.message('complite_purchase', name: 'complite_purchase', locale: Intl.defaultLocale);
|
static String completePurchase() => Intl.message('complite_purchase', name: 'complite_purchase', locale: Intl.defaultLocale);
|
||||||
static String scan() => Intl.message('scan', name: 'scan', locale: Intl.defaultLocale);
|
static String scan() => Intl.message('scan', name: 'scan', locale: Intl.defaultLocale);
|
||||||
|
|||||||
Reference in New Issue
Block a user