// // StockingGoodsListViewController.m // IBOSSmini // // Created by apple on 2017/5/17. // Copyright © 2017年 elongtian. All rights reserved. // #import "StockingGoodsListViewController.h" #import "StockingGoodsCell.h" @interface StockingGoodsListViewController () @end @implementation StockingGoodsListViewController @synthesize customTableView; #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; [self showTitle:@"库存商品一览"]; [self initUI]; [self reloadDataByOnlyCode]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ self.view.backgroundColor = [UIColor whiteColor]; customTableView.frame = self.view.safeAreaLayoutGuide.layoutFrame; [super viewSafeAreaInsetsDidChange]; } #pragma mark - 委托回调函数 #pragma mark - tableView回调 /** 单元格cell个数 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_newdataList count]; } /** <#Description#> @param tableView <#tableView description#> @return <#return value description#> */ -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } /** 高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 181; } /** 每个单元格cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"StockingGoodsCell"; StockingGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell=[[StockingGoodsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; } else //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免 { while ([cell.contentView.subviews lastObject] != nil) { [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview]; } } // StockingGoodsCell *cell=[[StockingGoodsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; // cell.selectionStyle=UITableViewCellSelectionStyleNone; _infoModel = [_newdataList objectAtIndex:indexPath.row]; cell.model = _infoModel; // 强制布局 xib时调用 //[cell layoutIfNeeded]; return cell; } /** 点击单元格事件 @param tableView <#tableView description#> @param indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([self.stockDelegate respondsToSelector:@selector(stockTextDoneDatas:)]) { [self.stockDelegate stockTextDoneDatas:self.newdataList[indexPath.row]]; } [self.navigationController popViewControllerAnimated:YES]; } #pragma mark - scrollView回调 /** 刷新数据源 */ -(void)refreshTableView { [self.customTableView reloadData]; } /** 加载列表数据失败回调 @param sender <#sender description#> */ - (void)onLoadFail:(ASIDownManager *)sender { [self cancel]; [self showAlertViewText:@"加载失败"]; } /** 加载列表数据成功回调 @param sender <#sender description#> */ - (void)onLoadFinish:(ASIDownManager *)sender { [self cancel]; NSDictionary *dic = [sender.mWebStr JSONValue]; // 服务器返回数据是否正确 if (dic && [dic isKindOfClass:[NSDictionary class]]) { // 服务器返回数据状态值 int iStatus = [[dic objectForKey:@"Status"] intValue]; // 服务器返回数据消息 NSString *message=[dic objectForKey:@"Message"]; // 服务器返回数据状态值正确 if (iStatus == 0) { NSArray * infoArr=[dic objectForKey:@"Result"]; if(infoArr!=nil&& infoArr.count>0) { [self.dataList removeAllObjects]; [_newdataList removeAllObjects]; [self.dataList addObjectsFromArray:infoArr]; // 转换model对象 if(self.dataList.count >0 ) { // 格式化日期 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; for (int i = 0; i < self.dataList.count; i++) { NSDictionary *dicValue = self.dataList[i]; StockingModel *model = [StockingModel new]; model.inventoryID = [[dicValue objectForKey:@"InventoryID"]stringValue]; model.codeID = [[dicValue objectForKey:@"CodeID"]stringValue]; model.code = [dicValue objectForKey:@"Code"]; model.onlyCode = [dicValue objectForKey:@"OnlyCode"]; model.specification = [dicValue objectForKey:@"Specification"]; model.colorNumber = [dicValue objectForKey:@"ColorNumber"]; model.gradeName = [dicValue objectForKey:@"GradeName"]; model.warehouseName = [dicValue objectForKey:@"WarehouseName"]; model.positionNumber = [dicValue objectForKey:@"PositionNumber"]; model.quantity = [[dicValue objectForKey:@"InventoryQuantity"] stringValue]; model.balanceQuantity = [[dicValue objectForKey:@"BalanceQuantity"] stringValue]; [_newdataList addObject:model]; } } if(self.dataList.count==0){ [self showAlertViewText:@"未找到匹配结果"]; } [customTableView reloadData]; } else{ // 有刷新数据的时候 if(_dataList == nil || _dataList.count==0){ [self showAlertViewBackText:@"未找到匹配结果"]; } } } // 服务器返回数据状态值异常 else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid) { [self showReLoginDialog:message]; } else { [self showAlertViewText:message]; return; } } } #pragma mark - 刷新回调 /** 隐藏进度条 */ - (void)cancel { [self stopLoading]; } /** 隐藏键盘 @param scrollView <#scrollView description#> */ -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [self.view endEditing:YES]; } #pragma mark - 私有函数 /** 初始化ui */ - (void)initUI{ _dataList=[[NSMutableArray alloc]init]; _newdataList=[[NSMutableArray alloc]init]; _infoModel=[[StockingModel alloc]init]; customTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, Screen_Height-rectNavHeight-rectStatusHeight)]; customTableView.separatorStyle = UITableViewCellSeparatorStyleNone; customTableView.delegate = self; customTableView.dataSource = self; [self.view addSubview:customTableView]; } /** 加载数据 */ -(void)reloadDataByOnlyCode { //NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetInventoryByOnlyCodeIphone" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; [dict setObject:_onlyCode forKeyedSubscript:@"OnlyCode"]; self.downManager = [[ASIDownManager alloc] init]; self.downManager.delegate = self; self.downManager.OnImageDown = @selector(onLoadFinish:); self.downManager.OnImageFail = @selector(onLoadFail:); [self.downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil]; } @end