StockingGoodsListViewController.m 8.7 KB

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