|
|
|
|
@ -44,7 +44,7 @@ class AdVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
AdVM({required this.commonServices, required this.commonRepo, required this.adsRepo});
|
|
|
|
|
|
|
|
|
|
AdCreationSteps currentProgressStep = AdCreationSteps.vehicleDetails;
|
|
|
|
|
AdCreationStepsEnum currentProgressStep = AdCreationStepsEnum.vehicleDetails;
|
|
|
|
|
|
|
|
|
|
VehicleDetailsModel? vehicleDetails;
|
|
|
|
|
|
|
|
|
|
@ -82,6 +82,7 @@ class AdVM extends BaseVM {
|
|
|
|
|
// Edit Variables Amir
|
|
|
|
|
bool isExtendAdEditEnabled = false;
|
|
|
|
|
bool isAdEditEnabled = false;
|
|
|
|
|
bool isDraftEditEnabled = false;
|
|
|
|
|
AdDetailsModel? previousAdDetails;
|
|
|
|
|
|
|
|
|
|
List<AdDetailsModel> myDraftAds = [];
|
|
|
|
|
@ -347,15 +348,20 @@ class AdVM extends BaseVM {
|
|
|
|
|
int pageIndexForMyDrafts = 1;
|
|
|
|
|
|
|
|
|
|
Future<void> getMyDraftAds() async {
|
|
|
|
|
pageIndexForMyAds = 1;
|
|
|
|
|
hasMoreDataForMyAds = true;
|
|
|
|
|
setState(ViewState.busy);
|
|
|
|
|
myDraftAds = await adsRepo.getMyDraftAds();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
try {
|
|
|
|
|
pageIndexForMyAds = 1;
|
|
|
|
|
hasMoreDataForMyAds = true;
|
|
|
|
|
setState(ViewState.busy);
|
|
|
|
|
myDraftAds = await adsRepo.getMyDraftAds();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
logger.e(e.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> fetchMoreDraftAds({required AdPostStatus adsStatus}) async {
|
|
|
|
|
Future<void> fetchMoreDraftAds() async {
|
|
|
|
|
if (isLoadingMore) return;
|
|
|
|
|
hasMoreDataForMyDraftsAds = true;
|
|
|
|
|
isLoadingMore = true;
|
|
|
|
|
@ -1213,64 +1219,167 @@ class AdVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
void onBackButtonPressed(BuildContext context) {
|
|
|
|
|
switch (currentProgressStep) {
|
|
|
|
|
case AdCreationSteps.vehicleDetails:
|
|
|
|
|
case AdCreationStepsEnum.vehicleDetails:
|
|
|
|
|
isAdEditEnabled = false;
|
|
|
|
|
isDraftEditEnabled = false;
|
|
|
|
|
resetValues();
|
|
|
|
|
pop(context);
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.damageParts:
|
|
|
|
|
currentProgressStep = AdCreationSteps.vehicleDetails;
|
|
|
|
|
case AdCreationStepsEnum.damageParts:
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.vehicleDetails;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.adDuration:
|
|
|
|
|
currentProgressStep = AdCreationSteps.damageParts;
|
|
|
|
|
case AdCreationStepsEnum.adDuration:
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.damageParts;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.reviewAd:
|
|
|
|
|
currentProgressStep = AdCreationSteps.adDuration;
|
|
|
|
|
case AdCreationStepsEnum.reviewAd:
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.adDuration;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<int> saveAdVehicleDetailsDraft({required bool isNew, required BuildContext context, required AdCreationStepsEnum stepNoEnum}) async {
|
|
|
|
|
AppState appState = injector.get<AppState>();
|
|
|
|
|
|
|
|
|
|
log("selectionDurationStartDate: $selectionDurationStartDate");
|
|
|
|
|
log("specialServiceCards: ${specialServiceCards.length}");
|
|
|
|
|
|
|
|
|
|
List<int> adsSelectedServices = [];
|
|
|
|
|
|
|
|
|
|
for (var value in specialServiceCards) {
|
|
|
|
|
adsSelectedServices.add(value.serviceSelectedId!.selectedId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
Ads ads = Ads(
|
|
|
|
|
id: !isNew ? previousAdDetails!.id : 0,
|
|
|
|
|
adsDurationID: vehicleAdDurationId.selectedId == -1 ? 0 : vehicleAdDurationId.selectedId,
|
|
|
|
|
startDate: selectionDurationStartDate,
|
|
|
|
|
countryId: vehicleCountryId.selectedId,
|
|
|
|
|
specialServiceIDs: adsSelectedServices,
|
|
|
|
|
showContactDetail: isPhoneNumberShown,
|
|
|
|
|
isOnWhatsApp: isNumberOnWhatsApp,
|
|
|
|
|
);
|
|
|
|
|
List<VehiclePostingImages> vehicleImages = [];
|
|
|
|
|
|
|
|
|
|
for (var image in pickedPostingImages) {
|
|
|
|
|
vehicleImages.add(await convertFileToVehiclePostingImages(imageModel: image));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<VehiclePostingDamageParts> vehicleDamageImages = [];
|
|
|
|
|
|
|
|
|
|
for (var card in vehicleDamageCards) {
|
|
|
|
|
if (card.partImages != null && card.partImages!.isNotEmpty) {
|
|
|
|
|
for (var image in card.partImages!) {
|
|
|
|
|
VehiclePostingDamageParts stringImage = await convertFileToVehiclePostingDamageParts(
|
|
|
|
|
imageModel: image,
|
|
|
|
|
damagePartId: card.partSelectedId!.selectedId,
|
|
|
|
|
commentParam: card.damagePartDescription ?? "",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
vehicleDamageImages.add(stringImage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VehiclePosting vehiclePosting = VehiclePosting(
|
|
|
|
|
id: !isNew ? previousAdDetails!.vehiclePostingID : null,
|
|
|
|
|
userID: appState.getUser.data!.userInfo!.userId,
|
|
|
|
|
vehicleType: vehicleTypeId.selectedId,
|
|
|
|
|
vehicleModelID: vehicleModelId.selectedId,
|
|
|
|
|
vehicleModelYearID: vehicleModelYearId.selectedId,
|
|
|
|
|
vehicleColorID: vehicleColorId.selectedId,
|
|
|
|
|
vehicleCategoryID: vehicleCategoryId.selectedId,
|
|
|
|
|
vehicleConditionID: vehicleConditionId.selectedId,
|
|
|
|
|
vehicleMileageID: vehicleMileageId.selectedId,
|
|
|
|
|
vehicleTransmissionID: vehicleTransmissionId.selectedId,
|
|
|
|
|
vehicleSellerTypeID: vehicleSellerTypeId.selectedId == -1 ? 1 : vehicleSellerTypeId.selectedId,
|
|
|
|
|
cityID: vehicleCityId.selectedId,
|
|
|
|
|
price: int.parse(vehicleDemandAmount),
|
|
|
|
|
vehicleVIN: vehicleVin,
|
|
|
|
|
vehicleDescription: vehicleDescription,
|
|
|
|
|
vehicleTitle: vehicleTitle,
|
|
|
|
|
vehicleDescriptionN: vehicleDescription,
|
|
|
|
|
isFinanceAvailable: financeAvailableStatus,
|
|
|
|
|
warantyYears: int.parse(warrantyDuration),
|
|
|
|
|
demandAmount: int.parse(vehicleDemandAmount),
|
|
|
|
|
vehiclePostingImages: vehicleImages,
|
|
|
|
|
vehiclePostingDamageParts: vehicleDamageImages,
|
|
|
|
|
phoneNo: isPhoneNumberShown ? adPhoneNumberDialCode + adPhoneNumber : null,
|
|
|
|
|
whatsAppNo: (isPhoneNumberShown && isNumberOnWhatsApp) ? adPhoneNumberDialCode + adPhoneNumber : null,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
AdsCreationPayloadModel adsCreationPayloadModel = AdsCreationPayloadModel(ads: ads, vehiclePosting: vehiclePosting);
|
|
|
|
|
|
|
|
|
|
GenericRespModel respModel = await adsRepo.createOrUpdateDraftAd(
|
|
|
|
|
adsCreationPayloadModel: adsCreationPayloadModel,
|
|
|
|
|
isCreateNew: isNew,
|
|
|
|
|
stepNo: stepNoEnum,
|
|
|
|
|
);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
return Future.value(respModel.messageStatus == 1 ? respModel.data : -1);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
logger.e(e.toString());
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future saveAdDamagePartDetailsDraft() async {}
|
|
|
|
|
|
|
|
|
|
Future saveAdDurationsDraft() async {}
|
|
|
|
|
|
|
|
|
|
void updateCurrentStep(BuildContext context) async {
|
|
|
|
|
switch (currentProgressStep) {
|
|
|
|
|
case AdCreationSteps.vehicleDetails:
|
|
|
|
|
case AdCreationStepsEnum.vehicleDetails:
|
|
|
|
|
if (isVehicleDetailsValidated()) {
|
|
|
|
|
currentProgressStep = AdCreationSteps.damageParts;
|
|
|
|
|
int adID = await saveAdVehicleDetailsDraft(isNew: previousAdDetails == null || previousAdDetails!.id == null, context: context, stepNoEnum: AdCreationStepsEnum.vehicleDetails);
|
|
|
|
|
if (previousAdDetails == null || previousAdDetails!.id == null) {
|
|
|
|
|
previousAdDetails = AdDetailsModel();
|
|
|
|
|
previousAdDetails!.id = adID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.damageParts;
|
|
|
|
|
getVehicleDamagePartsList();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.damageParts:
|
|
|
|
|
case AdCreationStepsEnum.damageParts:
|
|
|
|
|
if (isDamagePartsValidated()) {
|
|
|
|
|
currentProgressStep = AdCreationSteps.adDuration;
|
|
|
|
|
await saveAdVehicleDetailsDraft(isNew: false, context: context, stepNoEnum: AdCreationStepsEnum.damageParts);
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.adDuration;
|
|
|
|
|
if (vehicleAdsDurations.isEmpty) {
|
|
|
|
|
getVehicleAdsDuration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getVehicleAdsSpecialServices(countryId: vehicleCountryId.selectedId, cityId: vehicleCityId.selectedId, specialServiceType: 1);
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.adDuration:
|
|
|
|
|
case AdCreationStepsEnum.adDuration:
|
|
|
|
|
// log("state: ${AppState().getUser.data!.accessToken}");
|
|
|
|
|
if (isAdDurationValidated()) {
|
|
|
|
|
currentProgressStep = AdCreationSteps.reviewAd;
|
|
|
|
|
await saveAdVehicleDetailsDraft(isNew: false, context: context, stepNoEnum: AdCreationStepsEnum.adDuration);
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.reviewAd;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.reviewAd:
|
|
|
|
|
case AdCreationStepsEnum.reviewAd:
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
int status = await createNewAd();
|
|
|
|
|
if (status != 1) {
|
|
|
|
|
bool status = await createNewAd();
|
|
|
|
|
if (!status) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
isAdEditEnabled = false;
|
|
|
|
|
isDraftEditEnabled = false;
|
|
|
|
|
isExtendAdEditEnabled = false;
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
currentProgressStep = AdCreationSteps.vehicleDetails;
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.vehicleDetails;
|
|
|
|
|
resetValues();
|
|
|
|
|
updateIsExploreAds(false);
|
|
|
|
|
applyFilterOnMyAds(adPostStatusEnum: AdPostStatus.pendingForReview); //pending for review
|
|
|
|
|
@ -1444,7 +1553,7 @@ class AdVM extends BaseVM {
|
|
|
|
|
vehicleDamageCards.clear();
|
|
|
|
|
specialServiceCards.clear();
|
|
|
|
|
vehicleAdsSpecialServices.clear();
|
|
|
|
|
currentProgressStep = AdCreationSteps.vehicleDetails;
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.vehicleDetails;
|
|
|
|
|
vehicleTypeId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
vehicleModelId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
// vehicleAdDurationId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
@ -1604,7 +1713,7 @@ class AdVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<int> createNewAd() async {
|
|
|
|
|
Future<bool> createNewAd() async {
|
|
|
|
|
AppState appState = injector.get<AppState>();
|
|
|
|
|
List<int> adsSelectedServices = [];
|
|
|
|
|
|
|
|
|
|
@ -1625,7 +1734,11 @@ class AdVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
log("selectionDurationStartDate: $selectionDurationStartDate");
|
|
|
|
|
Ads ads = Ads(
|
|
|
|
|
id: isAdEditEnabled ? previousAdDetails!.id : null,
|
|
|
|
|
id: isDraftEditEnabled
|
|
|
|
|
? null
|
|
|
|
|
: isAdEditEnabled
|
|
|
|
|
? previousAdDetails!.id
|
|
|
|
|
: null,
|
|
|
|
|
adsDurationID: vehicleAdDurationId.selectedId == -1 ? 0 : vehicleAdDurationId.selectedId,
|
|
|
|
|
startDate: selectionDurationStartDate,
|
|
|
|
|
countryId: vehicleCountryId.selectedId,
|
|
|
|
|
@ -1683,11 +1796,15 @@ class AdVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
AdsCreationPayloadModel adsCreationPayloadModel = AdsCreationPayloadModel(ads: ads, vehiclePosting: vehiclePosting);
|
|
|
|
|
|
|
|
|
|
GenericRespModel respModel = await adsRepo.createOrUpdateAd(adsCreationPayloadModel: adsCreationPayloadModel, isCreateNew: !isAdEditEnabled, isExtendAdEditEnabled: isExtendAdEditEnabled);
|
|
|
|
|
GenericRespModel respModel = await adsRepo.createOrUpdateAd(
|
|
|
|
|
adsCreationPayloadModel: adsCreationPayloadModel,
|
|
|
|
|
isCreateNew: isDraftEditEnabled ? true : !isAdEditEnabled,
|
|
|
|
|
isExtendAdEditEnabled: isExtendAdEditEnabled,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Utils.showToast(respModel.message.toString());
|
|
|
|
|
|
|
|
|
|
return Future.value(respModel.messageStatus);
|
|
|
|
|
return Future.value(respModel.messageStatus == 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<VehiclePostingImages> convertFileToVehiclePostingImages({required ImageModel imageModel}) async {
|
|
|
|
|
@ -2221,13 +2338,16 @@ class AdVM extends BaseVM {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onEditUpdateAdPressed({required BuildContext context, required AdDetailsModel previousDetails, required bool isFromExtendAd}) {
|
|
|
|
|
void onEditUpdateAdPressed({required BuildContext context, required AdDetailsModel previousDetails, required bool isFromExtendAd, bool isForDraft = false}) {
|
|
|
|
|
isAdEditEnabled = true;
|
|
|
|
|
isDraftEditEnabled = true;
|
|
|
|
|
isExtendAdEditEnabled = isFromExtendAd;
|
|
|
|
|
previousAdDetails = previousDetails;
|
|
|
|
|
autoFillSelectedVehicleType();
|
|
|
|
|
autoFillSelectedVehicleAdsDuration();
|
|
|
|
|
|
|
|
|
|
if (isForDraft) {
|
|
|
|
|
autoFillSelectedVehicleAdsDetails();
|
|
|
|
|
}
|
|
|
|
|
navigateWithName(context, AppRoutes.selectAdTypeView, arguments: [AppState().currentAppType == AppType.provider, isFromExtendAd, previousDetails.id]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -2256,12 +2376,14 @@ class AdVM extends BaseVM {
|
|
|
|
|
void autoFillSelectedVehicleType() async {
|
|
|
|
|
if (vehicleTypes.isEmpty) {
|
|
|
|
|
await getVehicleTypes();
|
|
|
|
|
return;
|
|
|
|
|
// return;
|
|
|
|
|
}
|
|
|
|
|
if (vehicleTypes.isNotEmpty) {
|
|
|
|
|
for (var vehicle in vehicleTypes) {
|
|
|
|
|
vehicle.isSelected = false;
|
|
|
|
|
if (vehicle.id == previousAdDetails!.vehicle?.vehicleType) {
|
|
|
|
|
vehicle.isSelected = true;
|
|
|
|
|
log("Hi: ${vehicle.vehicleTypeName}");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -2302,6 +2424,9 @@ class AdVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void autoFillSelectedVehicleAdsDetails() async {
|
|
|
|
|
if (vehicleBrands.isEmpty) {
|
|
|
|
|
await getVehicleBrandsByVehicleTypeId();
|
|
|
|
|
}
|
|
|
|
|
int index = vehicleBrands.indexWhere((element) => element.id == previousAdDetails!.vehicle!.model!.vehicleBrandID);
|
|
|
|
|
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
@ -2335,6 +2460,7 @@ class AdVM extends BaseVM {
|
|
|
|
|
for (var element in previousAdDetails!.vehicle!.image!) {
|
|
|
|
|
if (element.imageUrl != null) {
|
|
|
|
|
ImageModel imageModel = ImageModel(id: element.id, filePath: element.imageUrl, isFromNetwork: true);
|
|
|
|
|
log("running");
|
|
|
|
|
pickedPostingImages.add(imageModel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -2376,12 +2502,16 @@ class AdVM extends BaseVM {
|
|
|
|
|
address: "",
|
|
|
|
|
serviceTime: "",
|
|
|
|
|
);
|
|
|
|
|
addNewSpecialServiceCard(specialServiceCard: specialServiceCard);
|
|
|
|
|
int index = ifSpecialServiceAlreadyThere(element.specialServiceID!);
|
|
|
|
|
log("Found at : $index");
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
addNewSpecialServiceCard(specialServiceCard: specialServiceCard);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// selectionDurationStartDate = DateHelper.formatDateT(previousAdDetails!.startdate ?? "");
|
|
|
|
|
selectionDurationStartDate = "";
|
|
|
|
|
selectionDurationStartDate = ""; // You have to mention this each time
|
|
|
|
|
isPhoneNumberShown = previousAdDetails!.showContactDetail ?? false;
|
|
|
|
|
adPhoneNumber = previousAdDetails!.adOwnerDetails!.mobileNo ?? "";
|
|
|
|
|
|
|
|
|
|
|