UseStorageVC.m 11 KB

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