| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638 |
- //
- // InventoryViewController.m
- // IBOSS
- //
- // Created by apple on 2017/5/15.
- // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
- //
- // 功能描述:库存明细表控制器
- //
- #import "InventoryViewController.h"
- #import "InventoryDetailViewController.h"
- #import "InventoryCell.h"
- #import "InventorySearchModel.h"
- @interface InventoryViewController ()<UITableViewDataSource, UITableViewDelegate,RefreshTableViewDelegate>{
- NSMutableDictionary *_cellHeight;
- // 页码
- int _pageNumber;
- }
- @end
- @implementation InventoryViewController
- @synthesize customTableView;
- #pragma mark - 公共函数
- /**
- viewDidLoad函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self initUI];
- _ceaseFlag=@"";
- _settingValues=@"0";
- [self loadNavStyle];
- [self getSystemSettingsValue];
- [self initSlideSlip];
- UIView *noDataView = [self noDataViewByFrame:customTableView.mTableView.bounds];
- customTableView.mTableView.backgroundView =noDataView;
- //[self startLoading];
- //[self reloadData];
- }
- /**
- 安全区视图发生变化
- */
- -(void)viewSafeAreaInsetsDidChange{
- [self.view setBackgroundColor:[UIColor whiteColor]];
- customTableView.frame = self.view.safeAreaLayoutGuide.layoutFrame;
- [super viewSafeAreaInsetsDidChange];
- }
- /**
- didReceiveMemoryWarning函数
- */
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- #pragma mark - 委托回调函数
- /**
- 单元格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 [_cellHeight[@(indexPath.row)] floatValue];
- }
- /**
- 预防高度
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 250;
- }
- /**
- 每个单元格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 = [_arrNewdataList objectAtIndex:indexPath.row];
- cell.model = _infoModel;
- _cellHeight[@(indexPath.row)] = @(cell.cellHeight);
- // 强制布局 xib时调用
- //[cell layoutIfNeeded];
- 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= [_arrNewdataList objectAtIndex:indexPath.row];
- detailVc.inventoryId=_infoModel.inventoryId;
- detailVc.code = _infoModel.code;
- detailVc.onlyCode = _infoModel.onlyCode;
- detailVc.settingValues=_settingValues;
- detailVc.wareHouseName = _infoModel.wareHouseName;
- detailVc.specification = _infoModel.specification;
- detailVc.brandName = _infoModel.brandName;
- detailVc.goodName = _infoModel.goodName;
- detailVc.gradeName = _infoModel.gradeName;
- detailVc.colorNumber = _infoModel.colorNumber;
- detailVc.inventoryQuantity = _infoModel.inventoryQuantity;
- detailVc.canSaleQuantity = _infoModel.canSaleQuantity;
- detailVc.positionNumber = _infoModel.positionNumber;
- detailVc.occupyQuantity=_infoModel.occupyQuantity;
- detailVc.displayStandardPrice=_infoModel.displayStandardPrice;
- detailVc.displayInventoryQuantity=_infoModel.displayInventoryQuantityFlag;
- detailVc.displayCanSalesQuantity=_infoModel.displayCanSalesQuantityFlag;
- detailVc.price = _infoModel.price;
- detailVc.boxPieceFlag = _infoModel.boxPieceFlag;
- detailVc.box = _infoModel.box;
- detailVc.piece = _infoModel.piece;
- [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:@"网络异常"];
- }
- - (void)onSystemSettingLoadFinish:(ASIDownManager *)sender {
- [self cancel];
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- // 服务器返回数据状态值
- int iStatus = resultModel.status;
-
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- NSArray * infoArr = (NSArray *)resultModel.result;
- if(infoArr != nil && infoArr.count>0)
- {
- NSDictionary *infoDic= infoArr[0];
- _settingValues = [infoDic objectForKey:@"SettingValues"];
- }
-
-
- }
- else
- {
- _settingValues=@"0";
- }
- }
- /**
- 加载列表数据失败回调
-
- @param sender <#sender description#>
- */
- - (void)onSystemSettingLoadFail:(ASIDownManager *)sender {
- _settingValues=@"0";
- [self cancel];
- [self showAlertViewText:@"网络异常"];
- }
- /**
- 加载列表数据成功回调
-
- @param sender <#sender description#>
- */
- - (void)onLoadFinish:(ASIDownManager *)sender {
-
- int iNewCount = 0;
- customTableView.mTableView.backgroundView = nil;
- // 取消进度条
- [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)
- {
- if (_pageNumber == 1)
- {
- [self.arrDataList removeAllObjects];
- [self.arrNewdataList removeAllObjects];
- }
- [self.arrDataList addObjectsFromArray:infoArr];
- // 转换model对象
- if(infoArr.count > 0 ){
- for (int i = 0; i < infoArr.count; i++) {
- NSDictionary *str = infoArr[i];
- InventoryModel *model = [InventoryModel dk_modelWithDictionary:str];
- model.settingValues=_settingValues;
- if(model.price==nil||[model.price isEqualToString:@""])
- {
- model.displayStandardPrice=NO;
- }
- else
- {
- model.displayStandardPrice=YES;
- }
-
- if(model.inventoryQuantity==nil||[model.inventoryQuantity isEqualToString:@""])
- {
- model.displayInventoryQuantityFlag=NO;
- }
- else
- {
- model.displayInventoryQuantityFlag=YES;
- }
- model.costPrice=[NSString stringWithFormat:@"%.2f",[model.costPrice doubleValue]];
-
- if(model.canSaleQuantity != nil && ![model.canSaleQuantity isEqualToString:@""]){
- model.displayCanSalesQuantityFlag=YES;
- if(model.circulateType != nil && ![model.circulateType isEqualToString:@""]){
- model.boxPieceFlag = YES;
- if(model.package != nil && ![model.package isEqualToString:@""]){
-
- int circulateType= [model.circulateType intValue];
- float acreage=[model.acreage floatValue];
- if(circulateType==1)
- {
- if([model.canSaleQuantity doubleValue]>=0)
- {
- model.box = [NSString stringWithFormat:@"%ld",(long)floor([model.canSaleQuantity doubleValue]/[model.package doubleValue])];
-
- }
- else
- {
- model.box = [NSString stringWithFormat:@"%ld",(long)ceil([model.canSaleQuantity doubleValue]/[model.package doubleValue])];
- }
-
- model.piece = [NSString stringWithFormat:@"%ld",(long)[model.canSaleQuantity intValue]%[model.package intValue]];
- }
-
- else
- {
- if([model.package intValue]>0&&acreage>0)
- {
- long canSalesPieces=0;
- int canSalesBox=0;
- if([model.canSaleQuantity doubleValue]>=0)
- {
- canSalesPieces=(long)ceil([model.canSaleQuantity doubleValue]/acreage);
- canSalesBox=(int)floor(canSalesPieces/[model.package intValue]);
-
- }
- else
- {
-
- canSalesPieces=(long)floor([model.canSaleQuantity doubleValue]/acreage);
- canSalesBox=(int)ceil(canSalesPieces/[model.package intValue]);
-
- }
-
- int canSalesPiece=canSalesPieces%[model.package intValue];
-
- model.box = [NSString stringWithFormat:@"%d",canSalesBox];
- model.piece=[NSString stringWithFormat:@"%d",canSalesPiece];
- }
- }
-
-
- }else{
- model.box = @"0";
- model.piece = @"0";
- }
- }else{
- model.boxPieceFlag = NO;
- }
- }
- else{
- model.displayCanSalesQuantityFlag=NO;
- model.boxPieceFlag = NO;
- }
- [_arrNewdataList addObject:model];
- }
- }
-
- iNewCount =(int)infoArr.count;
- customTableView.mbMoreHidden = (iNewCount == 0);
- [customTableView FinishLoading];
- [customTableView reloadData];
-
- }
- else{
- [customTableView FinishLoading];
- customTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- // 无数据
- if(self.arrDataList.count == 0){
- // 无数据的view
- UIView *noDataView = [self noDataViewByFrame:customTableView.mTableView.bounds];
- customTableView.mTableView.backgroundView =noDataView;
-
- }
- if(self.arrDataList== nil || self.arrDataList.count == 0){
- [self showAlertViewBackText:@"未找到匹配结果"];
- }
- }
- }
- // 服务器返回数据状态值异常
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [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 reloadData];
- }
- /**
- 下拉刷新
-
- @param sender <#sender description#>
- */
- - (void)ReloadList:(RefreshTableView *)sender{
- _pageNumber = 1;
- [self.arrDataList removeAllObjects];
- [self.arrNewdataList 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 = @"库存明细表";
- _arrDataList = [[NSMutableArray alloc]init];
- _arrNewdataList = [[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];
- _pageNumber = 1;
- _cellHeight = [[NSMutableDictionary alloc] init];
- _isFilterQuantityEqZero = YES;
- }
- /**
- 导航按钮样式
- */
- - (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 setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0,45,22);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- }
- /**
- 抽屉弹出
- */
- - (void)search{
- [_filterController show];
- }
- /**
- 抽屉初始化
- */
- - (void)initSlideSlip{
- // 抽屉对象
- __weak typeof(self) weakself=self;
- SideSlipFilterController *extractedExpr = [[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.goodsSpecification=m.goodsSpecification;
- self.minimumCanSalesQuantity=m.minimumCanSalesQuantity;
- self.maximumCanSalesQuantity=m.maximumCanSalesQuantity;
- self.ceaseFlag=m.ceaseFlag;
- self.warehouseIdStr = m.warehouseId;
- self.isFilterQuantityEqZero = m.isfilterQuantityEqZero;
- self.positionNumberValue=m.positionNumberName;
- [weakself.filterController dismiss];
- [self ReloadList:self.customTableView];
- }];
- self.filterController = extractedExpr;
- _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)getSystemSettingsValue{
- [self startLoading];
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict= [NSMutableDictionary new];
-
- [dict setObject:@"GetSystemSettingValues" forKey:@"Action"];
- [dict setObject:kkAccountCode forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:@"SS_IVT_08" forKey:@"SettingType"];
- self.downManager= [[ASIDownManager alloc] init];;
- self.downManager.delegate = self;
- self.downManager.onRequestSuccess = @selector(onSystemSettingLoadFinish:);
- self.downManager.onRequestFail = @selector(onSystemSettingLoadFail:);
- [self.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
- }
- /**
- 加载数据
- */
- - (void)reloadData
- {
- //NSString *urlStr = ServerURL;
- 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==nil? @"":_goodsNameStr forKeyedSubscript:@"GoodsName"];
- [dict setObject:_goodsCodeStr==nil?@"":_goodsCodeStr forKeyedSubscript:@"GoodsCode"];
- [dict setObject:_onlyCodeStr==nil?@"":_onlyCodeStr forKeyedSubscript:@"OnlyCode"];
- [dict setObject:_warehouseIdStr==nil?@"":_warehouseIdStr forKeyedSubscript:@"WarehouseCode"];
- [dict setObject:_brandIdStr==nil?@"":_brandIdStr forKeyedSubscript:@"BrandID"];
- [dict setObject:self.ceaseFlag==nil||[self.ceaseFlag isEqualToString:@""]?@"2":self.ceaseFlag forKeyedSubscript:@"CeaseFlag"];
- [dict setObject:_goodsSpecification forKeyedSubscript:@"Specification"];
- [dict setObject:_minimumCanSalesQuantity forKeyedSubscript:@"CanSaleQuantityBegin"];
- [dict setObject:_maximumCanSalesQuantity forKeyedSubscript:@"CanSaleQuantityEnd"];
-
- [dict setObject:self.positionNumberValue==nil?@"":self.positionNumberValue forKey:@"PositionNumber"];
- if(_isFilterQuantityEqZero){
- [dict setObject:@"true" forKey:@"isfilterQuantityEqZero"];
- }else{
- [dict setObject:@"false" forKey:@"isfilterQuantityEqZero"];
- }
-
- _downManager = [[ASIDownManager alloc] init];
- _downManager.delegate = self;
- _downManager.onRequestSuccess = @selector(onLoadFinish:);
- _downManager.onRequestFail = @selector(onLoadFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- @end
|