// // MerchantBusinessLicenseView.m // merchant // // Created by qitewei on 2025/8/14. // Copyright © 2025 xfg. All rights reserved. // #import "MerchantBusinessLicenseView.h" #import "UIView+Extention.h" @implementation MerchantBusinessLicenseView - (NSDictionary *)getMerchantEnrollParameters { return @{ @"company_name":self.companyNameTextField.text ?: @"", @"licence_credit_code":self.creditCodeTextField.text ?: @"", @"licence_image":self.licenseURL ?: @"", }; } - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setupUI]; [self setupConstraints]; } return self; } - (void)setupUI { self.backgroundColor = [UIColor clearColor]; // 添加公司名称区域 [self setupCompanyNameSection]; // 添加统一社会信用代码区域 [self setupCreditCodeSection]; // 添加营业执照扫描件区域 [self setupLicenseImageSection]; } - (void)setupCompanyNameSection { [self.contentView addSubview:self.companyNameLabel]; [self.contentView addSubview:self.companyNameTextField]; } - (void)setupCreditCodeSection { [self.contentView addSubview:self.creditCodeLabel]; [self.contentView addSubview:self.creditCodeTextField]; } - (void)setupLicenseImageSection { [self.contentView addSubview:self.licenseImageLabel]; [self.contentView addSubview:self.licenseUploadView]; [self.licenseUploadView addSubview:self.uploadImageView]; [self.licenseUploadView addSubview:self.uploadIconImageView]; [self.licenseUploadView addSubview:self.uploadTipLabel]; } - (void)setupConstraints { // 公司名称 [self.companyNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(kRealValue(24)); make.top.equalTo(self.contentView).offset(kRealValue(20)); }]; [self.companyNameTextField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.companyNameLabel); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.companyNameLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(48)); }]; // 统一社会信用代码 [self.creditCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.companyNameLabel); make.top.equalTo(self.companyNameTextField.mas_bottom).offset(kRealValue(24)); }]; [self.creditCodeTextField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.creditCodeLabel); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.creditCodeLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(48)); }]; // 营业执照扫描件 [self.licenseImageLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.companyNameLabel); make.top.equalTo(self.creditCodeTextField.mas_bottom).offset(kRealValue(24)); }]; [self.licenseUploadView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.licenseImageLabel); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.licenseImageLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(200)); make.bottom.equalTo(self.contentView).offset(-kRealValue(20)); }]; [self.uploadImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_offset(0); }]; [self.uploadIconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.licenseUploadView); make.centerY.equalTo(self.licenseUploadView).offset(-kRealValue(20)); make.width.height.mas_equalTo(kRealValue(40)); }]; [self.uploadTipLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.licenseUploadView); make.top.equalTo(self.uploadIconImageView.mas_bottom).offset(kRealValue(16)); }]; } #pragma mark - MerchantEnrollDataFillDelegate - (void)fillWithData:(NSDictionary *)data { if (!data || ![data isKindOfClass:[NSDictionary class]]) { return; } self.companyNameTextField.text = data[@"company_name"]; self.creditCodeTextField.text = data[@"licence_credit_code"]; NSString *url = data[@"licence_image"]; if ([url hasPrefix:@"http"]) { self.licenseURL = url; [self.uploadImageView setImageWithURL:[NSURL URLWithString:url] placeholder:nil]; } } #pragma mark - Actions - (void)licenseUploadTapped:(UITapGestureRecognizer *)gesture { WeakSelf [self pickImageWithCompletion:^(UIImage * _Nonnull image) { weakSelf.uploadImageView.image = image; weakSelf.uploadIconImageView.hidden = YES; weakSelf.uploadTipLabel.hidden = YES; [weakSelf uploadImage:image completion:^(NSString * _Nonnull url) { weakSelf.licenseURL = url; }]; }]; } #pragma mark - Lazy Loading - (UILabel *)companyNameLabel { if (!_companyNameLabel) { _companyNameLabel = [[UILabel alloc] init]; _companyNameLabel.text = ASLocalizedString(@"公司名称"); _companyNameLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _companyNameLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_companyNameLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _companyNameLabel.attributedText = attributedText; } return _companyNameLabel; } - (UITextField *)companyNameTextField { if (!_companyNameTextField) { _companyNameTextField = [[UITextField alloc] init]; _companyNameTextField.placeholder = ASLocalizedString(@"请输入公司名称"); _companyNameTextField.font = [UIFont systemFontOfSize:16]; _companyNameTextField.textColor = [UIColor blackColor]; _companyNameTextField.backgroundColor = [UIColor whiteColor]; _companyNameTextField.layer.cornerRadius = kRealValue(8); _companyNameTextField.layer.borderWidth = 1; _companyNameTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; // 设置内边距 UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _companyNameTextField.leftView = leftView; _companyNameTextField.leftViewMode = UITextFieldViewModeAlways; UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _companyNameTextField.rightView = rightView; _companyNameTextField.rightViewMode = UITextFieldViewModeAlways; } return _companyNameTextField; } - (UILabel *)creditCodeLabel { if (!_creditCodeLabel) { _creditCodeLabel = [[UILabel alloc] init]; _creditCodeLabel.text = ASLocalizedString(@"统一社会信用代码"); _creditCodeLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _creditCodeLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_creditCodeLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _creditCodeLabel.attributedText = attributedText; } return _creditCodeLabel; } - (UITextField *)creditCodeTextField { if (!_creditCodeTextField) { _creditCodeTextField = [[UITextField alloc] init]; _creditCodeTextField.placeholder = ASLocalizedString(@"请输入统一社会信用代码"); _creditCodeTextField.font = [UIFont systemFontOfSize:16]; _creditCodeTextField.textColor = [UIColor blackColor]; _creditCodeTextField.backgroundColor = [UIColor whiteColor]; _creditCodeTextField.layer.cornerRadius = kRealValue(8); _creditCodeTextField.layer.borderWidth = 1; _creditCodeTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; // 设置内边距 UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _creditCodeTextField.leftView = leftView; _creditCodeTextField.leftViewMode = UITextFieldViewModeAlways; UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _creditCodeTextField.rightView = rightView; _creditCodeTextField.rightViewMode = UITextFieldViewModeAlways; } return _creditCodeTextField; } - (UILabel *)licenseImageLabel { if (!_licenseImageLabel) { _licenseImageLabel = [[UILabel alloc] init]; _licenseImageLabel.text = ASLocalizedString(@"营业执照扫描件"); _licenseImageLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _licenseImageLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_licenseImageLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _licenseImageLabel.attributedText = attributedText; } return _licenseImageLabel; } - (UIView *)licenseUploadView { if (!_licenseUploadView) { _licenseUploadView = [[UIView alloc] init]; _licenseUploadView.backgroundColor = [UIColor whiteColor]; _licenseUploadView.layer.cornerRadius = kRealValue(8); _licenseUploadView.layer.borderWidth = 1; _licenseUploadView.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; // 添加点击手势 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(licenseUploadTapped:)]; [_licenseUploadView addGestureRecognizer:tapGesture]; } return _licenseUploadView; } - (UIImageView *)uploadIconImageView { if (!_uploadIconImageView) { _uploadIconImageView = [[UIImageView alloc] init]; _uploadIconImageView.image = [UIImage imageNamed:@"store_upload"]; _uploadIconImageView.contentMode = UIViewContentModeScaleAspectFit; _uploadIconImageView.tintColor = [UIColor colorWithHexString:@"#CCCCCC"]; } return _uploadIconImageView; } - (UILabel *)uploadTipLabel { if (!_uploadTipLabel) { _uploadTipLabel = [[UILabel alloc] init]; _uploadTipLabel.text = ASLocalizedString(@"上传图片"); _uploadTipLabel.font = [UIFont systemFontOfSize:14]; _uploadTipLabel.textColor = [UIColor colorWithHexString:@"#999999"]; _uploadTipLabel.textAlignment = NSTextAlignmentCenter; } return _uploadTipLabel; } - (UIImageView *)uploadImageView { if (!_uploadImageView) { _uploadImageView = [[UIImageView alloc] init]; _uploadImageView.contentMode = UIViewContentModeScaleToFill; _uploadImageView.clipsToBounds = YES; } return _uploadImageView; } @end