// // MerchantStoreInfoView.m // merchant // // Created by qitewei on 2025/8/14. // Copyright © 2025 xfg. All rights reserved. // #import "MerchantStoreInfoView.h" #import "UIView+Extention.h" #import "IndustryCategoryModel.h" #import "CategoryPickerView.h" #import "MerchantEnrollDataManager.h" @interface MerchantStoreInfoView () @property (nonatomic, copy, nullable) NSString *logoURL; @end @implementation MerchantStoreInfoView - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (NSDictionary *)getMerchantEnrollParameters { // 获取店铺简介内容,排除占位符文本 NSString *description = @""; if (![self.descriptionTextView.text isEqualToString:ASLocalizedString(@"请输入店铺简介")]) { description = self.descriptionTextView.text ?: @""; } return @{ @"shop_name": self.storeNameTextField.text ?: @"", @"shop_logo": self.logoURL ?: @"", @"shop_desc": description, @"cate_id":@(self.selectedCategory.categoryId), @"shop_address":self.addressTextField.text ?: @"" }; } - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setupUI]; [self setupConstraints]; [self initData]; } return self; } - (void)setupUI { self.backgroundColor = [UIColor clearColor]; // 添加店铺名称区域 [self setupStoreNameSection]; // 添加店铺Logo区域 [self setupLogoSection]; // 添加经营类别区域 [self setupCategorySection]; // 添加店铺简介区域 [self setupDescriptionSection]; // 添加店铺地址区域 [self setupAddressSection]; // 添加下一步按钮 [self addSubview:self.nextButton]; } - (void)setupStoreNameSection { [self.contentView addSubview:self.storeNameLabel]; [self.contentView addSubview:self.storeNameTextField]; [self.contentView addSubview:self.storeNameStatusLabel]; } - (void)setupLogoSection { [self.contentView addSubview:self.logoLabel]; [self.contentView addSubview:self.logoUploadView]; [self.logoUploadView addSubview:self.logoImageView]; [self.logoUploadView addSubview:self.logoCloseButton]; [self.contentView addSubview:self.logoTipLabel]; } - (void)setupCategorySection { [self.contentView addSubview:self.categoryLabel]; [self.contentView addSubview:self.categoryButton]; [self.contentView addSubview:self.categoryStatusLabel]; [self.contentView addSubview:self.categoryTipLabel]; } - (void)setupDescriptionSection { [self.contentView addSubview:self.descriptionLabel]; [self.contentView addSubview:self.descriptionTextView]; [self.contentView addSubview:self.descriptionCountLabel]; } - (void)setupAddressSection { [self.contentView addSubview:self.addressLabel]; [self.contentView addSubview:self.addressTextField]; } - (void)setupConstraints { // 店铺名称 [self.storeNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(kRealValue(24)); make.top.equalTo(self.contentView).offset(kRealValue(20)); }]; [self.storeNameTextField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.storeNameLabel); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.storeNameLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(48)); }]; [self.storeNameStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.storeNameTextField); make.top.equalTo(self.storeNameTextField.mas_bottom).offset(kRealValue(8)); }]; // 店铺Logo [self.logoLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.storeNameLabel); make.top.equalTo(self.storeNameStatusLabel.mas_bottom).offset(kRealValue(24)); }]; [self.logoUploadView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.logoLabel); make.top.equalTo(self.logoLabel.mas_bottom).offset(kRealValue(12)); make.width.height.mas_equalTo(kRealValue(100)); }]; [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.logoUploadView); }]; [self.logoCloseButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.right.equalTo(self.logoUploadView); make.width.height.mas_equalTo(kRealValue(20)); }]; [self.logoTipLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.logoUploadView); make.top.equalTo(self.logoUploadView.mas_bottom).offset(kRealValue(8)); }]; // 经营类别 [self.categoryLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.storeNameLabel); make.top.equalTo(self.logoTipLabel.mas_bottom).offset(kRealValue(24)); }]; [self.categoryButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.categoryLabel); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.categoryLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(48)); }]; [self.categoryStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.categoryButton); make.top.equalTo(self.categoryButton.mas_bottom).offset(kRealValue(8)); }]; [self.categoryTipLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.categoryStatusLabel); make.right.mas_offset(-16); make.top.equalTo(self.categoryStatusLabel.mas_bottom).offset(kRealValue(4)); }]; // 店铺简介 [self.descriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.storeNameLabel); make.top.equalTo(self.categoryTipLabel.mas_bottom).offset(kRealValue(24)); }]; [self.descriptionTextView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.descriptionLabel); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.descriptionLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(100)); }]; [self.descriptionCountLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.descriptionTextView); make.top.equalTo(self.descriptionTextView.mas_bottom).offset(kRealValue(8)); }]; // 店铺地址 [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.storeNameLabel); make.top.equalTo(self.descriptionCountLabel.mas_bottom).offset(kRealValue(24)); }]; [self.addressTextField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.addressLabel); make.right.equalTo(self.contentView).offset(-kRealValue(24)); make.top.equalTo(self.addressLabel.mas_bottom).offset(kRealValue(12)); make.height.mas_equalTo(kRealValue(48)); make.bottom.equalTo(self.contentView).offset(-kRealValue(20)); }]; // 下一步按钮 [self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_offset(0); make.size.mas_equalTo(self.nextButton.size); make.bottom.mas_offset(kRealValue(-20)); }]; } - (void)initData { NSString *path = @"/industrycategory"; [self.netManager storeGETWithPath:path SuccessBlock:^(NSDictionary *responseJson) { // 解析接口返回数据 if ([responseJson[@"code"] integerValue] == 1) { NSArray *dataArray = responseJson[@"data"]; if ([dataArray isKindOfClass:[NSArray class]]) { self.categories = [IndustryCategoryModel mj_objectArrayWithKeyValuesArray:dataArray]; // 如果有数据,默认选择第一个 if (self.categories.count > 0) { self.selectedCategory = self.categories.firstObject; [self updateCategoryDisplay]; } // 加载行业分类后,自动填充之前保存的数据 [self loadSavedData]; } } } FailureBlock:^(NSError *error) { NSLog(@"获取行业分类失败: %@", error.localizedDescription); }]; } - (void)checkShopNameIsCanUse { [[BGHUDHelper sharedInstance] syncLoading]; NSString *path = @"/checkShopNameIsCanUse"; NSMutableDictionary *dict = @{ @"shop_name":self.storeNameTextField.text }.mutableCopy; [self.netManager storePOSTWithPath:path paramDict:dict SuccessBlock:^(NSDictionary *responseJson) { [[BGHUDHelper sharedInstance] syncStopLoading]; NSInteger is_can_use = [responseJson[@"is_can_use"] integerValue]; if (is_can_use == 1) { [self goNext]; } else { [self makeToast:@""]; } } FailureBlock:^(NSError *error) { [[BGHUDHelper sharedInstance] tipMessage:error.localizedDescription]; }]; } - (void)uploadImage:(UIImage *)image { WeakSelf [self uploadImage:image completion:^(NSString * _Nonnull url) { weakSelf.logoURL = url; }]; } #pragma mark - Actions - (void)goNext { NSString *shop_name = self.storeNameTextField.text; NSString *address = self.addressTextField.text; if (shop_name.length == 0) { [self makeToast:self.storeNameTextField.placeholder]; return; } if (![self.logoURL hasPrefix:@"http"]) { [self makeToast:ASLocalizedString(@"请上传图片")]; return; } if (address.length == 0) { [self makeToast:self.addressTextField.placeholder]; return; } [self checkShopNameIsCanUse]; } - (void)logoUploadTapped:(UITapGestureRecognizer *)gesture { WeakSelf [self pickImageWithCompletion:^(UIImage * _Nonnull image) { weakSelf.logoImageView.image = image; weakSelf.logoCloseButton.hidden = NO; [weakSelf uploadImage:image]; }]; } - (void)logoCloseButtonTapped:(UIButton *)sender { self.logoImageView.image = nil; sender.hidden = YES; } - (void)categoryButtonTapped:(UIButton *)sender { if (self.categories.count == 0) { NSLog(@"暂无行业分类数据"); return; } // 显示类别选择器 if (!self.categoryPickerView) { self.categoryPickerView = [[CategoryPickerView alloc] init]; self.categoryPickerView.delegate = self; } self.categoryPickerView.categories = self.categories; [self.categoryPickerView showInView:self.superview fromRect:sender.frame]; } - (void)storeNameTextFieldChanged:(UITextField *)textField { // 实时验证店铺名称 NSString *text = textField.text; if (text.length > 0) { // 这里模拟检查名称可用性 self.storeNameStatusLabel.text = ASLocalizedString(@"✓ 名称可使用"); self.storeNameStatusLabel.textColor = [UIColor colorWithHexString:@"#00C853"]; } else { self.storeNameStatusLabel.text = @""; } } - (void)descriptionTextViewDidChange:(NSNotification *)notification { UITextView *textView = notification.object; NSString *text = textView.text; NSInteger currentLength = text.length; NSInteger maxLength = 200; // 限制字数不超过200字 if (currentLength > maxLength) { textView.text = [text substringToIndex:maxLength]; currentLength = maxLength; } // 更新字数显示 self.descriptionCountLabel.text = [NSString stringWithFormat:@"%ld/200", (long)currentLength]; // 根据字数变化颜色 if (currentLength >= maxLength) { self.descriptionCountLabel.textColor = [UIColor colorWithHexString:@"#FF5722"]; } else { self.descriptionCountLabel.textColor = [UIColor colorWithHexString:@"#999999"]; } } - (void)descriptionTextViewDidBeginEditing:(NSNotification *)notification { UITextView *textView = notification.object; if ([textView.text isEqualToString:ASLocalizedString(@"请输入店铺简介")]) { textView.text = @""; textView.textColor = [UIColor blackColor]; } } - (void)descriptionTextViewDidEndEditing:(NSNotification *)notification { UITextView *textView = notification.object; if (textView.text.length == 0) { textView.text = ASLocalizedString(@"请输入店铺简介"); textView.textColor = [UIColor colorWithHexString:@"#999999"]; self.descriptionCountLabel.text = @"0/200"; } } - (void)updateCategoryDisplay { if (self.selectedCategory) { // 更新按钮显示 [self.categoryButton setTitle:self.selectedCategory.name forState:UIControlStateNormal]; [self.categoryButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; // 更新状态标签 self.categoryStatusLabel.text = [NSString stringWithFormat:ASLocalizedString(@"✓ 已选 %@"), self.selectedCategory.name]; self.categoryStatusLabel.textColor = [UIColor colorWithHexString:@"#00C853"]; // 更新提示标签 NSString *depositText = [NSString stringWithFormat:@"%.2f", [self.selectedCategory.depositAmount floatValue]]; NSString *commissionText = [NSString stringWithFormat:@"%.0f%%", [self.selectedCategory.commissionRate floatValue] * 100]; NSString *tipText = [NSString stringWithFormat:ASLocalizedString(@"该类目保证金为: ¥%@,佣金比例为: %@。"), depositText, commissionText]; NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:tipText]; // 设置整体样式 [attributedText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, tipText.length)]; [attributedText addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#FF9800"] range:NSMakeRange(0, tipText.length)]; // 设置金额和百分比的颜色 NSRange moneyRange = [tipText rangeOfString:[NSString stringWithFormat:@"¥%@", depositText]]; NSRange percentRange = [tipText rangeOfString:commissionText]; if (moneyRange.location != NSNotFound) { [attributedText addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#FF5722"] range:moneyRange]; } if (percentRange.location != NSNotFound) { [attributedText addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#FF5722"] range:percentRange]; } self.categoryTipLabel.attributedText = attributedText; } } #pragma mark - CategoryPickerViewDelegate - (void)categoryPickerView:(UIView *)pickerView didSelectCategory:(IndustryCategoryModel *)category { self.selectedCategory = category; [self updateCategoryDisplay]; } #pragma mark - 数据自动填充 - (void)loadSavedData { NSDictionary *savedData = [[MerchantEnrollDataManager sharedManager] getStoreInfoData]; if (savedData) { [self fillWithData:savedData]; } } - (void)fillWithData:(NSDictionary *)data { if (!data || ![data isKindOfClass:[NSDictionary class]]) { return; } // 填充店铺名称 NSString *shopName = data[@"shop_name"]; if (shopName && [shopName isKindOfClass:[NSString class]]) { self.storeNameTextField.text = shopName; [self storeNameTextFieldChanged:self.storeNameTextField]; } // 填充店铺Logo NSString *shopLogo = data[@"shop_logo"]; if (shopLogo && [shopLogo isKindOfClass:[NSString class]] && [shopLogo hasPrefix:@"http"]) { self.logoURL = shopLogo; [self.logoImageView setImageURL:[NSURL URLWithString:shopLogo]]; self.logoCloseButton.hidden = NO; } // 填充店铺简介 NSString *shopDesc = data[@"shop_desc"]; if (shopDesc && [shopDesc isKindOfClass:[NSString class]] && shopDesc.length > 0) { self.descriptionTextView.text = shopDesc; self.descriptionTextView.textColor = [UIColor blackColor]; // 更新字数统计 NSInteger currentLength = shopDesc.length; self.descriptionCountLabel.text = [NSString stringWithFormat:@"%ld/200", (long)currentLength]; if (currentLength >= 200) { self.descriptionCountLabel.textColor = [UIColor colorWithHexString:@"#FF5722"]; } else { self.descriptionCountLabel.textColor = [UIColor colorWithHexString:@"#999999"]; } } // 填充经营类别 NSNumber *cateId = data[@"cate_id"]; if (cateId && [cateId isKindOfClass:[NSNumber class]] && self.categories.count > 0) { NSInteger categoryId = [cateId integerValue]; for (IndustryCategoryModel *category in self.categories) { if (category.categoryId == categoryId) { self.selectedCategory = category; [self updateCategoryDisplay]; break; } } } // 填充店铺地址 NSString *shopAddress = data[@"shop_address"]; if (shopAddress && [shopAddress isKindOfClass:[NSString class]]) { self.addressTextField.text = shopAddress; } } #pragma mark - Lazy Loading - (UILabel *)storeNameLabel { if (!_storeNameLabel) { _storeNameLabel = [[UILabel alloc] init]; _storeNameLabel.text = ASLocalizedString(@"店铺名称"); _storeNameLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _storeNameLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_storeNameLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _storeNameLabel.attributedText = attributedText; } return _storeNameLabel; } - (UITextField *)storeNameTextField { if (!_storeNameTextField) { _storeNameTextField = [[UITextField alloc] init]; _storeNameTextField.placeholder = ASLocalizedString(@"请输入店铺名称"); _storeNameTextField.font = [UIFont systemFontOfSize:16]; _storeNameTextField.textColor = [UIColor blackColor]; _storeNameTextField.backgroundColor = [UIColor whiteColor]; _storeNameTextField.layer.cornerRadius = kRealValue(8); _storeNameTextField.layer.borderWidth = 1; _storeNameTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; // 设置内边距 UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _storeNameTextField.leftView = leftView; _storeNameTextField.leftViewMode = UITextFieldViewModeAlways; UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _storeNameTextField.rightView = rightView; _storeNameTextField.rightViewMode = UITextFieldViewModeAlways; [_storeNameTextField addTarget:self action:@selector(storeNameTextFieldChanged:) forControlEvents:UIControlEventEditingChanged]; } return _storeNameTextField; } - (UILabel *)storeNameStatusLabel { if (!_storeNameStatusLabel) { _storeNameStatusLabel = [[UILabel alloc] init]; _storeNameStatusLabel.font = [UIFont systemFontOfSize:12]; _storeNameStatusLabel.text = ASLocalizedString(@"✓ 名称可使用"); _storeNameStatusLabel.textColor = [UIColor colorWithHexString:@"#00C853"]; } return _storeNameStatusLabel; } - (UILabel *)logoLabel { if (!_logoLabel) { _logoLabel = [[UILabel alloc] init]; _logoLabel.text = ASLocalizedString(@"店铺Logo"); _logoLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _logoLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_logoLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _logoLabel.attributedText = attributedText; } return _logoLabel; } - (UIView *)logoUploadView { if (!_logoUploadView) { _logoUploadView = [[UIView alloc] init]; _logoUploadView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.8]; _logoUploadView.layer.cornerRadius = kRealValue(8); _logoUploadView.clipsToBounds = YES; // 添加点击手势 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(logoUploadTapped:)]; [_logoUploadView addGestureRecognizer:tapGesture]; } return _logoUploadView; } - (UIImageView *)logoImageView { if (!_logoImageView) { _logoImageView = [[UIImageView alloc] init]; _logoImageView.contentMode = UIViewContentModeScaleAspectFill; _logoImageView.clipsToBounds = YES; } return _logoImageView; } - (UIButton *)logoCloseButton { if (!_logoCloseButton) { _logoCloseButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_logoCloseButton setImage:[UIImage imageNamed:@"store_close"] forState:UIControlStateNormal]; [_logoCloseButton addTarget:self action:@selector(logoCloseButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; _logoCloseButton.hidden = YES; } return _logoCloseButton; } - (UILabel *)logoTipLabel { if (!_logoTipLabel) { _logoTipLabel = [[UILabel alloc] init]; _logoTipLabel.text = ASLocalizedString(@"不大于10M的jpg或png格式的图片"); _logoTipLabel.font = [UIFont systemFontOfSize:12]; _logoTipLabel.textColor = [UIColor colorWithHexString:@"#999999"]; } return _logoTipLabel; } - (UILabel *)categoryLabel { if (!_categoryLabel) { _categoryLabel = [[UILabel alloc] init]; _categoryLabel.text = ASLocalizedString(@"经营类别"); _categoryLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _categoryLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_categoryLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _categoryLabel.attributedText = attributedText; } return _categoryLabel; } - (UIButton *)categoryButton { if (!_categoryButton) { _categoryButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_categoryButton setTitle:ASLocalizedString(@"请选择经营类别") forState:UIControlStateNormal]; [_categoryButton setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal]; _categoryButton.titleLabel.font = [UIFont systemFontOfSize:16]; _categoryButton.backgroundColor = [UIColor whiteColor]; _categoryButton.layer.cornerRadius = kRealValue(8); _categoryButton.layer.borderWidth = 1; _categoryButton.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; _categoryButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; _categoryButton.contentEdgeInsets = UIEdgeInsetsMake(0, kRealValue(16), 0, kRealValue(16)); // 添加下拉箭头 [_categoryButton setImage:[UIImage imageNamed:@"store_arrow_down"] forState:UIControlStateNormal]; _categoryButton.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; _categoryButton.imageEdgeInsets = UIEdgeInsetsMake(0, kRealValue(16), 0, 0); [_categoryButton addTarget:self action:@selector(categoryButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; } return _categoryButton; } - (UILabel *)categoryStatusLabel { if (!_categoryStatusLabel) { _categoryStatusLabel = [[UILabel alloc] init]; _categoryStatusLabel.text = @""; // 初始为空,等待选择后更新 _categoryStatusLabel.font = [UIFont systemFontOfSize:12]; _categoryStatusLabel.textColor = [UIColor colorWithHexString:@"#00C853"]; } return _categoryStatusLabel; } - (UILabel *)categoryTipLabel { if (!_categoryTipLabel) { _categoryTipLabel = [[UILabel alloc] init]; _categoryTipLabel.text = @""; // 初始为空,等待选择后更新 _categoryTipLabel.font = [UIFont systemFontOfSize:12]; _categoryTipLabel.textColor = [UIColor colorWithHexString:@"#FF9800"]; _categoryTipLabel.numberOfLines = 0; } return _categoryTipLabel; } - (UILabel *)descriptionLabel { if (!_descriptionLabel) { _descriptionLabel = [[UILabel alloc] init]; _descriptionLabel.text = ASLocalizedString(@"店铺简介"); _descriptionLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _descriptionLabel.textColor = [UIColor blackColor]; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_descriptionLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _descriptionLabel.attributedText = attributedText; } return _descriptionLabel; } - (UITextView *)descriptionTextView { if (!_descriptionTextView) { _descriptionTextView = [[UITextView alloc] init]; _descriptionTextView.font = [UIFont systemFontOfSize:16]; _descriptionTextView.textColor = [UIColor blackColor]; _descriptionTextView.backgroundColor = [UIColor whiteColor]; _descriptionTextView.layer.cornerRadius = kRealValue(8); _descriptionTextView.layer.borderWidth = 1; _descriptionTextView.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; _descriptionTextView.textContainerInset = UIEdgeInsetsMake(kRealValue(12), kRealValue(12), kRealValue(12), kRealValue(12)); _descriptionTextView.showsVerticalScrollIndicator = YES; // 设置占位符 _descriptionTextView.text = ASLocalizedString(@"请输入店铺简介"); _descriptionTextView.textColor = [UIColor colorWithHexString:@"#999999"]; // 添加文本变化监听 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(descriptionTextViewDidChange:) name:UITextViewTextDidChangeNotification object:_descriptionTextView]; // 添加开始和结束编辑监听 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(descriptionTextViewDidBeginEditing:) name:UITextViewTextDidBeginEditingNotification object:_descriptionTextView]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(descriptionTextViewDidEndEditing:) name:UITextViewTextDidEndEditingNotification object:_descriptionTextView]; } return _descriptionTextView; } - (UILabel *)descriptionCountLabel { if (!_descriptionCountLabel) { _descriptionCountLabel = [[UILabel alloc] init]; _descriptionCountLabel.text = @"0/200"; _descriptionCountLabel.font = [UIFont systemFontOfSize:12]; _descriptionCountLabel.textColor = [UIColor colorWithHexString:@"#999999"]; _descriptionCountLabel.textAlignment = NSTextAlignmentRight; } return _descriptionCountLabel; } - (UILabel *)addressLabel { if (!_addressLabel) { _addressLabel = [[UILabel alloc] init]; _addressLabel.text = ASLocalizedString(@"店铺地址"); _addressLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; _addressLabel.textColor = [UIColor blackColor]; _addressLabel.numberOfLines = 0; // 添加红色星号 NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_addressLabel.text]; NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{ NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium] }]; [attributedText appendAttributedString:redStar]; _addressLabel.attributedText = attributedText; } return _addressLabel; } - (UITextField *)addressTextField { if (!_addressTextField) { _addressTextField = [[UITextField alloc] init]; _addressTextField.placeholder = ASLocalizedString(@"请输入店铺地址"); _addressTextField.font = [UIFont systemFontOfSize:16]; _addressTextField.textColor = [UIColor blackColor]; _addressTextField.backgroundColor = [UIColor whiteColor]; _addressTextField.layer.cornerRadius = kRealValue(8); _addressTextField.layer.borderWidth = 1; _addressTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor; // 设置内边距 UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _addressTextField.leftView = leftView; _addressTextField.leftViewMode = UITextFieldViewModeAlways; UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))]; _addressTextField.rightView = rightView; _addressTextField.rightViewMode = UITextFieldViewModeAlways; } return _addressTextField; } @end