SPSBPurchasersListViewController.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // SPSBPurchasersListViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/5/14.
  6. //
  7. #import "SPSBPurchasersListViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "UIViewController+SPSBNetworkManager.h"
  10. #import "SPSBBusinessManager.h"
  11. #import "SPSBPurchasersModel.h"
  12. #import "SPSBPurchasersListTableViewController.h"
  13. #import "SPSBMyPurchaseOrder.h"
  14. #import "SPSBQuickPurchaseModel.h"
  15. #import "SPSBQuickPurchaseViewController.h"
  16. #import "SPSBAccumulationFundImformationViewController.h"
  17. #import "SPSBSocialInsuranceImformationViewController.h"
  18. @interface SPSBPurchasersListViewController () {
  19. SPSBPurchasersListTableViewController *_tableVC;
  20. UIView *_confirmView;
  21. }
  22. @end
  23. @implementation SPSBPurchasersListViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. [self setupUI];
  27. }
  28. #pragma mark - Action
  29. - (void)confirmAction {
  30. SPSBPurchasersModel *model = _tableVC.spsb_chosePurchasers;
  31. if (!model) return;
  32. switch (_spsb_type) {
  33. case SPSBPurchasersListTypePurchase:
  34. [self pushAction:model];
  35. break;
  36. case SPSBPurchasersListTypeQuickPurchase:
  37. [self getQuickPurchaseDataWithPurchasers:model type:_spsb_bussessType];
  38. break;
  39. case SPSBPurchasersListTypeQuery:
  40. if (_spsb_finishChose) {
  41. _spsb_finishChose(model);
  42. }
  43. [self dismissViewControllerAnimated:true completion:nil];
  44. default:
  45. break;
  46. }
  47. }
  48. - (void)pushAction:(SPSBPurchasersModel *)purchasers {
  49. spsb_myPurchaseOrder().spsb_purchasersData = [SPSBMyPurchasers getModelWithDictionary:[purchasers getDictionary]];
  50. spsb_myPurchaseOrder().spsb_purchasersData.spsb_sbuId = purchasers.spsb_id;
  51. spsb_myPurchaseOrder().spsb_isNewPurchasers = false;
  52. switch (_spsb_bussessType) {
  53. case SPSBSocialInsurancePurchase: {
  54. [self.navigationController pushViewController:SPSBSocialInsuranceImformationViewController.new animated:true];
  55. }
  56. break;
  57. case SPSBAccumulationFundPurchase: {
  58. [self.navigationController pushViewController:SPSBAccumulationFundImformationViewController.new animated:true];
  59. }
  60. break;
  61. default:
  62. break;
  63. }
  64. }
  65. - (void)pushQuickPurchaseDetailsViewControllerWithPurchasers:(SPSBPurchasersModel *)purchasers type:(SPSBPurchaseBusinessType)type quickPurchaseModel:(SPSBQuickPurchaseModel *)quickPurchaseModel {
  66. SPSBQuickPurchaseViewController *vc = SPSBQuickPurchaseViewController.new;
  67. vc.spsb_type = type;
  68. vc.spsb_purchasers = purchasers;
  69. vc.spsb_quickPurchaseModel = quickPurchaseModel;
  70. [self.navigationController pushViewController:vc animated:true];
  71. }
  72. #pragma mark - Network Action
  73. - (void)getQuickPurchaseDataWithPurchasers:(SPSBPurchasersModel *)purchasers type:(SPSBPurchaseBusinessType)type {
  74. @weakify(self)
  75. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在加载" isLogin:true url:spsb_appUrl(SPSBUrlGetQuickPurchaseData) urlParameters:nil parameters:^NSDictionary * _Nonnull{
  76. return @{@"sbuId": purchasers.spsb_id, @"pay_for": type == SPSBSocialInsurancePurchase ? @"1" : @"2"};
  77. } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  78. @strongify(self)
  79. SPSBQuickPurchaseModel *model = [SPSBQuickPurchaseModel getModelWithDictionary:data[@"data"]];
  80. bool judgeShebao = [model.spsb_buyShebao isEqualToString:@""] || ![model.spsb_buyShebao boolValue];
  81. bool judgeFund = [model.spsb_fund_price isEqualToString:@""] || [model.spsb_fund_price isEqualToString:@"0"];
  82. if (judgeShebao && judgeFund) {
  83. [self.view showToastWithTitle:@"此购买人没有成功下单记录哦,请返回选择“我要购买”" duration:3];
  84. return nil;
  85. } else {
  86. [model judgeDataWithName:purchasers.spsb_user_name type:type];
  87. [self pushQuickPurchaseDetailsViewControllerWithPurchasers:purchasers type:type quickPurchaseModel:model];
  88. return @"";
  89. }
  90. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  91. return @"加载失败";
  92. }];
  93. }
  94. #pragma mark - UI
  95. - (void)setupUI {
  96. self.title = _spsb_type == SPSBPurchasersListTypeManage ? @"人员管理" : @"选择人员";
  97. self.view.backgroundColor = spsb_F5F5F5_color();
  98. if (_spsb_type != SPSBPurchasersListTypeManage) {
  99. [self createConfirmView];
  100. }
  101. [self createTabelView];
  102. }
  103. - (void)createConfirmView {
  104. _confirmView = UIView.new;
  105. _confirmView.backgroundColor = spsb_FFFFFF_color(1.f);
  106. [self.view addSubview:_confirmView];
  107. [_confirmView makeConstraints:^(JXHConstraintMaker *make) {
  108. make.leading.and.trailing.and.bottom.equalTo(0);
  109. make.top.equalTo(self.view.safebottom).offset(-56);
  110. }];
  111. UIButton *confirmButton = [UIButton convenienceWithFont:spsb_semiboldFont(16) target:self action:@selector(confirmAction)];
  112. [confirmButton setTitle:@"确定" titleColor:spsb_FFFFFF_color(1.f) image:nil backgroundImage:jxh_getImage(confirm_n) state:JXHButtonControlStateNormal];
  113. [confirmButton setBackgroundImage:jxh_getImage(confirm_h) state:JXHButtonControlStateHighlighted];
  114. [confirmButton setLayerCornerRadius:22.5 clipToBounds:true];
  115. [_confirmView addSubview:confirmButton];
  116. [confirmButton makeConstraints:^(JXHConstraintMaker *make) {
  117. make.top.equalTo(6);
  118. make.leading.equalTo(10);
  119. make.trailing.equalTo(-10);
  120. make.height.equalTo(45);
  121. }];
  122. }
  123. - (void)createTabelView {
  124. _tableVC = SPSBPurchasersListTableViewController.new;
  125. _tableVC.spsb_type = _spsb_type;
  126. _tableVC.spsb_bussessType = _spsb_bussessType;
  127. [self addChildViewController:_tableVC];
  128. [self.view addSubview:_tableVC.tableView];
  129. if (_confirmView) {
  130. [_tableVC.tableView makeConstraints:^(JXHConstraintMaker *make) {
  131. make.top.and.leading.and.trailing.equalTo(0);
  132. make.bottom.equalTo(self->_confirmView.top);
  133. }];
  134. } else {
  135. [_tableVC.tableView makeConstraints:^(JXHConstraintMaker *make) {
  136. make.edges.equalTo(self.view);
  137. }];
  138. }
  139. }
  140. @end