// // MerchantBankInfoView.m // merchant // // Created by qitewei on 2025/8/14. // Copyright © 2025 xfg. All rights reserved. // #import "MerchantBankInfoView.h" #import "UIView+Extention.h" @implementation MerchantBankInfoView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setupUI]; [self setupConstraints]; } return self; } - (void)setupUI { self.backgroundColor = [UIColor clearColor]; // 添加提示信息区域 [self setupWarningSection]; // 添加账户名称区域 [self setupAccountNameSection]; // 添加账户号码区域 [self setupAccountNumberSection]; // 添加开户行区域 [self setupBankNameSection]; // 添加银行卡上传区域 [self setupBankCardSection]; } - (void)setupWarningSection { [self.contentView addSubview:self.warningView]; [self.warningView addSubview:self.warningIcon]; [self.warningView addSubview:self.warningLabel]; } - (void)setupAccountNameSection { [self.contentView addSubview:self.accountNameLabel]; [self.contentView addSubview:self.accountNameTextField]; } - (void)setupAccountNumberSection { [self.contentView addSubview:self.accountNumberLabel]; [self.contentView addSubview:self.accountNumberTextField]; } - (void)setupBankNameSection { [self.contentView addSubview:self.bankNameLabel]; [self.contentView addSubview:self.bankNameTextField]; } - (void)setupBankCardSection { [self.contentView addSubview:self.uploadBankCardLabel]; [self.contentView addSubview:self.frontCardView]; [self.contentView addSubview:self.backCardView]; // 正面 [self.frontCardView addSubview:self.frontCardTitleLabel]; [self.frontCardView addSubview:self.frontCardSubtitleLabel]; [self.frontCardView addSubview:self.frontCardImageView]; // 反面 [self.backCardView addSubview:self.backCardTitleLabel]; [self.backCardView addSubview:self.backCardSubtitleLabel]; [self.backCardView addSubview:self.backCardImageView]; } - (void)setupConstraints { // 提示信息 [self.warningView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(kRealValue(24)); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.contentView).offset(kRealValue(20)); make.height.mas_equalTo(kRealValue(44)); }]; [self.warningIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.warningView).offset(kRealValue(12)); make.centerY.equalTo(self.warningView); make.size.mas_equalTo(CGSizeMake(kRealValue(16), kRealValue(16))); }]; [self.warningLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.warningIcon.mas_right).offset(kRealValue(8)); make.right.equalTo(self.warningView).offset(-kRealValue(12)); make.centerY.equalTo(self.warningView); }]; // 账户名称 [self.accountNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(kRealValue(24)); make.top.equalTo(self.warningView.mas_bottom).offset(kRealValue(24)); }]; [self.accountNameTextField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.accountNameLabel); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.accountNameLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(48)); }]; // 账户号码 [self.accountNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.accountNameLabel); make.top.equalTo(self.accountNameTextField.mas_bottom).offset(kRealValue(24)); }]; [self.accountNumberTextField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.accountNumberLabel); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.accountNumberLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(48)); }]; // 开户行 [self.bankNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.accountNameLabel); make.top.equalTo(self.accountNumberTextField.mas_bottom).offset(kRealValue(24)); }]; [self.bankNameTextField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.bankNameLabel); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.bankNameLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(48)); }]; // 请上传银行卡 [self.uploadBankCardLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.accountNameLabel); make.top.equalTo(self.bankNameTextField.mas_bottom).offset(kRealValue(24)); }]; // 正面 [self.frontCardView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.uploadBankCardLabel); make.right.equalTo(self.bankNameTextField); make.top.equalTo(self.uploadBankCardLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(152)); }]; [self.frontCardTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.frontCardView).offset(kRealValue(12)); make.top.equalTo(self.frontCardView).offset(kRealValue(12)); }]; [self.frontCardSubtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.frontCardTitleLabel); make.right.equalTo(self.frontCardImageView.mas_left).mas_offset(-8); make.top.equalTo(self.frontCardTitleLabel.mas_bottom).offset(kRealValue(4)); }]; [self.frontCardImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.frontCardView).inset(kRealValue(16)); make.centerY.equalTo(self.frontCardView); make.height.mas_equalTo(kRealValue(120)); make.width.mas_equalTo(kRealValue(185)); }]; // 反面 [self.backCardView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.frontCardView); make.top.equalTo(self.frontCardView.mas_bottom).offset(kRealValue(16)); make.height.mas_equalTo(kRealValue(152)); make.bottom.equalTo(self.contentView).offset(-kRealValue(20)); }]; [self.backCardTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backCardView).offset(kRealValue(12)); make.top.equalTo(self.backCardView).offset(kRealValue(12)); }]; [self.backCardSubtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backCardTitleLabel); make.right.equalTo(self.backCardImageView.mas_left).mas_offset(-8); make.top.equalTo(self.backCardTitleLabel.mas_bottom).offset(kRealValue(4)); }]; [self.backCardImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.backCardView).inset(kRealValue(16)); make.centerY.equalTo(self.backCardView); make.size.mas_equalTo(self.frontCardImageView); }]; } #pragma mark - Validation - (BOOL)validateForm { // 验证账户名称 if (self.accountNameTextField.text.length == 0) { [self makeToast:self.accountNameTextField.placeholder]; return NO; } // 验证账户号码 if (self.accountNumberTextField.text.length == 0) { [self makeToast:self.accountNumberTextField.placeholder]; return NO; } // 验证开户行 if (self.bankNameTextField.text.length == 0) { [self makeToast:self.bankNameTextField.placeholder]; return NO; } // 验证银行卡正面照片 if (self.frontURL.length == 0) { [self makeToast:self.frontCardSubtitleLabel.text]; return NO; } // 验证银行卡反面照片 if (self.backURL.length == 0) { [self makeToast:self.backCardSubtitleLabel.text]; return NO; } return YES; } #pragma mark - Public Methods - (BOOL)canGoNext { return [self validateForm]; } - (void)goNext { if ([self validateForm]) { [super goNext]; } } #pragma mark - Actions - (void)frontCardTapped:(UITapGestureRecognizer *)gesture { WeakSelf [self pickImageWithCompletion:^(UIImage *image) { weakSelf.frontCardImageView.image = image; // 上传图片到服务器 [weakSelf uploadImage:image completion:^(NSString *url) { weakSelf.frontURL = url; }]; }]; } - (void)backCardTapped:(UITapGestureRecognizer *)gesture { WeakSelf [self pickImageWithCompletion:^(UIImage *image) { weakSelf.backCardImageView.image = image; // 上传图片到服务器 [weakSelf uploadImage:image completion:^(NSString *url) { weakSelf.backURL = url; }]; }]; } #pragma mark - MerchantEnrollParametersDataSource - (NSDictionary *)getMerchantEnrollParameters { return @{ @"bank_card_number": self.accountNumberTextField.text ?: @"", @"bank_card_name": self.accountNameTextField.text ?: @"", @"bank_opening_account": self.bankNameTextField.text ?: @"", @"bank_front_photo": self.frontURL ?: @"", @"bank_back_photo": self.backURL ?: @"", }; } #pragma mark - MerchantEnrollDataFillDelegate - (void)fillWithData:(NSDictionary *)data { if (!data) { return; } // 填充文本字段 self.accountNameTextField.text = data[@"bank_card_name"] ?: @""; self.accountNumberTextField.text = data[@"bank_card_number"] ?: @""; self.bankNameTextField.text = data[@"bank_opening_account"] ?: @""; // 填充图片URL self.frontURL = data[@"bank_front_photo"] ?: @""; self.backURL = data[@"bank_back_photo"] ?: @""; // 如果有图片URL,可以考虑异步加载图片 if (self.frontURL.length > 0) { [self loadImageFromURL:self.frontURL forImageView:self.frontCardImageView]; } if (self.backURL.length > 0) { [self loadImageFromURL:self.backURL forImageView:self.backCardImageView]; } } - (void)loadImageFromURL:(NSString *)urlString forImageView:(UIImageView *)imageView { if (urlString.length == 0) { return; } NSURL *url = [NSURL URLWithString:urlString]; if (!url) { return; } [imageView setImageURL:url]; } #pragma mark - Lazy Loading - (UIView *)warningView { if (!_warningView) { _warningView = [[UIView alloc] init]; _warningView.backgroundColor = [UIColor colorWithHexString:@"#FFF8E1"]; _warningView.layer.cornerRadius = kRealValue(8); _warningView.layer.borderWidth = 1; _warningView.layer.borderColor = [UIColor colorWithHexString:@"#FFD54F"].CGColor; } return _warningView; } - (UIImageView *)warningIcon { if (!_warningIcon) { _warningIcon = [[UIImageView alloc] init]; // 使用系统内置的警告图标,如果找不到自定义图标 UIImage *warningImage = [UIImage imageNamed:@"store_bank_tips"]; _warningIcon.image = warningImage; _warningIcon.contentMode = UIViewContentModeScaleAspectFit; _warningIcon.tintColor = [UIColor colorWithHexString:@"#F57C00"]; } return _warningIcon; } - (UILabel *)warningLabel { if (!_warningLabel) { _warningLabel = [[UILabel alloc] init]; _warningLabel.text = ASLocalizedString(@"用于收款和缴保证金,请确认账户可以正常交易。"); _warningLabel.font = [UIFont systemFontOfSize:12]; _warningLabel.textColor = [UIColor colorWithHexString:@"#F57C00"]; _warningLabel.numberOfLines = 0; } return _warningLabel; } - (UILabel *)accountNameLabel { if (!_accountNameLabel) { _accountNameLabel = [[UILabel alloc] init]; _accountNameLabel.text = ASLocalizedString(@"账户名称"); _accountNameLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _accountNameLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_accountNameLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _accountNameLabel.attributedText = attributedText; } return _accountNameLabel; } - (UITextField *)accountNameTextField { if (!_accountNameTextField) { _accountNameTextField = [[UITextField alloc] init]; _accountNameTextField.placeholder = ASLocalizedString(@"请输入账户名称"); _accountNameTextField.font = [UIFont systemFontOfSize:16]; _accountNameTextField.textColor = [UIColor blackColor]; _accountNameTextField.backgroundColor = [UIColor whiteColor]; _accountNameTextField.layer.cornerRadius = kRealValue(8); _accountNameTextField.layer.borderWidth = 1; _accountNameTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; // 设置内边距 UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _accountNameTextField.leftView = leftView; _accountNameTextField.leftViewMode = UITextFieldViewModeAlways; UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _accountNameTextField.rightView = rightView; _accountNameTextField.rightViewMode = UITextFieldViewModeAlways; // 设置键盘返回键类型 _accountNameTextField.returnKeyType = UIReturnKeyNext; _accountNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing; } return _accountNameTextField; } - (UILabel *)accountNumberLabel { if (!_accountNumberLabel) { _accountNumberLabel = [[UILabel alloc] init]; _accountNumberLabel.text = ASLocalizedString(@"账户号码"); _accountNumberLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _accountNumberLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_accountNumberLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _accountNumberLabel.attributedText = attributedText; } return _accountNumberLabel; } - (UITextField *)accountNumberTextField { if (!_accountNumberTextField) { _accountNumberTextField = [[UITextField alloc] init]; _accountNumberTextField.placeholder = ASLocalizedString(@"请输入账户号码"); _accountNumberTextField.font = [UIFont systemFontOfSize:16]; _accountNumberTextField.textColor = [UIColor blackColor]; _accountNumberTextField.backgroundColor = [UIColor whiteColor]; _accountNumberTextField.layer.cornerRadius = kRealValue(8); _accountNumberTextField.layer.borderWidth = 1; _accountNumberTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; _accountNumberTextField.keyboardType = UIKeyboardTypeDecimalPad; // 设置内边距 UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _accountNumberTextField.leftView = leftView; _accountNumberTextField.leftViewMode = UITextFieldViewModeAlways; UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _accountNumberTextField.rightView = rightView; _accountNumberTextField.rightViewMode = UITextFieldViewModeAlways; _accountNumberTextField.clearButtonMode = UITextFieldViewModeWhileEditing; } return _accountNumberTextField; } - (UILabel *)bankNameLabel { if (!_bankNameLabel) { _bankNameLabel = [[UILabel alloc] init]; _bankNameLabel.text = ASLocalizedString(@"开户行"); _bankNameLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _bankNameLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_bankNameLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _bankNameLabel.attributedText = attributedText; } return _bankNameLabel; } - (UITextField *)bankNameTextField { if (!_bankNameTextField) { _bankNameTextField = [[UITextField alloc] init]; _bankNameTextField.placeholder = ASLocalizedString(@"请输入开户行"); _bankNameTextField.font = [UIFont systemFontOfSize:16]; _bankNameTextField.textColor = [UIColor blackColor]; _bankNameTextField.backgroundColor = [UIColor whiteColor]; _bankNameTextField.layer.cornerRadius = kRealValue(8); _bankNameTextField.layer.borderWidth = 1; _bankNameTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; // 设置内边距 UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _bankNameTextField.leftView = leftView; _bankNameTextField.leftViewMode = UITextFieldViewModeAlways; UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _bankNameTextField.rightView = rightView; _bankNameTextField.rightViewMode = UITextFieldViewModeAlways; // 设置键盘返回键类型 _bankNameTextField.returnKeyType = UIReturnKeyDone; _bankNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing; } return _bankNameTextField; } - (UILabel *)uploadBankCardLabel { if (!_uploadBankCardLabel) { _uploadBankCardLabel = [[UILabel alloc] init]; _uploadBankCardLabel.text = ASLocalizedString(@"请上传银行卡"); _uploadBankCardLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _uploadBankCardLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_uploadBankCardLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _uploadBankCardLabel.attributedText = attributedText; } return _uploadBankCardLabel; } - (UIView *)frontCardView { if (!_frontCardView) { _frontCardView = [[UIView alloc] init]; _frontCardView.backgroundColor = [UIColor whiteColor]; _frontCardView.layer.cornerRadius = kRealValue(8); _frontCardView.layer.borderWidth = 1; _frontCardView.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; // 添加点击手势 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(frontCardTapped:)]; [_frontCardView addGestureRecognizer:tapGesture]; } return _frontCardView; } - (UILabel *)frontCardTitleLabel { if (!_frontCardTitleLabel) { _frontCardTitleLabel = [[UILabel alloc] init]; _frontCardTitleLabel.text = ASLocalizedString(@"正面"); _frontCardTitleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium]; _frontCardTitleLabel.textColor = [UIColor blackColor]; } return _frontCardTitleLabel; } - (UILabel *)frontCardSubtitleLabel { if (!_frontCardSubtitleLabel) { _frontCardSubtitleLabel = [[UILabel alloc] init]; _frontCardSubtitleLabel.text = ASLocalizedString(@"上传银行卡正面"); _frontCardSubtitleLabel.font = [UIFont systemFontOfSize:12]; _frontCardSubtitleLabel.textColor = [UIColor colorWithHexString:@"#999999"]; _frontCardSubtitleLabel.numberOfLines = 2; } return _frontCardSubtitleLabel; } - (UIImageView *)frontCardImageView { if (!_frontCardImageView) { _frontCardImageView = [[UIImageView alloc] init]; // 使用身份证图片作为银行卡示例,或者创建占位图 UIImage *cardImage = [UIImage imageNamed:@"store_bank_front"]; _frontCardImageView.image = cardImage; _frontCardImageView.contentMode = UIViewContentModeScaleAspectFit; } return _frontCardImageView; } - (UIView *)backCardView { if (!_backCardView) { _backCardView = [[UIView alloc] init]; _backCardView.backgroundColor = [UIColor whiteColor]; _backCardView.layer.cornerRadius = kRealValue(8); _backCardView.layer.borderWidth = 1; _backCardView.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; // 添加点击手势 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backCardTapped:)]; [_backCardView addGestureRecognizer:tapGesture]; } return _backCardView; } - (UILabel *)backCardTitleLabel { if (!_backCardTitleLabel) { _backCardTitleLabel = [[UILabel alloc] init]; _backCardTitleLabel.text = ASLocalizedString(@"反面"); _backCardTitleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium]; _backCardTitleLabel.textColor = [UIColor blackColor]; } return _backCardTitleLabel; } - (UILabel *)backCardSubtitleLabel { if (!_backCardSubtitleLabel) { _backCardSubtitleLabel = [[UILabel alloc] init]; _backCardSubtitleLabel.text = ASLocalizedString(@"上传银行卡反面"); _backCardSubtitleLabel.font = [UIFont systemFontOfSize:12]; _backCardSubtitleLabel.textColor = [UIColor colorWithHexString:@"#999999"]; _backCardSubtitleLabel.numberOfLines = 2; } return _backCardSubtitleLabel; } - (UIImageView *)backCardImageView { if (!_backCardImageView) { _backCardImageView = [[UIImageView alloc] init]; // 使用上传图标作为银行卡反面示例,或者创建占位图 UIImage *cardImage = [UIImage imageNamed:@"store_bank_back"]; _backCardImageView.image = cardImage; _backCardImageView.contentMode = UIViewContentModeScaleAspectFit; } return _backCardImageView; } @end