CollecteAmountVC.m 9.8 KB

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