// // SPSBPurchasersListViewController.m // 我的社保 // // Created by shanp on 2021/5/14. // #import "SPSBPurchasersListViewController.h" #import "SPSBUIGeneralHeader.h" #import "UIViewController+SPSBNetworkManager.h" #import "SPSBBusinessManager.h" #import "SPSBPurchasersModel.h" #import "SPSBPurchasersListTableViewController.h" #import "SPSBMyPurchaseOrder.h" #import "SPSBQuickPurchaseModel.h" #import "SPSBQuickPurchaseViewController.h" #import "SPSBAccumulationFundImformationViewController.h" #import "SPSBSocialInsuranceImformationViewController.h" @interface SPSBPurchasersListViewController () { SPSBPurchasersListTableViewController *_tableVC; UIView *_confirmView; } @end @implementation SPSBPurchasersListViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupUI]; } #pragma mark - Action - (void)confirmAction { SPSBPurchasersModel *model = _tableVC.spsb_chosePurchasers; if (!model) return; switch (_spsb_type) { case SPSBPurchasersListTypePurchase: [self pushAction:model]; break; case SPSBPurchasersListTypeQuickPurchase: [self getQuickPurchaseDataWithPurchasers:model type:_spsb_bussessType]; break; case SPSBPurchasersListTypeQuery: if (_spsb_finishChose) { _spsb_finishChose(model); } [self dismissViewControllerAnimated:true completion:nil]; default: break; } } - (void)pushAction:(SPSBPurchasersModel *)purchasers { spsb_myPurchaseOrder().spsb_purchasersData = [SPSBMyPurchasers getModelWithDictionary:[purchasers getDictionary]]; spsb_myPurchaseOrder().spsb_purchasersData.spsb_sbuId = purchasers.spsb_id; spsb_myPurchaseOrder().spsb_isNewPurchasers = false; switch (_spsb_bussessType) { case SPSBSocialInsurancePurchase: { [self.navigationController pushViewController:SPSBSocialInsuranceImformationViewController.new animated:true]; } break; case SPSBAccumulationFundPurchase: { [self.navigationController pushViewController:SPSBAccumulationFundImformationViewController.new animated:true]; } break; default: break; } } - (void)pushQuickPurchaseDetailsViewControllerWithPurchasers:(SPSBPurchasersModel *)purchasers type:(SPSBPurchaseBusinessType)type quickPurchaseModel:(SPSBQuickPurchaseModel *)quickPurchaseModel { SPSBQuickPurchaseViewController *vc = SPSBQuickPurchaseViewController.new; vc.spsb_type = type; vc.spsb_purchasers = purchasers; vc.spsb_quickPurchaseModel = quickPurchaseModel; [self.navigationController pushViewController:vc animated:true]; } #pragma mark - Network Action - (void)getQuickPurchaseDataWithPurchasers:(SPSBPurchasersModel *)purchasers type:(SPSBPurchaseBusinessType)type { @weakify(self) [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在加载" isLogin:true url:spsb_appUrl(SPSBUrlGetQuickPurchaseData) urlParameters:nil parameters:^NSDictionary * _Nonnull{ return @{@"sbuId": purchasers.spsb_id, @"pay_for": type == SPSBSocialInsurancePurchase ? @"1" : @"2"}; } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) { @strongify(self) SPSBQuickPurchaseModel *model = [SPSBQuickPurchaseModel getModelWithDictionary:data[@"data"]]; bool judgeShebao = [model.spsb_buyShebao isEqualToString:@""] || ![model.spsb_buyShebao boolValue]; bool judgeFund = [model.spsb_fund_price isEqualToString:@""] || [model.spsb_fund_price isEqualToString:@"0"]; if (judgeShebao && judgeFund) { [self.view showToastWithTitle:@"此购买人没有成功下单记录哦,请返回选择“我要购买”" duration:3]; return nil; } else { [model judgeDataWithName:purchasers.spsb_user_name type:type]; [self pushQuickPurchaseDetailsViewControllerWithPurchasers:purchasers type:type quickPurchaseModel:model]; return @""; } } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) { return @"加载失败"; }]; } #pragma mark - UI - (void)setupUI { self.title = _spsb_type == SPSBPurchasersListTypeManage ? @"人员管理" : @"选择人员"; self.view.backgroundColor = spsb_F5F5F5_color(); if (_spsb_type != SPSBPurchasersListTypeManage) { [self createConfirmView]; } [self createTabelView]; } - (void)createConfirmView { _confirmView = UIView.new; _confirmView.backgroundColor = spsb_FFFFFF_color(1.f); [self.view addSubview:_confirmView]; [_confirmView makeConstraints:^(JXHConstraintMaker *make) { make.leading.and.trailing.and.bottom.equalTo(0); make.top.equalTo(self.view.safebottom).offset(-56); }]; UIButton *confirmButton = [UIButton convenienceWithFont:spsb_semiboldFont(16) target:self action:@selector(confirmAction)]; [confirmButton setTitle:@"确定" titleColor:spsb_FFFFFF_color(1.f) image:nil backgroundImage:jxh_getImage(confirm_n) state:JXHButtonControlStateNormal]; [confirmButton setBackgroundImage:jxh_getImage(confirm_h) state:JXHButtonControlStateHighlighted]; [confirmButton setLayerCornerRadius:22.5 clipToBounds:true]; [_confirmView addSubview:confirmButton]; [confirmButton makeConstraints:^(JXHConstraintMaker *make) { make.top.equalTo(6); make.leading.equalTo(10); make.trailing.equalTo(-10); make.height.equalTo(45); }]; } - (void)createTabelView { _tableVC = SPSBPurchasersListTableViewController.new; _tableVC.spsb_type = _spsb_type; _tableVC.spsb_bussessType = _spsb_bussessType; [self addChildViewController:_tableVC]; [self.view addSubview:_tableVC.tableView]; if (_confirmView) { [_tableVC.tableView makeConstraints:^(JXHConstraintMaker *make) { make.top.and.leading.and.trailing.equalTo(0); make.bottom.equalTo(self->_confirmView.top); }]; } else { [_tableVC.tableView makeConstraints:^(JXHConstraintMaker *make) { make.edges.equalTo(self.view); }]; } } @end