// // SearchViewController.m // shiku_im // // Created by huangyp-pc on 16/2/24. // Copyright © 2016年 Reese. All rights reserved. // #import "SearchViewController.h" #import "SearchCell.h" //#import "ScheduleTableViewController.h" #import "OrderFormTableViewController.h" #import "StatisticDoubleListViewController.h" #import "DoubleListCell.h" #import "PieCharViewController.h" #import "DataItemCharViewController.h" #import "Config.h" #import "GMDCircleLoader.h" static NSString *cellID = @"cellID"; @interface SearchViewController () @property (nonatomic,strong) UICollectionView *grid; @property (nonatomic,assign) int count; //每行多少个item @property (nonatomic,strong) UIButton *chaxunBtn; @property (nonatomic,strong) UIButton *tongjiBtn; @property (nonatomic,strong) NSArray *imageArr; @end @implementation SearchViewController { NSMutableArray* allSearchMenu; UIColor *addingCellBackColor; NSMutableArray *menuViewDataArray; UISegmentedControl *segmentedControl; //doubleList UASNetworkManager *DoublistNetManager; NSArray *datasAllKeys; BOOL isHadOpen; NSInteger innum; //// NSDictionary *doubleAllDataDic; //// NSArray * arrayTest; DoubleListCell *preCell; UASNetworkManager *searchMenuViewManager; } - (void)viewDidLoad { [super viewDidLoad]; //初始化数据 _count = 3; menuViewDataArray=[[NSMutableArray alloc] init]; allSearchMenu=[[NSMutableArray alloc]init]; addingCellBackColor=[UIColor whiteColor]; self.view.backgroundColor = addingCellBackColor; _imageArr = @[@"uu_work_kucunchaxun",@"uu_work_dingdanchaxun",@"uu_work_caigouchaxun",@"uu_work_feiyongbaoxiao",@"uu_work_xiaoshoufahuo",@"uu_work_qingjiadanchaxun",@"uu_work_yingshoufapiao",@"uu_work_chalvfeibaoxiao",@"uu_work_qinggouchaxun",@"uu_work_caigouruku",@"uu_work_jipiaoyuding",@"uu_work_fahuotongzhi",@"uu_work_yingfufapiao"]; [self getDataFromSever]; [self initGridView]; //设置查询页面 _chaxunBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _chaxunBtn.frame = CGRectMake(0, 0, 65, 30); [_chaxunBtn setBackgroundImage:[UIImage imageNamed:@"uu_work_chaxun_normal"] forState:UIControlStateNormal]; [_chaxunBtn setBackgroundImage:[UIImage imageNamed:@"uu_work_chaxun_press"] forState:UIControlStateDisabled]; _chaxunBtn.enabled = NO; [_chaxunBtn addTarget:self action:@selector(changeChaxunViewController) forControlEvents:UIControlEventTouchUpInside]; _tongjiBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _tongjiBtn.frame = CGRectMake(65, 0, 65, 30); [_tongjiBtn setBackgroundImage:[UIImage imageNamed:@"uu_work_tongji_normal"] forState:UIControlStateNormal]; [_tongjiBtn setBackgroundImage:[UIImage imageNamed:@"uu_work_tongji_press"] forState:UIControlStateDisabled]; _tongjiBtn.enabled = YES; [_tongjiBtn addTarget:self action:@selector(changeTongjiViewController) forControlEvents:UIControlEventTouchUpInside]; UIImageView *testimage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 130, 30)]; testimage.userInteractionEnabled = YES; [testimage addSubview:_chaxunBtn]; [testimage addSubview:_tongjiBtn]; NSArray *segmentedArray = @[@"查询",@"统计"]; segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray]; segmentedControl.frame = CGRectMake(0, 0, self.view.bounds.size.width/2, 36); segmentedControl.selectedSegmentIndex = 0; UIColor *color = [UIColor colorWithRed:13/255.0 green:143/255.0 blue:219/255.0 alpha:255/255.0]; segmentedControl.tintColor = color; //[segmentedControl addTarget:self action:@selector(changeViewController:) forControlEvents:UIControlEventValueChanged]; [self.navigationItem setTitleView:testimage]; //设置统计页面 _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height-64)]; _tableView.delegate=self; _tableView.dataSource=self; [self initDoubleListTable]; _tableView.hidden=YES; [self.view addSubview:_tableView]; // UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; // btn.frame = CGRectMake(-10, 0, 60, 30); // [btn setTitle:@"< 返回" forState:UIControlStateNormal]; // [btn setBackgroundColor:[UIColor clearColor]]; // [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // [btn addTarget:self action:@selector(backToView) forControlEvents:UIControlEventTouchUpInside]; // // UIBarButtonItem *leftBBI = [[UIBarButtonItem alloc] initWithCustomView:btn]; // self.navigationItem.leftBarButtonItem = leftBBI; //消息通知(切换帐套) [[NSNotificationCenter defaultCenter] removeObserver:self name:@"mytest" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mytest:) name:@"mytest" object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"hideBottomView" object:nil]; } -(void)backToView { [self.navigationController popViewControllerAnimated:YES]; } -(void)viewWillDisappear:(BOOL)animated { [GMDCircleLoader hideFromView:self.view animated:YES]; } -(void)viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] postNotificationName:@"hideBottomView" object:nil]; } -(void)changeChaxunViewController { _chaxunBtn.enabled = NO; _tongjiBtn.enabled = YES; _tableView.hidden = YES; } -(void)changeTongjiViewController { _chaxunBtn.enabled = YES; _tongjiBtn.enabled = NO; _tableView.hidden = NO; } -(void)changeViewController:(id)sender { UISegmentedControl* control = (UISegmentedControl*)sender; switch (control.selectedSegmentIndex) { case 0: _tableView.hidden=YES; break; case 1: _tableView.hidden=NO; break; default: break; } } -(void)mytest:(NSNotification*) notification { [self getDataFromSever]; [self GetDatasFromSever]; [self.grid reloadData]; } -(void)getDataFromSever { searchMenuViewManager=[UASNetworkManager shareManager]; searchMenuViewManager.responseSerializer=[AFHTTPResponseSerializer serializer]; NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults]; NSString *sessionId=[userDefaults stringForKey:@"sessionId"]; NSString *ip=[userDefaults objectForKey:@"ipAndPort"]; NSString *urlStr1=[@"" stringByAppendingFormat: @"%@mobile/common/getMobileQuerys.action?sessionId=%@",ip,sessionId]; //__block NSDictionary *objectDetailArr; DLog(@"开始请求数据!!!!"); //NSMutableDictionary *params=@{@"Page":@"2"}; NSString *params=@""; DLog(@"search urlStr=%@",urlStr1); [searchMenuViewManager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId]; [searchMenuViewManager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"]; [searchMenuViewManager request:urlStr1 method:POST parameters:params progress:nil success:^(NSURLSessionDataTask *task, id responseObject) { DLog(@"成功!"); [GMDCircleLoader hideFromView:self.view animated:YES]; NSData *data=responseObject; id tempDic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; menuViewDataArray=[tempDic objectForKey:@"querys"]; if ([menuViewDataArray isKindOfClass:[NSNull class]]) { DLog(@"没有数据~~~~~~~~~~~~~~~~~~~~~~~~~~~"); }else { allSearchMenu=[NSMutableArray arrayWithArray:menuViewDataArray]; } [_grid reloadData]; DLog(@"hypishandsomedataall========%@",menuViewDataArray); DLog(@"allSearchMenu:%lu",(unsigned long)allSearchMenu.count); } failure:^(NSURLSessionDataTask *task, NSError *error) { DLog(@"失败 !hkjhkjhjjjjjjjjjjjjjjjjjjjjjj:%@",error); [GMDCircleLoader hideFromView:self.view animated:YES]; }]; } -(void)GetDatasFromSever { DoublistNetManager=[UASNetworkManager shareManager]; DoublistNetManager.responseSerializer=[AFHTTPResponseSerializer serializer]; NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults]; NSString *sessionId=[userDefaults stringForKey:@"sessionId"]; NSString *ip=[userDefaults stringForKey:@"ipAndPort"]; NSString *urlStr1=[@"" stringByAppendingFormat:@"%@mobile/common/Stats.action?sessionId=%@",ip,sessionId]; DLog(@"开始请求数据!!!!"); NSString *params=@""; DLog(@"urlStr=%@",urlStr1); [DoublistNetManager request:urlStr1 method:POST parameters:params progress:nil success:^(NSURLSessionDataTask *task, id responseObject) { DLog(@"成功了吗?????"); [GMDCircleLoader hideFromView:self.view animated:YES]; NSData *data=responseObject; _TableArry = [[NSMutableArray alloc]init]; id dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; preCell=nil; doubleAllDataDic=[dic objectForKey:@"Stats"]; [self parseDatas]; [_tableView reloadData]; if (doubleAllDataDic.count == 0) { DLog(@"空了你不知道????"); [self showNoDataView]; } DLog(@"data=%@",doubleAllDataDic); DLog(@"hypishandsomelalala:%@",dic); } failure:^(NSURLSessionDataTask *task, NSError *error) { DLog(@"失败 !:%@",error); }]; innum++; DLog(@"innum>>>>>>>>>>>>>>>>>>>>>>>>>>>>=%ld",(long)innum); } //数据解析 -(void)parseDatas { datasAllKeys=[doubleAllDataDic allKeys]; for (int i=0; i<[datasAllKeys count]; i++) { DoubleListCell *cell=[[DoubleListCell alloc] init:NO]; NSArray *array=[doubleAllDataDic objectForKey:[datasAllKeys objectAtIndex:i]] ; NSMutableArray *childArray = [[NSMutableArray alloc] init]; for (int m =0;m<[array count];m ++) { DoubleListCell *childCell=[[DoubleListCell alloc] init:YES]; childCell.Name.text=[[array objectAtIndex:m] objectForKey:@"st_title"]; childCell.type= [[array objectAtIndex:m] objectForKey:@"st_type"]; childCell.cellId= [NSString stringWithFormat:@"%@",[[array objectAtIndex:m] objectForKey:@"st_id"]] ; childCell.ChildArray=nil; [childArray addObject:childCell]; } cell.Name.text =[datasAllKeys objectAtIndex:i]; cell.ChildArray=childArray; [_TableArry addObject:cell]; } } //显示暂无数据 -(void)showNoDataView { UILabel *noDataLbl = [[UILabel alloc]initWithFrame:self.view.frame]; noDataLbl.center = self.view.center; noDataLbl.text = @"对不起!暂无数据!"; noDataLbl.textColor = [UIColor lightGrayColor]; noDataLbl.font = [UIFont boldSystemFontOfSize:18]; noDataLbl.textAlignment = NSTextAlignmentCenter; [self.tableView addSubview:noDataLbl]; } /******************************统计页面*************************************/ -(void)initDoubleListTable { innum = 0; preCell = nil; _TableArry = [[NSMutableArray alloc] init]; _InsertArry = [[NSMutableArray alloc] init]; _DeleteArry = [[NSMutableArray alloc] init]; isHadOpen = NO; //设置背景 UIImageView *backImageView = [[UIImageView alloc]initWithFrame:self.view.bounds]; [backImageView setImage:[UIImage imageNamed:@""]]; self.tableView.backgroundView = backImageView; self.tableView.separatorStyle = UITableViewCellSelectionStyleNone; UIImageView *testd = [[UIImageView alloc]initWithFrame:self.view.bounds]; testd.image = [UIImage imageNamed:@"uu_background_huibai"]; self.tableView.backgroundView = testd; //向页面添加一个 加载动画 [GMDCircleLoader setOnView:self.view withTitle:@"Loading" animated:YES]; [self GetDatasFromSever]; //设置切换帐套的监听 //[[NSNotificationCenter defaultCenter] removeObserver:self name:@"mytest" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mytest:) name:@"mytest" object:nil]; } #pragma mark -- tableView delegate //返回tableView中cell的个数 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _TableArry.count; } //设置 cell 的样式 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [[DoubleListCell alloc] init]; if (indexPath.row < _TableArry.count) { cell = [_TableArry objectAtIndex:indexPath.row]; } if (indexPath.row%2 == 0) { cell.backgroundColor = [UIColor colorWithRed:160/255.0 green:160/255.0 blue:160/255.0 alpha:0.1]; }else { cell.backgroundColor = [UIColor clearColor]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } //返回cell的高度 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 55; } //当cell被选择(被点击)时调用的函数 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DoubleListCell *cell = [_TableArry objectAtIndex:indexPath.row]; { if (!cell.Open)//如果子菜单是关闭的 { double delayInSeconds = 0.0f; if (preCell!=cell && preCell.Open && cell.ChildArray.count!=0) { delayInSeconds = 0.3; [self closeWithIndex:[_TableArry indexOfObject:preCell] tableView:tableView isAnimation:NO]; preCell.Open = NO; [UIView animateWithDuration:0.2 animations:^{ if (preCell.Open) { preCell.iconView.transform = CGAffineTransformMakeRotation(M_PI); } else { preCell.iconView.transform = CGAffineTransformMakeRotation(0); } } completion:^(BOOL finished) { }]; } NSArray * array = [self insertOperation:cell]; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ //[self openWithIndex:[m_datas indexOfObject:m] tableView:tableView isAnimation:NO]; [self.tableView insertRowsAtIndexPaths: array withRowAnimation:UITableViewRowAnimationBottom ]; //cell.Open = YES; }); isHadOpen=YES; } else//如果子菜单是打开的 { NSArray *array = [self deleteOperation:cell]; if (array.count > 0 ) { //从视图中删除 [self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationBottom]; } } } if (cell.ChildArray.count == 0) { UIStoryboard *testStoryboard = [UIStoryboard storyboardWithName:@"Test" bundle:[NSBundle mainBundle]]; if ([[cell GetType] intValue] == 1) { DataItemCharViewController *dataItemCharView = [[DataItemCharViewController alloc] init]; dataItemCharView.m_id = cell.cellId; dataItemCharView.m_titile = cell.Name.text; if ([cell.Name.text isEqualToString:@"销售额按天统计"]) { dataItemCharView.isDay = @"YES"; }else { dataItemCharView.isDay = @"NO"; } [self.navigationController pushViewController:dataItemCharView animated:YES]; } else { PieCharViewController *pieCharVC = [testStoryboard instantiateViewControllerWithIdentifier:@"pieCharView"]; pieCharVC.m_id = cell.cellId; pieCharVC.m_title = cell.Name.text; [self.navigationController pushViewController:pieCharVC animated:YES]; } } else { [UIView animateWithDuration:0.2 animations:^{ if (cell.Open) { cell.iconView.transform = CGAffineTransformMakeRotation(M_PI); }else { cell.iconView.transform = CGAffineTransformMakeRotation(0); } } completion:^(BOOL finished) { }]; } } -(void)closeWithIndex:(NSInteger)index tableView:(UITableView*)tableView isAnimation:(BOOL)animation { DoubleListCell* m = _TableArry[index]; NSMutableArray* indexPathArray = [NSMutableArray array]; for (int i = 1; i <= m.ChildArray.count; i++) { NSIndexPath* subIndexPath = [NSIndexPath indexPathForRow:index+i inSection:0]; [indexPathArray addObject:subIndexPath]; } NSRange range; range.length = m.ChildArray.count; range.location = index+1; NSIndexSet* indexSet = [NSIndexSet indexSetWithIndexesInRange:range]; [_TableArry removeObjectsAtIndexes:indexSet]; if (animation) { [tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationFade]; } else [tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationNone]; } -(NSArray *) insertOperation:(DoubleListCell *)item { [_InsertArry removeAllObjects];//将插入菜单清空 NSIndexPath *path = [NSIndexPath indexPathForRow:[_TableArry indexOfObject:item] inSection:0];//获取选取的cell的位置 DoubleListCell *child = [[DoubleListCell alloc]init]; //遍历当前选取cell 的子菜单 for(int i=0;i, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>) return UIEdgeInsetsMake(5, 15, 5, 15); } //选择item -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { UIStoryboard *testStoryboard = [UIStoryboard storyboardWithName:@"Test" bundle:[NSBundle mainBundle]]; OrderFormTableViewController *orderFormController=(OrderFormTableViewController *)[testStoryboard instantiateViewControllerWithIdentifier:@"orderFormController"]; orderFormController.caller=[[allSearchMenu objectAtIndex:indexPath.row] objectForKey:@"mq_caller"]; orderFormController.titile=[[allSearchMenu objectAtIndex:indexPath.row] objectForKey:@"mq_title"]; orderFormController.isHaveCreatList = @"NO"; orderFormController.is49 = @"NO"; [self.navigationController pushViewController:orderFormController animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end