|
@@ -1,11 +1,16 @@
|
|
import 'dart:typed_data';
|
|
import 'dart:typed_data';
|
|
|
|
|
|
import 'package:domain/entity/response/attendance_entity.dart';
|
|
import 'package:domain/entity/response/attendance_entity.dart';
|
|
|
|
+import 'package:domain/entity/response/u_k_security_attendance_entity.dart';
|
|
|
|
+import 'package:domain/entity/response/u_k_security_attendance_option_entity.dart';
|
|
import 'package:domain/repository/job_repository.dart';
|
|
import 'package:domain/repository/job_repository.dart';
|
|
|
|
+import 'package:domain/repository/uk_attendance_repository.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:plugin_platform/engine/dialog/dialog_engine.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/engine/toast/toast_engine.dart';
|
|
import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
|
|
import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
|
|
|
|
+import 'package:plugin_platform/http/http_result.dart';
|
|
import 'package:shared/utils/date_time_utils.dart';
|
|
import 'package:shared/utils/date_time_utils.dart';
|
|
import 'package:shared/utils/log_utils.dart';
|
|
import 'package:shared/utils/log_utils.dart';
|
|
import 'package:widgets/load_state_layout.dart';
|
|
import 'package:widgets/load_state_layout.dart';
|
|
@@ -16,9 +21,10 @@ import 'security_registration_state.dart';
|
|
import 'widget/security_edit_dialog.dart';
|
|
import 'widget/security_edit_dialog.dart';
|
|
|
|
|
|
class SecurityRegistrationController extends GetxController with DioCancelableMixin {
|
|
class SecurityRegistrationController extends GetxController with DioCancelableMixin {
|
|
- final JobRepository _jobRepository = Get.find();
|
|
|
|
|
|
+ final UKAttendanceRepository _attendanceRepository = Get.find();
|
|
final EAttendanceListState state = EAttendanceListState();
|
|
final EAttendanceListState state = EAttendanceListState();
|
|
|
|
|
|
|
|
+ var _curPage = 1;
|
|
var _needShowPlaceholder = true;
|
|
var _needShowPlaceholder = true;
|
|
|
|
|
|
//页面PlaceHolder的展示
|
|
//页面PlaceHolder的展示
|
|
@@ -34,16 +40,24 @@ class SecurityRegistrationController extends GetxController with DioCancelableMi
|
|
// Refresh 控制器
|
|
// Refresh 控制器
|
|
final EasyRefreshController refreshController = EasyRefreshController(
|
|
final EasyRefreshController refreshController = EasyRefreshController(
|
|
controlFinishRefresh: true,
|
|
controlFinishRefresh: true,
|
|
- controlFinishLoad: false,
|
|
|
|
|
|
+ controlFinishLoad: true,
|
|
);
|
|
);
|
|
|
|
|
|
// Refresh 刷新事件
|
|
// Refresh 刷新事件
|
|
Future onRefresh() async {
|
|
Future onRefresh() async {
|
|
|
|
+ _curPage = 1;
|
|
|
|
+ fetchAttendanceList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Refresh 加载事件
|
|
|
|
+ Future loadMore() async {
|
|
|
|
+ _curPage++;
|
|
fetchAttendanceList();
|
|
fetchAttendanceList();
|
|
}
|
|
}
|
|
|
|
|
|
// 重试请求
|
|
// 重试请求
|
|
Future retryRequest() async {
|
|
Future retryRequest() async {
|
|
|
|
+ _curPage = 1;
|
|
_needShowPlaceholder = true;
|
|
_needShowPlaceholder = true;
|
|
fetchAttendanceList();
|
|
fetchAttendanceList();
|
|
}
|
|
}
|
|
@@ -54,40 +68,73 @@ class SecurityRegistrationController extends GetxController with DioCancelableMi
|
|
changeLoadingState(LoadState.State_Loading);
|
|
changeLoadingState(LoadState.State_Loading);
|
|
}
|
|
}
|
|
|
|
|
|
- //获取到数据
|
|
|
|
- var result = await _jobRepository.fetchAttendanceList(
|
|
|
|
- state.keyword,
|
|
|
|
- DateTimeUtils.formatDate(state.selectedStartDate, format: "yyyy-MM-dd"),
|
|
|
|
- DateTimeUtils.formatDate(state.selectedEndDate, format: "yyyy-MM-dd"),
|
|
|
|
- cancelToken: cancelToken,
|
|
|
|
- );
|
|
|
|
|
|
+ // 并发执行两个请求
|
|
|
|
+ var futures = [
|
|
|
|
+ _attendanceRepository.fetchSecurityAttendanceList(
|
|
|
|
+ startDate: DateTimeUtils.formatDate(state.selectedStartDate, format: "yyyy-MM-dd"),
|
|
|
|
+ endDate: DateTimeUtils.formatDate(state.selectedEndDate, format: "yyyy-MM-dd"),
|
|
|
|
+ keyword: state.selectedStaffName,
|
|
|
|
+ departmentId: state.selectedDepartmentId,
|
|
|
|
+ curPage: _curPage,
|
|
|
|
+ cancelToken: cancelToken,
|
|
|
|
+ ),
|
|
|
|
+ state.indexOptions == null
|
|
|
|
+ ? _attendanceRepository.fetchSecurityAttendanceOptions(
|
|
|
|
+ cancelToken: cancelToken,
|
|
|
|
+ )
|
|
|
|
+ : Future(() => HttpResult(isSuccess: true).convert(data: state.indexOptions!)),
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ //拿到结果
|
|
|
|
+ var results = await Future.wait(futures);
|
|
|
|
+ var listResult = results[0] as HttpResult<UKSecurityAttendanceEntity>;
|
|
|
|
+ var optionResult = results[1] as HttpResult<UKSecurityAttendanceOptionEntity>;
|
|
|
|
+
|
|
|
|
+ //选项数据
|
|
|
|
+ if (state.indexOptions == null && optionResult.isSuccess) {
|
|
|
|
+ state.indexOptions = optionResult.data!;
|
|
|
|
+ }
|
|
|
|
|
|
- //处理数据
|
|
|
|
- if (result.isSuccess) {
|
|
|
|
- handleList(result.data?.rows);
|
|
|
|
- refreshController.finishRefresh(IndicatorResult.success);
|
|
|
|
|
|
+ // 处理数据
|
|
|
|
+ if (listResult.isSuccess) {
|
|
|
|
+ handleList(listResult.data?.rows);
|
|
} else {
|
|
} else {
|
|
- errorMessage = result.errorMsg;
|
|
|
|
|
|
+ errorMessage = listResult.errorMsg;
|
|
changeLoadingState(LoadState.State_Error);
|
|
changeLoadingState(LoadState.State_Error);
|
|
- refreshController.finishRefresh(IndicatorResult.fail);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- //最后赋值
|
|
|
|
|
|
+ // 最后赋值
|
|
_needShowPlaceholder = false;
|
|
_needShowPlaceholder = false;
|
|
}
|
|
}
|
|
|
|
|
|
// 处理数据与展示的逻辑
|
|
// 处理数据与展示的逻辑
|
|
- void handleList(List<AttendanceList>? list) {
|
|
|
|
|
|
+ void handleList(List<UKSecurityAttendanceRows>? list) {
|
|
if (list != null && list.isNotEmpty) {
|
|
if (list != null && list.isNotEmpty) {
|
|
//有数据,判断是刷新还是加载更多的数据
|
|
//有数据,判断是刷新还是加载更多的数据
|
|
- state.datas.clear();
|
|
|
|
- state.datas.addAll(list);
|
|
|
|
- //更新状态
|
|
|
|
- changeLoadingState(LoadState.State_Success);
|
|
|
|
|
|
+ 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 {
|
|
} else {
|
|
- //展示无数据的布局
|
|
|
|
- state.datas.clear();
|
|
|
|
- changeLoadingState(LoadState.State_Empty);
|
|
|
|
|
|
+ if (_curPage == 1) {
|
|
|
|
+ //展示无数据的布局
|
|
|
|
+ state.datas.clear();
|
|
|
|
+ changeLoadingState(LoadState.State_Empty);
|
|
|
|
+ refreshController.finishRefresh();
|
|
|
|
+ } else {
|
|
|
|
+ //展示加载完成,没有更多数据了
|
|
|
|
+ refreshController.finishLoad(IndicatorResult.noMore);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -105,12 +152,15 @@ class SecurityRegistrationController extends GetxController with DioCancelableMi
|
|
|
|
|
|
/// 展示标题栏的 Filter 弹窗
|
|
/// 展示标题栏的 Filter 弹窗
|
|
void showFilterDialog() {
|
|
void showFilterDialog() {
|
|
|
|
+ if (state.indexOptions == null) return;
|
|
|
|
+
|
|
DialogEngine.show(
|
|
DialogEngine.show(
|
|
widget: JobListFilter(
|
|
widget: JobListFilter(
|
|
selectedStartDate: state.selectedStartDate,
|
|
selectedStartDate: state.selectedStartDate,
|
|
selectedEndDate: state.selectedEndDate,
|
|
selectedEndDate: state.selectedEndDate,
|
|
staffName: state.selectedStaffName,
|
|
staffName: state.selectedStaffName,
|
|
selectedDepartmentId: state.selectedDepartmentId,
|
|
selectedDepartmentId: state.selectedDepartmentId,
|
|
|
|
+ departmentList: state.indexOptions?.departmentList,
|
|
onFilterAction: (startDate, endDate, staffName, departmentId) {
|
|
onFilterAction: (startDate, endDate, staffName, departmentId) {
|
|
Log.d("startDate:$startDate endDate:$endDate staffName:$staffName departmentId:$departmentId");
|
|
Log.d("startDate:$startDate endDate:$endDate staffName:$staffName departmentId:$departmentId");
|
|
|
|
|
|
@@ -129,23 +179,70 @@ class SecurityRegistrationController extends GetxController with DioCancelableMi
|
|
}
|
|
}
|
|
|
|
|
|
//查看UK员工的详情
|
|
//查看UK员工的详情
|
|
- void gotoStaffDetailPage(AttendanceList data) {
|
|
|
|
- UKAppliedStaffDetailPage.startInstance(data.staffId.toString());
|
|
|
|
|
|
+ void gotoStaffDetailPage(UKSecurityAttendanceRows data) {
|
|
|
|
+ // UKAppliedStaffDetailPage.startInstance(data.staffName.toString());
|
|
}
|
|
}
|
|
|
|
|
|
/// 展示编辑的弹窗
|
|
/// 展示编辑的弹窗
|
|
- void showEditDialog(AttendanceList data) {
|
|
|
|
|
|
+ void showEditDialog(UKSecurityAttendanceRows data) {
|
|
|
|
+ String? dateStr = data.jobTime?.split(" ")[0];
|
|
|
|
+ String? startStr = data.jobTime?.split(" ").sublist(1).join(" ").split(" ~ ")[0];
|
|
|
|
+ String? endStr = data.jobTime?.split(" ").sublist(1).join(" ").split(" ~ ")[1];
|
|
|
|
+
|
|
|
|
+ if (dateStr == null || startStr == null || endStr == null) return;
|
|
|
|
+
|
|
DialogEngine.show(
|
|
DialogEngine.show(
|
|
widget: SecurityEditDialog(
|
|
widget: SecurityEditDialog(
|
|
- startTime: DateTimeUtils.getDateTime(data.startTime ?? ""),
|
|
|
|
- endTime: DateTimeUtils.getDateTime(data.endTime ?? ""),
|
|
|
|
- securityInTime: DateTimeUtils.getDateTime(data.securityIn ?? ""),
|
|
|
|
- securityOutTime: DateTimeUtils.getDateTime(data.securityOut ?? ""),
|
|
|
|
|
|
+ startTime: DateTimeUtils.getDateTime("$dateStr $startStr"),
|
|
|
|
+ endTime: DateTimeUtils.getDateTime("$dateStr $endStr"),
|
|
|
|
+ securityInTime: DateTimeUtils.getDateTime(data.securityIn?.time == null ? "" : "$dateStr ${data.securityIn?.time}"),
|
|
|
|
+ securityOutTime: DateTimeUtils.getDateTime(data.securityOut?.time == null ? "" : "$dateStr ${data.securityOut?.time}"),
|
|
staffName: data.staffName ?? "",
|
|
staffName: data.staffName ?? "",
|
|
confirmAction: (inTime, outTime) {
|
|
confirmAction: (inTime, outTime) {
|
|
- ToastEngine.show("编辑了 inTime:$inTime outTime:$outTime");
|
|
|
|
|
|
+ _submitAttendance(data.id, inTime, outTime);
|
|
},
|
|
},
|
|
),
|
|
),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /// 请求接口提交门卫签到数据
|
|
|
|
+ void _submitAttendance(String? appliedId, DateTime? inTime, DateTime? outTime) async {
|
|
|
|
+ final result = await _attendanceRepository.submitSecurityAttendanceEdit(
|
|
|
|
+ appliedId: appliedId,
|
|
|
|
+ formView: "security",
|
|
|
|
+ securityIn: DateTimeUtils.formatDate(inTime),
|
|
|
|
+ securityOut: DateTimeUtils.formatDate(outTime),
|
|
|
|
+ cancelToken: cancelToken,
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (result.isSuccess) {
|
|
|
|
+ NotifyEngine.showSuccess("Successful".tr);
|
|
|
|
+
|
|
|
|
+ //把签到的时间赋值给列表
|
|
|
|
+ _updateItems(appliedId,DateTimeUtils.formatDate(inTime),DateTimeUtils.formatDate(outTime));
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 遍历当前列表找到对应的Item更新签到签出的时间
|
|
|
|
+ void _updateItems(String? appliedId, String inTime, String outTime) {
|
|
|
|
+ UKSecurityAttendanceRows? element = state.datas.firstWhereOrNull(
|
|
|
|
+ (element) => element.id == appliedId,
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (element != null) {
|
|
|
|
+ element.securityIn ??= UKSecurityInOut();
|
|
|
|
+ element.securityIn?.time = inTime;
|
|
|
|
+ element.securityIn?.changed = 1;
|
|
|
|
+
|
|
|
|
+ element.securityOut ??= UKSecurityInOut();
|
|
|
|
+ element.securityOut?.time = outTime;
|
|
|
|
+ element.securityOut?.changed = 1;
|
|
|
|
+
|
|
|
|
+ update();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|