StockingGoodsListViewController.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. //
  2. // StockingGoodsListViewController.m
  3. // IBOSS
  4. //
  5. // Created by apple on 2017/5/17.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:库存商品一览控制器
  9. //
  10. #import "StockingGoodsListViewController.h"
  11. #import "StockingGoodsCell.h"
  12. @interface StockingGoodsListViewController ()<UITableViewDataSource, UITableViewDelegate>
  13. @end
  14. @implementation StockingGoodsListViewController
  15. @synthesize customTableView;
  16. #pragma mark - 公共函数
  17. /**
  18. viewDidLoad函数
  19. */
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. [self showTitle:@"库存商品一览"];
  23. [self initUI];
  24. [self reloadDataByOnlyCode];
  25. }
  26. /**
  27. 安全区视图发生变化
  28. */
  29. -(void)viewSafeAreaInsetsDidChange{
  30. [self.view setBackgroundColor:[UIColor whiteColor]];
  31. customTableView.frame =self.view.safeAreaLayoutGuide.layoutFrame;
  32. [super viewSafeAreaInsetsDidChange];
  33. }
  34. #pragma mark - 委托回调函数
  35. #pragma mark - tableView回调
  36. /**
  37. 单元格cell个数
  38. @param tableView <#tableView description#>
  39. @param section <#section description#>
  40. @return <#return value description#>
  41. */
  42. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  43. {
  44. return [self.arrNewDataList count];
  45. }
  46. /**
  47. <#Description#>
  48. @param tableView <#tableView description#>
  49. @return <#return value description#>
  50. */
  51. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  52. return 1;
  53. }
  54. /**
  55. 高度
  56. @param tableView <#tableView description#>
  57. @param indexPath <#indexPath description#>
  58. @return <#return value description#>
  59. */
  60. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  61. return 181;
  62. }
  63. /**
  64. 每个单元格cell
  65. @param tableView <#tableView description#>
  66. @param indexPath <#indexPath description#>
  67. @return <#return value description#>
  68. */
  69. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  70. {
  71. static NSString *CellIdentifier = @"StockingGoodsCell";
  72. StockingGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  73. // 新建cell
  74. if (!cell) {
  75. cell = [[StockingGoodsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  76. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  77. }
  78. else
  79. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  80. {
  81. while ([cell.contentView.subviews lastObject] != nil) {
  82. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  83. }
  84. }
  85. _infoModel = [self.arrNewDataList objectAtIndex:indexPath.row];
  86. cell.model = _infoModel;
  87. // 强制布局 xib时调用
  88. //[cell layoutIfNeeded];
  89. return cell;
  90. }
  91. /**
  92. 点击单元格事件
  93. @param tableView <#tableView description#>
  94. @param indexPath <#indexPath description#>
  95. */
  96. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  97. {
  98. if ([self.stockDelegate respondsToSelector:@selector(stockTextDoneDatas:)]) {
  99. [self.stockDelegate stockTextDoneDatas:self.arrNewDataList[indexPath.row]];
  100. }
  101. [self.navigationController popViewControllerAnimated:YES];
  102. }
  103. #pragma mark - scrollView回调
  104. /**
  105. 刷新数据源
  106. */
  107. - (void)refreshTableView
  108. {
  109. [self.customTableView reloadData];
  110. }
  111. /**
  112. 加载列表数据失败回调
  113. @param sender <#sender description#>
  114. */
  115. - (void)onLoadFail:(ASIDownManager *)sender {
  116. [self cancel];
  117. [self showAlertViewText:@"网络异常"];
  118. }
  119. /**
  120. 加载列表数据成功回调
  121. @param sender <#sender description#>
  122. */
  123. - (void)onLoadFinish:(ASIDownManager *)sender
  124. {
  125. [self cancel];
  126. // 服务器返回数据
  127. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  128. // 服务器返回数据状态值
  129. int iStatus = resultModel.status;
  130. // 服务器返回数据消息
  131. NSString *message = resultModel.message;
  132. // 服务器返回数据状态值正确
  133. if (iStatus == 0)
  134. {
  135. NSArray * infoArr = (NSArray *)resultModel.result;
  136. if(infoArr != nil && infoArr.count > 0)
  137. {
  138. [self.arrDataList removeAllObjects];
  139. [self.arrNewDataList removeAllObjects];
  140. [self.arrDataList addObjectsFromArray:infoArr];
  141. // 转换model对象
  142. for (int i = 0; i < self.arrDataList.count; i++)
  143. {
  144. NSDictionary *dicValue = self.arrDataList[i];
  145. StockingModel *model = [StockingModel dk_modelWithDictionary:dicValue];
  146. [self.arrNewDataList addObject:model];
  147. }
  148. [customTableView reloadData];
  149. }
  150. else{
  151. // 有刷新数据的时候
  152. if(self.arrDataList == nil || self.arrDataList.count == 0){
  153. [self showAlertViewBackText:@"未找到匹配结果"];
  154. }
  155. }
  156. }
  157. // 服务器返回数据状态值异常
  158. else if(iStatus == ActionResultStatusAuthError
  159. || iStatus == ActionResultStatusNoLogin
  160. || iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue)
  161. {
  162. [self showReLoginDialog:message];
  163. }
  164. else
  165. {
  166. [self showAlertViewText:message];
  167. return;
  168. }
  169. }
  170. #pragma mark - 刷新回调
  171. /**
  172. 隐藏进度条
  173. */
  174. - (void)cancel {
  175. [self stopLoading];
  176. }
  177. /**
  178. 隐藏键盘
  179. @param scrollView <#scrollView description#>
  180. */
  181. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  182. {
  183. [self.view endEditing:YES];
  184. }
  185. #pragma mark - 私有函数
  186. /**
  187. 初始化ui
  188. */
  189. - (void)initUI{
  190. self.arrDataList = [[NSMutableArray alloc]init];
  191. self.arrNewDataList = [[NSMutableArray alloc]init];
  192. _infoModel = [[StockingModel alloc]init];
  193. customTableView = [[UITableView alloc]
  194. initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,
  195. Screen_Height-rectNavHeight-rectStatusHeight)];
  196. customTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  197. customTableView.delegate = self;
  198. customTableView.dataSource = self;
  199. [self.view addSubview:customTableView];
  200. }
  201. /**
  202. 加载数据
  203. */
  204. - (void)reloadDataByOnlyCode
  205. {
  206. //NSString *urlStr = ServerURL;
  207. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  208. [dict setObject:@"GetInventoryByOnlyCodeIphone" forKey:@"Action"];
  209. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  210. [dict setObject:kkUserCode forKey:@"UserCode"];
  211. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  212. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  213. [dict setObject:_onlyCode forKeyedSubscript:@"OnlyCode"];
  214. self.downManager = [[ASIDownManager alloc] init];
  215. self.downManager.delegate = self;
  216. self.downManager.onRequestSuccess = @selector(onLoadFinish:);
  217. self.downManager.onRequestFail = @selector(onLoadFail:);
  218. [self.downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  219. }
  220. @end