|
|
|
|
@ -3,6 +3,7 @@ import 'dart:developer';
|
|
|
|
|
import 'package:car_provider_app/main.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
|
|
|
|
import 'package:mc_common_app/models/appointments_models/appointment_basic_detail_model.dart';
|
|
|
|
|
import 'package:mc_common_app/models/general_models/generic_resp_model.dart';
|
|
|
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
|
|
|
import 'package:mc_common_app/view_models/service_view_model.dart';
|
|
|
|
|
@ -49,14 +50,13 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
DropValue? service;
|
|
|
|
|
|
|
|
|
|
bool isEditDisabled = false;
|
|
|
|
|
bool isServiceActive = true;
|
|
|
|
|
bool isServiceActive = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
scheduleMicrotask(() async {
|
|
|
|
|
ServiceVM serviceVM = context.read<ServiceVM>();
|
|
|
|
|
log("widget.branchModel!.categoryId: ${widget.branchModel!.categoryId}");
|
|
|
|
|
if (widget.branchModel!.categoryId != null) {
|
|
|
|
|
await serviceVM.fetchServicesByCategoryId(int.parse(widget.branchModel!.categoryId ?? "0"));
|
|
|
|
|
category = DropValue(int.parse(widget.branchModel!.categoryId ?? "0"), widget.branchModel!.categoryName ?? "", "");
|
|
|
|
|
@ -64,7 +64,7 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
isAppointmentAvailable = widget.branchModel?.serviceProviderService?.isAllowAppointment ?? false;
|
|
|
|
|
serviceRage = widget.branchModel?.serviceProviderService?.customerLocationRange ?? 0;
|
|
|
|
|
serviceStatusEnum = widget.branchModel?.serviceProviderService?.serviceStatusEnum ?? ServiceStatusEnum.pending;
|
|
|
|
|
isServiceActive = widget.branchModel?.serviceProviderService?.isActive ?? true;
|
|
|
|
|
isServiceActive = widget.branchModel?.serviceProviderService?.serviceStatusEnum != ServiceStatusEnum.deactivated;
|
|
|
|
|
isEditDisabled = serviceStatusEnum == ServiceStatusEnum.blocked;
|
|
|
|
|
if (serviceRage > 0) {
|
|
|
|
|
isHomeAppointmentAvailable = true;
|
|
|
|
|
@ -86,7 +86,7 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height: double.infinity,
|
|
|
|
|
child: Consumer<ServiceVM>(
|
|
|
|
|
builder: (context, model, _) {
|
|
|
|
|
builder: (context, serviceVM, _) {
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
@ -104,10 +104,10 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
serviceId = -1;
|
|
|
|
|
isAppointmentAvailable = false;
|
|
|
|
|
isHomeAppointmentAvailable = false;
|
|
|
|
|
model.fetchServicesByCategoryId(value.id);
|
|
|
|
|
serviceVM.fetchServicesByCategoryId(value.id);
|
|
|
|
|
},
|
|
|
|
|
dropdownValue: category,
|
|
|
|
|
list: model.categoryDropList,
|
|
|
|
|
list: serviceVM.categoryDropList,
|
|
|
|
|
hint: category != null ? category!.value : LocaleKeys.selectServiceCategory.tr(),
|
|
|
|
|
),
|
|
|
|
|
if (widget.branchModel!.isForEdit) ...[
|
|
|
|
|
@ -133,9 +133,10 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
trackColor: MyColors.white,
|
|
|
|
|
thumbColor: MyColors.greyACColor,
|
|
|
|
|
value: isServiceActive,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
onChanged: (value) async {
|
|
|
|
|
if (isEditDisabled) return;
|
|
|
|
|
isServiceActive = value;
|
|
|
|
|
|
|
|
|
|
isServiceActive = await updateServiceStatus(context, value);
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
@ -147,23 +148,23 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
] else ...[
|
|
|
|
|
12.height,
|
|
|
|
|
],
|
|
|
|
|
(model.state == ViewState.idle)
|
|
|
|
|
? categoryId != -1 && model.servicesDropList.isNotEmpty
|
|
|
|
|
(serviceVM.state == ViewState.idle)
|
|
|
|
|
? categoryId != -1 && serviceVM.servicesDropList.isNotEmpty
|
|
|
|
|
? DropdownField(
|
|
|
|
|
(DropValue value) {
|
|
|
|
|
service = value;
|
|
|
|
|
serviceId = value.id;
|
|
|
|
|
isAppointmentAvailable = false;
|
|
|
|
|
isHomeAppointmentAvailable = false;
|
|
|
|
|
model.setState(ViewState.idle);
|
|
|
|
|
serviceVM.setState(ViewState.idle);
|
|
|
|
|
},
|
|
|
|
|
dropdownValue: service,
|
|
|
|
|
list: model.servicesDropList,
|
|
|
|
|
list: serviceVM.servicesDropList,
|
|
|
|
|
hint: LocaleKeys.defineServices.tr(),
|
|
|
|
|
)
|
|
|
|
|
: categoryId == -1
|
|
|
|
|
? const SizedBox()
|
|
|
|
|
: model.state == ViewState.idle
|
|
|
|
|
: serviceVM.state == ViewState.idle
|
|
|
|
|
? EmptyWidget(text: LocaleKeys.noServicesAvailable.tr())
|
|
|
|
|
: const SizedBox()
|
|
|
|
|
: const CircularProgressIndicator(),
|
|
|
|
|
@ -182,7 +183,7 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
if (!isAppointmentAvailable) {
|
|
|
|
|
isHomeAppointmentAvailable = false;
|
|
|
|
|
}
|
|
|
|
|
model.setState(ViewState.idle);
|
|
|
|
|
serviceVM.setState(ViewState.idle);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
20.height,
|
|
|
|
|
@ -197,7 +198,7 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
if (isHomeAppointmentAvailable && !isAppointmentAvailable) {
|
|
|
|
|
isAppointmentAvailable = true;
|
|
|
|
|
}
|
|
|
|
|
model.setState(ViewState.idle);
|
|
|
|
|
serviceVM.setState(ViewState.idle);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
20.height,
|
|
|
|
|
@ -265,10 +266,10 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
margin: const EdgeInsets.all(20),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
if (widget.branchModel!.serviceProviderService != null) {
|
|
|
|
|
updateService(context, model);
|
|
|
|
|
updateService(context, serviceVM);
|
|
|
|
|
} else {
|
|
|
|
|
if (model.services != null) {
|
|
|
|
|
createService(context, model);
|
|
|
|
|
if (serviceVM.services != null) {
|
|
|
|
|
createService(context, serviceVM);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
@ -338,7 +339,7 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
{
|
|
|
|
|
"id": widget.branchModel!.serviceProviderService!.serviceProviderServiceId.toString(),
|
|
|
|
|
"isAllowAppointment": isAppointmentAvailable,
|
|
|
|
|
"isActive": isServiceActive,
|
|
|
|
|
"isActive": true,
|
|
|
|
|
"customerLocationRange": serviceRage,
|
|
|
|
|
"rangePricePerKm": chargersPerKm.isEmpty ? "0.0" : chargersPerKm,
|
|
|
|
|
}
|
|
|
|
|
@ -348,21 +349,70 @@ class _CreateServicesPage3State extends State<CreateServicesPage3> {
|
|
|
|
|
{
|
|
|
|
|
"id": widget.branchModel!.serviceProviderService!.serviceProviderServiceId.toString(),
|
|
|
|
|
"isAllowAppointment": isAppointmentAvailable,
|
|
|
|
|
"isActive": isServiceActive,
|
|
|
|
|
"isActive": true,
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// print(map);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
GenericRespModel mResponse = await model.updateServices(map);
|
|
|
|
|
model.getBranchAndServices();
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.showToast(mResponse.message ?? "");
|
|
|
|
|
if (mResponse.messageStatus == 1) {
|
|
|
|
|
context.read<ServiceVM>().filterUserBranchCategories();
|
|
|
|
|
context.read<ServiceVM>().isNeedRefreshServicesList = true;
|
|
|
|
|
pop(context);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
log(e.toString());
|
|
|
|
|
Utils.showToast(e.toString() ?? "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// print(map);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
GenericRespModel mResponse = await model.updateServices(map);
|
|
|
|
|
model.getBranchAndServices();
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.showToast(mResponse.message ?? "");
|
|
|
|
|
if (mResponse.messageStatus == 1) {
|
|
|
|
|
context.read<ServiceVM>().filterUserBranchCategories();
|
|
|
|
|
context.read<ServiceVM>().isNeedRefreshServicesList = true;
|
|
|
|
|
pop(context);
|
|
|
|
|
Future<bool> updateServiceStatus(BuildContext context, bool value) async {
|
|
|
|
|
List<Map<String, dynamic>> map = [
|
|
|
|
|
{
|
|
|
|
|
"id": widget.branchModel!.serviceProviderService!.serviceProviderServiceId.toString(),
|
|
|
|
|
"isActive": true,
|
|
|
|
|
|
|
|
|
|
//TODO: ZAHOOR WILL ADD SERVICE STATUS HERE TO UPDATE
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
try {
|
|
|
|
|
final serviceVM = context.read<ServiceVM>();
|
|
|
|
|
List<AppointmentBasicDetailsModel> list = await serviceVM.getAppointmentsByServiceID(
|
|
|
|
|
context: context,
|
|
|
|
|
branchId: int.parse(widget.branchModel!.branchId),
|
|
|
|
|
serviceId: widget.branchModel!.serviceProviderService!.serviceProviderServiceId!,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
List<int> providerServiceIds = [];
|
|
|
|
|
providerServiceIds.add(widget.branchModel!.serviceProviderService!.serviceProviderServiceId!);
|
|
|
|
|
if (list.isEmpty) {
|
|
|
|
|
bool status = await serviceVM.updateServiceStatus(
|
|
|
|
|
context: context,
|
|
|
|
|
serviceStatusEnum: ServiceStatusEnum.deactivated,
|
|
|
|
|
branchId: int.parse(widget.branchModel!.branchId),
|
|
|
|
|
providerServiceIds: providerServiceIds,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return !status;
|
|
|
|
|
} else {
|
|
|
|
|
serviceVM.buildDealNotCompletedBottomSheetOptions(
|
|
|
|
|
mainContext: context,
|
|
|
|
|
appointments: list,
|
|
|
|
|
branchName: widget.branchModel!.branchName,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
log(e.toString());
|
|
|
|
|
Utils.showToast(e.toString() ?? "");
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|