// // StockingViewController.m // IBOSSmini // // Created by apple on 2017/5/15. // Copyright © 2017年 elongtian. All rights reserved. // #import "StockingViewController.h" #import "StockingDetailViewController.h" #import "StockingCell.h" #import "NewStockingViewController.h" #import "SideSlipModel.h" #import "StockingSearchModel.h" #import "DateFormat.h" @interface StockingViewController (){ int pageNumber; } @end @implementation StockingViewController @synthesize customTableView; #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; [self loadNavStyle]; [self initUI]; [self initSlideSlip]; [self startLoading]; [self reloadData]; } #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.dataList 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 220; } /** 预计高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 220; } /** 每个单元格cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"StockingCell"; StockingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell=[[StockingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; } else //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免 { while ([cell.contentView.subviews lastObject] != nil) { [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview]; } } // StockingCell *cell=[[StockingCell 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 { self.hidesBottomBarWhenPushed=YES; StockingDetailViewController *detailVc=[[StockingDetailViewController alloc] init]; _infoModel= [_newdataList objectAtIndex:indexPath.row]; detailVc.stockingID = _infoModel.stockingID; [self.navigationController pushViewController:detailVc animated:YES]; } #pragma mark - scrollView回调 /** 显示下拉更新 @param scrollView <#scrollView description#> */ - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (scrollView.isDragging) {//显示下拉更新 if (customTableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [customTableView CanRefresh]) { [customTableView.mRefreshHeader setState:PullRefreshNormal]; } else if (customTableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [customTableView CanRefresh]) {//显示松开更新 [customTableView.mRefreshHeader setState:PullRefreshPulling]; } } } /** 刷新数据源 */ -(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]; int iNewCount = 0; customTableView.mTableView.backgroundView = nil; // 服务器返回数据是否正确 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) { if (pageNumber == 1) { [self.dataList removeAllObjects]; [self.newdataList removeAllObjects]; } [self.dataList addObjectsFromArray:infoArr]; // 转换model对象 if(self.dataList.count >0 ) { DateFormat *d =[DateFormat new]; for (int i = 0; i < self.dataList.count; i++) { NSDictionary *dicValue = self.dataList[i]; StockingModel *model = [StockingModel new]; 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.stockingNo = [dicValue objectForKey:@"CheckNo"]; model.stockingID = [[dicValue objectForKey:@"DetailID"]stringValue]; model.createUser = [dicValue objectForKey:@"UserName"]; model.createTime = [d dateFormat:[dicValue objectForKey:@"CreateTime"]]; [self.newdataList addObject:model]; } } if(self.dataList.count==0){ [self showAlertViewText:@"未找到匹配结果"]; } iNewCount =(int)infoArr.count; //pageNumber ++; customTableView.mbMoreHidden = (iNewCount == 0); [customTableView FinishLoading]; [customTableView reloadData]; } else{ // 无数据 关宏厚 2017-7-6 [customTableView FinishLoading]; customTableView.separatorStyle = UITableViewCellSeparatorStyleNone; UIView *noDataView=[[UIView alloc]init]; noDataView.frame= customTableView.mTableView.bounds; UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)]; [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]]; [noDataView addSubview:nodataImgView]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)]; label.font=[UIFont systemFontOfSize:NoDataFontOfSize]; label.text = @"无数据"; label.numberOfLines = 2; label.textColor = [UIColor lightGrayColor]; [noDataView addSubview:label]; ; // 有刷新数据的时候 if(_dataList == nil || _dataList.count==0){ customTableView.mTableView.backgroundView = noDataView; [self showAlertViewBackText:@"未找到匹配结果"]; } } } // 服务器返回数据状态值异常 else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [self showReLoginDialog:message]; } else{ [customTableView FinishLoading]; [self showAlertViewText:message]; } } } #pragma mark - 刷新回调 /** 新增盘点后刷新回调 */ - (void)refreshData{ pageNumber = 1; [_dataList removeAllObjects]; [_newdataList removeAllObjects]; [customTableView reloadData]; customTableView.mbMoreHidden=YES; [self startLoading]; [self reloadData]; } /** 取消刷新 @param sender <#sender description#> @return <#return value description#> */ - (BOOL)CanRefreshTableView:(RefreshTableView *)sender { return YES; } /** 加载更多 @param sender <#sender description#> */ - (void)LoadMoreList:(RefreshTableView *)sender { pageNumber++; [self startLoading]; [self reloadData]; } /** 下拉刷新 @param sender <#sender description#> */ - (void)ReloadList:(RefreshTableView *)sender{ pageNumber = 1; [_dataList removeAllObjects]; [_newdataList removeAllObjects]; [customTableView reloadData]; customTableView.mbMoreHidden=YES; [self startLoading]; [self reloadData]; } /** 隐藏进度条 */ - (void)cancel { [self stopLoading]; } /** 隐藏键盘 @param scrollView <#scrollView description#> */ -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [self.view endEditing:YES]; } #pragma mark - 私有函数 /** 返回 */ - (void)goBack { [self.navigationController popViewControllerAnimated:YES]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ self.view.backgroundColor = [UIColor whiteColor]; customTableView.frame = CGRectMake(0, 50, Screen_Width, self.view.safeAreaLayoutGuide.layoutFrame.size.height-50); [super viewSafeAreaInsetsDidChange]; } /** 导航按钮样式 */ -(void)loadNavStyle { self.navigationItem.title = @"库存盘点"; //右边 UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom]; [btnAdd addTarget:self action:@selector(add) forControlEvents:UIControlEventTouchUpInside]; UIImage *pic =[UIImage imageNamed:@"title_add"]; btnAdd.frame =CGRectMake(0, 0, 18, 18); [btnAdd setTitleColor:NavBarItemColor forState:UIControlStateNormal]; [btnAdd setBackgroundImage:pic forState:UIControlStateNormal]; UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd]; self.navigationItem.rightBarButtonItem = menubtnAdd; //返回 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0, 15, 18); UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = menuButton; } /** 新增 */ - (void)add{ self.hidesBottomBarWhenPushed=YES; NewStockingViewController *vc=[[NewStockingViewController alloc] init]; vc.stockDelegate = self; [self.navigationController pushViewController:vc animated:YES]; } /** 初始化ui */ - (void)initUI{ CGFloat height = 40; UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 50)]; searchView.backgroundColor = [UIColor whiteColor]; UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom]; btnSearch.frame = CGRectMake(20, 5, Screen_Width-height, height); btnSearch.layer.cornerRadius = 6.0f; [btnSearch setTitle:@"搜索" forState:UIControlStateNormal]; [btnSearch setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal]; btnSearch.titleLabel.textAlignment = NSTextAlignmentCenter; btnSearch.titleLabel.font = [UIFont systemFontOfSize:LabelAndTextFontOfSize]; btnSearch.backgroundColor = LineBackgroundColor; [btnSearch addTarget:self action:@selector(dataSearch) forControlEvents:UIControlEventTouchUpInside]; [searchView addSubview:btnSearch]; [self.view addSubview:searchView]; _dataList=[[NSMutableArray alloc]init]; _newdataList=[[NSMutableArray alloc]init]; _infoModel=[[StockingModel alloc]init]; customTableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(searchView.frame), self.view.frame.size.width, Screen_Height - CGRectGetMaxY(searchView.frame) + 5 )]; customTableView.separatorStyle = UITableViewCellSeparatorStyleNone; customTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; customTableView.backgroundColor = [UIColor whiteColor]; customTableView.delegate = self; [self.view addSubview:customTableView]; pageNumber = 1; } /** 加载数据 */ -(void)reloadData { //NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetInventoryCheckDataIphone" 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:[NSString stringWithFormat:@"%d",pageNumber] forKey:@"PageNum"]; [dict setObject:[NSString stringWithFormat:@"%d",pageSize] forKey:@"PageSize"]; [dict setObject:_stockNo forKeyedSubscript:@"CheckNo"]; [dict setObject:_onlyCode forKeyedSubscript:@"OnlyCode"]; [dict setObject:_warehouse forKeyedSubscript:@"WarehouseName"]; //[dict setObject:@"1" forKeyedSubscript:@"DetailID"]; self.downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.OnImageDown = @selector(onLoadFinish:); _downManager.OnImageFail = @selector(onLoadFail:); [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil]; } /** 抽屉弹出 */ - (void)dataSearch{ [_filterController show]; } /** 抽屉初始化 */ - (void)initSlideSlip{ // 抽屉对象 __weak typeof(self) weakself=self; self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) { for (SideSlipModel *model in dataList) { //selectedItem model.selectedItemList = nil; model.customDict = nil; } } commitBlock:^(NSArray *dataList) { // 查询条件 SideSlipModel *serviceRegionModel = dataList[0]; StockingSearchModel *m = [serviceRegionModel.customDict objectForKey:STOCKING_SEARCH_RANGE_MODEL]; // NSLog(@"%@--%@--%@--%@--%d",m.brandID,m.goodsCode,m.onlyCode,m.warehouseID,m.isfilterQuantityEqZero); self.stockNo = m.stockingNo; self.onlyCode = m.onlyCode; self.warehouse = m.warehouse; [weakself.filterController dismiss]; [self ReloadList:self.customTableView]; }]; _filterController.animationDuration = AnimationDuration; _filterController.hasHeadView = YES; _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width; _filterController.dataList = [self packageDataList]; } /** 数据源 @return <#return value description#> */ - (NSArray *)packageDataList { NSMutableArray *dataArray = [NSMutableArray array]; SideSlipModel *model = [[SideSlipModel alloc] init]; model.containerCellClass = @"StockingSearchCell"; model.regionTitle = @"查询条件"; [dataArray addObject:model]; return [dataArray mutableCopy]; } @end