UseEarnestAmountVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. //
  2. // UseEarnestAmountVC.m
  3. // IBOSSmini
  4. //
  5. // Created by ssl on 2018/2/28.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "UseEarnestAmountVC.h"
  9. @interface UseEarnestAmountVC ()<UseEarnestAmountCellDelegate>
  10. @end
  11. @implementation UseEarnestAmountVC
  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. if(_earnestList!=nil&&_earnestList.count>0){
  41. _arr= [[NSMutableArray alloc]initWithArray:_earnestList copyItems:YES];
  42. [_vTableView reloadData];
  43. }
  44. if(_earnestList == nil && _orderId != nil){
  45. _earnestList = [NSMutableArray array];
  46. [self loadEarnestDataSource];
  47. }
  48. }
  49. -(void)submitData{
  50. [self.view endEditing:YES];
  51. if([self.useEarnestAmountDelegate respondsToSelector:@selector(callbackUseEarnestAmount:)])
  52. {
  53. [self.useEarnestAmountDelegate callbackUseEarnestAmount:_earnestList];
  54. }
  55. [self.navigationController popViewControllerAnimated:YES];
  56. }
  57. -(void)initUI{
  58. _vTableView = [[UITableView alloc]
  59. initWithFrame:CGRectMake(0,
  60. 0,
  61. self.view.frame.size.width,
  62. self.view.frame.size.height)];
  63. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  64. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  65. _vTableView.backgroundColor = [UIColor whiteColor];
  66. _vTableView.delegate = self;
  67. _vTableView.dataSource=self;
  68. [self.view addSubview:_vTableView];
  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 160;
  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. UseEarnestAmountCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  108. cell=[[UseEarnestAmountCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  109. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  110. cell.position= indexPath.row;
  111. cell.cellDelegate = self;
  112. UseEarnestAmountModel *earnestModel = [_earnestList objectAtIndex:indexPath.row];
  113. [cell parseEarnestInfo:earnestModel];
  114. return cell;
  115. }
  116. - (void)goBack
  117. {
  118. if([self.useEarnestAmountDelegate respondsToSelector:@selector(callbackUseEarnestAmount:)])
  119. {
  120. [self.useEarnestAmountDelegate callbackUseEarnestAmount:_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:@"GetUseEarnestAmountDataIphone" 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. [dict setObject:_orderId forKey:@"OrderID"];
  138. [dict setObject:@"" forKey:@"SalesID"];
  139. [dict setObject:[NSString stringWithFormat:@"%d",_editFLag-1] forKey:@"Flg"];
  140. _downManager = [[ASIDownManager alloc] init];
  141. _downManager.delegate = self;
  142. _downManager.OnImageDown = @selector(onEarnestLoadFinish:);
  143. _downManager.OnImageFail = @selector(onEarnestLoadFail:);
  144. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  145. }
  146. -(void)onEarnestLoadFinish:(ASIDownManager *)sender{
  147. NSDictionary *dic = [sender.mWebStr JSONValue];
  148. [self stopLoading];
  149. // 服务器返回数据是否正确
  150. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  151. // 服务器返回数据状态值
  152. int iStatus = [[dic objectForKey:@"Status"] intValue];
  153. // 服务器返回数据消息
  154. NSString *message=[dic objectForKey:@"Message"];
  155. // 服务器返回数据状态值正确
  156. if (iStatus == 0) {
  157. NSArray * infoArr=[dic objectForKey:@"Result"];
  158. if(infoArr!=nil&& infoArr.count>0)
  159. {
  160. for (int i = 0; i < infoArr.count; i++) {
  161. NSDictionary *dic=infoArr[i];
  162. double unusedEarnest = [[dic objectForKey:@"UnusedEarnest"] doubleValue];
  163. if(unusedEarnest != 0){
  164. UseEarnestAmountModel *model = [[UseEarnestAmountModel alloc] init];
  165. if(self.goodsAmount != 0){
  166. if(self.goodsAmount > unusedEarnest){
  167. model.moneyInformation = [NSString stringWithFormat:@"%.4f",unusedEarnest];
  168. self.goodsAmount -= unusedEarnest;
  169. }else{
  170. model.moneyInformation = [NSString stringWithFormat:@"%.4f",self.goodsAmount];
  171. self.goodsAmount -= self.goodsAmount;
  172. }
  173. }else{
  174. model.moneyInformation = @"0";
  175. }
  176. NSString *settlementType = [dic objectForKey:@"SettlementType"];
  177. NSString *settlementTypeName = [dic objectForKey:@"SettlementTypeName"];
  178. NSString *unusedEarnest = [NSString stringWithFormat:@"%.4f",[[dic objectForKey:@"UnusedEarnest"] doubleValue]];
  179. model.settlementType = settlementType;
  180. model.settlementTypeName = settlementTypeName;
  181. model.unUserdEarnest = unusedEarnest;
  182. [_earnestList addObject:model];
  183. }
  184. }
  185. if(_earnestList.count>0){
  186. _arr= [[NSMutableArray alloc]initWithArray:_earnestList copyItems:YES];
  187. }
  188. [_vTableView reloadData];
  189. }
  190. }
  191. else if(iStatus==ActionResultStatusAuthError
  192. ||iStatus==ActionResultStatusNoLogin
  193. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  194. [self showReLoginDialog:message];
  195. }
  196. else{
  197. [self showAlertViewText:message];
  198. }
  199. }
  200. }
  201. -(void)onEarnestLoadFail:(ASIDownManager *)sender{
  202. [self stopLoading];
  203. [self showAlertViewText:@"加载失败"];
  204. }
  205. -(void)update:(int) position flag:(int) flag text:(NSString *) str{
  206. UseEarnestAmountModel *model = [self.earnestList objectAtIndex:position];
  207. if(flag == 1){
  208. model.moneyInformation = str;
  209. }else{
  210. model.remarks = str;
  211. }
  212. }
  213. // 键盘弹出改变tableview高度
  214. - (void)registerKeybordNotification {
  215. NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
  216. [notification removeObserver:self];
  217. [notification addObserver:self
  218. selector:@selector(showKeyboard:)
  219. name:UIKeyboardWillShowNotification
  220. object:nil];
  221. [notification addObserver:self
  222. selector:@selector(hideKeyboard:)
  223. name:UIKeyboardWillHideNotification
  224. object:nil];
  225. #ifdef __IPHONE_5_0
  226. // 5.0以上系统中文键盘高度与4.0系统不一样
  227. float version = [[[UIDevice currentDevice] systemVersion] floatValue];
  228. if (version >= 5.0) {
  229. [notification addObserver:self
  230. selector:@selector(showKeyboard:)
  231. name:UIKeyboardWillChangeFrameNotification
  232. object:nil];
  233. }
  234. #endif
  235. }
  236. - (void)showKeyboard:(NSNotification *)notification {
  237. NSDictionary *userInfo = [notification userInfo];
  238. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  239. CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
  240. CGFloat height = CGRectGetHeight(self.view.frame) - keyboardHeight;
  241. /* 使用动画效果,过度更加平滑 */
  242. [UIView beginAnimations:nil context:nil];
  243. [UIView setAnimationDuration:0.1];
  244. {
  245. CGRect rect = _vTableView.frame;
  246. rect.size.height = height;
  247. _vTableView.frame = rect;
  248. }
  249. [UIView commitAnimations];
  250. }
  251. - (void)hideKeyboard:(NSNotification *)notification {
  252. [UIView beginAnimations:nil context:nil];
  253. [UIView setAnimationDuration:0.1];
  254. {
  255. CGRect rect = _vTableView.frame;
  256. rect.size.height = CGRectGetHeight(self.view.frame) ;
  257. _vTableView.frame = rect;
  258. }
  259. [UIView commitAnimations];
  260. }
  261. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  262. if(scrollView.isDragging){
  263. [self.view endEditing:YES];
  264. }
  265. }
  266. @end