// // StockingGoodsListViewController.m // IBOSS // // Created by apple on 2017/5/17. // Copyright © 2017年 沈阳东科云信软件有限公司. 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 setBackgroundColor:[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 [self.arrNewDataList 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]; // 新建cell 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]; } } _infoModel = [self.arrNewDataList 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.arrNewDataList[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]; // 服务器返回数据 RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; // 服务器返回数据状态值 int iStatus = resultModel.status; // 服务器返回数据消息 NSString *message = resultModel.message; // 服务器返回数据状态值正确 if (iStatus == 0) { NSArray * infoArr = (NSArray *)resultModel.result; if(infoArr != nil && infoArr.count > 0) { [self.arrDataList removeAllObjects]; [self.arrNewDataList removeAllObjects]; [self.arrDataList addObjectsFromArray:infoArr]; // 转换model对象 for (int i = 0; i < self.arrDataList.count; i++) { NSDictionary *dicValue = self.arrDataList[i]; StockingModel *model = [StockingModel dk_modelWithDictionary:dicValue]; [self.arrNewDataList addObject:model]; } [customTableView reloadData]; } else{ // 有刷新数据的时候 if(self.arrDataList == nil || self.arrDataList.count == 0){ [self showAlertViewBackText:@"未找到匹配结果"]; } } } // 服务器返回数据状态值异常 else if(iStatus == ActionResultStatusAuthError || iStatus == ActionResultStatusNoLogin || iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue) { [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{ self.arrDataList = [[NSMutableArray alloc]init]; self.arrNewDataList = [[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.onRequestSuccess = @selector(onLoadFinish:); self.downManager.onRequestFail = @selector(onLoadFail:); [self.downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil]; } @end