|
|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
|
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
|
|
|
@ -44,7 +44,6 @@ import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/txt_field.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
|
|
|
|
|
class AppointmentsVM extends BaseVM {
|
|
|
|
|
final CommonRepo commonRepo;
|
|
|
|
|
@ -660,10 +659,10 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<List<ItemData>> getServiceItems(int serviceId) async {
|
|
|
|
|
Future<List<ItemData>> getServiceItems({required int serviceId}) async {
|
|
|
|
|
setState(ViewState.busy);
|
|
|
|
|
serviceItemsFromApi.clear();
|
|
|
|
|
serviceItemsFromApi = await branchRepo.getServiceItems(serviceId);
|
|
|
|
|
serviceItemsFromApi = await branchRepo.getServiceItems(serviceId: serviceId);
|
|
|
|
|
selectedSubServicesCounter = 0;
|
|
|
|
|
for (var item in serviceItemsFromApi) {
|
|
|
|
|
if (ifItemAlreadySelected(item.id!)) {
|
|
|
|
|
@ -1301,8 +1300,9 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DropValue> categoryDropList = [];
|
|
|
|
|
List<DropValue> servicesDropList = [];
|
|
|
|
|
List<DropValue> providersDropList = [];
|
|
|
|
|
List<DropValue> servicesDropList = [];
|
|
|
|
|
List<DropValue> itemsDropList = [];
|
|
|
|
|
|
|
|
|
|
Future<void> fetchAllProviders() async {
|
|
|
|
|
if (providersDropList.isNotEmpty) return;
|
|
|
|
|
@ -1349,10 +1349,30 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> fetchAllItems() async {
|
|
|
|
|
if (itemsDropList.isNotEmpty) return;
|
|
|
|
|
itemsDropList.clear();
|
|
|
|
|
setState(ViewState.busy);
|
|
|
|
|
List<ItemData> itemsList = await branchRepo.getServiceItems(serviceId: -1); // to get all services
|
|
|
|
|
|
|
|
|
|
for (ItemData element in itemsList) {
|
|
|
|
|
if (element.name != null && element.name!.isNotEmpty) {
|
|
|
|
|
itemsDropList.add(
|
|
|
|
|
DropValue(
|
|
|
|
|
element.id ?? 0,
|
|
|
|
|
element.name ?? "",
|
|
|
|
|
"",
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> populateDataForBranchesFilter() async {
|
|
|
|
|
await fetchAllProviders(); // saudi arabia
|
|
|
|
|
await fetchAllCategories(); // saudi arabia
|
|
|
|
|
await fetchAllServices(); // saudi arabia
|
|
|
|
|
await fetchAllProviders();
|
|
|
|
|
await fetchAllCategories();
|
|
|
|
|
await fetchAllServices();
|
|
|
|
|
updateBranchFilterCurrentDistance(25.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1446,6 +1466,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
await fetchAllProviders();
|
|
|
|
|
await fetchAllCategories();
|
|
|
|
|
await fetchAllServices();
|
|
|
|
|
await fetchAllItems();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int appointmentFiltersCounter = 0;
|
|
|
|
|
@ -1621,14 +1642,53 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DropValue> appointmentFilterItemsSearchHistory = [];
|
|
|
|
|
|
|
|
|
|
void removeAppointmentFilterItemsSearchHistory({bool isClear = false, required int index}) {
|
|
|
|
|
if (isClear) {
|
|
|
|
|
appointmentFilterItemsSearchHistory.clear();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
appointmentFilterItemsSearchHistory.removeAt(index);
|
|
|
|
|
if (appointmentFilterItemsSearchHistory.isEmpty) {
|
|
|
|
|
updateAppointmentFiltersCounter(appointmentFiltersCounter - 1);
|
|
|
|
|
// appointmentFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addAppointmentFilterItemsSearchHistory({required DropValue value}) {
|
|
|
|
|
if (appointmentFilterItemsSearchHistory.isEmpty) {
|
|
|
|
|
updateAppointmentFiltersCounter(appointmentFiltersCounter + 1);
|
|
|
|
|
}
|
|
|
|
|
appointmentFilterItemsSearchHistory.add(value);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectionModel appointmentFilterSelectedItemId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
|
|
|
|
|
void updateAppointmentFilterSelectedItemId(SelectionModel id, {bool isForSearch = false}) async {
|
|
|
|
|
if (isForSearch) {
|
|
|
|
|
DropValue itemsDrop = itemsDropList.firstWhere((element) => element.id == id.selectedId);
|
|
|
|
|
if (!ifAlreadyExist(list: appointmentFilterItemsSearchHistory, value: itemsDrop)) {
|
|
|
|
|
addAppointmentFilterItemsSearchHistory(value: itemsDrop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// appointmentFilterSelectedServiceId = id;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearAppointmentFilterSelections() {
|
|
|
|
|
appointmentFilterSelectedProviderId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
appointmentFilterSelectedCategoryId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
appointmentFilterSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
appointmentFilterSelectedItemId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
appointmentFilterSelectedBranchId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearAppointmentFilters() {
|
|
|
|
|
appointmentFilterItemsSearchHistory.clear();
|
|
|
|
|
appointmentFilterServicesSearchHistory.clear();
|
|
|
|
|
appointmentFilterCategorySearchHistory.clear();
|
|
|
|
|
appointmentFilterProviderSearchHistory.clear();
|
|
|
|
|
@ -1659,6 +1719,12 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
servicesIdsList.add(element.id.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<String> itemIdsList = [];
|
|
|
|
|
if (appointmentFilterItemsSearchHistory.isNotEmpty) {
|
|
|
|
|
for (var element in appointmentFilterItemsSearchHistory) {
|
|
|
|
|
itemIdsList.add(element.id.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<String> branchesIdsList = [];
|
|
|
|
|
if (appointmentFilterBranchSearchHistory.isNotEmpty) {
|
|
|
|
|
for (var element in appointmentFilterBranchSearchHistory) {
|
|
|
|
|
@ -1670,6 +1736,7 @@ class AppointmentsVM extends BaseVM {
|
|
|
|
|
providerIdsList: providersIdsList,
|
|
|
|
|
categoryIdsList: categoryIdsList,
|
|
|
|
|
serviceIdsList: servicesIdsList,
|
|
|
|
|
itemIdsList: itemIdsList,
|
|
|
|
|
branchIdsList: branchesIdsList,
|
|
|
|
|
);
|
|
|
|
|
applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments);
|
|
|
|
|
|