SPSBMinePurchasersDetailsTableViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. //
  2. // SPSBMinePurchasersDetailsTableViewController.m
  3. // 我的社保
  4. //
  5. // Created by jiaxian_he on 2021/5/14.
  6. //
  7. #import "SPSBMinePurchasersDetailsTableViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBPurchasersModel.h"
  10. #import <UITextView+JXHPlaceHolder.h>
  11. #import "SPSBTextField.h"
  12. #import "SPSBVerificationProfile.h"
  13. #import "SPSBBusinessManager.h"
  14. #import "SPSBPurchasersDetailsCheckIdCardViewController.h"
  15. #import "SPSBDisplayIdentityCardViewController.h"
  16. #import "SPSBBankDetailsViewController.h"
  17. #define spsb_minePurhcaserDetailsTitleTag 3000
  18. #define spsb_minePurhcaserDetailsContentTag 4000
  19. #define spsb_minePurhcaserDetailsLineTag 5000
  20. #define spsb_minePurhcaserDetailsContentLeft 130
  21. #define spsb_minePurhcaserDetailsTextViewRight 15
  22. #define spsb_minePurhcaserDetailsTextViewWidth (jxh_screenWidth() - 130 - 15)
  23. #define spsb_minePurhcaserDetailsRowHeight 50
  24. @interface SPSBMinePurchasersDetailsTableViewController ()<UITextViewDelegate, UITextFieldDelegate> {
  25. NSArray *_titleArray;
  26. NSMutableArray<NSString *> *_contentArray;
  27. UITextView *_textView;
  28. SPSBTextField *_textField;
  29. CGFloat _textViewHeight;
  30. }
  31. @property (nonatomic, strong) UITableViewCell *spsb_addressCell;
  32. @property (nonatomic, strong) UITableViewCell *spsb_phoneCell;
  33. @property (nonatomic, strong) UITableViewCell *spsb_bankCell;
  34. @end
  35. @implementation SPSBMinePurchasersDetailsTableViewController
  36. - (instancetype)init {
  37. self = [super initWithStyle:UITableViewStyleGrouped backgroundColor:SPSBTableViewBackgroundColorGray];
  38. if (!self) return nil;
  39. return self;
  40. }
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. [self initData];
  44. [self setupTableView];
  45. }
  46. - (void)initData {
  47. NSMutableArray *titleArray = [@[@"真实姓名", @"民族", @"身份证号", @"户籍地址", @"手机号码", @"银行卡号"] mutableCopy];
  48. _contentArray = [@[_spsb_purchasers.spsb_user_name, _spsb_purchasers.spsb_nation, _spsb_purchasers.spsb_id_card, [_spsb_purchasers.spsb_hk_address isEqualToString:@""] ? @"未填写" : _spsb_purchasers.spsb_hk_address, _spsb_purchasers.spsb_phone, _spsb_purchasers.spsb_bank_code] mutableCopy];
  49. if (![_spsb_purchasers.spsb_shebao_card isEqualToString:@""]) {
  50. [titleArray addObject:@"社保号"];
  51. [_contentArray addObject:_spsb_purchasers.spsb_shebao_card];
  52. }
  53. if (![_spsb_purchasers.spsb_fund_card isEqualToString:@""]) {
  54. [titleArray addObject:@"公积金账号"];
  55. [_contentArray addObject:_spsb_purchasers.spsb_fund_card];
  56. }
  57. _titleArray = titleArray;
  58. }
  59. #pragma mark - Action
  60. - (void)reloadPurchasers:(SPSBPurchasersModel *)purchasers {
  61. _spsb_purchasers = purchasers;
  62. [self initData];
  63. }
  64. - (NSString *)spsb_phone {
  65. return _textField.text;
  66. }
  67. - (NSString *)spsb_address {
  68. return _textView.text;
  69. }
  70. #pragma mark - UITextViewDelegate
  71. - (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
  72. jxh_handleInputTextView(textView, textView.font, 4, 0, NSTextAlignmentRight);
  73. return true;
  74. }
  75. - (void)textViewDidChange:(UITextView *)textView {
  76. UITextRange *selectedRange = [textView markedTextRange];
  77. if (!selectedRange) {
  78. if (textView.text.length > SPSBMaxHouseholdRegisterAddressLength) {
  79. textView.text = [textView.text substringToIndex:SPSBMaxHouseholdRegisterAddressLength];
  80. }
  81. }
  82. CGFloat height = [textView sizeThatFits:(CGSize){spsb_minePurhcaserDetailsTextViewWidth, CGFLOAT_MAX}].height;
  83. if (height == _textViewHeight) return;
  84. _textViewHeight = height;
  85. [textView makeConstraints:^(JXHConstraintMaker *make) {
  86. make.height.update(height);
  87. }];
  88. if ([textView isFirstResponder]) {
  89. if (@available(iOS 11.0, *)) {
  90. [self.tableView performBatchUpdates:^{
  91. } completion:^(BOOL finished) {
  92. }];
  93. } else {
  94. [self.tableView beginUpdates];
  95. [self.tableView endUpdates];
  96. }
  97. } else {
  98. [self.tableView reloadData];
  99. }
  100. }
  101. #pragma mark - Delegate & DataSource
  102. static NSString * const reuseIdentifier = @"SPSBMinePurchasersDetailsTableViewCell";
  103. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  104. if (indexPath.row == 3) {
  105. return self.spsb_addressCell;
  106. }
  107. if (indexPath.section == 1) {
  108. if (indexPath.row == 0) {
  109. return self.spsb_phoneCell;
  110. }
  111. if (indexPath.row == 1) {
  112. return self.spsb_bankCell;
  113. }
  114. }
  115. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
  116. if (!cell) {
  117. cell = [self createCellWithReuseIdentifier:reuseIdentifier];
  118. }
  119. UILabel *titleLabel = [cell.contentView viewWithTag:spsb_minePurhcaserDetailsTitleTag];
  120. UILabel *contentLabel = [cell.contentView viewWithTag:spsb_minePurhcaserDetailsContentTag];
  121. contentLabel.textColor = _spsb_isEdit ? (indexPath.row == 2 ? spsb_666666_color() : spsb_AAAAAA_color()) : spsb_808080_color();
  122. if (indexPath.section == 0) {
  123. titleLabel.text = _titleArray[indexPath.row];
  124. contentLabel.text = _contentArray[indexPath.row];
  125. if (indexPath.row == 2) {
  126. cell.selectionStyle = _spsb_isEdit ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;
  127. }
  128. } else if (indexPath.section == 2) {
  129. titleLabel.text = _titleArray[indexPath.row + 6];
  130. contentLabel.text = _contentArray[indexPath.row + 6];
  131. }
  132. [cell.contentView viewWithTag:spsb_minePurhcaserDetailsLineTag].hidden = indexPath.row == 0;
  133. return cell;
  134. }
  135. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  136. if (_titleArray.count > 6) return 3;
  137. return 2;
  138. }
  139. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  140. if (section == 0) return 4;
  141. if (section == 2) return _titleArray.count - 6;
  142. return 2;
  143. }
  144. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  145. if (_spsb_isEdit && indexPath.row == 3) {
  146. CGFloat height = _textViewHeight + 18;
  147. if (height < spsb_minePurhcaserDetailsRowHeight) return spsb_minePurhcaserDetailsRowHeight;
  148. return height;
  149. }
  150. return spsb_minePurhcaserDetailsRowHeight;
  151. }
  152. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  153. [tableView deselectRowAtIndexPath:indexPath animated:false];
  154. if (indexPath.section == 0 && indexPath.row == 2 && _spsb_isEdit) {
  155. SPSBPurchasersDetailsCheckIdCardViewController *vc = SPSBPurchasersDetailsCheckIdCardViewController.new;
  156. vc.spsb_purchasersId = _spsb_purchasers.spsb_id;
  157. @weakify(self)
  158. vc.spsb_checkSuccess = ^(NSString * _Nonnull number) {
  159. @strongify(self)
  160. SPSBDisplayIdentityCardViewController *vc = SPSBDisplayIdentityCardViewController.new;
  161. vc.spsb_identityCardNum = number;
  162. [self.navigationController pushViewController:vc animated:true];
  163. };
  164. [self presentViewController:vc animated:false completion:nil];
  165. } else if (indexPath.section == 1 && indexPath.row == 1) {
  166. SPSBBankDetailsViewController *vc = SPSBBankDetailsViewController.new;
  167. vc.spsb_purchasers = _spsb_purchasers;
  168. vc.spsb_isEdit = _spsb_isEdit;
  169. @weakify(self)
  170. vc.spsb_hadChnaged = ^(SPSBPurchasersModel * _Nonnull purchasers) {
  171. @strongify(self)
  172. self->_spsb_purchasers = purchasers;
  173. if (self->_spsb_hadChnaged) {
  174. self->_spsb_hadChnaged(purchasers);
  175. }
  176. [self initData];
  177. [self.tableView reloadData];
  178. };
  179. [self.navigationController pushViewController:vc animated:true];
  180. }
  181. }
  182. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  183. return jxh_onePixe();
  184. }
  185. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  186. return UIView.new;
  187. }
  188. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  189. return 12;
  190. }
  191. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  192. return UIView.new;
  193. }
  194. #pragma mark - UI
  195. - (void)setupTableView {
  196. if (@available(iOS 11.0, *)) {
  197. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
  198. }
  199. }
  200. - (UITableViewCell *)spsb_bankCell {
  201. if (!_spsb_bankCell) {
  202. _spsb_bankCell = [self createCellWithReuseIdentifier:nil];
  203. ((UILabel *)[_spsb_bankCell.contentView viewWithTag:spsb_minePurhcaserDetailsTitleTag]).text = _titleArray[5];
  204. UILabel *contentLabel = [_spsb_bankCell.contentView viewWithTag:spsb_minePurhcaserDetailsContentTag];
  205. [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
  206. make.trailing.update(-34);
  207. }];
  208. UIImageView *arrowView = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
  209. [_spsb_bankCell.contentView addSubview:arrowView];
  210. [arrowView makeConstraints:^(JXHConstraintMaker *make) {
  211. make.trailing.equalTo(-15);
  212. make.centerY.equalTo(0);
  213. }];
  214. }
  215. UILabel *contentLabel = [_spsb_bankCell.contentView viewWithTag:spsb_minePurhcaserDetailsContentTag];
  216. contentLabel.textColor = _spsb_isEdit ? spsb_666666_color() : spsb_808080_color();
  217. contentLabel.text = _contentArray[5].length > 0 ? spsb_changeDisplayBankCode(_contentArray[5]) : @"未添加";
  218. _spsb_bankCell.selectionStyle = UITableViewCellSelectionStyleDefault;
  219. return _spsb_bankCell;
  220. }
  221. - (UITableViewCell *)spsb_phoneCell {
  222. if (!_spsb_phoneCell) {
  223. _spsb_phoneCell = [self createCellWithReuseIdentifier:nil];
  224. ((UILabel *)[_spsb_phoneCell.contentView viewWithTag:spsb_minePurhcaserDetailsTitleTag]).text = _titleArray[4];
  225. _textField = [SPSBTextField convenienceWithFont:spsb_font(16) placeholder:@"请输入手机号码" placeholderColor:spsb_CCCCCC_color() textColor:spsb_666666_color() clearButtonMode:UITextFieldViewModeWhileEditing returnType:UIReturnKeyDone keyboardType:UIKeyboardTypePhonePad delegate:self];
  226. _textField.text = _spsb_purchasers.spsb_phone;
  227. _textField.spsb_maxCount = SPSBPhoneNumLength;
  228. _textField.textAlignment = NSTextAlignmentRight;
  229. [_spsb_phoneCell.contentView addSubview:_textField];
  230. [_textField makeConstraints:^(JXHConstraintMaker *make) {
  231. make.leading.equalTo(spsb_minePurhcaserDetailsContentLeft);
  232. make.right.equalTo(-15);
  233. make.top.and.bottom.equalTo(0);
  234. }];
  235. }
  236. UILabel *contentLabel = [_spsb_phoneCell.contentView viewWithTag:spsb_minePurhcaserDetailsContentTag];
  237. if (_spsb_isEdit) {
  238. contentLabel.hidden = true;
  239. _textField.hidden = false;
  240. } else {
  241. contentLabel.hidden = false;
  242. _textField.hidden = true;
  243. contentLabel.text = _contentArray[4];
  244. }
  245. [_spsb_phoneCell.contentView viewWithTag:spsb_minePurhcaserDetailsLineTag].hidden = true;
  246. return _spsb_phoneCell;
  247. }
  248. - (UITableViewCell *)spsb_addressCell {
  249. if (!_spsb_addressCell) {
  250. _spsb_addressCell = [self createCellWithReuseIdentifier:nil];
  251. ((UILabel *)[_spsb_addressCell.contentView viewWithTag:spsb_minePurhcaserDetailsTitleTag]).text = _titleArray[3];
  252. _textView = UITextView.new;
  253. _textView.delegate = self;
  254. _textView.textColor = spsb_666666_color();
  255. _textView.font = spsb_font(16);
  256. _textView.textAlignment = NSTextAlignmentRight;
  257. _textView.enablesReturnKeyAutomatically = true;
  258. [_textView setTextContainerInset:UIEdgeInsetsZero];
  259. _textView.textContainer.lineFragmentPadding = 0;
  260. _textView.scrollEnabled = false;
  261. _textView.text = _spsb_purchasers.spsb_hk_address;
  262. UILabel *label = [UILabel convenienceWithFont:spsb_font(16) text:@"请输入户籍地址" textColor:spsb_CCCCCC_color() textAlignment:NSTextAlignmentRight];
  263. [_textView setPlaceholderLabel:label];
  264. [_spsb_addressCell.contentView addSubview:_textView];
  265. [_textView makeConstraints:^(JXHConstraintMaker *make) {
  266. make.leading.equalTo(spsb_minePurhcaserDetailsContentLeft);
  267. make.trailing.equalTo(-spsb_minePurhcaserDetailsTextViewRight);
  268. make.centerY.equalTo(0);
  269. make.height.equalTo(0);
  270. }];
  271. _textViewHeight = 0.f;
  272. }
  273. UILabel *contentLabel = [_spsb_addressCell.contentView viewWithTag:spsb_minePurhcaserDetailsContentTag];
  274. if (_spsb_isEdit) {
  275. contentLabel.hidden = true;
  276. _textView.hidden = false;
  277. [self textViewDidChange:_textView];
  278. } else {
  279. contentLabel.hidden = false;
  280. _textView.hidden = true;
  281. contentLabel.text = _contentArray[3];
  282. }
  283. return _spsb_addressCell;
  284. }
  285. - (UITableViewCell *)createCellWithReuseIdentifier:(nullable NSString *)reuseIdentifier {
  286. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
  287. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  288. UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(16) text:@"" textColor:spsb_333333_color()];
  289. titleLabel.tag = spsb_minePurhcaserDetailsTitleTag;
  290. [cell.contentView addSubview:titleLabel];
  291. [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
  292. make.leading.equalTo(15);
  293. make.top.equalTo(0);
  294. make.height.equalTo(spsb_minePurhcaserDetailsRowHeight);
  295. }];
  296. UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(16) text:nil textColor:spsb_808080_color() textAlignment:NSTextAlignmentRight];
  297. contentLabel.tag = spsb_minePurhcaserDetailsContentTag;
  298. [cell.contentView addSubview:contentLabel];
  299. [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
  300. make.leading.equalTo(spsb_minePurhcaserDetailsContentLeft);
  301. make.trailing.equalTo(-15);
  302. make.centerY.equalTo(0);
  303. }];
  304. UIView *line = [cell.contentView createLineWithLocation:JXHLineLocationTop headOffset:15 footOffset:0];
  305. line.tag = spsb_minePurhcaserDetailsLineTag;
  306. return cell;
  307. }
  308. @end
  309. #undef spsb_minePurhcaserDetailsTitleTag
  310. #undef spsb_minePurhcaserDetailsContentTag
  311. #undef spsb_minePurhcaserDetailsLineTag
  312. #undef spsb_minePurhcaserDetailsContentLeft
  313. #undef spsb_minePurhcaserDetailsTextViewRight
  314. #undef spsb_minePurhcaserDetailsTextViewWidth
  315. #undef spsb_minePurhcaserDetailsRowHeight