|
@@ -1,134 +1,71 @@
|
|
|
-import 'package:domain/repository/labour_sg_repository.dart';
|
|
|
+import 'package:domain/repository/sg_agency_repository.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/util.dart';
|
|
|
|
|
|
import 'position_add_state.dart';
|
|
|
|
|
|
class PositionAddController extends GetxController with DioCancelableMixin {
|
|
|
- final LabourSGRepository _labourRepository = Get.find();
|
|
|
+ final SGAgencyRepository _agencyRepository = Get.find();
|
|
|
final PositionAddState state = PositionAddState();
|
|
|
|
|
|
- // 获取添加或者编辑的详情
|
|
|
- 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);
|
|
|
- // }
|
|
|
+ // 编辑模式下展示对应的文本
|
|
|
+ void _showPositionName() async {
|
|
|
+
|
|
|
+ if (Utils.isNotEmpty(state.positionName)){
|
|
|
+ var positionController = state.formData['position']!['controller'];
|
|
|
+ positionController.text = state.positionName;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// 提交
|
|
|
void doSubmit() async {
|
|
|
|
|
|
-
|
|
|
- var agencyNameController = state.formData['agency_name']!['controller'];
|
|
|
- var acraController = state.formData['acra']!['controller'];
|
|
|
- var personController = state.formData['person_in_charge']!['controller'];
|
|
|
- var addressController = state.formData['address']!['controller'];
|
|
|
- var emailController = state.formData['email']!['controller'];
|
|
|
- var phoneController = state.formData['phone']!['controller'];
|
|
|
-
|
|
|
- String agencyName = agencyNameController.text.toString();
|
|
|
- String acra = acraController.text.toString();
|
|
|
- String personName = personController.text.toString();
|
|
|
- String address = addressController.text.toString();
|
|
|
- String email = emailController.text.toString();
|
|
|
- String phone = phoneController.text.toString();
|
|
|
+ var positionController = state.formData['position']!['controller'];
|
|
|
+ String positionName = positionController.text.toString();
|
|
|
|
|
|
//校验必填项
|
|
|
- if (Utils.isEmpty(agencyName)) {
|
|
|
- ToastEngine.show("Enter Agency Name".tr);
|
|
|
+ if (Utils.isEmpty(positionName)) {
|
|
|
+ ToastEngine.show("Enter Position Name".tr);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (Utils.isEmpty(acra)) {
|
|
|
- ToastEngine.show("Enter ACRA NO".tr);
|
|
|
- return;
|
|
|
+ Future<HttpResult> taskFuture;
|
|
|
+ if (Utils.isNotEmpty(state.positionId) && state.positionId != "0") {
|
|
|
+ taskFuture = _agencyRepository.editPositionSubmit(
|
|
|
+ positionId: state.positionId,
|
|
|
+ name: positionName,
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ taskFuture = _agencyRepository.addPositionSubmit(
|
|
|
+ name: positionName,
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
- // 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);
|
|
|
- // }
|
|
|
+ var result = await taskFuture;
|
|
|
+
|
|
|
+ //处理数据
|
|
|
+ if (result.isSuccess) {
|
|
|
+ NotifyEngine.showSuccess("Successful".tr);
|
|
|
+
|
|
|
+ //根据类型刷新
|
|
|
+ state.cb?.call(state.positionId);
|
|
|
+
|
|
|
+ Get.back();
|
|
|
+ } else {
|
|
|
+ ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
void onReady() {
|
|
|
super.onReady();
|
|
|
- _fetchAddEditIndexDetail();
|
|
|
+ _showPositionName();
|
|
|
}
|
|
|
}
|