Bläddra i källkod

中介模块的合同Renew

liukai 1 vecka sedan
förälder
incheckning
eaf2d7d4bd

+ 21 - 10
packages/cpt_sg/lib/modules/agency/contract_add/contract_add_controller.dart

@@ -23,7 +23,7 @@ class ContractAddController extends GetxController with DioCancelableMixin {
   void _fetchAddEditIndexDetail() async {
     // //获取到数据
     Future<HttpResult<ContractDetailEntity>> taskFuture;
-    if (Utils.isNotEmpty(state.contractId) && state.contractId != "0") {
+    if (state.type != 0) {
       //编辑
       taskFuture = _agencyRepository.fetchContractEditDetail(contractId: state.contractId, cancelToken: cancelToken);
     } else {
@@ -37,16 +37,17 @@ class ContractAddController extends GetxController with DioCancelableMixin {
     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!];
+      if (state.type == 1){
+        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!);
+      }
+
+      if (Utils.isNotEmpty(state.detailOption?.row?.file) && state.type == 1) {
+        List<String> images = [state.detailOption!.row!.file!];
         state.selectedPaths = images;
       }
 
@@ -59,7 +60,16 @@ class ContractAddController extends GetxController with DioCancelableMixin {
   /// 提交
   void doSubmit() async {
     Future<HttpResult> taskFuture;
-    if (Utils.isNotEmpty(state.contractId) && state.contractId != "0") {
+    if (state.type == 0) {
+      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,
+      );
+
+    } else if (state.type == 1){
       taskFuture = _agencyRepository.editContractSubmit(
         contractId: state.contractId,
         agencyId: state.selectedAgencyId,
@@ -68,8 +78,9 @@ class ContractAddController extends GetxController with DioCancelableMixin {
         paths: state.selectedPaths,
         cancelToken: cancelToken,
       );
-    } else {
-      taskFuture = _agencyRepository.addContractSubmit(
+    }else{
+      taskFuture = _agencyRepository.renewContractSubmit(
+        contractId: state.contractId,
         agencyId: state.selectedAgencyId,
         startDate: DateTimeUtils.formatDate(state.selectedStartTime!, format: 'yyyy-MM-dd'),
         endDate: DateTimeUtils.formatDate(state.selectedEndTime!, format: 'yyyy-MM-dd'),

+ 15 - 5
packages/cpt_sg/lib/modules/agency/contract_add/contract_add_page.dart

@@ -30,9 +30,10 @@ class SGContractAddPage extends BaseStatelessPage<ContractAddController> {
   //启动当前页面
   static void startInstance(
     String? contractId,
+    int type, //0 add  1 edit  2 renew
     void Function(dynamic value)? cb,
   ) {
-    return Get.start(RouterPath.SGContractAdd, arguments: {'contractId': contractId, 'cb': cb});
+    return Get.start(RouterPath.SGContractAdd, arguments: {'contractId': contractId, 'type': type, 'cb': cb});
   }
 
   late ContractAddState state;
@@ -41,6 +42,7 @@ class SGContractAddPage extends BaseStatelessPage<ContractAddController> {
   void initState() {
     state = controller.state;
     state.contractId = Get.arguments['contractId'];
+    state.type = Get.arguments['type'];
     state.cb = Get.arguments['cb'] as void Function(dynamic)?;
   }
 
@@ -54,7 +56,13 @@ class SGContractAddPage extends BaseStatelessPage<ContractAddController> {
     return autoCtlGetBuilder(builder: (controller) {
       return Scaffold(
         extendBodyBehindAppBar: true,
-        appBar: MyAppBar.appBar(context, Utils.isEmpty(state.contractId) ? "Add Contract".tr : "Edit Contract".tr),
+        appBar: MyAppBar.appBar(
+            context,
+            state.type == 0
+                ? "Add Contract".tr
+                : state.type == 1
+                    ? "Edit Contract".tr
+                    : "Renew Contract"),
         body: SafeArea(
           bottom: true,
           top: false,
@@ -91,7 +99,7 @@ class SGContractAddPage extends BaseStatelessPage<ContractAddController> {
                         margin: const EdgeInsets.only(top: 10, left: 15, right: 15),
                         height: 48,
                         decoration: BoxDecoration(
-                          color: const Color(0xFF4DCFF6).withOpacity(0.2),
+                          color: const Color(0xFF4DCFF6).withOpacity(state.type == 0 ? 0.2 : 0.5),
                           borderRadius: const BorderRadius.all(Radius.circular(5)),
                         ),
                         child: Row(
@@ -113,8 +121,10 @@ class SGContractAddPage extends BaseStatelessPage<ContractAddController> {
                           ],
                         ),
                       ).onTap(() {
-                        FocusScope.of(context).unfocus();
-                        controller.pickAgency();
+                        if (state.type == 0) {
+                          FocusScope.of(context).unfocus();
+                          controller.pickAgency();
+                        }
                       }),
 
                       //必填 - 合同开始时间

+ 1 - 0
packages/cpt_sg/lib/modules/agency/contract_add/contract_add_state.dart

@@ -14,6 +14,7 @@ class ContractAddState {
   List<String> selectedPaths = [];  //选择的文件路径
 
   String? contractId;
+  int type = 0;
 
   ContractDetailEntity? detailOption;
   void Function(dynamic value)? cb;

+ 12 - 4
packages/cpt_sg/lib/modules/agency/contract_list/contract_list_controller.dart

@@ -179,7 +179,7 @@ class ContractListController extends GetxController with DioCancelableMixin {
 
   //跳转到添加页面
   void gotoAddPage() {
-    SGContractAddPage.startInstance("", (result) {
+    SGContractAddPage.startInstance("", 0, (result) {
       if (result != null) {
         refreshController.callRefresh();
       }
@@ -189,7 +189,7 @@ class ContractListController extends GetxController with DioCancelableMixin {
   //去详情页面
   void gotoDetailPage(ContractTableRows data) {
     SGContractRateListPage.startInstance(data.id, (result) {
-      if (result != null){
+      if (result != null) {
         fetchItemByIdAndRefreshItem(data.id);
       }
     });
@@ -197,7 +197,16 @@ class ContractListController extends GetxController with DioCancelableMixin {
 
   //去编辑页面
   void gotoEditPage(ContractTableRows data) {
-    SGContractAddPage.startInstance(data.id, (result) {
+    SGContractAddPage.startInstance(data.id, 1, (result) {
+      if (result != null) {
+        fetchItemByIdAndRefreshItem(data.id.toString());
+      }
+    });
+  }
+
+  //去Renew页面
+  void gotoRenewPage(ContractTableRows data) {
+    SGContractAddPage.startInstance(data.id, 2, (result) {
       if (result != null) {
         fetchItemByIdAndRefreshItem(data.id.toString());
       }
@@ -259,5 +268,4 @@ class ContractListController extends GetxController with DioCancelableMixin {
       },
     );
   }
-
 }

+ 1 - 1
packages/cpt_sg/lib/modules/agency/contract_list/contract_list_page.dart

@@ -193,7 +193,7 @@ class _LabourRequestListState extends BaseState<SGContractListPage, ContractList
                             controller.gotoDetailPage(state.datas[index]);
                           },
                           onRenewAction: () {
-
+                            controller.gotoRenewPage(state.datas[index]);
                           },
                           onEditAction: () {
                             controller.gotoEditPage(state.datas[index]);

+ 39 - 0
packages/cs_domain/lib/repository/sg_agency_repository.dart

@@ -603,6 +603,45 @@ class SGAgencyRepository extends GetxService {
     return result.convert();
   }
 
+  /// Renew合同
+  Future<HttpResult> renewContractSubmit({
+    required String? contractId,
+    required String? agencyId,
+    required String? startDate,
+    required String? endDate,
+    List<String>? paths,
+    CancelToken? cancelToken,
+  }) async {
+    //参数
+    Map<String, String> params = {};
+    params['contract_id'] = contractId ?? "";
+    params['agency_id'] = agencyId ?? "";
+    params['start_date'] = startDate ?? "";
+    params['end_date'] = endDate ?? "";
+
+    //文件
+    Map<String, String> fileParams = {};
+    if (paths != null && paths.isNotEmpty) {
+      fileParams['file'] = paths[0];
+    }
+
+    final result = await httpProvider.requestNetResult(
+      ApiConstants.apiContractRenew,
+      method: HttpMethod.POST,
+      params: params,
+      paths: fileParams,
+      networkDebounce: true,
+      isShowLoadingDialog: true,
+      cancelToken: cancelToken,
+    );
+
+    if (result.isSuccess) {
+      //重新赋值data或list
+      return result.convert();
+    }
+    return result.convert();
+  }
+
   /// 合同关联职位 Option
   Future<HttpResult<ContractPositionOptionEntity>> fetchContractPositionOption({
     required String? contractId,