|
@@ -3,16 +3,24 @@ import 'package:domain/entity/response/labour_request_index_entity.dart';
|
|
|
import 'package:domain/entity/response/labour_request_list_entity.dart';
|
|
|
import 'package:domain/repository/labour_repository.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
+import 'package:plugin_basic/constants/app_constant.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:plugin_platform/http/http_result.dart';
|
|
|
import 'package:shared/utils/date_time_utils.dart';
|
|
|
+import 'package:shared/utils/event_bus.dart';
|
|
|
+import 'package:shared/utils/util.dart';
|
|
|
+import 'package:widgets/dialog/app_default_dialog.dart';
|
|
|
import 'package:widgets/load_state_layout.dart';
|
|
|
import 'package:widgets/widget_export.dart';
|
|
|
|
|
|
import '../../widget/labour_request_filter.dart';
|
|
|
+import '../labour_request_workflow/labour_request_workflow_page.dart';
|
|
|
import 'labour_request_list_state.dart';
|
|
|
|
|
|
-class LabourRequestListController extends GetxController {
|
|
|
+class LabourRequestListController extends GetxController with DioCancelableMixin {
|
|
|
final LabourRepository _labourRepository = Get.find();
|
|
|
final LabourRequestListState state = LabourRequestListState();
|
|
|
|
|
@@ -69,8 +77,13 @@ class LabourRequestListController extends GetxController {
|
|
|
state.selectedStatusId,
|
|
|
state.selectedDepartmentId,
|
|
|
curPage: _curPage,
|
|
|
+ cancelToken: cancelToken,
|
|
|
),
|
|
|
- state.indexOptions == null ? _labourRepository.fetchLabourRequestIndex() : Future(() => HttpResult(isSuccess: true).convert(data: state.indexOptions!)),
|
|
|
+ state.indexOptions == null
|
|
|
+ ? _labourRepository.fetchLabourRequestIndex(
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ )
|
|
|
+ : Future(() => HttpResult(isSuccess: true).convert(data: state.indexOptions!)),
|
|
|
];
|
|
|
|
|
|
//拿到结果
|
|
@@ -157,10 +170,6 @@ class LabourRequestListController extends GetxController {
|
|
|
selectedEndDate: state.selectedEndDate,
|
|
|
selectedStatusId: state.selectedStatusId,
|
|
|
selectedDepartmentId: state.selectedDepartmentId,
|
|
|
- onResetAction: () {
|
|
|
- //重置参数
|
|
|
- resetFiltering();
|
|
|
- },
|
|
|
onFilterAction: (startDate, endDate, statusId, departmentId) {
|
|
|
state.selectedStartDate = startDate;
|
|
|
state.selectedEndDate = endDate;
|
|
@@ -177,10 +186,78 @@ class LabourRequestListController extends GetxController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// 执行Recall请求
|
|
|
+ void requestRecall(String requestId) async {
|
|
|
+ var recallResult = await _labourRepository.recallLabourRequest(
|
|
|
+ requestId,
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ );
|
|
|
+
|
|
|
+ //处理数据
|
|
|
+ if (recallResult.isSuccess) {
|
|
|
+ NotifyEngine.showSuccess("Successful".tr);
|
|
|
+ fetchItemByIdAndRefreshItem(requestId);
|
|
|
+ } else {
|
|
|
+ ToastEngine.show(recallResult.errorMsg ?? "Network Load Error".tr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 根据ID获取Item对象,用于刷新
|
|
|
+ void fetchItemByIdAndRefreshItem(String requestId) async {
|
|
|
+ var result = await _labourRepository.fetchItemByRequestId(
|
|
|
+ requestId,
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ );
|
|
|
+
|
|
|
+ //处理数据
|
|
|
+ if (result.isSuccess) {
|
|
|
+ var data = result.data;
|
|
|
+ if (data != null && data.rows != null && data.rows!.isNotEmpty) {
|
|
|
+ final requestItem = data.rows![0];
|
|
|
+
|
|
|
+ //找到当前数据中的此 requestId,并替换对象,再刷新
|
|
|
+ var index = state.datas.indexWhere((element) => element.requestId == requestItem.requestId);
|
|
|
+ if (index >= 0) {
|
|
|
+ state.datas[index] = requestItem;
|
|
|
+ update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
void onReady() {
|
|
|
super.onReady();
|
|
|
fetchNotifyList();
|
|
|
+
|
|
|
+ registerEventBus();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void onClose() {
|
|
|
+ unregisterEventBus();
|
|
|
+ state.datas.clear();
|
|
|
+ super.onClose();
|
|
|
+ }
|
|
|
+
|
|
|
+ // EventBus 的事件接收
|
|
|
+ Subscription? subscribe;
|
|
|
+
|
|
|
+ void registerEventBus() {
|
|
|
+ subscribe = bus.on(AppConstant.eventLabourRequestRefresh, (arg) {
|
|
|
+ var requestId = arg as String;
|
|
|
+ if (Utils.isNotEmpty(requestId)) {
|
|
|
+ fetchItemByIdAndRefreshItem(requestId);
|
|
|
+ } else {
|
|
|
+ refreshController.callRefresh();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ void unregisterEventBus() {
|
|
|
+ bus.off(AppConstant.eventLabourRequestRefresh, subscribe);
|
|
|
}
|
|
|
|
|
|
//跳转到添加页面
|
|
@@ -198,5 +275,21 @@ class LabourRequestListController extends GetxController {
|
|
|
LabourRequestAddPage.startInstance(1, data.requestId.toString());
|
|
|
}
|
|
|
|
|
|
- void doRecall(LabourRequestListRows data) {}
|
|
|
+ //去状态工作流的页面
|
|
|
+ void gotoWorkflowPage(LabourRequestListRows data) {
|
|
|
+ LabourRequestWorkflowPage.startInstance(data.requestId.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ void doRecall(LabourRequestListRows data) {
|
|
|
+ DialogEngine.show(
|
|
|
+ widget: AppDefaultDialog(
|
|
|
+ title: "Message".tr,
|
|
|
+ message: "Are you sure you want to recall?".tr,
|
|
|
+ confirmAction: () {
|
|
|
+ requestRecall(data.requestId.toString());
|
|
|
+ },
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|