// // SPSBMinePurchasersDetailsTableViewController.m // 我的社保 // // Created by jiaxian_he on 2021/5/14. // #import "SPSBMinePurchasersDetailsTableViewController.h" #import "SPSBUIGeneralHeader.h" #import "SPSBPurchasersModel.h" #import #import "SPSBTextField.h" #import "SPSBVerificationProfile.h" #import "SPSBBusinessManager.h" #import "SPSBPurchasersDetailsCheckIdCardViewController.h" #import "SPSBDisplayIdentityCardViewController.h" #import "SPSBBankDetailsViewController.h" #define spsb_minePurhcaserDetailsTitleTag 3000 #define spsb_minePurhcaserDetailsContentTag 4000 #define spsb_minePurhcaserDetailsLineTag 5000 #define spsb_minePurhcaserDetailsContentLeft 130 #define spsb_minePurhcaserDetailsTextViewRight 15 #define spsb_minePurhcaserDetailsTextViewWidth (jxh_screenWidth() - 130 - 15) #define spsb_minePurhcaserDetailsRowHeight 50 @interface SPSBMinePurchasersDetailsTableViewController () { NSArray *_titleArray; NSMutableArray *_contentArray; UITextView *_textView; SPSBTextField *_textField; CGFloat _textViewHeight; } @property (nonatomic, strong) UITableViewCell *spsb_addressCell; @property (nonatomic, strong) UITableViewCell *spsb_phoneCell; @property (nonatomic, strong) UITableViewCell *spsb_bankCell; @end @implementation SPSBMinePurchasersDetailsTableViewController - (instancetype)init { self = [super initWithStyle:UITableViewStyleGrouped backgroundColor:SPSBTableViewBackgroundColorGray]; if (!self) return nil; return self; } - (void)viewDidLoad { [super viewDidLoad]; [self initData]; [self setupTableView]; } - (void)initData { NSMutableArray *titleArray = [@[@"真实姓名", @"民族", @"身份证号", @"户籍地址", @"手机号码", @"银行卡号"] mutableCopy]; _contentArray = [@[_spsb_purchasers.spsb_user_name, _spsb_purchasers.spsb_nation, _spsb_purchasers.spsb_id_card, [_spsb_purchasers.spsb_hk_address isEqualToString:@""] ? @"未填写" : _spsb_purchasers.spsb_hk_address, _spsb_purchasers.spsb_phone, _spsb_purchasers.spsb_bank_code] mutableCopy]; if (![_spsb_purchasers.spsb_shebao_card isEqualToString:@""]) { [titleArray addObject:@"社保号"]; [_contentArray addObject:_spsb_purchasers.spsb_shebao_card]; } if (![_spsb_purchasers.spsb_fund_card isEqualToString:@""]) { [titleArray addObject:@"公积金账号"]; [_contentArray addObject:_spsb_purchasers.spsb_fund_card]; } _titleArray = titleArray; } #pragma mark - Action - (void)reloadPurchasers:(SPSBPurchasersModel *)purchasers { _spsb_purchasers = purchasers; [self initData]; } - (NSString *)spsb_phone { return _textField.text; } - (NSString *)spsb_address { return _textView.text; } #pragma mark - UITextViewDelegate - (BOOL)textViewShouldBeginEditing:(UITextView *)textView { jxh_handleInputTextView(textView, textView.font, 4, 0, NSTextAlignmentRight); return true; } - (void)textViewDidChange:(UITextView *)textView { UITextRange *selectedRange = [textView markedTextRange]; if (!selectedRange) { if (textView.text.length > SPSBMaxHouseholdRegisterAddressLength) { textView.text = [textView.text substringToIndex:SPSBMaxHouseholdRegisterAddressLength]; } } CGFloat height = [textView sizeThatFits:(CGSize){spsb_minePurhcaserDetailsTextViewWidth, CGFLOAT_MAX}].height; if (height == _textViewHeight) return; _textViewHeight = height; [textView makeConstraints:^(JXHConstraintMaker *make) { make.height.update(height); }]; if ([textView isFirstResponder]) { if (@available(iOS 11.0, *)) { [self.tableView performBatchUpdates:^{ } completion:^(BOOL finished) { }]; } else { [self.tableView beginUpdates]; [self.tableView endUpdates]; } } else { [self.tableView reloadData]; } } #pragma mark - Delegate & DataSource static NSString * const reuseIdentifier = @"SPSBMinePurchasersDetailsTableViewCell"; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 3) { return self.spsb_addressCell; } if (indexPath.section == 1) { if (indexPath.row == 0) { return self.spsb_phoneCell; } if (indexPath.row == 1) { return self.spsb_bankCell; } } UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; if (!cell) { cell = [self createCellWithReuseIdentifier:reuseIdentifier]; } UILabel *titleLabel = [cell.contentView viewWithTag:spsb_minePurhcaserDetailsTitleTag]; UILabel *contentLabel = [cell.contentView viewWithTag:spsb_minePurhcaserDetailsContentTag]; contentLabel.textColor = _spsb_isEdit ? (indexPath.row == 2 ? spsb_666666_color() : spsb_AAAAAA_color()) : spsb_808080_color(); if (indexPath.section == 0) { titleLabel.text = _titleArray[indexPath.row]; contentLabel.text = _contentArray[indexPath.row]; if (indexPath.row == 2) { cell.selectionStyle = _spsb_isEdit ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone; } } else if (indexPath.section == 2) { titleLabel.text = _titleArray[indexPath.row + 6]; contentLabel.text = _contentArray[indexPath.row + 6]; } [cell.contentView viewWithTag:spsb_minePurhcaserDetailsLineTag].hidden = indexPath.row == 0; return cell; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if (_titleArray.count > 6) return 3; return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 0) return 4; if (section == 2) return _titleArray.count - 6; return 2; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (_spsb_isEdit && indexPath.row == 3) { CGFloat height = _textViewHeight + 18; if (height < spsb_minePurhcaserDetailsRowHeight) return spsb_minePurhcaserDetailsRowHeight; return height; } return spsb_minePurhcaserDetailsRowHeight; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:false]; if (indexPath.section == 0 && indexPath.row == 2 && _spsb_isEdit) { SPSBPurchasersDetailsCheckIdCardViewController *vc = SPSBPurchasersDetailsCheckIdCardViewController.new; vc.spsb_purchasersId = _spsb_purchasers.spsb_id; @weakify(self) vc.spsb_checkSuccess = ^(NSString * _Nonnull number) { @strongify(self) SPSBDisplayIdentityCardViewController *vc = SPSBDisplayIdentityCardViewController.new; vc.spsb_identityCardNum = number; [self.navigationController pushViewController:vc animated:true]; }; [self presentViewController:vc animated:false completion:nil]; } else if (indexPath.section == 1 && indexPath.row == 1) { SPSBBankDetailsViewController *vc = SPSBBankDetailsViewController.new; vc.spsb_purchasers = _spsb_purchasers; vc.spsb_isEdit = _spsb_isEdit; @weakify(self) vc.spsb_hadChnaged = ^(SPSBPurchasersModel * _Nonnull purchasers) { @strongify(self) self->_spsb_purchasers = purchasers; if (self->_spsb_hadChnaged) { self->_spsb_hadChnaged(purchasers); } [self initData]; [self.tableView reloadData]; }; [self.navigationController pushViewController:vc animated:true]; } } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return jxh_onePixe(); } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return UIView.new; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 12; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return UIView.new; } #pragma mark - UI - (void)setupTableView { if (@available(iOS 11.0, *)) { self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic; } } - (UITableViewCell *)spsb_bankCell { if (!_spsb_bankCell) { _spsb_bankCell = [self createCellWithReuseIdentifier:nil]; ((UILabel *)[_spsb_bankCell.contentView viewWithTag:spsb_minePurhcaserDetailsTitleTag]).text = _titleArray[5]; UILabel *contentLabel = [_spsb_bankCell.contentView viewWithTag:spsb_minePurhcaserDetailsContentTag]; [contentLabel makeConstraints:^(JXHConstraintMaker *make) { make.trailing.update(-34); }]; UIImageView *arrowView = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)]; [_spsb_bankCell.contentView addSubview:arrowView]; [arrowView makeConstraints:^(JXHConstraintMaker *make) { make.trailing.equalTo(-15); make.centerY.equalTo(0); }]; } UILabel *contentLabel = [_spsb_bankCell.contentView viewWithTag:spsb_minePurhcaserDetailsContentTag]; contentLabel.textColor = _spsb_isEdit ? spsb_666666_color() : spsb_808080_color(); contentLabel.text = _contentArray[5].length > 0 ? spsb_changeDisplayBankCode(_contentArray[5]) : @"未添加"; _spsb_bankCell.selectionStyle = UITableViewCellSelectionStyleDefault; return _spsb_bankCell; } - (UITableViewCell *)spsb_phoneCell { if (!_spsb_phoneCell) { _spsb_phoneCell = [self createCellWithReuseIdentifier:nil]; ((UILabel *)[_spsb_phoneCell.contentView viewWithTag:spsb_minePurhcaserDetailsTitleTag]).text = _titleArray[4]; _textField = [SPSBTextField convenienceWithFont:spsb_font(16) placeholder:@"请输入手机号码" placeholderColor:spsb_CCCCCC_color() textColor:spsb_666666_color() clearButtonMode:UITextFieldViewModeWhileEditing returnType:UIReturnKeyDone keyboardType:UIKeyboardTypePhonePad delegate:self]; _textField.text = _spsb_purchasers.spsb_phone; _textField.spsb_maxCount = SPSBPhoneNumLength; _textField.textAlignment = NSTextAlignmentRight; [_spsb_phoneCell.contentView addSubview:_textField]; [_textField makeConstraints:^(JXHConstraintMaker *make) { make.leading.equalTo(spsb_minePurhcaserDetailsContentLeft); make.right.equalTo(-15); make.top.and.bottom.equalTo(0); }]; } UILabel *contentLabel = [_spsb_phoneCell.contentView viewWithTag:spsb_minePurhcaserDetailsContentTag]; if (_spsb_isEdit) { contentLabel.hidden = true; _textField.hidden = false; } else { contentLabel.hidden = false; _textField.hidden = true; contentLabel.text = _contentArray[4]; } [_spsb_phoneCell.contentView viewWithTag:spsb_minePurhcaserDetailsLineTag].hidden = true; return _spsb_phoneCell; } - (UITableViewCell *)spsb_addressCell { if (!_spsb_addressCell) { _spsb_addressCell = [self createCellWithReuseIdentifier:nil]; ((UILabel *)[_spsb_addressCell.contentView viewWithTag:spsb_minePurhcaserDetailsTitleTag]).text = _titleArray[3]; _textView = UITextView.new; _textView.delegate = self; _textView.textColor = spsb_666666_color(); _textView.font = spsb_font(16); _textView.textAlignment = NSTextAlignmentRight; _textView.enablesReturnKeyAutomatically = true; [_textView setTextContainerInset:UIEdgeInsetsZero]; _textView.textContainer.lineFragmentPadding = 0; _textView.scrollEnabled = false; _textView.text = _spsb_purchasers.spsb_hk_address; UILabel *label = [UILabel convenienceWithFont:spsb_font(16) text:@"请输入户籍地址" textColor:spsb_CCCCCC_color() textAlignment:NSTextAlignmentRight]; [_textView setPlaceholderLabel:label]; [_spsb_addressCell.contentView addSubview:_textView]; [_textView makeConstraints:^(JXHConstraintMaker *make) { make.leading.equalTo(spsb_minePurhcaserDetailsContentLeft); make.trailing.equalTo(-spsb_minePurhcaserDetailsTextViewRight); make.centerY.equalTo(0); make.height.equalTo(0); }]; _textViewHeight = 0.f; } UILabel *contentLabel = [_spsb_addressCell.contentView viewWithTag:spsb_minePurhcaserDetailsContentTag]; if (_spsb_isEdit) { contentLabel.hidden = true; _textView.hidden = false; [self textViewDidChange:_textView]; } else { contentLabel.hidden = false; _textView.hidden = true; contentLabel.text = _contentArray[3]; } return _spsb_addressCell; } - (UITableViewCell *)createCellWithReuseIdentifier:(nullable NSString *)reuseIdentifier { UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(16) text:@"" textColor:spsb_333333_color()]; titleLabel.tag = spsb_minePurhcaserDetailsTitleTag; [cell.contentView addSubview:titleLabel]; [titleLabel makeConstraints:^(JXHConstraintMaker *make) { make.leading.equalTo(15); make.top.equalTo(0); make.height.equalTo(spsb_minePurhcaserDetailsRowHeight); }]; UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(16) text:nil textColor:spsb_808080_color() textAlignment:NSTextAlignmentRight]; contentLabel.tag = spsb_minePurhcaserDetailsContentTag; [cell.contentView addSubview:contentLabel]; [contentLabel makeConstraints:^(JXHConstraintMaker *make) { make.leading.equalTo(spsb_minePurhcaserDetailsContentLeft); make.trailing.equalTo(-15); make.centerY.equalTo(0); }]; UIView *line = [cell.contentView createLineWithLocation:JXHLineLocationTop headOffset:15 footOffset:0]; line.tag = spsb_minePurhcaserDetailsLineTag; return cell; } @end #undef spsb_minePurhcaserDetailsTitleTag #undef spsb_minePurhcaserDetailsContentTag #undef spsb_minePurhcaserDetailsLineTag #undef spsb_minePurhcaserDetailsContentLeft #undef spsb_minePurhcaserDetailsTextViewRight #undef spsb_minePurhcaserDetailsTextViewWidth #undef spsb_minePurhcaserDetailsRowHeight