You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
213 lines
6.9 KiB
Dart
213 lines
6.9 KiB
Dart
import 'package:car_customer_app/repositories/provider_repo.dart';
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
import 'package:mc_common_app/models/appointments_models/appointment_list_model.dart';
|
|
import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart';
|
|
import 'package:mc_common_app/models/provider_branches_models/provider_profile_model.dart';
|
|
import 'package:mc_common_app/models/services/item_model.dart';
|
|
import 'package:mc_common_app/models/services/service_model.dart';
|
|
import 'package:mc_common_app/models/widgets_models.dart';
|
|
import 'package:mc_common_app/repositories/common_repo.dart';
|
|
import 'package:mc_common_app/services/common_services.dart';
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
import 'package:mc_common_app/view_models/base_view_model.dart';
|
|
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
|
|
class AppointmentsVM extends BaseVM {
|
|
final CommonRepo commonRepo;
|
|
final CommonAppServices commonServices;
|
|
final ProviderRepo providerRepo;
|
|
|
|
AppointmentsVM({required this.commonServices, required this.providerRepo, required this.commonRepo});
|
|
|
|
bool isFetchingLists = false;
|
|
|
|
List<AppointmentListModel> myAppointments = [];
|
|
List<FilterListModel> appointmentsFilterOptions = [];
|
|
|
|
bool isFetchingServices = false;
|
|
|
|
List<DropValue> branchCategories = [];
|
|
|
|
bool isHomeTapped = false;
|
|
|
|
void updateIsHomeTapped(bool value) {
|
|
isHomeTapped = value;
|
|
notifyListeners();
|
|
}
|
|
|
|
String pickedHomeLocation = "";
|
|
|
|
void updatePickedHomeLocation(String value) {
|
|
pickedHomeLocation = value;
|
|
notifyListeners();
|
|
}
|
|
|
|
SelectionModel branchSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
void updateProviderCategoryId(SelectionModel id) async {
|
|
branchSelectedCategoryId = id;
|
|
await getProviderServices(id.selectedId);
|
|
notifyListeners();
|
|
}
|
|
|
|
List<ServiceModel> branchServices = [];
|
|
|
|
SelectionModel branchSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
void updateBranchServiceId(SelectionModel id) async {
|
|
branchSelectedServiceId = id;
|
|
notifyListeners();
|
|
}
|
|
|
|
getProviderServices(int categoryId) async {
|
|
branchSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
isHomeTapped = false;
|
|
pickedHomeLocation = "";
|
|
if (categoryId != -1) {
|
|
isFetchingServices = true;
|
|
notifyListeners();
|
|
// branchServices = await commonRepo.getProviderServices(categoryId: categoryId);
|
|
isFetchingServices = false;
|
|
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
populateAppointmentsFilterList() {
|
|
appointmentsFilterOptions.clear();
|
|
appointmentsFilterOptions = [
|
|
FilterListModel(title: "All Appointments", isSelected: true, id: -1),
|
|
FilterListModel(title: "Booked", isSelected: false, id: 1),
|
|
FilterListModel(title: "Confirmed", isSelected: false, id: 2),
|
|
FilterListModel(title: "Arrived", isSelected: false, id: 3),
|
|
FilterListModel(title: "Cancelled", isSelected: false, id: 4),
|
|
];
|
|
notifyListeners();
|
|
}
|
|
|
|
applyFilterOnAppointmentsVM({required int index}) {
|
|
if (appointmentsFilterOptions.isEmpty) return;
|
|
for (var value in appointmentsFilterOptions) {
|
|
value.isSelected = false;
|
|
}
|
|
appointmentsFilterOptions[index].isSelected = true;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> getMyAppointments() async {
|
|
isFetchingLists = true;
|
|
myAppointments = await commonRepo.getMyAppointments();
|
|
isFetchingLists = false;
|
|
notifyListeners();
|
|
}
|
|
|
|
List<FilterListModel> providersFilterOptions = [];
|
|
List<BranchDetailModel> nearbyBranches = [];
|
|
List<ServiceItemModel> serviceItems = [];
|
|
ProviderProfileModel? providerProfileModel;
|
|
|
|
populateProvidersFilterList() {
|
|
providersFilterOptions.clear();
|
|
providersFilterOptions = [
|
|
FilterListModel(title: "All Providers", isSelected: true, id: -1),
|
|
FilterListModel(title: "Maintenance", isSelected: false, id: 0),
|
|
FilterListModel(title: "Oil Service", isSelected: false, id: 1),
|
|
FilterListModel(title: "Accessories", isSelected: false, id: 2),
|
|
FilterListModel(title: "Tire Service", isSelected: false, id: 3),
|
|
FilterListModel(title: "Dent and Paint", isSelected: false, id: 4),
|
|
];
|
|
notifyListeners();
|
|
}
|
|
|
|
applyFilterOnProviders({required int index}) {
|
|
if (providersFilterOptions.isEmpty) return;
|
|
for (var value in providersFilterOptions) {
|
|
value.isSelected = false;
|
|
}
|
|
providersFilterOptions[index].isSelected = true;
|
|
notifyListeners();
|
|
}
|
|
|
|
//Create new branch
|
|
getAllNearBranches({bool isNeedToRebuild = false}) async {
|
|
//TODO: needs to lat,long into API
|
|
nearbyBranches.clear();
|
|
if (isNeedToRebuild) setState(ViewState.busy);
|
|
nearbyBranches = await providerRepo.getAllNearBranchAndServices();
|
|
setState(ViewState.idle);
|
|
}
|
|
|
|
Future<List<ServiceItemModel>> getServiceItems(int serviceId) async {
|
|
serviceItems.clear();
|
|
serviceItems = await providerRepo.getServiceItems(serviceId);
|
|
setState(ViewState.idle);
|
|
return serviceItems;
|
|
}
|
|
|
|
getBranchAndServices(int providerId) async {
|
|
providerProfileModel = null;
|
|
providerProfileModel = await providerRepo.getBranchAndServices(providerId);
|
|
setState(ViewState.idle);
|
|
}
|
|
|
|
String pickHomeLocationError = "";
|
|
|
|
SelectionModel branchServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
bool isCategoryAlreadyPresent(int id) {
|
|
final contain = branchCategories.where((element) => element.id == id);
|
|
if (contain.isEmpty) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void getBranchCategories() async {
|
|
for (var value in branchServices) {
|
|
if (!isCategoryAlreadyPresent(value.categoryId!)) {
|
|
branchCategories.add(DropValue(value.categoryId!, value.categoryName!, ""));
|
|
}
|
|
}
|
|
notifyListeners();
|
|
}
|
|
|
|
getBranchServices(int categoryId) async {
|
|
branchServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
isHomeTapped = false;
|
|
pickedHomeLocation = "";
|
|
pickHomeLocationError = "";
|
|
if (categoryId != -1) {
|
|
isFetchingServices = true;
|
|
notifyListeners();
|
|
branchServices = getFilteredBranchServices(categoryId: categoryId, branchId: 6);
|
|
isFetchingServices = false;
|
|
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
List<ServiceModel> getFilteredBranchServices({required int branchId, required int categoryId}) {
|
|
// List<BranchServices> filteredServices = nearbyBranchesList.where((element) => element)
|
|
return [];
|
|
}
|
|
|
|
void updatePickHomeLocationError(String value) {
|
|
pickHomeLocationError = value;
|
|
notifyListeners();
|
|
}
|
|
|
|
bool isServiceSelectionValidated() {
|
|
if (branchServiceId.selectedId == -1) {
|
|
return false;
|
|
}
|
|
|
|
if (isHomeTapped) {
|
|
if (pickedHomeLocation == "") {
|
|
updatePickHomeLocationError(GlobalConsts.homeLocationEmptyError);
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|