MerchantLegalInfoView.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. //
  2. // MerchantLegalInfoView.m
  3. // merchant
  4. //
  5. // Created by qitewei on 2025/8/14.
  6. // Copyright © 2025 xfg. All rights reserved.
  7. //
  8. #import "MerchantLegalInfoView.h"
  9. #import "UIView+Extention.h"
  10. @implementation MerchantLegalInfoView
  11. - (NSDictionary *)getMerchantEnrollParameters {
  12. return @{
  13. @"username":self.nameTextField.text ?: @"",
  14. @"identification_card":self.idNumberTextField.text ?: @"",
  15. @"identity_front_photo":self.frontURL ?: @"",
  16. @"identity_back_photo":self.backURL ?: @"",
  17. };
  18. }
  19. - (instancetype)initWithFrame:(CGRect)frame
  20. {
  21. self = [super initWithFrame:frame];
  22. if (self) {
  23. [self setupUI];
  24. [self setupConstraints];
  25. }
  26. return self;
  27. }
  28. - (void)setupUI {
  29. self.backgroundColor = [UIColor clearColor];
  30. // 添加姓名区域
  31. [self setupNameSection];
  32. // 添加身份证号码区域
  33. [self setupIdNumberSection];
  34. // 添加身份证上传区域
  35. [self setupIdCardSection];
  36. }
  37. - (void)setupNameSection {
  38. [self.contentView addSubview:self.nameLabel];
  39. [self.contentView addSubview:self.nameTextField];
  40. }
  41. - (void)setupIdNumberSection {
  42. [self.contentView addSubview:self.idNumberLabel];
  43. [self.contentView addSubview:self.idNumberTextField];
  44. }
  45. - (void)setupIdCardSection {
  46. [self.contentView addSubview:self.idCardLabel];
  47. [self.contentView addSubview:self.frontCardView];
  48. [self.contentView addSubview:self.backCardView];
  49. // 正面
  50. [self.frontCardView addSubview:self.frontCardTitleLabel];
  51. [self.frontCardView addSubview:self.frontCardSubtitleLabel];
  52. [self.frontCardView addSubview:self.frontCardImageView];
  53. // 反面
  54. [self.backCardView addSubview:self.backCardTitleLabel];
  55. [self.backCardView addSubview:self.backCardSubtitleLabel];
  56. [self.backCardView addSubview:self.backCardImageView];
  57. }
  58. - (void)setupConstraints {
  59. // 姓名
  60. [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.equalTo(self.contentView).offset(kRealValue(24));
  62. make.top.equalTo(self.contentView).offset(kRealValue(20));
  63. }];
  64. [self.nameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.equalTo(self.nameLabel);
  66. make.right.equalTo(self.contentView).offset(-kRealValue(24));
  67. make.top.equalTo(self.nameLabel.mas_bottom).offset(kRealValue(12));
  68. make.height.mas_equalTo(kRealValue(48));
  69. }];
  70. // 身份证号码
  71. [self.idNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.equalTo(self.nameLabel);
  73. make.top.equalTo(self.nameTextField.mas_bottom).offset(kRealValue(24));
  74. }];
  75. [self.idNumberTextField mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.equalTo(self.idNumberLabel);
  77. make.right.equalTo(self.contentView).offset(-kRealValue(24));
  78. make.top.equalTo(self.idNumberLabel.mas_bottom).offset(kRealValue(12));
  79. make.height.mas_equalTo(kRealValue(48));
  80. }];
  81. // 请上传身份证
  82. [self.idCardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.equalTo(self.nameLabel);
  84. make.top.equalTo(self.idNumberTextField.mas_bottom).offset(kRealValue(24));
  85. }];
  86. // 正面
  87. [self.frontCardView mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.equalTo(self.idCardLabel);
  89. make.right.equalTo(self.idNumberTextField);
  90. make.top.equalTo(self.idCardLabel.mas_bottom).offset(kRealValue(12));
  91. make.height.mas_equalTo(kRealValue(152));
  92. }];
  93. [self.frontCardTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.left.equalTo(self.frontCardView).offset(kRealValue(12));
  95. make.top.equalTo(self.frontCardView).offset(kRealValue(12));
  96. }];
  97. [self.frontCardSubtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.left.equalTo(self.frontCardTitleLabel);
  99. make.right.equalTo(self.frontCardImageView.mas_left).mas_offset(-8);
  100. make.top.equalTo(self.frontCardTitleLabel.mas_bottom).offset(kRealValue(4));
  101. }];
  102. [self.frontCardImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  103. make.right.equalTo(self.frontCardView).inset(kRealValue(16));
  104. make.centerY.equalTo(self.frontCardView);
  105. make.height.mas_equalTo(kRealValue(120));
  106. make.width.mas_equalTo(kRealValue(185));
  107. }];
  108. // 反面
  109. [self.backCardView mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.left.right.equalTo(self.frontCardView);
  111. make.top.equalTo(self.frontCardView.mas_bottom).offset(kRealValue(16));
  112. make.height.mas_equalTo(kRealValue(152));
  113. make.bottom.equalTo(self.contentView).offset(-kRealValue(20));
  114. }];
  115. [self.backCardTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.left.equalTo(self.backCardView).offset(kRealValue(12));
  117. make.top.equalTo(self.backCardView).offset(kRealValue(12));
  118. }];
  119. [self.backCardSubtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  120. make.left.equalTo(self.backCardTitleLabel);
  121. make.right.equalTo(self.backCardImageView.mas_left).mas_offset(-8);
  122. make.top.equalTo(self.backCardTitleLabel.mas_bottom).offset(kRealValue(4));
  123. }];
  124. [self.backCardImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.right.equalTo(self.backCardView).inset(kRealValue(16));
  126. make.centerY.equalTo(self.backCardView);
  127. make.size.mas_equalTo(self.frontCardImageView);
  128. }];
  129. }
  130. #pragma mark - MerchantEnrollDataFillDelegate
  131. - (void)fillWithData:(NSDictionary *)data {
  132. if (!data || ![data isKindOfClass:[NSDictionary class]]) {
  133. return;
  134. }
  135. self.nameTextField.text = data[@"username"];
  136. self.idNumberTextField.text = data[@"identification_card"];
  137. self.frontURL = data[@"identity_front_photo"];
  138. self.backURL = data[@"identity_back_photo"];
  139. [self.frontCardImageView setImageURL:[NSURL URLWithString:self.frontURL]];
  140. [self.backCardImageView setImageURL:[NSURL URLWithString:self.backURL]];
  141. }
  142. #pragma mark - Actions
  143. - (void)goNext {
  144. if (self.nameTextField.text.length == 0) {
  145. [self showToast:self.nameTextField.placeholder];
  146. return;
  147. }
  148. if (self.idNumberTextField.text.length == 0) {
  149. [self showToast:self.idNumberTextField.placeholder];
  150. return;
  151. }
  152. if (self.frontURL.length == 0) {
  153. [self showToast:self.frontCardSubtitleLabel.text];
  154. return;
  155. }
  156. if (self.backURL.length == 0) {
  157. [self showToast:self.backCardSubtitleLabel.text];
  158. return;
  159. }
  160. [super goNext];
  161. }
  162. - (void)frontCardTapped:(UITapGestureRecognizer *)gesture {
  163. WeakSelf
  164. [self pickImageWithCompletion:^(UIImage * _Nonnull image) {
  165. weakSelf.frontCardImageView.image = image;
  166. [weakSelf uploadImage:image completion:^(NSString * _Nonnull url) {
  167. weakSelf.frontURL = url;
  168. }];
  169. }];
  170. }
  171. - (void)backCardTapped:(UITapGestureRecognizer *)gesture {
  172. WeakSelf
  173. [self pickImageWithCompletion:^(UIImage * _Nonnull image) {
  174. weakSelf.backCardImageView.image = image;
  175. [weakSelf uploadImage:image completion:^(NSString * _Nonnull url) {
  176. weakSelf.backURL = url;
  177. }];
  178. }];
  179. }
  180. #pragma mark - Lazy Loading
  181. - (UILabel *)nameLabel {
  182. if (!_nameLabel) {
  183. _nameLabel = [[UILabel alloc] init];
  184. _nameLabel.text = ASLocalizedString(@"姓名");
  185. _nameLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  186. _nameLabel.textColor = [UIColor blackColor];
  187. // 添加红色星号
  188. NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_nameLabel.text];
  189. NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{
  190. NSForegroundColorAttributeName: [UIColor redColor],
  191. NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]
  192. }];
  193. [attributedText appendAttributedString:redStar];
  194. _nameLabel.attributedText = attributedText;
  195. }
  196. return _nameLabel;
  197. }
  198. - (UITextField *)nameTextField {
  199. if (!_nameTextField) {
  200. _nameTextField = [[UITextField alloc] init];
  201. _nameTextField.placeholder = ASLocalizedString(@"请输入法人姓名");
  202. _nameTextField.font = [UIFont systemFontOfSize:16];
  203. _nameTextField.textColor = [UIColor blackColor];
  204. _nameTextField.backgroundColor = [UIColor whiteColor];
  205. _nameTextField.layer.cornerRadius = kRealValue(8);
  206. _nameTextField.layer.borderWidth = 1;
  207. _nameTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor;
  208. // 设置内边距
  209. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))];
  210. _nameTextField.leftView = leftView;
  211. _nameTextField.leftViewMode = UITextFieldViewModeAlways;
  212. UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))];
  213. _nameTextField.rightView = rightView;
  214. _nameTextField.rightViewMode = UITextFieldViewModeAlways;
  215. }
  216. return _nameTextField;
  217. }
  218. - (UILabel *)idNumberLabel {
  219. if (!_idNumberLabel) {
  220. _idNumberLabel = [[UILabel alloc] init];
  221. _idNumberLabel.text = ASLocalizedString(@"身份证号码");
  222. _idNumberLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  223. _idNumberLabel.textColor = [UIColor blackColor];
  224. // 添加红色星号
  225. NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_idNumberLabel.text];
  226. NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{
  227. NSForegroundColorAttributeName: [UIColor redColor],
  228. NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]
  229. }];
  230. [attributedText appendAttributedString:redStar];
  231. _idNumberLabel.attributedText = attributedText;
  232. }
  233. return _idNumberLabel;
  234. }
  235. - (UITextField *)idNumberTextField {
  236. if (!_idNumberTextField) {
  237. _idNumberTextField = [[UITextField alloc] init];
  238. _idNumberTextField.placeholder = ASLocalizedString(@"请输入法人身份证号码");
  239. _idNumberTextField.font = [UIFont systemFontOfSize:16];
  240. _idNumberTextField.textColor = [UIColor blackColor];
  241. _idNumberTextField.backgroundColor = [UIColor whiteColor];
  242. _idNumberTextField.layer.cornerRadius = kRealValue(8);
  243. _idNumberTextField.layer.borderWidth = 1;
  244. _idNumberTextField.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor;
  245. // 设置内边距
  246. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))];
  247. _idNumberTextField.leftView = leftView;
  248. _idNumberTextField.leftViewMode = UITextFieldViewModeAlways;
  249. UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kRealValue(16), kRealValue(48))];
  250. _idNumberTextField.rightView = rightView;
  251. _idNumberTextField.rightViewMode = UITextFieldViewModeAlways;
  252. }
  253. return _idNumberTextField;
  254. }
  255. - (UILabel *)idCardLabel {
  256. if (!_idCardLabel) {
  257. _idCardLabel = [[UILabel alloc] init];
  258. _idCardLabel.text = ASLocalizedString(@"请上传身份证");
  259. _idCardLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  260. _idCardLabel.textColor = [UIColor blackColor];
  261. // 添加红色星号
  262. NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:_idCardLabel.text];
  263. NSAttributedString *redStar = [[NSAttributedString alloc] initWithString:@" *" attributes:@{
  264. NSForegroundColorAttributeName: [UIColor redColor],
  265. NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]
  266. }];
  267. [attributedText appendAttributedString:redStar];
  268. _idCardLabel.attributedText = attributedText;
  269. }
  270. return _idCardLabel;
  271. }
  272. - (UIView *)frontCardView {
  273. if (!_frontCardView) {
  274. _frontCardView = [[UIView alloc] init];
  275. _frontCardView.backgroundColor = [UIColor whiteColor];
  276. _frontCardView.layer.cornerRadius = kRealValue(8);
  277. _frontCardView.layer.borderWidth = 1;
  278. _frontCardView.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor;
  279. // 添加点击手势
  280. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(frontCardTapped:)];
  281. [_frontCardView addGestureRecognizer:tapGesture];
  282. }
  283. return _frontCardView;
  284. }
  285. - (UILabel *)frontCardTitleLabel {
  286. if (!_frontCardTitleLabel) {
  287. _frontCardTitleLabel = [[UILabel alloc] init];
  288. _frontCardTitleLabel.text = ASLocalizedString(@"正面");
  289. _frontCardTitleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
  290. _frontCardTitleLabel.textColor = [UIColor blackColor];
  291. }
  292. return _frontCardTitleLabel;
  293. }
  294. - (UILabel *)frontCardSubtitleLabel {
  295. if (!_frontCardSubtitleLabel) {
  296. _frontCardSubtitleLabel = [[UILabel alloc] init];
  297. _frontCardSubtitleLabel.text = ASLocalizedString(@"上传身份证正面");
  298. _frontCardSubtitleLabel.font = [UIFont systemFontOfSize:12];
  299. _frontCardSubtitleLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  300. _frontCardSubtitleLabel.numberOfLines = 2;
  301. }
  302. return _frontCardSubtitleLabel;
  303. }
  304. - (UIImageView *)frontCardImageView {
  305. if (!_frontCardImageView) {
  306. _frontCardImageView = [[UIImageView alloc] init];
  307. _frontCardImageView.image = [UIImage imageNamed:@"store_ID_front"];
  308. _frontCardImageView.contentMode = UIViewContentModeScaleAspectFit;
  309. }
  310. return _frontCardImageView;
  311. }
  312. - (UIView *)backCardView {
  313. if (!_backCardView) {
  314. _backCardView = [[UIView alloc] init];
  315. _backCardView.backgroundColor = [UIColor whiteColor];
  316. _backCardView.layer.cornerRadius = kRealValue(8);
  317. _backCardView.layer.borderWidth = 1;
  318. _backCardView.layer.borderColor = [UIColor colorWithHexString:@"#E5E5E5"].CGColor;
  319. // 添加点击手势
  320. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backCardTapped:)];
  321. [_backCardView addGestureRecognizer:tapGesture];
  322. }
  323. return _backCardView;
  324. }
  325. - (UILabel *)backCardTitleLabel {
  326. if (!_backCardTitleLabel) {
  327. _backCardTitleLabel = [[UILabel alloc] init];
  328. _backCardTitleLabel.text = ASLocalizedString(@"反面");
  329. _backCardTitleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
  330. _backCardTitleLabel.textColor = [UIColor blackColor];
  331. }
  332. return _backCardTitleLabel;
  333. }
  334. - (UILabel *)backCardSubtitleLabel {
  335. if (!_backCardSubtitleLabel) {
  336. _backCardSubtitleLabel = [[UILabel alloc] init];
  337. _backCardSubtitleLabel.text = ASLocalizedString(@"上传身份证反面");
  338. _backCardSubtitleLabel.font = [UIFont systemFontOfSize:12];
  339. _backCardSubtitleLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  340. _backCardSubtitleLabel.numberOfLines = 2;
  341. }
  342. return _backCardSubtitleLabel;
  343. }
  344. - (UIImageView *)backCardImageView {
  345. if (!_backCardImageView) {
  346. _backCardImageView = [[UIImageView alloc] init];
  347. _backCardImageView.image = [UIImage imageNamed:@"store_ID_back"];
  348. _backCardImageView.contentMode = UIViewContentModeScaleAspectFit;
  349. }
  350. return _backCardImageView;
  351. }
  352. @end