MerchantBusinessLicenseView.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. //
  2. // MerchantBusinessLicenseView.m
  3. // merchant
  4. //
  5. // Created by qitewei on 2025/8/14.
  6. // Copyright © 2025 xfg. All rights reserved.
  7. //
  8. #import "MerchantBusinessLicenseView.h"
  9. #import "UIView+Extention.h"
  10. @implementation MerchantBusinessLicenseView
  11. - (NSDictionary *)getMerchantEnrollParameters {
  12. return @{
  13. @"company_name":self.companyNameTextField.text ?: @"",
  14. @"licence_credit_code":self.creditCodeTextField.text ?: @"",
  15. @"licence_image":self.licenseURL ?: @"",
  16. };
  17. }
  18. - (instancetype)initWithFrame:(CGRect)frame
  19. {
  20. self = [super initWithFrame:frame];
  21. if (self) {
  22. [self setupUI];
  23. [self setupConstraints];
  24. }
  25. return self;
  26. }
  27. - (void)setupUI {
  28. self.backgroundColor = [UIColor clearColor];
  29. // 添加公司名称区域
  30. [self setupCompanyNameSection];
  31. // 添加统一社会信用代码区域
  32. [self setupCreditCodeSection];
  33. // 添加营业执照扫描件区域
  34. [self setupLicenseImageSection];
  35. }
  36. - (void)setupCompanyNameSection {
  37. [self.contentView addSubview:self.companyNameLabel];
  38. [self.contentView addSubview:self.companyNameTextField];
  39. }
  40. - (void)setupCreditCodeSection {
  41. [self.contentView addSubview:self.creditCodeLabel];
  42. [self.contentView addSubview:self.creditCodeTextField];
  43. }
  44. - (void)setupLicenseImageSection {
  45. [self.contentView addSubview:self.licenseImageLabel];
  46. [self.contentView addSubview:self.licenseUploadView];
  47. [self.licenseUploadView addSubview:self.uploadImageView];
  48. [self.licenseUploadView addSubview:self.uploadIconImageView];
  49. [self.licenseUploadView addSubview:self.uploadTipLabel];
  50. }
  51. - (void)setupConstraints {
  52. // 公司名称
  53. [self.companyNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.equalTo(self.contentView).offset(kRealValue(24));
  55. make.top.equalTo(self.contentView).offset(kRealValue(20));
  56. }];
  57. [self.companyNameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.equalTo(self.companyNameLabel);
  59. make.right.equalTo(self.contentView).offset(-kRealValue(24));
  60. make.top.equalTo(self.companyNameLabel.mas_bottom).offset(kRealValue(12));
  61. make.height.mas_equalTo(kRealValue(48));
  62. }];
  63. // 统一社会信用代码
  64. [self.creditCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.equalTo(self.companyNameLabel);
  66. make.top.equalTo(self.companyNameTextField.mas_bottom).offset(kRealValue(24));
  67. }];
  68. [self.creditCodeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.equalTo(self.creditCodeLabel);
  70. make.right.equalTo(self.contentView).offset(-kRealValue(24));
  71. make.top.equalTo(self.creditCodeLabel.mas_bottom).offset(kRealValue(12));
  72. make.height.mas_equalTo(kRealValue(48));
  73. }];
  74. // 营业执照扫描件
  75. [self.licenseImageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.equalTo(self.companyNameLabel);
  77. make.top.equalTo(self.creditCodeTextField.mas_bottom).offset(kRealValue(24));
  78. }];
  79. [self.licenseUploadView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.left.equalTo(self.licenseImageLabel);
  81. make.right.equalTo(self.contentView).offset(-kRealValue(24));
  82. make.top.equalTo(self.licenseImageLabel.mas_bottom).offset(kRealValue(12));
  83. make.height.mas_equalTo(kRealValue(200));
  84. make.bottom.equalTo(self.contentView).offset(-kRealValue(20));
  85. }];
  86. [self.uploadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.edges.mas_offset(0);
  88. }];
  89. [self.uploadIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.centerX.equalTo(self.licenseUploadView);
  91. make.centerY.equalTo(self.licenseUploadView).offset(-kRealValue(20));
  92. make.width.height.mas_equalTo(kRealValue(40));
  93. }];
  94. [self.uploadTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.centerX.equalTo(self.licenseUploadView);
  96. make.top.equalTo(self.uploadIconImageView.mas_bottom).offset(kRealValue(16));
  97. }];
  98. }
  99. #pragma mark - MerchantEnrollDataFillDelegate
  100. - (void)fillWithData:(NSDictionary *)data {
  101. if (!data || ![data isKindOfClass:[NSDictionary class]]) {
  102. return;
  103. }
  104. self.companyNameTextField.text = data[@"company_name"];
  105. self.creditCodeTextField.text = data[@"licence_credit_code"];
  106. NSString *url = data[@"licence_image"];
  107. if ([url hasPrefix:@"http"]) {
  108. self.licenseURL = url;
  109. [self.uploadImageView setImageWithURL:[NSURL URLWithString:url] placeholder:nil];
  110. }
  111. }
  112. #pragma mark - Actions
  113. - (void)licenseUploadTapped:(UITapGestureRecognizer *)gesture {
  114. WeakSelf
  115. [self pickImageWithCompletion:^(UIImage * _Nonnull image) {
  116. weakSelf.uploadImageView.image = image;
  117. weakSelf.uploadIconImageView.hidden = YES;
  118. weakSelf.uploadTipLabel.hidden = YES;
  119. [weakSelf uploadImage:image completion:^(NSString * _Nonnull url) {
  120. weakSelf.licenseURL = url;
  121. }];
  122. }];
  123. }
  124. #pragma mark - Lazy Loading
  125. - (UILabel *)companyNameLabel {
  126. if (!_companyNameLabel) {
  127. _companyNameLabel = [[UILabel alloc] init];
  128. _companyNameLabel.text = ASLocalizedString(@"公司名称");
  129. _companyNameLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  130. _companyNameLabel.textColor = [UIColor blackColor];
  131. // 添加红色星号
  132. NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_companyNameLabel.text];
  133. NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{
  134. NSForegroundColorAttributeName: [UIColor redColor],
  135. NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]
  136. }];
  137. [attributedText appendAttributedString:redStar];
  138. _companyNameLabel.attributedText = attributedText;
  139. }
  140. return _companyNameLabel;
  141. }
  142. - (UITextField *)companyNameTextField {
  143. if (!_companyNameTextField) {
  144. _companyNameTextField = [[UITextField alloc] init];
  145. _companyNameTextField.placeholder = ASLocalizedString(@"请输入公司名称");
  146. _companyNameTextField.font = [UIFont systemFontOfSize:16];
  147. _companyNameTextField.textColor = [UIColor blackColor];
  148. _companyNameTextField.backgroundColor = [UIColor whiteColor];
  149. _companyNameTextField.layer.cornerRadius = kRealValue(8);
  150. _companyNameTextField.layer.borderWidth = 1;
  151. _companyNameTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor;
  152. // 设置内边距
  153. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))];
  154. _companyNameTextField.leftView = leftView;
  155. _companyNameTextField.leftViewMode = UITextFieldViewModeAlways;
  156. UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))];
  157. _companyNameTextField.rightView = rightView;
  158. _companyNameTextField.rightViewMode = UITextFieldViewModeAlways;
  159. }
  160. return _companyNameTextField;
  161. }
  162. - (UILabel *)creditCodeLabel {
  163. if (!_creditCodeLabel) {
  164. _creditCodeLabel = [[UILabel alloc] init];
  165. _creditCodeLabel.text = ASLocalizedString(@"统一社会信用代码");
  166. _creditCodeLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  167. _creditCodeLabel.textColor = [UIColor blackColor];
  168. // 添加红色星号
  169. NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_creditCodeLabel.text];
  170. NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{
  171. NSForegroundColorAttributeName: [UIColor redColor],
  172. NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]
  173. }];
  174. [attributedText appendAttributedString:redStar];
  175. _creditCodeLabel.attributedText = attributedText;
  176. }
  177. return _creditCodeLabel;
  178. }
  179. - (UITextField *)creditCodeTextField {
  180. if (!_creditCodeTextField) {
  181. _creditCodeTextField = [[UITextField alloc] init];
  182. _creditCodeTextField.placeholder = ASLocalizedString(@"请输入统一社会信用代码");
  183. _creditCodeTextField.font = [UIFont systemFontOfSize:16];
  184. _creditCodeTextField.textColor = [UIColor blackColor];
  185. _creditCodeTextField.backgroundColor = [UIColor whiteColor];
  186. _creditCodeTextField.layer.cornerRadius = kRealValue(8);
  187. _creditCodeTextField.layer.borderWidth = 1;
  188. _creditCodeTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor;
  189. // 设置内边距
  190. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))];
  191. _creditCodeTextField.leftView = leftView;
  192. _creditCodeTextField.leftViewMode = UITextFieldViewModeAlways;
  193. UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))];
  194. _creditCodeTextField.rightView = rightView;
  195. _creditCodeTextField.rightViewMode = UITextFieldViewModeAlways;
  196. }
  197. return _creditCodeTextField;
  198. }
  199. - (UILabel *)licenseImageLabel {
  200. if (!_licenseImageLabel) {
  201. _licenseImageLabel = [[UILabel alloc] init];
  202. _licenseImageLabel.text = ASLocalizedString(@"营业执照扫描件");
  203. _licenseImageLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  204. _licenseImageLabel.textColor = [UIColor blackColor];
  205. // 添加红色星号
  206. NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_licenseImageLabel.text];
  207. NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{
  208. NSForegroundColorAttributeName: [UIColor redColor],
  209. NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]
  210. }];
  211. [attributedText appendAttributedString:redStar];
  212. _licenseImageLabel.attributedText = attributedText;
  213. }
  214. return _licenseImageLabel;
  215. }
  216. - (UIView *)licenseUploadView {
  217. if (!_licenseUploadView) {
  218. _licenseUploadView = [[UIView alloc] init];
  219. _licenseUploadView.backgroundColor = [UIColor whiteColor];
  220. _licenseUploadView.layer.cornerRadius = kRealValue(8);
  221. _licenseUploadView.layer.borderWidth = 1;
  222. _licenseUploadView.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor;
  223. // 添加点击手势
  224. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(licenseUploadTapped:)];
  225. [_licenseUploadView addGestureRecognizer:tapGesture];
  226. }
  227. return _licenseUploadView;
  228. }
  229. - (UIImageView *)uploadIconImageView {
  230. if (!_uploadIconImageView) {
  231. _uploadIconImageView = [[UIImageView alloc] init];
  232. _uploadIconImageView.image = [UIImage imageNamed:@"store_upload"];
  233. _uploadIconImageView.contentMode = UIViewContentModeScaleAspectFit;
  234. _uploadIconImageView.tintColor = [UIColor colorWithHexString:@"#CCCCCC"];
  235. }
  236. return _uploadIconImageView;
  237. }
  238. - (UILabel *)uploadTipLabel {
  239. if (!_uploadTipLabel) {
  240. _uploadTipLabel = [[UILabel alloc] init];
  241. _uploadTipLabel.text = ASLocalizedString(@"上传图片");
  242. _uploadTipLabel.font = [UIFont systemFontOfSize:14];
  243. _uploadTipLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  244. _uploadTipLabel.textAlignment = NSTextAlignmentCenter;
  245. }
  246. return _uploadTipLabel;
  247. }
  248. - (UIImageView *)uploadImageView {
  249. if (!_uploadImageView) {
  250. _uploadImageView = [[UIImageView alloc] init];
  251. _uploadImageView.contentMode = UIViewContentModeScaleToFill;
  252. _uploadImageView.clipsToBounds = YES;
  253. }
  254. return _uploadImageView;
  255. }
  256. @end