// // DeliveryRequirementReceiptController.m // IBOSSHSH // // Created by ssl on 2018/1/12. // Copyright © 2018年 elongtian. All rights reserved. // #import "DeliveryRequirementReceiptController.h" #import "RequirementReceiptModel.h" #import "RequirementReceiptFrame.h" #import "DeliveryRequirementDetailController.h" #import "DateFormat.h" #import "SideSlipModel.h" #import "RequirementReceiptCell.h" #import "RequirementReceiptSearchModel.h" #define receiptTextFont [UIFont systemFontOfSize:14] @interface DeliveryRequirementReceiptController () @end @implementation DeliveryRequirementReceiptController #pragma mark - 公共函数 /** 视图加载完成函数 */ - (void)viewDidLoad { [super viewDidLoad]; _dataList = [[NSMutableArray alloc]init]; UIView *searchView=[[UIView alloc]init]; searchView.frame=CGRectMake(0, 0, Screen_Width,55); [searchView setBackgroundColor:[UIColor whiteColor]]; _btnSearch = [UIButton buttonWithType:UIButtonTypeCustom]; _btnSearch.frame=CGRectMake(15, 10, Screen_Width-30, 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]]; _btnSearch.layer.cornerRadius = 10; _btnSearch.layer.masksToBounds = YES; [_btnSearch setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; _btnSearch.titleLabel.font=receiptTextFont; [_btnSearch addTarget:self action:@selector(searchReceiptData) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:searchView]; [searchView addSubview:_btnSearch]; _tableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(searchView.frame), self.view.frame.size.width - 20, self.view.frame.size.height-55)]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _tableView.backgroundColor = [UIColor clearColor]; _tableView.mTableView.showsVerticalScrollIndicator = NO; _tableView.delegate = self; [self.view addSubview:_tableView]; _pageNumber = 1; _deliveryNo=@""; _startDate=@""; _endDate=@""; _receiptType=@""; __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) { _pageNumber=1; SideSlipModel *serviceRegionModel = dataList[0]; RequirementReceiptSearchModel *m = [serviceRegionModel.customDict objectForKey:SEARCH_RANGE_MODEL]; _deliveryNo=m.deliveryNo; _receiptType=m.receiptType; _startDate=m.startDate; _endDate=m.endDate; if(_startDate!=nil&&_endDate!=nil){ NSUInteger result= [DateFormat compareDate:_startDate withDate:_endDate]; if(result == -1){ [self showAlertViewText:@"开始日期不能大于结束日期"]; return; } } if(_dataList!=nil&&_dataList.count>0){ [_dataList removeAllObjects]; [_tableView reloadData]; } [weakself.filterController dismiss]; [self reloadData]; }]; _filterController.animationDuration = .3f; _filterController.hasHeadView = YES; _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width; _filterController.dataList = [self packageDataList]; [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]; int iNewCount = 0; _tableView.mTableView.backgroundView = nil; int iStatus = resultModel.status; NSString *message = resultModel.message; if (iStatus == 0) { NSArray * infoArr =(NSArray*)resultModel.result; if(infoArr != nil&&infoArr.count > 0) { for(int i=0;i */ - (void)onLoadFail:(ASIDownManager *)sender { [self cancel]; [_tableView reloadData]; [self showAlertViewText:@"网络异常"]; } /** 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]; RequirementReceiptFrame *receiptedListFrame = [_dataList objectAtIndex:row]; NSInteger cellHeight = [receiptedListFrame cellHeight]; return cellHeight; } /** 获取tableview cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *DeliveryCellIdentifier = @"CellId"; RequirementReceiptCell *cell1 = [tableView dequeueReusableCellWithIdentifier:DeliveryCellIdentifier]; cell1 = [[RequirementReceiptCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DeliveryCellIdentifier]; cell1.delegate = self; NSUInteger row = [indexPath section]; RequirementReceiptFrame *frame= [_dataList objectAtIndex:row]; [cell1 setReceiptedListFrame:frame]; return cell1; } /** scrollview 回调函数 @param scrollView <#scrollView description#> */ - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (scrollView.isDragging) {//显示下拉更新 if (_tableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [_tableView CanRefresh]) { [_tableView.mRefreshHeader setState:PullRefreshNormal]; } else if (_tableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [_tableView CanRefresh]) { //显示松开更新 [_tableView.mRefreshHeader setState:PullRefreshPulling]; } } } /** 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列表项点击事件 @param tableView <#tableView description#> @param indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DeliveryRequirementDetailController *detail = [[DeliveryRequirementDetailController alloc] init]; NSUInteger row = [indexPath section]; RequirementReceiptFrame *frame = [_dataList objectAtIndex:row]; NSString *deliveryId = [frame.deliveryListModel deliveryId]; NSString *arrangementId = [frame.deliveryListModel arrangementId]; NSString *recReceiptNo = [frame.deliveryListModel recReceiptNo]; NSString *receiptID = [frame.deliveryListModel receiptID]; detail.receiptID= receiptID; detail.deliveryId = deliveryId; detail.arrangementId = arrangementId; detail.recReceiptNo = recReceiptNo; self.cNav.visibleViewController.hidesBottomBarWhenPushed = YES; [self.cNav pushViewController:detail animated:YES]; } /** 是否能刷新tableview函数 @param sender <#sender description#> @return <#return value description#> */ - (BOOL)CanRefreshTableView:(RefreshTableView *)sender { return YES; } /** 加载更多函数 @param sender <#sender description#> */ - (void)LoadMoreList:(RefreshTableView *)sender { _pageNumber++; [self reloadData]; } /** 下拉刷新函数回调 @param sender <#sender description#> */ - (void)ReloadList:(RefreshTableView *)sender{ _pageNumber = 1; [_dataList removeAllObjects]; [_tableView reloadData]; _tableView.mbMoreHidden = YES; [self reloadData]; } /** scrollview回调函数 @param scrollView <#scrollView description#> */ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [self.view endEditing:YES]; } #pragma mark - 私有函数 /** 加载数据函数 */ - (void)reloadData { [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetDeliveryRequirementReceiptIphone" 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:_deliveryNo forKeyedSubscript:@"DeliveryNo"]; [dict setObject:_receiptType forKeyedSubscript:@"ReceiptType"]; [dict setObject:_startDate forKeyedSubscript:@"BeginTime"]; [dict setObject:_endDate forKeyedSubscript:@"endTime"]; [dict setObject:[NSString stringWithFormat:@"%ld",(long)_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]; } -(void)searchReceiptData{ [_filterController showPagerView:self.cNav]; } /** 抽屉加载布局 @return */ - (NSArray *)packageDataList { NSMutableArray *dataArray = [NSMutableArray array]; SideSlipModel *model = [[SideSlipModel alloc] init]; model.containerCellClass = @"RequirementReceiptSearchCell"; model.regionTitle = @"查询条件"; [dataArray addObject:model]; return [dataArray mutableCopy]; } /** 取消进度条加载函数 */ - (void)cancel { [self stopLoading]; } /** 撤销回执 @param cell <#cell description#> */ - (void)showReturnReceipt:(RequirementReceiptModel*) model{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否要撤销回执?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ [self requestCancelDeliveryReceipt:model.receiptID]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ }]; UIColor *cancelColor = [UIColor blackColor]; UIColor *sureColor = [UIColor redColor]; [cancelAction setValue:cancelColor forKey:@"titleTextColor"]; [okAction setValue:sureColor forKey:@"titleTextColor"]; [alert addAction:okAction]; [alert addAction:cancelAction]; [self presentViewController:alert animated:YES completion:nil]; } /** 请求撤销回执 @param receiptID <#receiptID description#> */ -(void) requestCancelDeliveryReceipt:(NSString *) receiptID{ [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"CancelDeliveryReceiptIphone" 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:receiptID forKeyedSubscript:@"ReceiptID"]; self.mDownManager = [[ASIDownManager alloc] init]; _mDownManager.delegate = self; _mDownManager.onRequestSuccess = @selector(onRequestCancelReceiptFinish:); _mDownManager.onRequestFail = @selector(onRequestCancelReceiptFail:); [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 请求成功 @param sender <#sender description#> */ - (void)onRequestCancelReceiptFinish:(ASIDownManager *) sender{ RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; [self cancel]; int iNewCount = 0; int iStatus = resultModel.status; NSString *message = resultModel.message; if (iStatus == 0) { [self showAlertViewText:@"撤销成功"]; [self ReloadList:_tableView]; } else if(iStatus == ActionResultStatusAuthError ||iStatus == ActionResultStatusNoLogin ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){ [self showReLoginDialog:message]; return; } else{ [self showAlertViewText:message]; return; } } /** 请求失败 @param sender <#sender description#> */ - (void)onRequestCancelReceiptFail:(ASIDownManager *) sender{ [self cancel]; [self showAlertViewText:@"请求失败"]; } @end