|
|
|
|
@ -9,6 +9,8 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/order_detail.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/model/pharmacies/payment-checkout-data.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/service/parmacyModule/order-preview-service.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/navigation_service.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../locator.dart';
|
|
|
|
|
import '../base_view_model.dart';
|
|
|
|
|
@ -17,12 +19,14 @@ class OrderPreviewViewModel extends BaseViewModel {
|
|
|
|
|
OrderPreviewService _orderService = locator<OrderPreviewService>();
|
|
|
|
|
|
|
|
|
|
List<Addresses> get addresses => _orderService.addresses;
|
|
|
|
|
|
|
|
|
|
LacumAccountInformation get lacumInformation =>
|
|
|
|
|
_orderService.lacumInformation;
|
|
|
|
|
|
|
|
|
|
List<OrderDetailModel> get orderListModel => _orderService.orderList;
|
|
|
|
|
|
|
|
|
|
PharmacyModuleViewModel pharmacyModuleViewModel =
|
|
|
|
|
locator<PharmacyModuleViewModel>();
|
|
|
|
|
locator<PharmacyModuleViewModel>();
|
|
|
|
|
|
|
|
|
|
ShoppingCartResponse cartResponse = ShoppingCartResponse();
|
|
|
|
|
PaymentCheckoutData paymentCheckoutData = PaymentCheckoutData();
|
|
|
|
|
@ -38,24 +42,31 @@ class OrderPreviewViewModel extends BaseViewModel {
|
|
|
|
|
getShoppingCart();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void update(){
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
Future getShoppingCart() async {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
// setState(ViewState.Busy);
|
|
|
|
|
// GifLoaderDialogUtils.showMyDialog(
|
|
|
|
|
// locator<NavigationService>().navigatorKey.currentContext);
|
|
|
|
|
await _orderService.getShoppingCart().then((res) {
|
|
|
|
|
_handleGetShoppingCartResponse(res);
|
|
|
|
|
if (res != null) _handleGetShoppingCartResponse(res);
|
|
|
|
|
});
|
|
|
|
|
if (_orderService.hasError) {
|
|
|
|
|
error = _orderService.error;
|
|
|
|
|
setState(ViewState.Error);
|
|
|
|
|
// setState(ViewState.Error);
|
|
|
|
|
} else {
|
|
|
|
|
if (paymentCheckoutData != null) {
|
|
|
|
|
paymentCheckoutData.cartDataVisible = true;
|
|
|
|
|
}
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
// GifLoaderDialogUtils.hideDialog(
|
|
|
|
|
// locator<NavigationService>().navigatorKey.currentContext);
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future <ShoppingCartResponse> changeProductQuantity(ShoppingCart product) async {
|
|
|
|
|
Future<ShoppingCartResponse> changeProductQuantity(
|
|
|
|
|
ShoppingCart product) async {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
var resp = await _orderService.changeProductQuantity(product.id, product);
|
|
|
|
|
var object = _handleGetShoppingCartResponse(resp);
|
|
|
|
|
@ -112,7 +123,8 @@ class OrderPreviewViewModel extends BaseViewModel {
|
|
|
|
|
res["shopping_carts"].forEach((item) {
|
|
|
|
|
ShoppingCart shoppingCart = ShoppingCart.fromJson(item);
|
|
|
|
|
cartResponse.shoppingCarts.add(shoppingCart);
|
|
|
|
|
totalAdditionalShippingCharge += shoppingCart.product.additionalShippingCharge;
|
|
|
|
|
totalAdditionalShippingCharge +=
|
|
|
|
|
shoppingCart.product.additionalShippingCharge;
|
|
|
|
|
});
|
|
|
|
|
return cartResponse;
|
|
|
|
|
}
|
|
|
|
|
@ -164,7 +176,8 @@ class OrderPreviewViewModel extends BaseViewModel {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
await _orderService.getLacumGroupInformation();
|
|
|
|
|
paymentCheckoutData.lacumInformation = _orderService.lacumGroupInformation;
|
|
|
|
|
paymentCheckoutData.usedLakumPoints = paymentCheckoutData.lacumInformation.lakumInquiryInformationObjVersion.pointsBalanceAmount;
|
|
|
|
|
paymentCheckoutData.usedLakumPoints = paymentCheckoutData
|
|
|
|
|
.lacumInformation.lakumInquiryInformationObjVersion.pointsBalanceAmount;
|
|
|
|
|
if (_orderService.hasError) {
|
|
|
|
|
error = _orderService.error;
|
|
|
|
|
setState(ViewState.Error);
|
|
|
|
|
@ -175,8 +188,10 @@ class OrderPreviewViewModel extends BaseViewModel {
|
|
|
|
|
|
|
|
|
|
getShippingOption() async {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
await _orderService.getShippingOption(paymentCheckoutData.address).then((res) {
|
|
|
|
|
paymentCheckoutData.shippingOption = ShippingOption.fromJson(res);
|
|
|
|
|
await _orderService
|
|
|
|
|
.getShippingOption(paymentCheckoutData.address)
|
|
|
|
|
.then((res) {
|
|
|
|
|
paymentCheckoutData.shippingOption = ShippingOption.fromJson(res);
|
|
|
|
|
paymentCheckoutData.updateData();
|
|
|
|
|
});
|
|
|
|
|
if (_orderService.hasError) {
|
|
|
|
|
@ -191,7 +206,8 @@ class OrderPreviewViewModel extends BaseViewModel {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
await pharmacyModuleViewModel.generatePharmacyToken();
|
|
|
|
|
|
|
|
|
|
await _orderService.makeOrder(paymentCheckoutData, cartResponse.shoppingCarts);
|
|
|
|
|
await _orderService.makeOrder(
|
|
|
|
|
paymentCheckoutData, cartResponse.shoppingCarts);
|
|
|
|
|
if (_orderService.hasError) {
|
|
|
|
|
error = _orderService.error;
|
|
|
|
|
setState(ViewState.ErrorLocal);
|
|
|
|
|
|