|
@@ -1,7 +1,14 @@
|
|
|
-import 'package:domain/repository/labour_sg_repository.dart';
|
|
|
+import 'package:domain/entity/response/contract_detail_entity.dart';
|
|
|
+import 'package:domain/entity/response/index_option_entity.dart';
|
|
|
+import 'package:domain/repository/sg_agency_repository.dart';
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:get/get.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/log_utils.dart';
|
|
|
import 'package:shared/utils/util.dart';
|
|
|
import 'package:widgets/picker/date_picker_util.dart';
|
|
|
import 'package:widgets/picker/option_pick_util.dart';
|
|
@@ -9,98 +16,81 @@ import 'package:widgets/picker/option_pick_util.dart';
|
|
|
import 'contract_add_state.dart';
|
|
|
|
|
|
class ContractAddController extends GetxController with DioCancelableMixin {
|
|
|
- final LabourSGRepository _labourRepository = Get.find();
|
|
|
+ final SGAgencyRepository _agencyRepository = Get.find();
|
|
|
final ContractAddState state = ContractAddState();
|
|
|
|
|
|
// 获取添加或者编辑的详情
|
|
|
void _fetchAddEditIndexDetail() async {
|
|
|
// //获取到数据
|
|
|
- // Future<HttpResult<JobTemplateEditIndexEntity>> taskFuture;
|
|
|
- // if (Utils.isNotEmpty(state.templateId) && state.templateId != "0") {
|
|
|
- // //编辑
|
|
|
- // taskFuture = _labourRepository.fetchJobTemplateEditIndex(state.templateId, cancelToken: cancelToken);
|
|
|
- // } else {
|
|
|
- // //新增
|
|
|
- // taskFuture = _labourRepository.fetchJobTemplateAddIndex(cancelToken: cancelToken);
|
|
|
- // }
|
|
|
- //
|
|
|
- // var result = await taskFuture;
|
|
|
- //
|
|
|
- // //处理数据
|
|
|
- // if (result.isSuccess) {
|
|
|
- // state.indexEntity = result.data;
|
|
|
- //
|
|
|
- // var templateNameController = state.formData['template_name']!['controller'];
|
|
|
- // var descController = state.formData['desc']!['controller'];
|
|
|
- // var contactController = state.formData['contact']!['controller'];
|
|
|
- // var contactNoController = state.formData['contact_no']!['controller'];
|
|
|
- // var noteController = state.formData['note']!['controller'];
|
|
|
- // templateNameController.text = state.indexEntity?.name ?? "";
|
|
|
- // descController.text = state.indexEntity?.description ?? "";
|
|
|
- // contactController.text = state.indexEntity?.contact ?? "";
|
|
|
- // contactNoController.text = state.indexEntity?.contactNo ?? "";
|
|
|
- // noteController.text = state.indexEntity?.note ?? "";
|
|
|
- //
|
|
|
- // //默认赋值
|
|
|
- // state.selectedAgeList = state.indexEntity?.ageList.where((e) => e.checked == "checked").map((e) => e.value!).toList() ?? [];
|
|
|
- // Log.d("当前选中的年龄1:${ state.selectedAgeList}");
|
|
|
- // state.selectedLanguageList = state.indexEntity?.languageList.where((e) => e.checked == "checked").map((e) => e.value!).toList() ?? [];
|
|
|
- // Log.d("当前选中的语言1:${ state.selectedLanguageList}");
|
|
|
- // state.foodCert = state.indexEntity?.withFoodCert.toString();
|
|
|
- //
|
|
|
- // update();
|
|
|
- // } else {
|
|
|
- // ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
|
- // }
|
|
|
+ Future<HttpResult<ContractDetailEntity>> taskFuture;
|
|
|
+ if (Utils.isNotEmpty(state.contractId) && state.contractId != "0") {
|
|
|
+ //编辑
|
|
|
+ taskFuture = _agencyRepository.fetchContractEditDetail(contractId: state.contractId, cancelToken: cancelToken);
|
|
|
+ } else {
|
|
|
+ //新增
|
|
|
+ taskFuture = _agencyRepository.fetchContractAddOption(cancelToken: cancelToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ var result = await taskFuture;
|
|
|
+
|
|
|
+ //处理数据
|
|
|
+ if (result.isSuccess) {
|
|
|
+ state.detailOption = result.data;
|
|
|
+
|
|
|
+ state.selectedStartTime = result.data?.row?.startDate == null ? null : DateTimeUtils.getDateTime(result.data!.row!.startDate!);
|
|
|
+ state.selectedEndTime = result.data?.row?.endDate == null ? null : DateTimeUtils.getDateTime(result.data!.row!.endDate!);
|
|
|
+
|
|
|
+ state.agencyList = state.detailOption?.agencyList ?? [];
|
|
|
+
|
|
|
+ state.selectedAgencyId = state.detailOption?.agencyList.firstWhere((e) => e.selected == "selected", orElse: () => IndexOptionEntity()).value;
|
|
|
+ state.selectedAgencyTxt = state.detailOption?.agencyList.firstWhere((e) => e.selected == "selected", orElse: () => IndexOptionEntity()).txt;
|
|
|
+
|
|
|
+ if(Utils.isNotEmpty(state.detailOption?.row?.file)){
|
|
|
+ List<String> images = [state.detailOption!.row!.file!];
|
|
|
+ state.selectedPaths = images;
|
|
|
+ }
|
|
|
+
|
|
|
+ update();
|
|
|
+ } else {
|
|
|
+ ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// 提交
|
|
|
void doSubmit() async {
|
|
|
-
|
|
|
-
|
|
|
- // Future<HttpResult> taskFuture;
|
|
|
- // if (Utils.isNotEmpty(state.templateId) && state.templateId != "0") {
|
|
|
- // taskFuture = _labourRepository.editJobTemplateSubmit(
|
|
|
- // state.templateId,
|
|
|
- // templateName,
|
|
|
- // contact,
|
|
|
- // contactNo,
|
|
|
- // desc,
|
|
|
- // note,
|
|
|
- // state.selectedAgeList.join(","),
|
|
|
- // state.gender,
|
|
|
- // state.foodCert,
|
|
|
- // state.selectedLanguageList.join(","),
|
|
|
- // cancelToken: cancelToken,
|
|
|
- // );
|
|
|
- // } else {
|
|
|
- // taskFuture = _labourRepository.addJobTemplateSubmit(
|
|
|
- // templateName,
|
|
|
- // contact,
|
|
|
- // contactNo,
|
|
|
- // desc,
|
|
|
- // note,
|
|
|
- // state.selectedAgeList.join(","),
|
|
|
- // state.gender,
|
|
|
- // state.foodCert,
|
|
|
- // state.selectedLanguageList.join(","),
|
|
|
- // cancelToken: cancelToken,
|
|
|
- // );
|
|
|
- // }
|
|
|
- //
|
|
|
- // var result = await taskFuture;
|
|
|
- //
|
|
|
- // //处理数据
|
|
|
- // if (result.isSuccess) {
|
|
|
- // NotifyEngine.showSuccess("Successful".tr);
|
|
|
- //
|
|
|
- // //根据类型刷新
|
|
|
- // state.cb?.call(state.templateId);
|
|
|
- //
|
|
|
- // Get.back();
|
|
|
- // } else {
|
|
|
- // ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
|
- // }
|
|
|
+ Future<HttpResult> taskFuture;
|
|
|
+ if (Utils.isNotEmpty(state.contractId) && state.contractId != "0") {
|
|
|
+ taskFuture = _agencyRepository.editContractSubmit(
|
|
|
+ contractId: state.contractId,
|
|
|
+ agencyId: state.selectedAgencyId,
|
|
|
+ startDate: DateTimeUtils.formatDate(state.selectedStartTime!, format: 'yyyy-MM-dd'),
|
|
|
+ endDate: DateTimeUtils.formatDate(state.selectedEndTime!, format: 'yyyy-MM-dd'),
|
|
|
+ paths: state.selectedPaths,
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ taskFuture = _agencyRepository.addContractSubmit(
|
|
|
+ agencyId: state.selectedAgencyId,
|
|
|
+ startDate: DateTimeUtils.formatDate(state.selectedStartTime!, format: 'yyyy-MM-dd'),
|
|
|
+ endDate: DateTimeUtils.formatDate(state.selectedEndTime!, format: 'yyyy-MM-dd'),
|
|
|
+ paths: state.selectedPaths,
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ var result = await taskFuture;
|
|
|
+
|
|
|
+ //处理数据
|
|
|
+ if (result.isSuccess) {
|
|
|
+ NotifyEngine.showSuccess("Successful".tr);
|
|
|
+
|
|
|
+ //根据类型刷新
|
|
|
+ state.cb?.call(state.contractId);
|
|
|
+
|
|
|
+ Get.back();
|
|
|
+ } else {
|
|
|
+ ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@override
|
|
@@ -111,7 +101,6 @@ class ContractAddController extends GetxController with DioCancelableMixin {
|
|
|
|
|
|
//选择开始时间
|
|
|
void pickStartTime() {
|
|
|
-
|
|
|
DatePickerUtil.showCupertinoDatePicker(
|
|
|
selectedDateTime: state.selectedStartTime,
|
|
|
mode: CupertinoDatePickerMode.date,
|
|
@@ -125,7 +114,6 @@ class ContractAddController extends GetxController with DioCancelableMixin {
|
|
|
|
|
|
// 选择结束时间
|
|
|
void pickEndTime() {
|
|
|
-
|
|
|
DatePickerUtil.showCupertinoDatePicker(
|
|
|
selectedDateTime: state.selectedEndTime ?? state.selectedStartTime,
|
|
|
mode: CupertinoDatePickerMode.date,
|
|
@@ -139,24 +127,25 @@ class ContractAddController extends GetxController with DioCancelableMixin {
|
|
|
|
|
|
// 选择中介商
|
|
|
void pickAgency() {
|
|
|
+ if (state.detailOption == null) return;
|
|
|
+
|
|
|
+ int selectedIndex;
|
|
|
+ if (state.selectedAgencyId == null) {
|
|
|
+ selectedIndex = 0;
|
|
|
+ } else {
|
|
|
+ selectedIndex = state.detailOption!.agencyList.indexWhere((bean) => bean.value.toString() == state.selectedAgencyId);
|
|
|
+ }
|
|
|
|
|
|
- // int selectedTemplateIndex;
|
|
|
- // if (state.selectedJobTitleId == null) {
|
|
|
- // selectedTemplateIndex = 0;
|
|
|
- // } else {
|
|
|
- // selectedTemplateIndex = state.indexEntity!.titleList.indexWhere((department) => department.value.toString() == state.selectedJobTitleId);
|
|
|
- // }
|
|
|
- //
|
|
|
- // if (selectedTemplateIndex < 0) {
|
|
|
- // selectedTemplateIndex = 0;
|
|
|
- // }
|
|
|
+ if (selectedIndex < 0) {
|
|
|
+ selectedIndex = 0;
|
|
|
+ }
|
|
|
|
|
|
OptionPickerUtil.showCupertinoOptionPicker(
|
|
|
- items: state.agencyList,
|
|
|
- initialSelectIndex: 0,
|
|
|
+ items: state.detailOption!.agencyList.map((e) => e.txt!.tr).toList(growable: false),
|
|
|
+ initialSelectIndex: selectedIndex,
|
|
|
onPickerChanged: (_, index) {
|
|
|
- state.selectedAgency = state.agencyList[index];
|
|
|
- state.selectedAgencyId = index.toString();
|
|
|
+ state.selectedAgencyId = state.detailOption!.agencyList[index].value!.toString();
|
|
|
+ state.selectedAgencyTxt = state.detailOption!.agencyList[index].txt!.toString();
|
|
|
update();
|
|
|
},
|
|
|
);
|
|
@@ -167,5 +156,4 @@ class ContractAddController extends GetxController with DioCancelableMixin {
|
|
|
state.selectedPaths = list;
|
|
|
update();
|
|
|
}
|
|
|
-
|
|
|
}
|