2025-09-13 11:36:44 +03:30
|
|
|
|
import 'package:flutter/material.dart';
|
2025-12-17 10:26:39 +03:30
|
|
|
|
=
|
|
|
|
|
|
import 'package:rasadyar_chicken/features/poultry_science/data/model/response/poultry_farm/poultry_farm.dart';
|
|
|
|
|
|
import 'package:rasadyar_chicken/features/poultry_science/presentation/pages/home/logic.dart';
|
|
|
|
|
|
import 'package:rasadyar_chicken/features/poultry_science/presentation/pages/root/logic.dart';
|
2025-09-13 11:36:44 +03:30
|
|
|
|
import 'package:rasadyar_core/core.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class FarmLogic extends GetxController {
|
2025-09-27 12:39:25 +03:30
|
|
|
|
List<String> routes = ['اقدام', 'فارم ها'];
|
2025-09-13 11:36:44 +03:30
|
|
|
|
PoultryScienceRootLogic rootLogic = Get.find<PoultryScienceRootLogic>();
|
2025-09-29 15:00:31 +03:30
|
|
|
|
BasePageLogic baseLogic = Get.find<BasePageLogic>();
|
2025-12-17 10:26:39 +03:30
|
|
|
|
final PoultryScienceHomeLogic _homeLogic =
|
|
|
|
|
|
Get.find<PoultryScienceHomeLogic>();
|
2025-09-13 11:36:44 +03:30
|
|
|
|
RxList<InformationTagData> tagInfo = <InformationTagData>[
|
|
|
|
|
|
InformationTagData(
|
|
|
|
|
|
labelTitle: 'کل فارم ها',
|
|
|
|
|
|
isLoading: true,
|
|
|
|
|
|
labelVecIcon: Assets.vec.cubeScanSvg.path,
|
2025-09-23 11:18:33 +03:30
|
|
|
|
iconColor: AppColor.blueNormalOld,
|
2025-09-13 11:36:44 +03:30
|
|
|
|
valueBgColor: Colors.white,
|
|
|
|
|
|
labelGradient: LinearGradient(
|
|
|
|
|
|
begin: Alignment.topCenter,
|
|
|
|
|
|
end: Alignment.bottomCenter,
|
|
|
|
|
|
colors: [AppColor.blueLight, Colors.white],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
InformationTagData(
|
|
|
|
|
|
labelTitle: 'حجم جوجه ریزی',
|
|
|
|
|
|
unit: 'قطعه',
|
|
|
|
|
|
isLoading: true,
|
|
|
|
|
|
labelVecIcon: Assets.vec.cubeCardSvg.path,
|
|
|
|
|
|
blendMode: BlendMode.dst,
|
|
|
|
|
|
valueBgColor: Colors.white,
|
|
|
|
|
|
labelGradient: LinearGradient(
|
|
|
|
|
|
begin: Alignment.topCenter,
|
|
|
|
|
|
end: Alignment.bottomCenter,
|
|
|
|
|
|
colors: [AppColor.greenLightHover, Colors.white],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
].obs;
|
|
|
|
|
|
Rx<Resource<PaginationModel<PoultryFarm>>> farmList =
|
|
|
|
|
|
Resource<PaginationModel<PoultryFarm>>.loading().obs;
|
|
|
|
|
|
|
|
|
|
|
|
RxInt currentPage = 1.obs;
|
|
|
|
|
|
final RxBool isLoadingMoreList = false.obs;
|
2025-09-20 13:12:16 +03:30
|
|
|
|
RxInt expandedIndex = RxInt(-1);
|
2025-09-13 11:36:44 +03:30
|
|
|
|
|
2025-09-27 12:39:25 +03:30
|
|
|
|
Rx<Jalali> fromDateFilter = Jalali.now().obs;
|
|
|
|
|
|
Rx<Jalali> toDateFilter = Jalali.now().obs;
|
|
|
|
|
|
RxnString searchedValue = RxnString();
|
|
|
|
|
|
|
2025-09-13 11:36:44 +03:30
|
|
|
|
@override
|
|
|
|
|
|
void onReady() {
|
|
|
|
|
|
super.onReady();
|
|
|
|
|
|
tagInfo[0] = tagInfo[0].copyWith(
|
|
|
|
|
|
isLoading: false,
|
|
|
|
|
|
value: _homeLogic.tagInfo['first']!.first.value,
|
|
|
|
|
|
);
|
|
|
|
|
|
tagInfo[1] = tagInfo[1].copyWith(
|
|
|
|
|
|
isLoading: false,
|
|
|
|
|
|
value: _homeLogic.tagInfo['second']!.first.value,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
getFarmList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void onClose() {
|
|
|
|
|
|
super.onClose();
|
2025-09-29 15:00:31 +03:30
|
|
|
|
baseLogic.clearSearch();
|
2025-09-13 11:36:44 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> getFarmList([bool isLoadingMore = false]) async {
|
|
|
|
|
|
if (isLoadingMore) {
|
|
|
|
|
|
isLoadingMoreList.value = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
farmList.value = Resource<PaginationModel<PoultryFarm>>.loading();
|
|
|
|
|
|
}
|
|
|
|
|
|
await safeCall(
|
2025-12-17 10:26:39 +03:30
|
|
|
|
call: () async =>
|
|
|
|
|
|
await rootLogic.poultryRepository.getPoultryScienceFarmList(
|
|
|
|
|
|
token: rootLogic.tokenService.accessToken.value!,
|
|
|
|
|
|
queryParameters: buildQueryParams(
|
|
|
|
|
|
queryParams: {'type': 'farm'},
|
|
|
|
|
|
role: 'PoultryScience',
|
|
|
|
|
|
pageSize: 50,
|
|
|
|
|
|
search: 'filter',
|
|
|
|
|
|
value: '',
|
|
|
|
|
|
page: currentPage.value,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2025-09-13 11:36:44 +03:30
|
|
|
|
onSuccess: (res) {
|
|
|
|
|
|
if ((res?.count ?? 0) == 0) {
|
|
|
|
|
|
farmList.value = Resource<PaginationModel<PoultryFarm>>.empty();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
farmList.value = Resource<PaginationModel<PoultryFarm>>.success(
|
|
|
|
|
|
PaginationModel<PoultryFarm>(
|
|
|
|
|
|
count: res?.count ?? 0,
|
|
|
|
|
|
next: res?.next,
|
|
|
|
|
|
previous: res?.previous,
|
2025-12-17 10:26:39 +03:30
|
|
|
|
results: [
|
|
|
|
|
|
...(farmList.value.data?.results ?? []),
|
|
|
|
|
|
...?res?.results,
|
|
|
|
|
|
],
|
2025-09-13 11:36:44 +03:30
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
onError: (error, stackTrace) {},
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-09-23 11:18:33 +03:30
|
|
|
|
|
2025-09-20 13:12:16 +03:30
|
|
|
|
void toggleExpanded(int index) {
|
|
|
|
|
|
expandedIndex.value = expandedIndex.value == index ? -1 : index;
|
|
|
|
|
|
}
|
2025-10-07 14:21:09 +03:30
|
|
|
|
|
|
|
|
|
|
Future<void> onRefresh() async {
|
|
|
|
|
|
currentPage.value = 1;
|
|
|
|
|
|
farmList.value = Resource<PaginationModel<PoultryFarm>>.loading();
|
|
|
|
|
|
await getFarmList();
|
|
|
|
|
|
}
|
2025-09-13 11:36:44 +03:30
|
|
|
|
}
|