SPSBBankDetailsViewController.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. //
  2. // SPSBBankDetailsViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/5/19.
  6. //
  7. #import "SPSBBankDetailsViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBTextField.h"
  10. #import "SPSBSQLProfile.h"
  11. #import "SPSBPurchasersModel.h"
  12. #import "SPSBBusinessManager.h"
  13. #import "SPSBVerificationProfile.h"
  14. #import <UITextView+JXHPlaceHolder.h>
  15. #import "UIViewController+SPSBNetworkManager.h"
  16. #import "SPSBChooseBankTableViewController.h"
  17. #import <JXHVerificationTools.h>
  18. #import "SPSBChooseCityViewController.h"
  19. #import "SPSBQueryCityModel.h"
  20. #import "SPSBNavigationController.h"
  21. #define spsb_bankDetailsTitleTag 3000
  22. #define spsb_bankDetailsContentTag 4000
  23. #define spsb_bankDetailsLineTag 5000
  24. #define spsb_bankDetailsContentLeft 130
  25. #define spsb_bankDetailsTextViewRight 15
  26. #define spsb_bankDetailsTextViewWidth (jxh_screenWidth() - 130 - 15)
  27. #define spsb_bankDetailsRowHeight 50
  28. @interface SPSBBankDetailsViewController ()<UITextViewDelegate, UITextFieldDelegate> {
  29. NSArray *_titleArray;
  30. NSMutableArray<NSString *> *_contentArray;
  31. NSMutableArray<NSString *> *_editContentArray;
  32. UITextView *_textView;
  33. SPSBTextField *_textField;
  34. CGFloat _textViewHeight;
  35. UIButton *_rightButton;
  36. UIView *_headerView;
  37. UIView *_footerView;
  38. UITableViewCell *_nameCell;
  39. bool _isBankCodeInput;
  40. }
  41. @property (nonatomic, strong) UITableViewCell *spsb_numberCell;
  42. @property (nonatomic, strong) UITableViewCell *spsb_bankCell;
  43. @property (nonatomic, strong) UITableViewCell *spsb_branchCell;
  44. @property (nonatomic, strong) UITableViewCell *spsb_cityCell;
  45. @end
  46. @implementation SPSBBankDetailsViewController
  47. - (instancetype)init {
  48. self = [super initWithStyle:UITableViewStyleGrouped backgroundColor:SPSBTableViewBackgroundColorGray];
  49. if (!self) return nil;
  50. return self;
  51. }
  52. - (void)viewDidLoad {
  53. [super viewDidLoad];
  54. [self initData];
  55. [self setupUI];
  56. }
  57. - (void)initData {
  58. _isBankCodeInput = false;
  59. _titleArray = [@[@"银行卡号", @"开户银行", @"开户支行", @"开户城市"] mutableCopy];
  60. NSString *bankCity = [self getBankCityWithCid:_spsb_purchasers.spsb_bank_cid];
  61. _contentArray = [@[[_spsb_purchasers.spsb_bank_code isEqualToString:@""] ? @"未填写" : spsb_changeDisplayBankCode(_spsb_purchasers.spsb_bank_code),
  62. [_spsb_purchasers.spsb_bank isEqualToString:@""] ? @"未填写" : _spsb_purchasers.spsb_bank,
  63. [_spsb_purchasers.spsb_bank_branch isEqualToString:@""] ? @"未填写" : _spsb_purchasers.spsb_bank_branch, [bankCity isEqualToString:@""] ? @"未填写" : bankCity] mutableCopy];
  64. _editContentArray = [@[_spsb_purchasers.spsb_bank_code, _spsb_purchasers.spsb_bank, _spsb_purchasers.spsb_bank_branch, _spsb_purchasers.spsb_bank_cid] mutableCopy];
  65. }
  66. - (NSString *)getBankCityWithCid:(NSString *)cid {
  67. if (cid.length == 0) return cid;
  68. NSArray *array = [JXHFMDBManager searchWithPath:SPSBShanpQueryCitySQL backKey:@"city_name" condition:^id(FMDatabase *database) {
  69. return [database executeQuery:@"select * from t_sp_query_city where cid = ?", cid];
  70. }];
  71. if (array.count == 0) return @"";
  72. return array[0];
  73. }
  74. #pragma mark - Action
  75. - (void)rightButtonAction {
  76. if (!_spsb_isEdit) {
  77. [self changeStatus];
  78. return;
  79. }
  80. [self saveAction];
  81. }
  82. - (void)changeStatus {
  83. _spsb_isEdit = !_spsb_isEdit;
  84. [self reloadView];
  85. [self.tableView reloadData];
  86. }
  87. - (void)saveAction {
  88. jxh_endEdit();
  89. if (!jxh_isNumber(_editContentArray[0]) || ((NSString *)_editContentArray[0]).length < SPSBMinBankNumLength) {
  90. [self.view showToastWithTitle:@"请输入正确的银行卡号"];
  91. return;
  92. }
  93. if (_editContentArray[1].length < SPSBMinBankNameLength) {
  94. [self.view showToastWithTitle:@"请输入正确的银行名称"];
  95. return;
  96. }
  97. if (((NSString *)_editContentArray[2]).length < 1) {
  98. [self.view showToastWithTitle:@"请输入正确的银行支行名称"];
  99. return;
  100. }
  101. if (((NSString *)_editContentArray[3]).length < 1) {
  102. [self.view showToastWithTitle:@"请选择开户城市"];
  103. return;
  104. }
  105. [self uploadBank];
  106. }
  107. - (void)chooseBank {
  108. if (_isBankCodeInput) {
  109. _isBankCodeInput = false;
  110. //先结束输入以获取textfield内容
  111. jxh_endEdit();
  112. [self getBankWithInChooseBank:true];
  113. return;
  114. }
  115. jxh_endEdit();
  116. SPSBChooseBankTableViewController *vc = SPSBChooseBankTableViewController.new;
  117. @weakify(self)
  118. vc.spsb_completionAction = ^(NSString * _Nonnull bank) {
  119. @strongify(self)
  120. [self changeBank:bank];
  121. };
  122. [self.navigationController pushViewController:vc animated:true];
  123. }
  124. - (void)changeBank:(NSString *)bank {
  125. _editContentArray[1] = bank;
  126. [self.tableView reloadData];
  127. }
  128. - (void)chooseCity {
  129. SPSBChooseCityViewController *vc = SPSBChooseCityViewController.new;
  130. @weakify(self)
  131. vc.spsb_finishChoose = ^(SPSBQueryCityModel * _Nonnull model) {
  132. @strongify(self)
  133. [self finishChooseCity:model];
  134. };
  135. SPSBNavigationController *nav = [[SPSBNavigationController alloc] initWithRootViewController:vc];
  136. [self presentViewController:nav animated:true completion:nil];
  137. }
  138. - (void)finishChooseCity:(SPSBQueryCityModel *)model {
  139. _editContentArray[3] = model.spsb_cid;
  140. _contentArray[3] = model.spsb_city_name;
  141. [self.tableView reloadData];
  142. }
  143. - (void)handleCache {
  144. NSMutableDictionary *dict = [[_spsb_purchasers getDictionary] mutableCopy];
  145. dict[@"bank_code"] = _editContentArray[0];
  146. dict[@"bank"] = _editContentArray[1];
  147. dict[@"bank_branch"] = _editContentArray[2];
  148. dict[@"bank_cid"] = _editContentArray[3];
  149. _spsb_purchasers = [SPSBPurchasersModel getModelWithDictionary:dict];
  150. @synchronized(spsb_purchasersArray()) {
  151. NSMutableArray *arr;
  152. NSArray *cacheArray = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceLocationSQL key:SPSBmyPurchasersSQLKey condition:^id(FMDatabase *database) {
  153. return [database executeQuery:@"select * from cache_data where key = ?", SPSBmyPurchasersSQLKey];
  154. }];
  155. if (cacheArray) {
  156. arr = [NSMutableArray arrayWithArray:cacheArray];
  157. for (NSInteger i = 0; i < arr.count; i ++) {
  158. NSDictionary *dic = arr[i];
  159. if ([[NSString stringWithFormat:@"%@", dic[@"id"]] isEqualToString:_spsb_purchasers.spsb_id]) {
  160. [arr removeObject:dic];
  161. [arr insertObject:dict atIndex:i];
  162. dict = nil;
  163. break;
  164. }
  165. }
  166. if (dict) {
  167. [arr addObject:dict];
  168. }
  169. [JXHFMDBManager updateWithPath:SPSBShanpSocialInsuranceLocationSQL condition:^id(FMDatabase *database) {
  170. return @([database executeUpdate:@"delete from cache_data where key = ?", SPSBmyPurchasersSQLKey]);
  171. }];
  172. } else {
  173. arr = [NSMutableArray arrayWithArray:@[dict]];
  174. }
  175. spsb_setPurchasersArray([SPSBPurchasersModel getModelListWithArray:arr]);
  176. [JXHFMDBManager updateWithPath:SPSBShanpSocialInsuranceLocationSQL condition:^id(FMDatabase *database) {
  177. return @([database executeUpdate:@"insert into cache_data values(?, ?)", SPSBmyPurchasersSQLKey, jxh_archiver(arr, SPSBmyPurchasersSQLKey)]);
  178. }];
  179. }
  180. if (_spsb_hadChnaged) {
  181. _spsb_hadChnaged(_spsb_purchasers);
  182. }
  183. }
  184. #pragma mark - Network Action
  185. - (void)uploadBank {
  186. @weakify(self)
  187. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在保存" isLogin:true url:spsb_appUrl(SPSBUrlModifyBank) urlParameters:nil parameters:^NSDictionary * _Nonnull{
  188. return @{@"sbu_id": self->_spsb_purchasers.spsb_id, @"bank": self->_editContentArray[1], @"bank_branch": self->_editContentArray[2], @"bank_code": self->_editContentArray[0], @"bank_cid": self->_editContentArray[3]};
  189. } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  190. @strongify(self)
  191. [self handleCache];
  192. [self.navigationController popViewControllerAnimated:true];
  193. return @"保存成功";
  194. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  195. return @"保存失败";
  196. }];
  197. }
  198. - (void)getBankWithInChooseBank:(bool)flag {
  199. @weakify(self)
  200. [self networkUseMethod:SPSBNetworkMethodGET loadingTips:nil isLogin:false url:[NSString stringWithFormat:@"%@%@", SPSBAlipayGetBank, _editContentArray[0]] urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  201. return nil;
  202. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  203. debugLog(@"%@", data);
  204. @strongify(self)
  205. if (data && data[@"bank"]) {
  206. NSDictionary *bankDic = spsb_alipayBankDictionary();
  207. if (bankDic[data[@"bank"]]) {
  208. NSString *bank = bankDic[data[@"bank"]];
  209. [self changeBank:bank];
  210. return nil;
  211. }
  212. }
  213. if (flag) {
  214. [self chooseBank];
  215. }
  216. return nil;
  217. }];
  218. }
  219. #pragma mark - UITextFieldDelegate
  220. - (void)textFieldDidBeginEditing:(UITextField *)textField {
  221. _isBankCodeInput = true;
  222. }
  223. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
  224. _editContentArray[0] = textField.text;
  225. if (_isBankCodeInput) {
  226. _isBankCodeInput = false;
  227. [self getBankWithInChooseBank:false];
  228. }
  229. return true;
  230. }
  231. #pragma mark - UITextViewDelegate
  232. - (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
  233. jxh_handleInputTextView(textView, textView.font, 4, 0, NSTextAlignmentRight);
  234. return true;
  235. }
  236. - (void)textViewDidChange:(UITextView *)textView {
  237. UITextRange *selectedRange = [textView markedTextRange];
  238. if (!selectedRange) {
  239. if (textView.text.length > SPSBMaxBankBranceLength) {
  240. textView.text = [textView.text substringToIndex:SPSBMaxBankBranceLength];
  241. }
  242. _editContentArray[2] = textView.text;
  243. }
  244. CGFloat height = [textView sizeThatFits:(CGSize){spsb_bankDetailsTextViewWidth, CGFLOAT_MAX}].height;
  245. if (height == _textViewHeight) return;
  246. _textViewHeight = height;
  247. [textView makeConstraints:^(JXHConstraintMaker *make) {
  248. make.height.update(height);
  249. }];
  250. if ([textView isFirstResponder]) {
  251. if (@available(iOS 11.0, *)) {
  252. [self.tableView performBatchUpdates:^{
  253. } completion:^(BOOL finished) {
  254. }];
  255. } else {
  256. [self.tableView beginUpdates];
  257. [self.tableView endUpdates];
  258. }
  259. } else {
  260. [self.tableView reloadData];
  261. }
  262. }
  263. #pragma mark - Delegate & DataSource
  264. static NSString * const reuseIdentifier = @"Cell";
  265. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  266. switch (indexPath.row) {
  267. case 0:
  268. return self.spsb_numberCell;
  269. break;
  270. case 1:
  271. return self.spsb_bankCell;
  272. break;
  273. case 2:
  274. return self.spsb_branchCell;
  275. break;
  276. case 3:
  277. return self.spsb_cityCell;
  278. break;
  279. default:
  280. break;
  281. }
  282. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
  283. if (!cell) {
  284. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
  285. }
  286. return cell;
  287. }
  288. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  289. return 4;
  290. }
  291. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  292. if (_spsb_isEdit && indexPath.row == 2) {
  293. CGFloat height = _textViewHeight + 18;
  294. if (height < spsb_bankDetailsRowHeight) return spsb_bankDetailsRowHeight;
  295. return height;
  296. }
  297. return spsb_bankDetailsRowHeight;
  298. }
  299. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  300. [tableView deselectRowAtIndexPath:indexPath animated:false];
  301. if (!_spsb_isEdit) return;
  302. switch (indexPath.row) {
  303. case 1:
  304. [self chooseBank];
  305. break;
  306. case 3:
  307. [self chooseCity];
  308. break;
  309. default:
  310. break;
  311. }
  312. }
  313. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  314. return _spsb_purchasers.spsb_bank_code.length == 0 ? 110 : 146;
  315. }
  316. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  317. if (!_headerView) {
  318. _headerView = UIView.new;
  319. UILabel *tipsLabel = [UILabel convenienceWithFont:spsb_font(13) text:@"已缴纳的社保流水费用,将返还于该银行卡号上" textColor:spsb_999999_color()];
  320. [_headerView addSubview:tipsLabel];
  321. [tipsLabel makeConstraints:^(JXHConstraintMaker *make) {
  322. make.leading.equalTo(15);
  323. make.top.equalTo(22);
  324. }];
  325. _nameCell = [self createCellWithTitle:@"持卡人姓名" content:_spsb_purchasers.spsb_user_name];
  326. _nameCell.contentView.backgroundColor = spsb_FFFFFF_color(1.f);
  327. [_headerView addSubview:_nameCell];
  328. [_nameCell makeConstraints:^(JXHConstraintMaker *make) {
  329. make.leading.and.trailing.equalTo(0);
  330. make.top.equalTo(48);
  331. make.height.equalTo(spsb_bankDetailsRowHeight);
  332. }];
  333. [_nameCell.contentView viewWithTag:spsb_bankDetailsLineTag].hidden = true;
  334. if (_spsb_purchasers.spsb_bank_code.length != 0) {
  335. tipsLabel = [UILabel convenienceWithFont:spsb_font(13) text:@"修改卡号后请通知客服,以免社保流水返还到旧卡上" textColor:spsb_999999_color()];
  336. [_headerView addSubview:tipsLabel];
  337. [tipsLabel makeConstraints:^(JXHConstraintMaker *make) {
  338. make.leading.equalTo(15);
  339. make.top.equalTo(self->_nameCell.bottom).offset(22);
  340. }];
  341. }
  342. }
  343. UILabel *content = [_nameCell.contentView viewWithTag:spsb_bankDetailsContentTag];
  344. content.textColor = _spsb_isEdit ? spsb_AAAAAA_color() : spsb_808080_color();
  345. return _headerView;
  346. }
  347. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  348. if (_spsb_isEdit && _spsb_purchasers.spsb_bank_code.length == 0) {
  349. return 93;
  350. }
  351. return jxh_onePixe();
  352. }
  353. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  354. if (_spsb_isEdit && _spsb_purchasers.spsb_bank_code.length == 0) {
  355. if (!_footerView) {
  356. _footerView = UIView.new;
  357. UIButton *addButton = [UIButton convenienceWithFont:spsb_semiboldFont(16) target:self action:@selector(saveAction)];
  358. [addButton setTitle:@"添加" titleColor:spsb_FFFFFF_color(1.f) image:nil backgroundImage:jxh_getImage(confirm_n) state:JXHButtonControlStateNormal];
  359. [addButton setBackgroundImage:jxh_getImage(confirm_h) state:JXHButtonControlStateHighlighted];
  360. [addButton setLayerCornerRadius:22.5 clipToBounds:true];
  361. [_footerView addSubview:addButton];
  362. [addButton makeConstraints:^(JXHConstraintMaker *make) {
  363. make.top.equalTo(24);
  364. make.leading.equalTo(16);
  365. make.trailing.equalTo(-16);
  366. make.height.equalTo(45);
  367. }];
  368. }
  369. return _footerView;
  370. }
  371. return UIView.new;
  372. }
  373. #pragma mark - UI
  374. - (void)setupUI {
  375. [self createRightButton];
  376. [self setupTableView];
  377. [self reloadView];
  378. }
  379. - (void)reloadView {
  380. self.title = _spsb_isEdit ? (_spsb_purchasers.spsb_bank_code.length == 0 ? @"添加银行卡" : @"修改银行卡") : @"银行卡信息";
  381. _rightButton.hidden = _spsb_isEdit && _spsb_purchasers.spsb_bank_code.length == 0;
  382. _rightButton.selected = _spsb_isEdit;
  383. }
  384. - (void)setupTableView {
  385. if (@available(iOS 11.0, *)) {
  386. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
  387. }
  388. }
  389. - (void)createRightButton {
  390. _rightButton = [UIButton convenienceWithFont:spsb_font(15) target:self action:@selector(rightButtonAction)];
  391. [_rightButton setTitle:@"编辑" titleColor:spsb_3296FB_color() state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
  392. [_rightButton setTitle:@"保存" state:JXHButtonControlStateSelected | JXHButtonControlStateSelectedAndHighlighted];
  393. [_rightButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
  394. _rightButton.frame = CGRectMake(0, 0, 60, 44);
  395. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:_rightButton];
  396. self.navigationItem.rightBarButtonItem = rightItem;
  397. }
  398. - (UITableViewCell *)spsb_numberCell {
  399. if (!_spsb_numberCell) {
  400. _spsb_numberCell = [self createCellWithTitle:_titleArray[0] content:_contentArray[0]];
  401. _textField = [SPSBTextField convenienceWithFont:spsb_font(16) placeholder:@"仅支持储蓄卡" placeholderColor:spsb_CCCCCC_color() textColor:spsb_666666_color() clearButtonMode:UITextFieldViewModeWhileEditing returnType:UIReturnKeyDone keyboardType:UIKeyboardTypePhonePad delegate:self];
  402. _textField.text = _editContentArray[0];
  403. _textField.spsb_maxCount = SPSBMaxBankNumLength;
  404. _textField.textAlignment = NSTextAlignmentRight;
  405. [_spsb_numberCell.contentView addSubview:_textField];
  406. [_textField makeConstraints:^(JXHConstraintMaker *make) {
  407. make.leading.equalTo(spsb_bankDetailsContentLeft);
  408. make.right.equalTo(-15);
  409. make.top.and.bottom.equalTo(0);
  410. }];
  411. }
  412. UILabel *contentLabel = [_spsb_numberCell.contentView viewWithTag:spsb_bankDetailsContentTag];
  413. if (_spsb_isEdit) {
  414. contentLabel.hidden = true;
  415. _textField.hidden = false;
  416. } else {
  417. contentLabel.hidden = false;
  418. _textField.hidden = true;
  419. }
  420. [_spsb_numberCell.contentView viewWithTag:spsb_bankDetailsLineTag].hidden = true;
  421. return _spsb_numberCell;
  422. }
  423. - (UITableViewCell *)spsb_bankCell {
  424. if (!_spsb_bankCell) {
  425. _spsb_bankCell = [self createCellWithTitle:_titleArray[1] content:_contentArray[1]];
  426. UILabel *contentLabel = [_spsb_bankCell.contentView viewWithTag:spsb_bankDetailsContentTag];
  427. [contentLabel removeFromSuperview];
  428. UIStackView *view = [UIStackView convenienceWithAxis:UILayoutConstraintAxisHorizontal alignment:UIStackViewAlignmentCenter distribution:UIStackViewDistributionEqualSpacing spacing:7];
  429. [_spsb_bankCell.contentView addSubview:view];
  430. [view makeConstraints:^(JXHConstraintMaker *make) {
  431. make.trailing.equalTo(-15);
  432. make.top.and.bottom.equalTo(0);
  433. }];
  434. UIImageView *icon = UIImageView.new;
  435. icon.tag = 10000;
  436. [view addArrangedSubview:icon];
  437. [view addArrangedSubview:contentLabel];
  438. UIImageView *arrow = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
  439. arrow.tag = 10001;
  440. [view addArrangedSubview:arrow];
  441. }
  442. UIImageView *icon = [_spsb_bankCell.contentView viewWithTag:10000];
  443. UIImageView *arrow = [_spsb_bankCell.contentView viewWithTag:10001];
  444. UILabel *contentLabel = [_spsb_bankCell.contentView viewWithTag:spsb_bankDetailsContentTag];
  445. if (_spsb_isEdit) {
  446. arrow.hidden = false;
  447. if ([_editContentArray[1] isEqualToString:@""]) {
  448. contentLabel.textColor = spsb_CCCCCC_color();
  449. contentLabel.text = @"请选择";
  450. } else {
  451. contentLabel.textColor = spsb_666666_color();
  452. contentLabel.text = _editContentArray[1];
  453. }
  454. _spsb_bankCell.selectionStyle = UITableViewCellSelectionStyleDefault;
  455. } else {
  456. arrow.hidden = true;
  457. contentLabel.text = _contentArray[1];
  458. contentLabel.textColor = spsb_808080_color();
  459. _spsb_bankCell.selectionStyle = UITableViewCellSelectionStyleNone;
  460. }
  461. NSString *bank = contentLabel.text;
  462. NSString *image = spsb_bankIconDictionary()[bank];
  463. if (image) {
  464. icon.image = [UIImage imageNamed:image];
  465. } else {
  466. icon.image = nil;
  467. }
  468. return _spsb_bankCell;
  469. }
  470. - (UITableViewCell *)spsb_branchCell {
  471. if (!_spsb_branchCell) {
  472. _spsb_branchCell = [self createCellWithTitle:_titleArray[2] content:_contentArray[2]];
  473. _textView = UITextView.new;
  474. _textView.delegate = self;
  475. _textView.textColor = spsb_666666_color();
  476. _textView.font = spsb_font(16);
  477. _textView.textAlignment = NSTextAlignmentRight;
  478. _textView.enablesReturnKeyAutomatically = true;
  479. [_textView setTextContainerInset:UIEdgeInsetsZero];
  480. _textView.textContainer.lineFragmentPadding = 0;
  481. _textView.scrollEnabled = false;
  482. _textView.text = _editContentArray[2];
  483. UILabel *label = [UILabel convenienceWithFont:spsb_font(16) text:@"请输入开户支行" textColor:spsb_CCCCCC_color() textAlignment:NSTextAlignmentRight];
  484. [_textView setPlaceholderLabel:label];
  485. [_spsb_branchCell.contentView addSubview:_textView];
  486. [_textView makeConstraints:^(JXHConstraintMaker *make) {
  487. make.leading.equalTo(spsb_bankDetailsContentLeft);
  488. make.trailing.equalTo(-spsb_bankDetailsTextViewRight);
  489. make.centerY.equalTo(0);
  490. make.height.equalTo(0);
  491. }];
  492. _textViewHeight = 0.f;
  493. }
  494. UILabel *contentLabel = [_spsb_branchCell.contentView viewWithTag:spsb_bankDetailsContentTag];
  495. if (_spsb_isEdit) {
  496. contentLabel.hidden = true;
  497. _textView.hidden = false;
  498. [self textViewDidChange:_textView];
  499. } else {
  500. contentLabel.hidden = false;
  501. _textView.hidden = true;
  502. }
  503. return _spsb_branchCell;
  504. }
  505. - (UITableViewCell *)spsb_cityCell {
  506. if (!_spsb_cityCell) {
  507. _spsb_cityCell = [self createCellWithTitle:_titleArray[3] content:_contentArray[3]];
  508. UILabel *contentLabel = [_spsb_cityCell.contentView viewWithTag:spsb_bankDetailsContentTag];
  509. [contentLabel removeFromSuperview];
  510. UIStackView *view = [UIStackView convenienceWithAxis:UILayoutConstraintAxisHorizontal alignment:UIStackViewAlignmentCenter distribution:UIStackViewDistributionEqualSpacing spacing:7];
  511. [_spsb_cityCell.contentView addSubview:view];
  512. [view makeConstraints:^(JXHConstraintMaker *make) {
  513. make.trailing.equalTo(-15);
  514. make.top.and.bottom.equalTo(0);
  515. }];
  516. [view addArrangedSubview:contentLabel];
  517. UIImageView *arrow = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
  518. arrow.tag = 10001;
  519. [view addArrangedSubview:arrow];
  520. }
  521. UILabel *contentLabel = [_spsb_cityCell.contentView viewWithTag:spsb_bankDetailsContentTag];
  522. UIImageView *arrow = [_spsb_cityCell.contentView viewWithTag:10001];
  523. if (_spsb_isEdit) {
  524. arrow.hidden = false;
  525. NSString *city = [self getBankCityWithCid:_editContentArray[3]];
  526. if ([city isEqualToString:@""]) {
  527. _editContentArray[3] = @"";
  528. contentLabel.textColor = spsb_CCCCCC_color();
  529. contentLabel.text = @"请选择";
  530. } else {
  531. contentLabel.textColor = spsb_666666_color();
  532. contentLabel.text = city;
  533. }
  534. _spsb_cityCell.selectionStyle = UITableViewCellSelectionStyleDefault;
  535. } else {
  536. arrow.hidden = true;
  537. contentLabel.text = _contentArray[3];
  538. contentLabel.textColor = spsb_808080_color();
  539. _spsb_cityCell.selectionStyle = UITableViewCellSelectionStyleNone;
  540. }
  541. return _spsb_cityCell;
  542. }
  543. - (UITableViewCell *)createCellWithTitle:(NSString *)title content:(NSString *)content {
  544. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
  545. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  546. UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(16) text:title textColor:spsb_333333_color()];
  547. titleLabel.tag = spsb_bankDetailsTitleTag;
  548. [cell.contentView addSubview:titleLabel];
  549. [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
  550. make.leading.equalTo(15);
  551. make.top.equalTo(0);
  552. make.height.equalTo(spsb_bankDetailsRowHeight);
  553. }];
  554. UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(16) text:content textColor:spsb_808080_color() textAlignment:NSTextAlignmentRight];
  555. contentLabel.tag = spsb_bankDetailsContentTag;
  556. [cell.contentView addSubview:contentLabel];
  557. [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
  558. make.leading.equalTo(spsb_bankDetailsContentLeft);
  559. make.trailing.equalTo(-15);
  560. make.centerY.equalTo(0);
  561. }];
  562. UIView *line = [cell.contentView createLineWithLocation:JXHLineLocationTop headOffset:15 footOffset:0];
  563. line.tag = spsb_bankDetailsLineTag;
  564. return cell;
  565. }
  566. @end
  567. #undef spsb_bankDetailsTitleTag
  568. #undef spsb_bankDetailsContentTag
  569. #undef spsb_bankDetailsLineTag
  570. #undef spsb_bankDetailsContentLeft
  571. #undef spsb_bankDetailsTextViewRight
  572. #undef spsb_bankDetailsTextViewWidth
  573. #undef spsb_bankDetailsRowHeight