// // RepairUnreceiptVC.m // IBOSS // // Created by guan hong hou on 2017/7/10. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved. // // 功能描述:维修未回执控制器 #import "RepairUnreceiptVC.h" #import "RepairUnReceiptFrame.h" #import "RepairUnReceiptCell.h" #import "NewRepairReceiptVC.h" #import "NoReceiptSearchModel.h" #import "DateFormat.h" #import "SideSlipModel.h" #define orderTextFont [UIFont systemFontOfSize:14] @interface RepairUnreceiptVC (){ /** 查询条件model */ NoReceiptSearchModel *_model; } @end @implementation RepairUnreceiptVC #pragma mark - 公共函数 /** 视图加载后函数 */ - (void)viewDidLoad { [super viewDidLoad]; _pageNumber = @"1"; _dataList = [[NSMutableArray alloc]init]; _repairUnReceiptInfo = [[RepairUnReceiptInfo alloc]init]; [self initUI]; [self reloadData]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _tableView.frame = CGRectMake(10,55,Screen_Width-20, self.view.superview.frame.size.height-55); [super viewSafeAreaInsetsDidChange]; } #pragma mark - 委托函数 /** 数据加载完成函数 @param sender <#sender description#> */ - (void)onLoadFinish:(ASIDownManager *)sender { RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; [self cancel]; _tableView.mTableView.backgroundView = nil; int iNewCount = 0; int iStatus = resultModel.status; NSString *message = resultModel.message; if (iStatus == 0) { if([_pageNumber isEqualToString:@"1"]){ [_dataList removeAllObjects]; } NSArray * infoArr =(NSArray*) resultModel.result; if(infoArr != nil && infoArr.count > 0) { [_dataList addObjectsFromArray:infoArr]; [_repairUnReceiptInfo parseUnRepairInfoArr:_dataList]; iNewCount = (int)infoArr.count; _tableView.mbMoreHidden = (iNewCount == 0); [_tableView FinishLoading]; [_tableView reloadData]; } else{ [_tableView FinishLoading]; _tableView.mbMoreHidden = YES; if(_dataList.count == 0){ [_tableView reloadData]; _tableView.mTableView.backgroundView = [self noDataViewByFrame:_tableView.mTableView.bounds]; // [self showAlertViewText:@"未找到匹配结果"]; return; } } } else if(iStatus == ActionResultStatusAuthError ||iStatus == ActionResultStatusNoLogin ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){ [self showReLoginDialog:message]; [_tableView FinishLoading]; return; } else{ [self showAlertViewText:message]; [_tableView FinishLoading]; return; } } /** 数据加载失败函数 @param sender <#sender description#> */ - (void)onLoadFail:(ASIDownManager *)sender { [self cancel]; [_tableView reloadData]; [self showAlertViewText:@"网络异常"]; } /** 加载更多函数 @param sender <#sender description#> */ - (void)LoadMoreList:(RefreshTableView *)sender { _pageNumber = [NSString stringWithFormat:@"%d",[_pageNumber intValue]+1]; [self reloadData]; } /** 下拉刷新函数 @param sender <#sender description#> */ - (void)ReloadList:(RefreshTableView *)sender{ _pageNumber = @"1"; [_dataList removeAllObjects]; [_tableView reloadData]; _tableView.mbMoreHidden=YES; [self reloadData]; } /** 刷新数据回调函数 */ - (void)refreshFollowUpData{ [_dataList removeAllObjects]; _pageNumber = @"1"; [_tableView reloadData]; _tableView.mbMoreHidden=YES; [self reloadData]; } /** 获取tableview的行数 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } /** 获取tableview的分区数 @param tableView <#tableView description#> @return <#return value description#> */ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return [_dataList count]; } /** 获取tableview的高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row = [indexPath section]; RepairUnReceiptFrame *repairUnReceiptFrame = [_repairUnReceiptInfo.unRepairInfoArr objectAtIndex:row]; NSInteger cellHeight = [repairUnReceiptFrame cellHeight]; return cellHeight+10; } /** tableview的分区 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor clearColor]; return view ; } /** tableview分区的间隔高度 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 10; } /** 获取tableview cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CellId"; RepairUnReceiptCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell = [[RepairUnReceiptCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; NSUInteger row = [indexPath section]; RepairUnReceiptFrame *repairUnReceiptFrame = [_repairUnReceiptInfo.unRepairInfoArr objectAtIndex:row]; [cell setUnRepairInfoFrame:repairUnReceiptFrame]; return cell; } /** tableview的点击事件 @param tableView <#tableView description#> @param indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NewRepairReceiptVC *newRepairVc = [[ NewRepairReceiptVC alloc] init]; NSUInteger row = [indexPath section]; newRepairVc.refreshDelegate = self; newRepairVc.operationFlag = @"unreceipt"; RepairUnReceiptFrame *frame = [_repairUnReceiptInfo.unRepairInfoArr objectAtIndex:row]; RepairUnReceiptModel *model = [frame unRepairModel]; newRepairVc.sCode=model.repairNo; newRepairVc.parentVC = self; self.cNav.visibleViewController.hidesBottomBarWhenPushed=YES; [self.cNav pushViewController:newRepairVc animated:YES]; } /** 是否能刷新tableview @param sender <#sender description#> @return <#return value description#> */ - (BOOL)CanRefreshTableView:(RefreshTableView *)sender { return YES; } - (void)reloadDataWithOnlyCode:(NSString *)code{ if(code!=nil&&code.length>0){ NewRepairReceiptVC *newRepairVc = [[ NewRepairReceiptVC alloc] init]; newRepairVc.refreshDelegate = self; newRepairVc.operationFlag = @"unreceipt"; newRepairVc.sCode=code; newRepairVc.parentVC = self; self.cNav.visibleViewController.hidesBottomBarWhenPushed=YES; [self.cNav pushViewController:newRepairVc animated:YES]; } } #pragma mark - 私有函数 /** 加载数据函数 */ - (void)reloadData{ [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetRepairNoReceiptIphone" 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:_model.strPresaleOrderNo forKeyedSubscript:@"RepairNo"]; [dict setObject:_model.strArrangementOrderNo forKeyedSubscript:@"ArrangementNo"]; [dict setObject:_model.strCustomerName forKeyedSubscript:@"CustomerName"]; [dict setObject:_model.strStartDate forKey:@"BeginTime"]; [dict setObject:_model.strEndDate forKey:@"EndTime"]; [dict setObject:_pageNumber forKey:@"PageNum"]; [dict setObject:[NSString stringWithFormat:@"%d",pageSize] forKey:@"PageSize"]; self.mDownManager = [[ASIDownManager alloc] init]; _mDownManager.delegate = self; _mDownManager.onRequestSuccess = @selector(onLoadFinish:); _mDownManager.onRequestFail = @selector(onLoadFail:); [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 刷新tableview */ - (void)refreshTableView { [self.tableView reloadData]; } /** 取消进度条函数 */ - (void)cancel { [self stopLoading]; } /** 初始化布局 */ - (void)initUI{ self.view.backgroundColor = LineBackgroundColor; UIView *back = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, 55)]; back.backgroundColor = [UIColor whiteColor]; [self.view addSubview:back]; UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom]; btnSearch.frame=CGRectMake(15, 10, Screen_Width-70, 35); [btnSearch setTitle:@"查询" forState:UIControlStateNormal]; [btnSearch setBackgroundColor:[UIColor colorWithRed:232.0/255.0 green:233.0/255.0 blue:235.0/255.0 alpha:1]]; [back addSubview:btnSearch]; btnSearch.layer.cornerRadius = 10; btnSearch.layer.masksToBounds = YES; btnSearch.titleLabel.font = orderTextFont; [btnSearch addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside]; [btnSearch setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; UIButton *scan=[UIButton buttonWithType:UIButtonTypeCustom]; scan.frame=CGRectMake(back.frame.size.width-40,15,25,25); scan.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight; UIImage *backgroundImg = [UIImage imageNamed:@"icon_scan"]; [scan setBackgroundImage:backgroundImg forState:UIControlStateNormal]; [back addSubview:scan]; [scan addTarget:self action:@selector(goScan) forControlEvents:UIControlEventTouchUpInside]; _tableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(btnSearch.frame)+10, self.view.frame.size.width-20, self.view.frame.size.height-rectNavHeight - rectStatusHeight - 130)]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _tableView.delegate = self; _tableView.mbMoreHidden = YES; _tableView.backgroundColor = LineBackgroundColor; [self.view addSubview:_tableView]; _model = [[NoReceiptSearchModel alloc] init]; _model.strPresaleOrderNo = @""; _model.strArrangementOrderNo = @""; _model.strStartDate = @""; _model.strEndDate = @""; _model.strCustomerName = @""; __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]; _model = [serviceRegionModel.customDict objectForKey:NORECEIPT_SEARCH_MODEL]; NSString *startDate= _model.strStartDate; NSString *endDate=_model.strEndDate; if(startDate == nil){ [self showAlertViewText:@"请选择开始日期"]; return; } if(endDate == nil){ [self showAlertViewText:@"请选择结束日期"]; return; } NSUInteger result = [DateFormat compareDate:startDate withDate:endDate]; if(result == -1){ [self showAlertViewText:@"开始日期不能大于结束日期"]; return; } [weakself.filterController dismiss]; _pageNumber = @"1"; [self reloadData]; }]; _filterController.animationDuration = .3f; _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 = @"RepairNoReciptSearchCell"; model.regionTitle = @"查询条件"; [dataArray addObject:model]; return [dataArray mutableCopy]; } /** 扫描函数 */ - (void)goScan { ScanViewController * rt = [[ScanViewController alloc]init]; rt.rootVC=self; self.cNav.visibleViewController.hidesBottomBarWhenPushed=YES; [self.cNav pushViewController:rt animated:YES]; } /** 弹出抽屉 */ - (void) search{ [_filterController showPagerView:self.cNav]; } /** 回调刷新 */ - (void)ReloadList{ [self ReloadList:_tableView]; } @end