Browse Source

用工请求的加入房间计费逻辑和金额类型

liukai 7 months ago
parent
commit
382c985ddf

+ 13 - 0
packages/cpt_labour/lib/modules/labour_request_add/labour_request_add_controller.dart

@@ -38,9 +38,13 @@ class LabourRequestAddController extends GetxController {
       state.noStaff = state.labReqOption?.needNum.toString() == "0" ? "" : state.labReqOption?.needNum.toString();
       var needNumController = state.formData['no_of_staff']!['controller'];
       needNumController.text = state.noStaff;
+      var amountController = state.formData['amount']!['controller'];
+      amountController.text = state.labReqOption?.amount ?? "";
       state.selectedTemplateId = state.labReqOption?.templateId;
       state.selectedDepartmentId = state.labReqOption?.departmentId;
 
+      state.chargeOptionId = state.labReqOption?.chargeList.firstWhere((element) => element.checked == "checked").value;
+
       update();
     } else {
       ToastEngine.show(result.errorMsg ?? "Network Load Error".tr);
@@ -56,7 +60,9 @@ class LabourRequestAddController extends GetxController {
   /// 提交
   void doSubmit() async {
     var needNumController = state.formData['no_of_staff']!['controller'];
+    var amountController = state.formData['amount']!['controller'];
     String needNum = needNumController.text.toString();
+    String amount = amountController.text.toString();
 
     if (Utils.isEmpty(state.selectedTemplateId)) {
       ToastEngine.show("Choose Job Title".tr);
@@ -73,6 +79,9 @@ class LabourRequestAddController extends GetxController {
     } else if (Utils.isEmpty(needNum)) {
       ToastEngine.show("Enter No. of Staff".tr);
       return;
+    } else if (state.labReqOption?.serviceType == 1 && Utils.isEmpty(amount)) {
+      ToastEngine.show("Enter Amount".tr);
+      return;
     }
 
     Future<HttpResult> taskFuture;
@@ -84,6 +93,8 @@ class LabourRequestAddController extends GetxController {
         DateTimeUtils.formatDate(state.selectedEndTime),
         state.selectedDepartmentId,
         needNum,
+        state.chargeOptionId,
+        state.labReqOption?.serviceType == 1 ? amount : null,
       );
     } else {
       taskFuture = _labourRepository.addLabourRequestSubmit(
@@ -92,6 +103,8 @@ class LabourRequestAddController extends GetxController {
         DateTimeUtils.formatDate(state.selectedEndTime),
         state.selectedDepartmentId,
         needNum,
+        state.chargeOptionId,
+        state.labReqOption?.serviceType == 1 ? amount : null,
       );
     }
 

+ 46 - 0
packages/cpt_labour/lib/modules/labour_request_add/labour_request_add_page.dart

@@ -12,6 +12,7 @@ import 'package:plugin_basic/utils/ext_get_nav.dart';
 import 'package:router/path/router_path.dart';
 import 'package:shared/utils/date_time_utils.dart';
 import 'package:shared/utils/screen_util.dart';
+import 'package:widgets/custom_radio_check.dart';
 import 'package:widgets/ext/ex_widget.dart';
 import 'package:widgets/my_appbar.dart';
 import 'package:widgets/my_button.dart';
@@ -285,6 +286,51 @@ class _LabourRequestAddState extends BaseState<LabourRequestAddPage, LabourReque
                         marginTop: 10,
                       ),
 
+                      FormRequireText(
+                        text: "Salary By".tr,
+                      ).marginOnly(top: 15),
+
+                      //选择计费类型
+                      state.labReqOption != null
+                          ? CustomRadioCheck(
+                        options: state.labReqOption!.chargeList.map((e) => e.txt).whereType<String>().toList(), //后台返回的数据展示,并且根据后台的数据匹配索引
+                        selectedPosition: state.labReqOption!.chargeList.indexWhere((element) => element.checked == "checked"),
+                        onOptionSelected: (index, text) {
+                          //修改内存的值
+                          state.chargeOptionId = state.labReqOption!.chargeList[index].value;
+                        },
+                      ).marginOnly(top: 15)
+                          : CircularProgressIndicator(),
+
+                      //选择是否需要输入金额
+                      Visibility(
+                        visible: state.labReqOption?.serviceType == 1,
+                        child: FormRequireText(
+                          text: "Amount".tr,
+                        ).marginOnly(top: 15),
+                      ),
+
+                      Visibility(
+                        visible: state.labReqOption?.serviceType == 1,
+                        child: CustomTextField(
+                          formKey: "amount",
+                          marginLeft: 0,
+                          marginRight: 0,
+                          paddingTop: 0,
+                          paddingBottom: 0,
+                          height: 45,
+                          fillBackgroundColor: Color(0xFF4DCFF6).withOpacity(state.pageType == 2 ? 0.5 : 0.2),
+                          enabled: state.pageType != 2,
+                          textInputType: TextInputType.number,
+                          formData: state.formData,
+                          textInputAction: TextInputAction.done,
+                          onSubmit: (key, value) {
+                            FocusScope.of(context).unfocus();
+                          },
+                          marginTop: 10,
+                        ),
+                      ),
+
                       //提交按钮
                       Visibility(
                         visible: state.pageType != 2,

+ 9 - 0
packages/cpt_labour/lib/modules/labour_request_add/labour_request_add_state.dart

@@ -17,6 +17,8 @@ class LabourRequestAddState {
   String? selectedDepartmentId;
   String? noStaff;  //成员数量
 
+  String? chargeOptionId;
+
   //表单的校验与数据
   Map<String, Map<String, dynamic>> formData = {
     'no_of_staff': {
@@ -26,6 +28,13 @@ class LabourRequestAddState {
       'hintText': 'Enter No. of Staff'.tr,
       'obsecure': false,
     },
+    'amount': {
+      'value': '',
+      'controller': TextEditingController(),
+      'focusNode': FocusNode(),
+      'hintText': 'Enter Amount'.tr,
+      'obsecure': false,
+    },
   };
 
 }

+ 1 - 1
packages/cs_domain/lib/constants/api_constants.dart

@@ -2,7 +2,7 @@
 
 class ApiConstants {
   //当前服务器环境
-  static const isServerRelease = true;
+  static const isServerRelease = false;
 
   //越南的域名
   static const baseUrl = isServerRelease ? 'https://vietnam.casualabour.com' : 'http://vietnam-dev.casualabour.com';

+ 8 - 1
packages/cs_domain/lib/entity/response/labour_request_edit_index_entity.dart

@@ -7,6 +7,8 @@ export 'package:domain/generated/json/labour_request_edit_index_entity.g.dart';
 class LabourRequestEditIndexEntity {
   @JSONField(name: "request_id")
   int requestId = 0;
+  @JSONField(name: "service_type")
+  int serviceType = 0;
   @JSONField(name: "job_start")
   String? jobStart;
   @JSONField(name: "job_end")
@@ -17,10 +19,14 @@ class LabourRequestEditIndexEntity {
   String? templateId;
   @JSONField(name: "need_num")
   int needNum = 0;
+  @JSONField(name: "amount")
+  String? amount = null;
   @JSONField(name: "template_list")
   List<LabourRequestEditIndexTemplateList> templateList = [];
   @JSONField(name: "department_list")
   List<LabourRequestEditIndexDepartmentList> departmentList = [];
+  @JSONField(name: "charge_list")
+  List<LabourRequestEditIndexDepartmentList> chargeList = [];
 
   LabourRequestEditIndexEntity();
 
@@ -54,9 +60,10 @@ class LabourRequestEditIndexTemplateList {
 
 @JsonSerializable()
 class LabourRequestEditIndexDepartmentList {
-  int? value = 0;
+  String? value = null;
   String? txt = '';
   String? selected = '';
+  String? checked = '';
 
   LabourRequestEditIndexDepartmentList();
 

+ 33 - 4
packages/cs_domain/lib/generated/json/labour_request_edit_index_entity.g.dart

@@ -7,6 +7,10 @@ LabourRequestEditIndexEntity $LabourRequestEditIndexEntityFromJson(Map<String, d
   if (requestId != null) {
     labourRequestEditIndexEntity.requestId = requestId;
   }
+  final int? serviceType = jsonConvert.convert<int>(json['service_type']);
+  if (serviceType != null) {
+    labourRequestEditIndexEntity.serviceType = serviceType;
+  }
   final String? jobStart = jsonConvert.convert<String>(json['job_start']);
   if (jobStart != null) {
     labourRequestEditIndexEntity.jobStart = jobStart;
@@ -27,6 +31,10 @@ LabourRequestEditIndexEntity $LabourRequestEditIndexEntityFromJson(Map<String, d
   if (needNum != null) {
     labourRequestEditIndexEntity.needNum = needNum;
   }
+  final String? amount = jsonConvert.convert<String>(json['amount']);
+  if (amount != null) {
+    labourRequestEditIndexEntity.amount = amount;
+  }
   final List<LabourRequestEditIndexTemplateList>? templateList = (json['template_list'] as List<dynamic>?)?.map(
           (e) => jsonConvert.convert<LabourRequestEditIndexTemplateList>(e) as LabourRequestEditIndexTemplateList).toList();
   if (templateList != null) {
@@ -37,42 +45,56 @@ LabourRequestEditIndexEntity $LabourRequestEditIndexEntityFromJson(Map<String, d
   if (departmentList != null) {
     labourRequestEditIndexEntity.departmentList = departmentList;
   }
+  final List<LabourRequestEditIndexDepartmentList>? chargeList = (json['charge_list'] as List<dynamic>?)?.map(
+          (e) => jsonConvert.convert<LabourRequestEditIndexDepartmentList>(e) as LabourRequestEditIndexDepartmentList).toList();
+  if (chargeList != null) {
+    labourRequestEditIndexEntity.chargeList = chargeList;
+  }
   return labourRequestEditIndexEntity;
 }
 
 Map<String, dynamic> $LabourRequestEditIndexEntityToJson(LabourRequestEditIndexEntity entity) {
   final Map<String, dynamic> data = <String, dynamic>{};
   data['request_id'] = entity.requestId;
+  data['service_type'] = entity.serviceType;
   data['job_start'] = entity.jobStart;
   data['job_end'] = entity.jobEnd;
   data['department_id'] = entity.departmentId;
   data['template_id'] = entity.templateId;
   data['need_num'] = entity.needNum;
+  data['amount'] = entity.amount;
   data['template_list'] = entity.templateList.map((v) => v.toJson()).toList();
   data['department_list'] = entity.departmentList.map((v) => v.toJson()).toList();
+  data['charge_list'] = entity.chargeList.map((v) => v.toJson()).toList();
   return data;
 }
 
 extension LabourRequestEditIndexEntityExtension on LabourRequestEditIndexEntity {
   LabourRequestEditIndexEntity copyWith({
     int? requestId,
+    int? serviceType,
     String? jobStart,
     String? jobEnd,
     String? departmentId,
     String? templateId,
     int? needNum,
+    String? amount,
     List<LabourRequestEditIndexTemplateList>? templateList,
     List<LabourRequestEditIndexDepartmentList>? departmentList,
+    List<LabourRequestEditIndexDepartmentList>? chargeList,
   }) {
     return LabourRequestEditIndexEntity()
       ..requestId = requestId ?? this.requestId
+      ..serviceType = serviceType ?? this.serviceType
       ..jobStart = jobStart ?? this.jobStart
       ..jobEnd = jobEnd ?? this.jobEnd
       ..departmentId = departmentId ?? this.departmentId
       ..templateId = templateId ?? this.templateId
       ..needNum = needNum ?? this.needNum
+      ..amount = amount ?? this.amount
       ..templateList = templateList ?? this.templateList
-      ..departmentList = departmentList ?? this.departmentList;
+      ..departmentList = departmentList ?? this.departmentList
+      ..chargeList = chargeList ?? this.chargeList;
   }
 }
 
@@ -116,7 +138,7 @@ extension LabourRequestEditIndexTemplateListExtension on LabourRequestEditIndexT
 
 LabourRequestEditIndexDepartmentList $LabourRequestEditIndexDepartmentListFromJson(Map<String, dynamic> json) {
   final LabourRequestEditIndexDepartmentList labourRequestEditIndexDepartmentList = LabourRequestEditIndexDepartmentList();
-  final int? value = jsonConvert.convert<int>(json['value']);
+  final String? value = jsonConvert.convert<String>(json['value']);
   if (value != null) {
     labourRequestEditIndexDepartmentList.value = value;
   }
@@ -128,6 +150,10 @@ LabourRequestEditIndexDepartmentList $LabourRequestEditIndexDepartmentListFromJs
   if (selected != null) {
     labourRequestEditIndexDepartmentList.selected = selected;
   }
+  final String? checked = jsonConvert.convert<String>(json['checked']);
+  if (checked != null) {
+    labourRequestEditIndexDepartmentList.checked = checked;
+  }
   return labourRequestEditIndexDepartmentList;
 }
 
@@ -136,18 +162,21 @@ Map<String, dynamic> $LabourRequestEditIndexDepartmentListToJson(LabourRequestEd
   data['value'] = entity.value;
   data['txt'] = entity.txt;
   data['selected'] = entity.selected;
+  data['checked'] = entity.checked;
   return data;
 }
 
 extension LabourRequestEditIndexDepartmentListExtension on LabourRequestEditIndexDepartmentList {
   LabourRequestEditIndexDepartmentList copyWith({
-    int? value,
+    String? value,
     String? txt,
     String? selected,
+    String? checked,
   }) {
     return LabourRequestEditIndexDepartmentList()
       ..value = value ?? this.value
       ..txt = txt ?? this.txt
-      ..selected = selected ?? this.selected;
+      ..selected = selected ?? this.selected
+      ..checked = checked ?? this.checked;
   }
 }

+ 18 - 3
packages/cs_domain/lib/repository/labour_repository.dart

@@ -143,7 +143,9 @@ class LabourRepository extends GetxService {
     String? jobStart,
     String? jobEnd,
     String? departmentId,
-    String? needNum, {
+    String? needNum,
+    String? salaryBy,
+    String? amount, {
     CancelToken? cancelToken,
   }) async {
     //参数
@@ -156,6 +158,12 @@ class LabourRepository extends GetxService {
       params["co_department_id"] = departmentId!;
     }
 
+    params['salary_by'] = salaryBy ?? "";
+
+    if (!Utils.isEmpty(amount)) {
+      params["amount"] = amount!;
+    }
+
     final result = await httpProvider.requestNetResult(
       ApiConstants.apiLabourRequestAddSubmit,
       method: HttpMethod.POST,
@@ -207,7 +215,9 @@ class LabourRepository extends GetxService {
     String? jobStart,
     String? jobEnd,
     String? departmentId,
-    String? needNum, {
+    String? needNum,
+    String? salaryBy,
+    String? amount, {
     CancelToken? cancelToken,
   }) async {
     //参数
@@ -221,6 +231,12 @@ class LabourRepository extends GetxService {
       params["co_department_id"] = departmentId!;
     }
 
+    params['salary_by'] = salaryBy ?? "";
+
+    if (!Utils.isEmpty(amount)) {
+      params["amount"] = amount!;
+    }
+
     final result = await httpProvider.requestNetResult(
       ApiConstants.apiLabourRequestEditSubmit,
       method: HttpMethod.POST,
@@ -291,5 +307,4 @@ class LabourRepository extends GetxService {
     }
     return result.convert();
   }
-
 }