|
@@ -0,0 +1,247 @@
|
|
|
+import 'package:domain/entity/response/attendance_review_entity.dart';
|
|
|
+import 'package:domain/repository/job_repository.dart';
|
|
|
+import 'package:get/get.dart';
|
|
|
+import 'package:plugin_platform/engine/dialog/dialog_engine.dart';
|
|
|
+import 'package:plugin_platform/engine/notify/notify_engine.dart';
|
|
|
+import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
|
+import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
|
|
|
+
|
|
|
+import 'package:shared/utils/log_utils.dart';
|
|
|
+import 'package:widgets/dialog/app_default_dialog.dart';
|
|
|
+import 'package:widgets/load_state_layout.dart';
|
|
|
+import 'package:widgets/widget_export.dart';
|
|
|
+
|
|
|
+import 'attendance_review_reject_dialog.dart';
|
|
|
+import 'attendance_review_state.dart';
|
|
|
+
|
|
|
+class AttendanceReviewController extends GetxController with DioCancelableMixin {
|
|
|
+ final JobRepository _jobRepository = Get.find();
|
|
|
+ final AttendanceReviewState state = AttendanceReviewState();
|
|
|
+
|
|
|
+ var _curPage = 1;
|
|
|
+ var _needShowPlaceholder = true;
|
|
|
+
|
|
|
+
|
|
|
+ LoadState loadingState = LoadState.State_Success;
|
|
|
+ String? errorMessage;
|
|
|
+
|
|
|
+
|
|
|
+ void changeLoadingState(LoadState state) {
|
|
|
+ loadingState = state;
|
|
|
+ update();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ final EasyRefreshController refreshController = EasyRefreshController(
|
|
|
+ controlFinishRefresh: true,
|
|
|
+ controlFinishLoad: true,
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ Future onRefresh() async {
|
|
|
+ _curPage = 1;
|
|
|
+ fetchAppliedStaffList();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Future loadMore() async {
|
|
|
+ _curPage++;
|
|
|
+ fetchAppliedStaffList();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Future retryRequest() async {
|
|
|
+ _curPage = 1;
|
|
|
+ _needShowPlaceholder = true;
|
|
|
+ fetchAppliedStaffList();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Future fetchAppliedStaffList() async {
|
|
|
+ if (_needShowPlaceholder) {
|
|
|
+ changeLoadingState(LoadState.State_Loading);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ final listResult = await _jobRepository.fetchAttendanceReviewList(
|
|
|
+ state.keyword,
|
|
|
+ curPage: _curPage,
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ if (listResult.isSuccess) {
|
|
|
+ handleList(listResult.data?.rows);
|
|
|
+ } else {
|
|
|
+ errorMessage = listResult.errorMsg;
|
|
|
+ changeLoadingState(LoadState.State_Error);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ _needShowPlaceholder = false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void handleList(List<AttendanceReviewRows>? list) {
|
|
|
+ if (list != null && list.isNotEmpty) {
|
|
|
+
|
|
|
+ if (_curPage == 1) {
|
|
|
+
|
|
|
+ state.datas.clear();
|
|
|
+ state.datas.addAll(list);
|
|
|
+ refreshController.finishRefresh();
|
|
|
+
|
|
|
+
|
|
|
+ changeLoadingState(LoadState.State_Success);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ state.datas.addAll(list);
|
|
|
+ refreshController.finishLoad();
|
|
|
+ update();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (_curPage == 1) {
|
|
|
+
|
|
|
+ state.datas.clear();
|
|
|
+ changeLoadingState(LoadState.State_Empty);
|
|
|
+ refreshController.finishRefresh();
|
|
|
+ } else {
|
|
|
+
|
|
|
+ refreshController.finishLoad(IndicatorResult.noMore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void onReady() {
|
|
|
+ super.onReady();
|
|
|
+ fetchAppliedStaffList();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void onClose() {
|
|
|
+ state.datas.clear();
|
|
|
+ super.onClose();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void doSearch(String keyword) {
|
|
|
+ state.keyword = keyword;
|
|
|
+
|
|
|
+ refreshController.callRefresh();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void resetFiltering() {
|
|
|
+ state.keyword = "";
|
|
|
+ state.searchController.text = "";
|
|
|
+
|
|
|
+
|
|
|
+ refreshController.callRefresh();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void doSelectedOrNot(AttendanceReviewRows data) {
|
|
|
+ data.isSelected = !data.isSelected;
|
|
|
+ Log.d("isSelected:${data.isSelected}");
|
|
|
+ update();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void _requestBatchApprove(String recordIds) async {
|
|
|
+
|
|
|
+ var result = await _jobRepository.approveAttendanceReviews(
|
|
|
+ recordIds,
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ );
|
|
|
+
|
|
|
+ if (result.isSuccess) {
|
|
|
+ NotifyEngine.showSuccess("Successful".tr);
|
|
|
+
|
|
|
+
|
|
|
+ _removeItemsByList(recordIds);
|
|
|
+ } else {
|
|
|
+ ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void _requestBatchReject(String recordIds, String? reason) async {
|
|
|
+
|
|
|
+ var result = await _jobRepository.rejectLabourReviews(
|
|
|
+ recordIds,
|
|
|
+ reason,
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ );
|
|
|
+
|
|
|
+ if (result.isSuccess) {
|
|
|
+ NotifyEngine.showSuccess("Successful".tr);
|
|
|
+
|
|
|
+
|
|
|
+ _removeItemsByList(recordIds);
|
|
|
+ } else {
|
|
|
+ ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void operationApprove() async {
|
|
|
+
|
|
|
+ var selectedList = state.datas.where((element) => element.isSelected).toList(growable: false);
|
|
|
+ if (selectedList.isNotEmpty) {
|
|
|
+ var ids = selectedList.map((e) => e.recordId.toString()).toList(growable: false);
|
|
|
+ var recordIds = ids.join(',');
|
|
|
+
|
|
|
+
|
|
|
+ DialogEngine.show(
|
|
|
+ widget: AppDefaultDialog(
|
|
|
+ title: "Message".tr,
|
|
|
+ message: "Are you sure you want to setting approved?".tr,
|
|
|
+ confirmAction: () {
|
|
|
+ _requestBatchApprove(recordIds);
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ ToastEngine.show("Please select the record".tr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void operationReject() async {
|
|
|
+
|
|
|
+ var selectedList = state.datas.where((element) => element.isSelected).toList(growable: false);
|
|
|
+ if (selectedList.isNotEmpty) {
|
|
|
+ var ids = selectedList.map((e) => e.recordId.toString()).toList(growable: false);
|
|
|
+ var recordIds = ids.join(',');
|
|
|
+
|
|
|
+
|
|
|
+ DialogEngine.show(
|
|
|
+ widget: AttendaceReviewRejectDialog(
|
|
|
+ confirmAction: (reason) {
|
|
|
+
|
|
|
+ _requestBatchReject(recordIds, reason);
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ ToastEngine.show("Please select the record".tr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void _removeItemsByList(String recordIds) {
|
|
|
+
|
|
|
+ List<String> recordIdList = recordIds.split(',');
|
|
|
+
|
|
|
+
|
|
|
+ state.datas.removeWhere((e) => recordIdList.contains(e.recordId));
|
|
|
+
|
|
|
+ update();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void gotoStatusViewPage(AttendanceReviewRows data) {}
|
|
|
+}
|