// // OrderAuditListViewController.m // IBOSS // // Created by 关宏厚 on 2018/11/12. // Copyright © 2018 elongtian. All rights reserved. // #import "OrderAuditListViewController.h" #import "OrderAuditDetailHomeViewController.h" @interface OrderAuditListViewController () { int _pageNumber; NSString *_isAudit; NSString *_orderIds; } @end @implementation OrderAuditListViewController #pragma mark - 公共函数 /** viewDidLoad */ - (void)viewDidLoad { [super viewDidLoad]; [self loadNavStyle]; [self initUI]; [self initSlideSlip]; _pageNumber=1; _isCheckAll=NO; _auditList=[[NSMutableArray alloc]init]; [self startLoading]; [self loadData]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _vCustomTableView.frame =CGRectMake(0, 0, self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40); _bottomView.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-40, self.view.frame.size.width, 40); [super viewSafeAreaInsetsDidChange]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - 委托函数 /** 加载列表数据成功回调 @param sender <#sender description#> */ - (void)onLoadFinish:(ASIDownManager *)sender { int iNewCount = 0; // 取消进度条 [self stopLoading]; // 服务器返回数据 RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; // 服务器返回数据状态值 int iStatus = resultModel.status; // 服务器返回数据消息 NSString *message = resultModel.message; [ _vCustomTableView FinishLoading]; // 服务器返回数据状态值正确 if (iStatus == 0) { // 服务器返回数据结果 NSArray *infoArr = (NSArray *)resultModel.result; if(infoArr != nil && infoArr.count>0) { for(int i=0;i0){ if([self isCheckedAll]){ _isCheckAll=YES; [_btnCheckAll setImage:[UIImage imageNamed:@"order_checked"] forState:UIControlStateNormal]; } else{ _isCheckAll=NO; [_btnCheckAll setImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal]; } } else{ _isCheckAll=NO; [_btnCheckAll setImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal]; } NSInteger num= [self getCheckedOrderCount:_auditList]; NSString *totalCount=[NSString stringWithFormat:@"%@%ld%@",@"共",(long)num,@"条"]; _lblTotalCount.text=totalCount; // 未找到匹配结果 if(_auditList == nil ||_auditList.count == 0){ _vCustomTableView.mTableView.backgroundView = [self noDataViewByFrame:_vCustomTableView.bounds]; [self showAlertViewBackText:@"未找到匹配结果"]; } } } // 服务器返回数据状态值异常 else if(iStatus == ActionResultStatusAuthError ||iStatus == ActionResultStatusNoLogin ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){ [_btnCheckAll setImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal]; [self showReLoginDialog:message]; } else{ [_btnCheckAll setImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal]; [self showAlertViewText:message]; return; } } /** 列表加载数据失败回调 @param sender <#sender description#> */ - (void)onLoadFail:(ASIDownManager *)sender { [ _vCustomTableView FinishLoading]; [self showAlertViewText:@"网络异常"]; } /** 选中产品回调 @param pos <#pos description#> */ -(void)btnCheckPressed:(NSInteger)pos{ OrderAuditListModel *auditModel= [_auditList objectAtIndex:pos]; auditModel.isChecked= !auditModel.isChecked; //1.当前所要刷新的cell,传入要刷新的 行数 和 组数 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:pos inSection:0]; //2.将indexPath添加到数组 NSArray *indexPathArray = @[indexPath]; //3.传入数组,对当前cell进行刷新 [_vCustomTableView.mTableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic]; if([self isCheckedAll]){ _isCheckAll=YES; [_btnCheckAll setImage:[UIImage imageNamed:@"order_checked"] forState:UIControlStateNormal]; } else{ _isCheckAll=NO; [_btnCheckAll setImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal]; } NSInteger num=[self getCheckedOrderCount:_auditList]; NSString *totalCount=[NSString stringWithFormat:@"%@%ld%@",@"共",(long)num,@"条"]; _lblTotalCount.text=totalCount; } /** 保存成功回调函数 @param sender <#sender description#> */ - (void)onSaveFinish:(ASIDownManager *)sender { [self stopLoading]; RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; int iStatus = resultModel.status; NSString *message=resultModel.message; if(iStatus==0){ [self showAlertViewText:@"保存成功"]; if(_auditList!=nil&&_auditList.count>0){ [_auditList removeAllObjects]; [_vCustomTableView reloadData]; _vCustomTableView.mbMoreHidden=YES; _orderIds=@""; [self startLoading]; _pageNumber=1; [self loadData]; } NSString *sureCount=[NSString stringWithFormat:@"%@%d%@",@"共",0,@"条"]; _lblTotalCount.text=sureCount; } // 服务器返回数据状态值异常 else if(iStatus == ActionResultStatusAuthError ||iStatus == ActionResultStatusNoLogin ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){ [self showReLoginDialog:message]; } else{ [self showAlertViewText:message]; return; } } /** 保存失败回调函数 @param sender <#sender description#> */ - (void)onSaveFail:(ASIDownManager *)sender { [self stopLoading]; [self showAlertViewText:@"网络异常"]; } #pragma mark - tableView回调 /** 单元格cell个数 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_auditList count]; } /** table view 分区数 @param tableView <#tableView description#> @return <#return value description#> */ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } /** cell 高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 271; } /** 每个单元格cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"OrderAuditListCell"; OrderAuditListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ]; if (!cell) { cell = [[OrderAuditListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; } else //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免 { while ([cell.contentView.subviews lastObject] != nil) { [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview]; } } _auditModel= [_auditList objectAtIndex:indexPath.row]; cell.delegate = self; cell.position = (int)indexPath.row; [cell setOrderAuditCell:_auditModel]; [cell setCheckBackground:_auditModel.isChecked]; return cell; } /** 点击单元格事件 @param tableView tableView description @param indexPath indexPath description */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.hidesBottomBarWhenPushed=YES; OrderAuditDetailHomeViewController *detailVc = [[OrderAuditDetailHomeViewController alloc] init]; OrderAuditListModel *auditListModel=[_auditList objectAtIndex:indexPath.row]; detailVc.orderId=auditListModel.orderId; detailVc.auditModel=auditListModel; [self.navigationController pushViewController:detailVc animated:YES]; } /** 取消刷新 @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 loadData]; } /** 下拉刷新 @param sender <#sender description#> */ - (void)ReloadList:(RefreshTableView *)sender{ _pageNumber = 1; [_auditList removeAllObjects]; [_vCustomTableView reloadData]; _vCustomTableView.mbMoreHidden=YES; [self startLoading]; [self loadData]; } /** 隐藏键盘 @param scrollView <#scrollView description#> */ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [self.view endEditing:YES]; } #pragma mark - 私有函数 /** 导航按钮样式 */ - (void)loadNavStyle { self.navigationItem.title =@"订单审核"; // 右边 UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 42, 12)]; 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)loadData{ NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetExamineListIphone" 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:_orderNo== nil?@"":_orderNo forKey:@"OrderNo"]; [dict setObject:_customerCode == nil?@"":_customerCode forKey:@"CustomerCode"]; [dict setObject:_customerName == nil?@"":_customerName forKey:@"CustomerName"]; [dict setObject:_telephone == nil?@"":_telephone forKey:@"Telephone"]; [dict setObject:_address == nil?@"":_address forKey:@"Address"]; [dict setObject:_beginDate == nil?@"":_beginDate forKey:@"AccountDateFrom"]; [dict setObject:_endDate == nil?@"":_endDate forKey:@"AccountDateEnd"]; [dict setObject:_status == nil?@"4":_status forKey:@"Status"]; [dict setObject:_checkFlag == nil?@"0":_checkFlag forKey:@"CheckFlag"]; _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.onRequestSuccess = @selector(onLoadFinish:); _downManager.onRequestFail = @selector(onLoadFail:); [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil]; } /** 获取选中的订单 @param goodsList <#goodsList description#> @return <#return value description#> */ -(NSInteger) getCheckedOrderCount:(NSMutableArray*)orderList{ int num=0; NSMutableArray *orderSubmitList=[[NSMutableArray alloc]init]; NSInteger count=orderList.count; for(int i=0;i */ -(BOOL)updateAllCellCheck { if(!_isCheckAll){ _isCheckAll=YES; [_btnCheckAll setImage:[UIImage imageNamed:@"order_checked"] forState:UIControlStateNormal]; for(OrderAuditListModel *auditModel in _auditList) { auditModel.isChecked=YES; } } else { [_btnCheckAll setImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal]; _isCheckAll=NO; for(OrderAuditListModel *auditModel in _auditList) { auditModel.isChecked=NO; } } return NO; } /** 看是否全选 @return <#return value description#> */ -(BOOL)isCheckedAll { BOOL ischecked=YES; for(OrderAuditListModel *model in _auditList) { if( !model.isChecked) { ischecked=NO; break; } } return ischecked; } /** 选中所有的项 */ -(void)checkAll { [self updateAllCellCheck]; NSInteger num= [self getCheckedOrderCount:_auditList]; NSString *totalCount=[NSString stringWithFormat:@"%@%ld%@",@"共",(long)num,@"条"]; _lblTotalCount.text=totalCount; [_vCustomTableView reloadData]; } /** 初始化ui */ - (void)initUI{ _vCustomTableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, Screen_Height- 40)]; _vCustomTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _vCustomTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _vCustomTableView.backgroundColor = [UIColor whiteColor]; _vCustomTableView.delegate = self; [self.view addSubview:_vCustomTableView]; self.vCustomTableView.mTableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 49, 0); //保存 _bottomView=[UIView new]; _bottomView.frame=CGRectMake(0,Screen_Height - 40 -rectNavHeight - rectStatusHeight, self.view.frame.size.width, 40); [self.view addSubview:_bottomView]; [_bottomView setBackgroundColor:[UIColor whiteColor]]; _btnCheckAll=[UIButton buttonWithType:UIButtonTypeCustom]; _btnCheckAll.frame=CGRectMake(10,8, 25, 25); [_btnCheckAll setImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal]; [_btnCheckAll addTarget:self action:@selector(checkAll) forControlEvents:UIControlEventTouchUpInside]; [_bottomView addSubview:_btnCheckAll]; UILabel *lblall=[UILabel new]; lblall.frame=CGRectMake(CGRectGetMaxX(_btnCheckAll.frame),8, 40, 25); lblall.text=@"全选"; [_bottomView addSubview:lblall]; _lblTotalCount=[UILabel new]; _lblTotalCount.frame=CGRectMake(CGRectGetMaxX(lblall.frame),8,Screen_Width-CGRectGetMaxX(lblall.frame)-190, 25); _lblTotalCount.textColor=[UIColor redColor]; _lblTotalCount.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize]; [_bottomView addSubview:_lblTotalCount]; _auditBtn=[UIButton buttonWithType:UIButtonTypeCustom]; [_auditBtn setTitle:@"审核" forState:UIControlStateNormal]; [_auditBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _auditBtn.frame=CGRectMake(Screen_Width-90,0,90,40); [_auditBtn setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]]; [_auditBtn addTarget:self action:@selector(submitAuditData) forControlEvents:UIControlEventTouchUpInside]; [_bottomView addSubview:_auditBtn]; _giveUpAuditBtn=[UIButton buttonWithType:UIButtonTypeCustom]; [_giveUpAuditBtn setTitle:@"弃审" forState:UIControlStateNormal]; [_giveUpAuditBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _giveUpAuditBtn.frame=CGRectMake(Screen_Width-90*2-10,0,90,40); [_giveUpAuditBtn setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]]; [_giveUpAuditBtn addTarget:self action:@selector(submitGiveUpAuditData) forControlEvents:UIControlEventTouchUpInside]; [_bottomView addSubview:_giveUpAuditBtn]; _pageNumber = 1; } -(void)dataSearch{ [_filterController show]; } -(void)submitAuditData { _isAudit=@"1"; [self saveData]; } -(void)submitGiveUpAuditData{ _isAudit=@"0"; [self saveData]; } -(void)saveData { if(_auditList!=nil&&_auditList.count>0){ NSInteger num= [self getCheckedOrderCount:_auditList]; if(num==0){ [self showAlertViewText:@"请选择单据"]; return; } NSMutableArray *checkedOrderList=[[NSMutableArray alloc]init]; for(OrderAuditListModel *model in _auditList){ if(model.isChecked){ NSString *orderIdStr=[NSString stringWithFormat:@"%d", model.orderId]; [checkedOrderList addObject:orderIdStr]; } } _orderIds=[checkedOrderList componentsJoinedByString:@","]; } else{ [self showAlertViewText:@"没有可选择的单据"]; return; } [self startLoading]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"SaveOrderCheckIphone" 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:_orderIds forKey:@"OrderID"]; [dict setObject:_isAudit forKey:@"IsAudits"]; _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.onRequestSuccess = @selector(onSaveFinish:); _downManager.onRequestFail = @selector(onSaveFail:); [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil]; } /** 抽屉初始化 */ - (void)initSlideSlip{ // 抽屉对象 __weak typeof(self) weakself = self; self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) { for (SideSlipModel *model in dataList) { model.selectedItemList = nil; model.customDict = nil; } } commitBlock:^(NSArray *dataList) { // 查询条件 SideSlipModel *serviceRegionModel = dataList[0]; OrderAuditSearchModel *m = [serviceRegionModel.customDict objectForKey:ORDER_AUDIT_SEARCH_RANGE_MODEL]; self.orderNo=m.orderNo; self.customerCode=m.customerCode; self.customerName=m.customerName; self.telephone=m.telephone; self.address=m.address; self.beginDate=m.startDate; self.endDate=m.endDate; self.status=m.invoiceStatusId; self.checkFlag=m.auditFlag; [weakself.filterController dismiss]; self->_pageNumber=1; if(self->_auditList!=nil&&self->_auditList.count>0){ [self->_auditList removeAllObjects]; [self->_vCustomTableView reloadData]; } self->_vCustomTableView.mTableView.backgroundView=nil; [self startLoading]; [self loadData]; }]; _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 = @"OrderAuditSearchCell"; model.regionTitle = @"查询条件"; [dataArray addObject:model]; return [dataArray mutableCopy]; } @end