PaymentMethodVC.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. //
  2. // DepositAmountVC.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2020/7/24.
  6. // Copyright © 2020 elongtian. All rights reserved.
  7. //
  8. #import "PaymentMethodVC.h"
  9. #import "PayTypeModel.h"
  10. @interface PaymentMethodVC ()
  11. @end
  12. @implementation PaymentMethodVC
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. [self loadNavStyle];
  16. [self initUI];
  17. if(_receivableList!=nil&&_receivableList.count>0)
  18. {
  19. [_vTableView reloadData];
  20. }
  21. else
  22. {
  23. [self reloadData];
  24. }
  25. [self registerKeybordNotification];
  26. }
  27. -(void)loadNavStyle
  28. {
  29. //右边
  30. UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];
  31. [btnAdd addTarget:self action:@selector(submitData)
  32. forControlEvents:UIControlEventTouchUpInside];
  33. btnAdd.frame = CGRectMake(0, 0,60,14);
  34. [btnAdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  35. btnAdd.titleLabel.font=[UIFont systemFontOfSize:16];
  36. [btnAdd setTitle:@"确定" forState:UIControlStateNormal];
  37. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
  38. self.navigationItem.title=@"请选择";
  39. self.navigationItem.rightBarButtonItem = menubtnAdd;
  40. //返回
  41. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  42. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  43. forState:UIControlStateNormal];
  44. [button addTarget:self action:@selector(goBack)
  45. forControlEvents:UIControlEventTouchUpInside];
  46. button.frame = CGRectMake(0, 0, 15, 18);
  47. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  48. self.navigationItem.leftBarButtonItem = menuButton;
  49. }
  50. /**
  51. 安全区视图发生变化
  52. */
  53. -(void)viewSafeAreaInsetsDidChange{
  54. _vTableView.frame = CGRectMake(0,0,self.view.frame.size.width, self.view.safeAreaLayoutGuide.layoutFrame.size.height);
  55. [super viewSafeAreaInsetsDidChange];
  56. }
  57. /**
  58. 加载数据函数
  59. */
  60. - (void)reloadData
  61. {
  62. [self startLoading];
  63. NSString *urlStr = ServerURL;
  64. NSMutableDictionary *dict = [NSMutableDictionary new];
  65. [dict setObject:@"GetReceivableWayIphone" forKey:@"Action"];
  66. [dict setObject:kkAccountCode forKey:@"AccountCode"];
  67. [dict setObject:kkUserCode forKey:@"UserCode"];
  68. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  69. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  70. self.downManager = [[ASIDownManager alloc] init];
  71. self.downManager.delegate = self;
  72. self.downManager.onRequestSuccess = @selector(onRequestSuccess:);
  73. self.downManager.onRequestFail = @selector(onRequestFail:);
  74. [self.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  75. }
  76. /**
  77. 数据加载成功函数
  78. @param sender <#sender description#>
  79. */
  80. - (void)onRequestSuccess:(ASIDownManager *)sender {
  81. // 取消进度条
  82. [self stopLoading];
  83. // 服务器返回数据转换model
  84. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  85. // 服务器返回数据状态值
  86. int iStatus = resultModel.status;
  87. // 服务器返回数据消息
  88. NSString *message = resultModel.message;
  89. // 服务器返回数据状态值正确
  90. if (iStatus == 0) {
  91. // 服务器返回数据结果
  92. NSArray *paymentMethodArr = (NSArray *)resultModel.result;
  93. if(paymentMethodArr != nil&&paymentMethodArr.count>0)
  94. {
  95. _receivableList=[[NSMutableArray alloc]init];
  96. for(int i=0;i<paymentMethodArr.count;i++)
  97. {
  98. NSDictionary *dic=[paymentMethodArr objectAtIndex:i];
  99. PayTypeModel *info=[PayTypeModel new];
  100. info.settlementType = [NSString stringWithFormat:@"%@",[dic objectForKey:@"SettlementType"]];
  101. info.settlementTypeName = [dic objectForKey:@"SettlementTypeName"];
  102. info.remarks = [NSString stringWithFormat:@"%@",[dic objectForKey:@"Remarks"]];
  103. info.valueFlag = [NSString stringWithFormat:@"%@",[dic objectForKey:@"ValueFlag"]];
  104. [_receivableList addObject:info];
  105. }
  106. [_vTableView reloadData];
  107. }
  108. }
  109. else if(iStatus == ActionResultStatusAuthError
  110. ||iStatus == ActionResultStatusNoLogin
  111. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  112. [self showReLoginDialog:message];
  113. return;
  114. }
  115. else {
  116. [self showAlertViewText:message];
  117. }
  118. }
  119. /**
  120. 数据加载失败函数
  121. @param sender <#sender description#>
  122. */
  123. - (void)onRequestFail:(ASIDownManager *)sender {
  124. [self showAlertViewText:@"网络异常"];
  125. }
  126. -(void)initUI{
  127. _vTableView = [[UITableView alloc]
  128. initWithFrame:CGRectMake(0,
  129. 0,
  130. self.view.frame.size.width,
  131. self.view.frame.size.height)];
  132. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  133. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  134. _vTableView.backgroundColor = [UIColor whiteColor];
  135. _vTableView.delegate = self;
  136. _vTableView.dataSource=self;
  137. [self.view addSubview:_vTableView];
  138. }
  139. -(void)submitData{
  140. [self.view endEditing:YES];
  141. if([self.paymentMethodDelegate respondsToSelector:@selector(callbackPaymentMethod:)])
  142. {
  143. [self.paymentMethodDelegate callbackPaymentMethod:_receivableList];
  144. }
  145. [self.navigationController popViewControllerAnimated:YES];
  146. }
  147. #pragma mark - tableView回调
  148. /**
  149. 单元格cell个数
  150. @param tableView <#tableView description#>
  151. @param section <#section description#>
  152. @return <#return value description#>
  153. */
  154. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  155. {
  156. return [_receivableList count];
  157. }
  158. /**
  159. <#Description#>
  160. @param tableView <#tableView description#>
  161. @return <#return value description#>
  162. */
  163. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  164. return 1;
  165. }
  166. /**
  167. 高度
  168. @param tableView <#tableView description#>
  169. @param indexPath <#indexPath description#>
  170. @return <#return value description#>
  171. */
  172. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  173. return 97;
  174. }
  175. /**
  176. 每个单元格cell
  177. @param tableView <#tableView description#>
  178. @param indexPath <#indexPath description#>
  179. @return <#return value description#>
  180. */
  181. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  182. {
  183. static NSString *cellIdentifier = @"PaymentMethodCell";
  184. PaymentMethodCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  185. cell=[[PaymentMethodCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  186. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  187. cell.position= indexPath.row;
  188. cell.cellDelegate=self;
  189. PayTypeModel *paytypeModel = [_receivableList objectAtIndex:indexPath.row];
  190. [cell parsePaymentMethod:paytypeModel];
  191. return cell;
  192. }
  193. -(void)update:(int) position flag:(int) flag text:(NSString *) str
  194. {
  195. PayTypeModel *model = [_receivableList objectAtIndex:position];
  196. if(flag == 1){
  197. model.receivableSum = str;
  198. }else{
  199. model.remarks = str;
  200. }
  201. }
  202. // 键盘弹出改变tableview高度
  203. - (void)registerKeybordNotification {
  204. NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
  205. [notification removeObserver:self];
  206. [notification addObserver:self
  207. selector:@selector(showKeyboard:)
  208. name:UIKeyboardWillShowNotification
  209. object:nil];
  210. [notification addObserver:self
  211. selector:@selector(hideKeyboard:)
  212. name:UIKeyboardWillHideNotification
  213. object:nil];
  214. #ifdef __IPHONE_5_0
  215. // 5.0以上系统中文键盘高度与4.0系统不一样
  216. float version = [[[UIDevice currentDevice] systemVersion] floatValue];
  217. if (version >= 5.0) {
  218. [notification addObserver:self
  219. selector:@selector(showKeyboard:)
  220. name:UIKeyboardWillChangeFrameNotification
  221. object:nil];
  222. }
  223. #endif
  224. }
  225. - (void)showKeyboard:(NSNotification *)notification {
  226. NSDictionary *userInfo = [notification userInfo];
  227. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  228. CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
  229. CGFloat height = CGRectGetHeight(self.view.frame) - keyboardHeight;
  230. /* 使用动画效果,过度更加平滑 */
  231. [UIView beginAnimations:nil context:nil];
  232. [UIView setAnimationDuration:0.1];
  233. {
  234. CGRect rect = _vTableView.frame;
  235. rect.size.height = height;
  236. _vTableView.frame = rect;
  237. }
  238. [UIView commitAnimations];
  239. }
  240. - (void)hideKeyboard:(NSNotification *)notification {
  241. [UIView beginAnimations:nil context:nil];
  242. [UIView setAnimationDuration:0.1];
  243. {
  244. CGRect rect = _vTableView.frame;
  245. rect.size.height = CGRectGetHeight(self.view.frame) ;
  246. _vTableView.frame = rect;
  247. }
  248. [UIView commitAnimations];
  249. }
  250. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  251. if(scrollView.isDragging){
  252. [self.view endEditing:YES];
  253. }
  254. }
  255. - (void)goBack
  256. {
  257. [self.navigationController popViewControllerAnimated:YES];
  258. }
  259. - (void)didReceiveMemoryWarning {
  260. [super didReceiveMemoryWarning];
  261. }
  262. @end