// // InventoryViewController.m // IBOSSmini // // Created by apple on 2017/5/15. // Copyright © 2017年 elongtian. All rights reserved. // #import "InventoryViewController.h" #import "InventoryDetailViewController.h" #import "InventoryCell.h" #import "InventorySearchModel.h" @interface InventoryViewController (){ int pageNumber; } @end @implementation InventoryViewController @synthesize customTableView; #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; [self initUI]; [self loadNavStyle]; [self initSlideSlip]; [self reloadData]; } /** didReceiveMemoryWarning函数 */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - 属性 /** 高度 @return <#return value description#> */ - (NSMutableDictionary *)heights{ if (_heights == nil){ _heights = [NSMutableDictionary dictionary]; } return _heights; } #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.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 292.0; } /** 每个单元格cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"InventoryCell"; InventoryCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (!cell) { cell=[[InventoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; } else //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免 { while ([cell.contentView.subviews lastObject] != nil) { [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview]; } } _infoModel = [_newdataList objectAtIndex:indexPath.row]; cell.model = _infoModel; return cell; } /** 点击单元格事件 @param tableView <#tableView description#> @param indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.hidesBottomBarWhenPushed=YES; InventoryDetailViewController *detailVc=[[InventoryDetailViewController alloc] init]; _infoModel= [_newdataList objectAtIndex:indexPath.row]; detailVc.code = _infoModel.code; detailVc.onlyCode = _infoModel.onlyCode; detailVc.wareHouseName = _infoModel.wareHouseName; detailVc.specification = _infoModel.specification; detailVc.brandName = _infoModel.brandName; detailVc.goodName = _infoModel.goodsName; detailVc.gradeName = _infoModel.gradeName; detailVc.colorNumber = _infoModel.colorNumber; detailVc.inventoryQuantity = _infoModel.inventoryQuantity; detailVc.canSaleQuantity = _infoModel.canSaleQuantity; detailVc.positionNumber = _infoModel.positionNumber; detailVc.price = _infoModel.price; detailVc.boxPieceFlag = _infoModel.boxPieceFlag; detailVc.package=_infoModel.package; detailVc.box = _infoModel.box; detailVc.piece = _infoModel.piece; detailVc.varietyName=_infoModel.varietyName; detailVc.inventoryId=_infoModel.inventoryId; [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) { [self.dataList addObjectsFromArray:infoArr]; // 转换model对象 if(self.dataList.count > 0 ){ for (int i = 0; i < self.dataList.count; i++) { NSDictionary *str=self.dataList[i]; InventoryModel *model = [InventoryModel new]; NSInteger inventoryIdValue= [[str objectForKey:@"InventoryID"]integerValue]; model.inventoryId=[NSString stringWithFormat:@"%ld",inventoryIdValue]; model.code=[str objectForKey:@"Code"]; model.onlyCode=[str objectForKey:@"OnlyCode"]; model.goodsName=[str objectForKey:@"GoodsName"]; model.specification=[str objectForKey:@"Specification"]; NSString *varietyName=[str objectForKey:@"VarietyName"]; model.varietyName=varietyName; model.colorNumber=[str objectForKey:@"ColorNumber"]; model.brandName=[str objectForKey:@"BrandName"]; model.gradeName=[str objectForKey:@"GradeName"]; model.wareHouseName=[str objectForKey:@"WarehouseName"]; model.positionNumber=[str objectForKey:@"PositionNumber"]; NSInteger circulateType=[[str objectForKey:@"CirculateType"]integerValue]; model.circulateType=circulateType; NSInteger package= [[str objectForKey:@"Package"]integerValue]; model.package=[NSString stringWithFormat:@"%d",package]; NSInteger decimalPlaces= [[str objectForKey:@"DecimalPlaces"]integerValue]; double inventoryQuantity = [[str objectForKey:@"InventoryQuantity"]doubleValue]; if (decimalPlaces == 0){ model.inventoryQuantity=[[str objectForKey:@"InventoryQuantity"]stringValue]; }else{ model.inventoryQuantity=[NSString stringWithFormat:[NSString stringWithFormat:@"%%.%ldf",(long)decimalPlaces ],inventoryQuantity]; } //model.inventoryQuantity=InventoryQuantity == nil?@"0":InventoryQuantity; double CanSaleQuantity = [[str objectForKey:@"CanSaleQuantity"]doubleValue]; if (decimalPlaces == 0){ model.canSaleQuantity=[[str objectForKey:@"CanSaleQuantity"]stringValue]; }else{ model.canSaleQuantity=[NSString stringWithFormat:[NSString stringWithFormat:@"%%.%ldf",(long)decimalPlaces ],CanSaleQuantity]; } if(model.canSaleQuantity != nil && ![model.canSaleQuantity isEqualToString:@""]){ if(model.circulateType!=0){ model.boxPieceFlag = YES; if(model.package != nil && ![model.package isEqualToString:@""]){ model.box = [NSString stringWithFormat:@"%ld",(long)floor([model.canSaleQuantity doubleValue]/[model.package doubleValue])]; model.piece = [NSString stringWithFormat:@"%ld",(long)floor([model.canSaleQuantity intValue]%[model.package intValue])]; }else{ model.box = @"0"; model.piece = @"0"; } }else{ model.boxPieceFlag = NO; } }else{ model.boxPieceFlag = NO; } // 20201026 jiang修改 model.price = [[str objectForKey:@"jzj"]stringValue]; //model.price=jzj==nil?@"0":jzj; [self.newdataList addObject:model]; } } iNewCount =(int)infoArr.count; customTableView.mbMoreHidden = (iNewCount == 0); [customTableView FinishLoading]; [customTableView reloadData]; } else{ [customTableView FinishLoading]; customTableView.mbMoreHidden=YES; customTableView.separatorStyle = UITableViewCellSeparatorStyleNone; if(self.dataList.count==0){ 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]; 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 - 刷新回调 /** 取消刷新 @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.dataList removeAllObjects]; [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 - 私有函数 /** 初始化ui */ - (void)initUI{ self.navigationItem.title=@"库存明细表"; _dataList=[[NSMutableArray alloc]init]; _newdataList=[[NSMutableArray alloc]init]; _infoModel=[[InventoryModel alloc]init]; customTableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; customTableView.separatorStyle = UITableViewCellSeparatorStyleNone; customTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; customTableView.backgroundColor = [UIColor whiteColor]; customTableView.delegate = self; [self.view addSubview:customTableView]; _isFilterQuantityEqZero = YES; pageNumber = 1; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ self.view.backgroundColor = [UIColor whiteColor]; customTableView.frame = self.view.safeAreaLayoutGuide.layoutFrame; [super viewSafeAreaInsetsDidChange]; } /** 导航按钮样式 */ -(void)loadNavStyle { //右边 UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 16)]; UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom]; [btnfilter addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside]; btnfilter.frame = CGRectMake(0, 0, 16, 16); [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal]; [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"] forState:UIControlStateNormal]; [v addSubview:btnfilter]; UIButton *filterLbl=[[UIButton alloc]init]; filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16); [filterLbl setTitle:@"筛选" forState:UIControlStateNormal]; [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; filterLbl.titleLabel.font=[UIFont systemFontOfSize:ButtonFontOfSize]; [filterLbl addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside]; [v addSubview:filterLbl]; UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v]; 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)search{ [_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]; InventorySearchModel *m = [serviceRegionModel.customDict objectForKey:INVENTORY_SEARCH_RANGE_MODEL]; //NSLog(@"%@--%@--%@--%@--%d",m.brandID,m.goodsCode,m.onlyCode,m.warehouseID,m.isfilterQuantityEqZero); self.brandIdStr = m.brandId; self.goodsCodeStr = m.goodsCode; self.goodsNameStr = m.goodsName; self.onlyCodeStr = m.onlyCode; self.warehouseIdStr = m.warehouseId; self.varietyIdStr=m.varietyId; self.isFilterQuantityEqZero = m.isfilterQuantityEqZero; [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 = @"InventorySearchCell"; model.regionTitle = @"查询条件"; [dataArray addObject:model]; return [dataArray mutableCopy]; } /** 加载数据 */ -(void)reloadData { NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetNewInventoryListIphone" 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:_goodsNameStr forKeyedSubscript:@"GoodsName"]; [dict setObject:_goodsCodeStr forKeyedSubscript:@"GoodsCode"]; [dict setObject:_onlyCodeStr forKeyedSubscript:@"OnlyCode"]; [dict setObject:_warehouseIdStr forKeyedSubscript:@"WarehouseCode"]; [dict setObject:_brandIdStr forKeyedSubscript:@"BrandID"]; [dict setObject:_varietyIdStr forKeyedSubscript:@"VarietyID"]; if(_isFilterQuantityEqZero){ [dict setObject:@"true" forKey:@"isfilterQuantityEqZero"]; }else{ [dict setObject:@"false" forKey:@"isfilterQuantityEqZero"]; } _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.OnImageDown = @selector(onLoadFinish:); _downManager.OnImageFail = @selector(onLoadFail:); [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil]; } @end