// // DeliveryRequirementNoReceiptController.m // IBOSSHSH // // Created by ssl on 2018/1/12. // Copyright © 2018年 elongtian. All rights reserved. // #import "DispatchRequirementNoReceiptController.h" #import "DispatchNoReceiptCell.h" #import "SideSlipModel.h" #import "DispatchNoReceiptSearchModel.h" #import "DateFormat.h" @import CoreLocation; @import MapKit; #define receiptTextFont [UIFont systemFontOfSize:14] @interface DispatchRequirementNoReceiptController () { __block CLLocationCoordinate2D coordinate; } @end @implementation DispatchRequirementNoReceiptController #pragma mark - 公共函数 /** 加载视图函数 */ - (void)viewDidLoad { [super viewDidLoad]; _pageNumber = 1; _dataList = [[NSMutableArray alloc]init]; NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; _appName = [infoDictionary objectForKey:@"CFBundleDisplayName"]; _urlScheme=@"ibossHJ://"; 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]]; [self.view addSubview:searchView]; [searchView addSubview:_btnSearch]; _btnSearch.layer.cornerRadius = 10; _btnSearch.layer.masksToBounds = YES; [_btnSearch setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; _btnSearch.titleLabel.font=receiptTextFont; [_btnSearch addTarget:self action:@selector(searchUnreceiptData) forControlEvents:UIControlEventTouchUpInside]; [self.view 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; _tableView.mTableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 49, 0); [self.view addSubview:_tableView]; _arrangementNo=@""; _customerName=@""; _startDate=@""; _endDate=@""; __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]; _pageNumber=1; DispatchNoReceiptSearchModel *m = [serviceRegionModel.customDict objectForKey:SEARCH_RANGE_MODEL]; _arrangementNo=m.arrangementNo; _customerName=m.customerName; _contactsTelephone=m.customerTelephone; _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]; } [self initData]; [weakself.filterController dismiss]; }]; _filterController.animationDuration = .3f; _filterController.hasHeadView = YES; _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width; _filterController.dataList = [self packageDataList]; [self initData]; } #pragma mark - 委托函数 -(void)onSaveLoadFinish:(ASIDownManager *)sender { RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; [self cancel]; int iStatus = resultModel.status; NSString *message =resultModel.message; if (iStatus == 0) { [self showAlertViewText:@"保存成功"]; if(_dataList!=nil&&_dataList.count>0){ [_dataList removeAllObjects]; [_tableView reloadData]; } [self initData]; } else if(iStatus == ActionResultStatusAuthError ||iStatus == ActionResultStatusNoLogin ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){ [self showReLoginDialog:message]; return; } else{ [self showAlertViewText:message]; [_tableView FinishLoading]; return; } } -(void)onSaveLoadFail:(ASIDownManager *)sender { [self stopLoading]; [self showAlertViewText:@"网络异常"]; } /** 数据加载完成函数 @param sender <#sender description#> */ - (void)onLoadFinish:(ASIDownManager *)sender { RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; [self cancel]; long iNewCount = 0; 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:@"网络异常"]; } -(void)dialTelephone:(NSString *)telephone{ NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@",telephone]; CGFloat version = [[[UIDevice currentDevice]systemVersion]floatValue]; if (version >= 10.0) { /// 大于等于10.0系统使用此openURL方法 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil]; } else { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]]; } } /** 加载更多函数 @param sender <#sender description#> */ - (void)LoadMoreList:(RefreshTableView *)sender { _pageNumber++; [self initData]; } /** 上拉刷新函数 @param sender <#sender description#> */ - (void)ReloadList:(RefreshTableView *)sender{ _pageNumber = 1; [_dataList removeAllObjects]; [_tableView reloadData]; _tableView.mbMoreHidden=YES; [self initData]; } /** 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 cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *DeliveryCellIdentifier = @"CellId"; DispatchNoReceiptCell *cell = [tableView dequeueReusableCellWithIdentifier:DeliveryCellIdentifier]; cell = [[DispatchNoReceiptCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DeliveryCellIdentifier]; cell.telephoneDelegate=self; NSUInteger row = [indexPath section]; DispatchNoReceiptFrame *frame = [_dataList objectAtIndex:row]; cell.position=row; cell.receiptFlagDelegate=self; [cell setUnReceiptListFrame:frame]; return cell; } -(void)goNavigation:(NSUInteger)position { DispatchNoReceiptFrame *frame = [_dataList objectAtIndex:position]; DispatchNoReceiptModel *noReceiptModel= frame.unReceiptListModel; if(noReceiptModel.deliveryAddress!=nil&&noReceiptModel.deliveryAddress.length>0) { CLGeocoder *myGeocoder = [[CLGeocoder alloc] init]; [myGeocoder geocodeAddressString:noReceiptModel.deliveryAddress completionHandler:^(NSArray *placemarks, NSError *error) { if ([placemarks count] > 0 && error == nil) { CLPlacemark *firstPlacemark= [placemarks objectAtIndex:0]; coordinate = CLLocationCoordinate2DMake(firstPlacemark.location.coordinate.latitude, firstPlacemark.location.coordinate.longitude) ; } // else if ([placemarks count] == 0 && error == nil) { //             NSLog(@"Found no placemarks."); // // } //         else if (error != nil) { //           NSLog(@"An error occurred = %@", error); } }]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择地图" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; //这个判断其实是不需要的 if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com/"]]) { UIAlertAction *action = [UIAlertAction actionWithTitle:@"苹果地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation]; MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]]; [MKMapItem openMapsWithItems:@[currentLocation, toLocation] launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}]; }]; [alert addAction:action]; } if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) { UIAlertAction *action = [UIAlertAction actionWithTitle:@"百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=gcj02",coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSLog(@"%@",urlString); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; }]; [alert addAction:action]; } if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) { UIAlertAction *action = [UIAlertAction actionWithTitle:@"高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dev=0&style=2",_appName,_urlScheme,coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSLog(@"%@",urlString); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; }]; [alert addAction:action]; } if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) { UIAlertAction *action = [UIAlertAction actionWithTitle:@"谷歌地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",_appName,_urlScheme,coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSLog(@"%@",urlString); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; }]; [alert addAction:action]; } UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; [alert addAction:action]; [self presentViewController:alert animated:YES completion:^{ }]; } } -(void)saveData:(NSUInteger)position { DispatchNoReceiptFrame *frame = [_dataList objectAtIndex:position]; if(frame.unReceiptListModel.truckName==nil||[frame.unReceiptListModel.truckName isEqualToString:@""]) { [self showAlertViewText:@"车牌号为空,请维护车牌号"]; return; } UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定要保存吗?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]; UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { DispatchNoReceiptFrame *frame = [_dataList objectAtIndex:position]; [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"SaveInstallationDemandReceiptDataByID" 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:frame.unReceiptListModel.arrangementId forKeyedSubscript:@"ArrangementID"]; [dict setObject:frame.unReceiptListModel.collectDetailId forKeyedSubscript:@"CollectDetailID"]; [dict setObject:frame.unReceiptListModel.customerId forKeyedSubscript:@"CustomerID"]; [dict setObject:frame.unReceiptListModel.receiptFlag forKeyedSubscript:@"RequirementType"]; [dict setObject:frame.unReceiptListModel.truckName forKeyedSubscript:@"truckNumber"]; [dict setObject:kkLicenseCode forKeyedSubscript:@"LicenseCode"]; self.mDownManager = [[ASIDownManager alloc] init]; self.mDownManager.delegate = self; self.mDownManager.onRequestSuccess = @selector(onSaveLoadFinish:); self.mDownManager.onRequestFail = @selector(onSaveLoadFail:); [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; }]; UIColor *cancelColor = [UIColor blackColor]; UIColor *sureColor = [UIColor redColor]; [cancelAction setValue:cancelColor forKey:@"titleTextColor"]; [otherAction setValue:sureColor forKey:@"titleTextColor"]; [alertController addAction:cancelAction]; [alertController addAction:otherAction]; [self presentViewController:alertController animated:YES completion:nil]; } -(void)updateReceiptFlag:(NSUInteger)position receiptFlag:(NSString *)flag { DispatchNoReceiptFrame *frame = [_dataList objectAtIndex:position]; [frame.unReceiptListModel setReceiptFlag:flag]; [_tableView reloadData]; } /** 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#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row = [indexPath section]; DispatchNoReceiptFrame *unReceiptListFrame = [_dataList objectAtIndex:row]; NSInteger cellHeight = [unReceiptListFrame cellHeight]; return cellHeight; } /** 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 indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NewDispatchRequirementHomeController *newDeliveryVC = [[NewDispatchRequirementHomeController alloc] init]; NSUInteger row = [indexPath section]; newDeliveryVC.refreshDelegate = self; DispatchNoReceiptFrame *frame = [_dataList objectAtIndex:row]; DispatchNoReceiptModel *model = [frame unReceiptListModel]; newDeliveryVC.noReceiptModel = model; self.cNav.visibleViewController.hidesBottomBarWhenPushed = YES; [self.cNav pushViewController:newDeliveryVC animated:YES]; } /** 刷新数据函数 */ - (void)refreshFollowUpData{ [_dataList removeAllObjects]; _tableView.mbMoreHidden = YES; [_tableView reloadData]; _pageNumber = 1; [self initData]; } /** 是否能刷新tableview @param sender <#sender description#> @return <#return value description#> */ - (BOOL)CanRefreshTableView:(RefreshTableView *)sender { return YES; } #pragma mark - 私有函数 -(void) refreshData { [_dataList removeAllObjects]; _tableView.mbMoreHidden = YES; [_tableView reloadData]; _pageNumber = 1; [self initData]; } /** 加载数据函数 */ - (void)initData { [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetInstallationReceiptNoReceiptIphone" 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:_arrangementNo forKeyedSubscript:@"ArrangementNo"]; [dict setObject:_customerName forKeyedSubscript:@"CustomerName"]; [dict setObject:_contactsTelephone forKeyedSubscript:@"Telephone"]; [dict setObject:_startDate forKeyedSubscript:@"BeginTime"]; [dict setObject:_endDate forKeyedSubscript:@"EndTime"]; [dict setObject:[NSString stringWithFormat:@"%d",(int)_pageNumber] forKey:@"PageNum"]; [dict setObject:[NSString stringWithFormat:@"%d",pageSize] forKey:@"PageSize"]; self.mDownManager = [[ASIDownManager alloc] init]; self.mDownManager.delegate = self; self.mDownManager.onRequestSuccess = @selector(onLoadFinish:); self.mDownManager.onRequestFail = @selector(onLoadFail:); [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 弹出抽屉 */ -(void)searchUnreceiptData{ [_filterController showPagerView:self.cNav]; } /** 抽屉加载布局 @return */ - (NSArray *)packageDataList { NSMutableArray *dataArray = [NSMutableArray array]; SideSlipModel *model = [[SideSlipModel alloc] init]; model.containerCellClass = @"DispatchNoReceiptSearchCell"; model.regionTitle = @"查询条件"; [dataArray addObject:model]; return [dataArray mutableCopy]; } /** 取消进度条 */ - (void)cancel { [self stopLoading]; } @end