SearchViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. //
  2. // SearchViewController.m
  3. // shiku_im
  4. //
  5. // Created by huangyp-pc on 16/2/24.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "SearchViewController.h"
  9. #import "SearchCell.h"
  10. //#import "ScheduleTableViewController.h"
  11. #import "OrderFormTableViewController.h"
  12. #import "StatisticDoubleListViewController.h"
  13. #import "DoubleListCell.h"
  14. #import "PieCharViewController.h"
  15. #import "DataItemCharViewController.h"
  16. #import "Config.h"
  17. #import "GMDCircleLoader.h"
  18. static NSString *cellID = @"cellID";
  19. @interface SearchViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UITableViewDelegate,UITableViewDataSource>
  20. @property (nonatomic,strong) UICollectionView *grid;
  21. @property (nonatomic,assign) int count; //每行多少个item
  22. @property (nonatomic,strong) UIButton *chaxunBtn;
  23. @property (nonatomic,strong) UIButton *tongjiBtn;
  24. @property (nonatomic,strong) NSArray *imageArr;
  25. @end
  26. @implementation SearchViewController
  27. {
  28. NSMutableArray* allSearchMenu;
  29. UIColor *addingCellBackColor;
  30. NSMutableArray *menuViewDataArray;
  31. UISegmentedControl *segmentedControl;
  32. //doubleList
  33. UASNetworkManager *DoublistNetManager;
  34. NSArray *datasAllKeys;
  35. BOOL isHadOpen;
  36. NSInteger innum;
  37. ////
  38. NSDictionary *doubleAllDataDic;
  39. ////
  40. NSArray * arrayTest;
  41. DoubleListCell *preCell;
  42. UASNetworkManager *searchMenuViewManager;
  43. }
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. //初始化数据
  47. _count = 3;
  48. menuViewDataArray=[[NSMutableArray alloc] init];
  49. allSearchMenu=[[NSMutableArray alloc]init];
  50. addingCellBackColor=[UIColor whiteColor];
  51. self.view.backgroundColor = addingCellBackColor;
  52. _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"];
  53. [self getDataFromSever];
  54. [self initGridView]; //设置查询页面
  55. _chaxunBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  56. _chaxunBtn.frame = CGRectMake(0, 0, 65, 30);
  57. [_chaxunBtn setBackgroundImage:[UIImage imageNamed:@"uu_work_chaxun_normal"] forState:UIControlStateNormal];
  58. [_chaxunBtn setBackgroundImage:[UIImage imageNamed:@"uu_work_chaxun_press"] forState:UIControlStateDisabled];
  59. _chaxunBtn.enabled = NO;
  60. [_chaxunBtn addTarget:self action:@selector(changeChaxunViewController) forControlEvents:UIControlEventTouchUpInside];
  61. _tongjiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  62. _tongjiBtn.frame = CGRectMake(65, 0, 65, 30);
  63. [_tongjiBtn setBackgroundImage:[UIImage imageNamed:@"uu_work_tongji_normal"] forState:UIControlStateNormal];
  64. [_tongjiBtn setBackgroundImage:[UIImage imageNamed:@"uu_work_tongji_press"] forState:UIControlStateDisabled];
  65. _tongjiBtn.enabled = YES;
  66. [_tongjiBtn addTarget:self action:@selector(changeTongjiViewController) forControlEvents:UIControlEventTouchUpInside];
  67. UIImageView *testimage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 130, 30)];
  68. testimage.userInteractionEnabled = YES;
  69. [testimage addSubview:_chaxunBtn];
  70. [testimage addSubview:_tongjiBtn];
  71. NSArray *segmentedArray = @[@"查询",@"统计"];
  72. segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];
  73. segmentedControl.frame = CGRectMake(0, 0, self.view.bounds.size.width/2, 36);
  74. segmentedControl.selectedSegmentIndex = 0;
  75. UIColor *color = [UIColor colorWithRed:13/255.0 green:143/255.0 blue:219/255.0 alpha:255/255.0];
  76. segmentedControl.tintColor = color;
  77. //[segmentedControl addTarget:self action:@selector(changeViewController:) forControlEvents:UIControlEventValueChanged];
  78. [self.navigationItem setTitleView:testimage];
  79. //设置统计页面
  80. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height-64)];
  81. _tableView.delegate=self;
  82. _tableView.dataSource=self;
  83. [self initDoubleListTable];
  84. _tableView.hidden=YES;
  85. [self.view addSubview:_tableView];
  86. // UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  87. // btn.frame = CGRectMake(-10, 0, 60, 30);
  88. // [btn setTitle:@"< 返回" forState:UIControlStateNormal];
  89. // [btn setBackgroundColor:[UIColor clearColor]];
  90. // [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  91. // [btn addTarget:self action:@selector(backToView) forControlEvents:UIControlEventTouchUpInside];
  92. //
  93. // UIBarButtonItem *leftBBI = [[UIBarButtonItem alloc] initWithCustomView:btn];
  94. // self.navigationItem.leftBarButtonItem = leftBBI;
  95. //消息通知(切换帐套)
  96. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"mytest" object:nil];
  97. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mytest:) name:@"mytest" object:nil];
  98. [[NSNotificationCenter defaultCenter] postNotificationName:@"hideBottomView" object:nil];
  99. }
  100. -(void)backToView
  101. {
  102. [self.navigationController popViewControllerAnimated:YES];
  103. }
  104. -(void)viewWillDisappear:(BOOL)animated
  105. {
  106. [GMDCircleLoader hideFromView:self.view animated:YES];
  107. }
  108. -(void)viewWillAppear:(BOOL)animated
  109. {
  110. [[NSNotificationCenter defaultCenter] postNotificationName:@"hideBottomView" object:nil];
  111. }
  112. -(void)changeChaxunViewController
  113. {
  114. _chaxunBtn.enabled = NO;
  115. _tongjiBtn.enabled = YES;
  116. _tableView.hidden = YES;
  117. }
  118. -(void)changeTongjiViewController
  119. {
  120. _chaxunBtn.enabled = YES;
  121. _tongjiBtn.enabled = NO;
  122. _tableView.hidden = NO;
  123. }
  124. -(void)changeViewController:(id)sender
  125. {
  126. UISegmentedControl* control = (UISegmentedControl*)sender;
  127. switch (control.selectedSegmentIndex) {
  128. case 0:
  129. _tableView.hidden=YES;
  130. break;
  131. case 1:
  132. _tableView.hidden=NO;
  133. break;
  134. default:
  135. break;
  136. }
  137. }
  138. -(void)mytest:(NSNotification*) notification
  139. {
  140. [self getDataFromSever];
  141. [self GetDatasFromSever];
  142. [self.grid reloadData];
  143. }
  144. -(void)getDataFromSever
  145. {
  146. searchMenuViewManager=[UASNetworkManager shareManager];
  147. searchMenuViewManager.responseSerializer=[AFHTTPResponseSerializer serializer];
  148. NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
  149. NSString *sessionId=[userDefaults stringForKey:@"sessionId"];
  150. NSString *ip=[userDefaults objectForKey:@"ipAndPort"];
  151. NSString *urlStr1=[@"" stringByAppendingFormat: @"%@mobile/common/getMobileQuerys.action?sessionId=%@",ip,sessionId];
  152. //__block NSDictionary *objectDetailArr;
  153. DLog(@"开始请求数据!!!!");
  154. //NSMutableDictionary *params=@{@"Page":@"2"};
  155. NSString *params=@"";
  156. DLog(@"search urlStr=%@",urlStr1);
  157. [searchMenuViewManager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  158. NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
  159. [searchMenuViewManager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
  160. [searchMenuViewManager request:urlStr1 method:POST parameters:params progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  161. DLog(@"成功!");
  162. [GMDCircleLoader hideFromView:self.view animated:YES];
  163. NSData *data=responseObject;
  164. id tempDic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  165. menuViewDataArray=[tempDic objectForKey:@"querys"];
  166. if ([menuViewDataArray isKindOfClass:[NSNull class]]) {
  167. DLog(@"没有数据~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  168. }else
  169. {
  170. allSearchMenu=[NSMutableArray arrayWithArray:menuViewDataArray];
  171. }
  172. [_grid reloadData];
  173. DLog(@"hypishandsomedataall========%@",menuViewDataArray);
  174. DLog(@"allSearchMenu:%lu",(unsigned long)allSearchMenu.count);
  175. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  176. DLog(@"失败 !hkjhkjhjjjjjjjjjjjjjjjjjjjjjj:%@",error);
  177. [GMDCircleLoader hideFromView:self.view animated:YES];
  178. }];
  179. }
  180. -(void)GetDatasFromSever
  181. {
  182. DoublistNetManager=[UASNetworkManager shareManager];
  183. DoublistNetManager.responseSerializer=[AFHTTPResponseSerializer serializer];
  184. NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
  185. NSString *sessionId=[userDefaults stringForKey:@"sessionId"];
  186. NSString *ip=[userDefaults stringForKey:@"ipAndPort"];
  187. NSString *urlStr1=[@"" stringByAppendingFormat:@"%@mobile/common/Stats.action?sessionId=%@",ip,sessionId];
  188. DLog(@"开始请求数据!!!!");
  189. NSString *params=@"";
  190. DLog(@"urlStr=%@",urlStr1);
  191. [DoublistNetManager request:urlStr1 method:POST parameters:params progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  192. DLog(@"成功了吗?????");
  193. [GMDCircleLoader hideFromView:self.view animated:YES];
  194. NSData *data=responseObject;
  195. _TableArry = [[NSMutableArray alloc]init];
  196. id dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  197. preCell=nil;
  198. doubleAllDataDic=[dic objectForKey:@"Stats"];
  199. [self parseDatas];
  200. [_tableView reloadData];
  201. if (doubleAllDataDic.count == 0) {
  202. DLog(@"空了你不知道????");
  203. [self showNoDataView];
  204. }
  205. DLog(@"data=%@",doubleAllDataDic);
  206. DLog(@"hypishandsomelalala:%@",dic);
  207. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  208. DLog(@"失败 !:%@",error);
  209. }];
  210. innum++;
  211. DLog(@"innum>>>>>>>>>>>>>>>>>>>>>>>>>>>>=%ld",(long)innum);
  212. }
  213. //数据解析
  214. -(void)parseDatas
  215. {
  216. datasAllKeys=[doubleAllDataDic allKeys];
  217. for (int i=0; i<[datasAllKeys count]; i++) {
  218. DoubleListCell *cell=[[DoubleListCell alloc] init:NO];
  219. NSArray *array=[doubleAllDataDic objectForKey:[datasAllKeys objectAtIndex:i]] ;
  220. NSMutableArray *childArray = [[NSMutableArray alloc] init];
  221. for (int m =0;m<[array count];m ++) {
  222. DoubleListCell *childCell=[[DoubleListCell alloc] init:YES];
  223. childCell.Name.text=[[array objectAtIndex:m] objectForKey:@"st_title"];
  224. childCell.type= [[array objectAtIndex:m] objectForKey:@"st_type"];
  225. childCell.cellId= [NSString stringWithFormat:@"%@",[[array objectAtIndex:m] objectForKey:@"st_id"]] ;
  226. childCell.ChildArray=nil;
  227. [childArray addObject:childCell];
  228. }
  229. cell.Name.text =[datasAllKeys objectAtIndex:i];
  230. cell.ChildArray=childArray;
  231. [_TableArry addObject:cell];
  232. }
  233. }
  234. //显示暂无数据
  235. -(void)showNoDataView
  236. {
  237. UILabel *noDataLbl = [[UILabel alloc]initWithFrame:self.view.frame];
  238. noDataLbl.center = self.view.center;
  239. noDataLbl.text = @"对不起!暂无数据!";
  240. noDataLbl.textColor = [UIColor lightGrayColor];
  241. noDataLbl.font = [UIFont boldSystemFontOfSize:18];
  242. noDataLbl.textAlignment = NSTextAlignmentCenter;
  243. [self.tableView addSubview:noDataLbl];
  244. }
  245. /******************************统计页面*************************************/
  246. -(void)initDoubleListTable
  247. {
  248. innum = 0;
  249. preCell = nil;
  250. _TableArry = [[NSMutableArray alloc] init];
  251. _InsertArry = [[NSMutableArray alloc] init];
  252. _DeleteArry = [[NSMutableArray alloc] init];
  253. isHadOpen = NO;
  254. //设置背景
  255. UIImageView *backImageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
  256. [backImageView setImage:[UIImage imageNamed:@""]];
  257. self.tableView.backgroundView = backImageView;
  258. self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
  259. UIImageView *testd = [[UIImageView alloc]initWithFrame:self.view.bounds];
  260. testd.image = [UIImage imageNamed:@"uu_background_huibai"];
  261. self.tableView.backgroundView = testd;
  262. //向页面添加一个 加载动画
  263. [GMDCircleLoader setOnView:self.view withTitle:@"Loading" animated:YES];
  264. [self GetDatasFromSever];
  265. //设置切换帐套的监听
  266. //[[NSNotificationCenter defaultCenter] removeObserver:self name:@"mytest" object:nil];
  267. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mytest:) name:@"mytest" object:nil];
  268. }
  269. #pragma mark -- tableView delegate
  270. //返回tableView中cell的个数
  271. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  272. {
  273. return _TableArry.count;
  274. }
  275. //设置 cell 的样式
  276. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  277. {
  278. UITableViewCell *cell = [[DoubleListCell alloc] init];
  279. if (indexPath.row < _TableArry.count)
  280. {
  281. cell = [_TableArry objectAtIndex:indexPath.row];
  282. }
  283. if (indexPath.row%2 == 0) {
  284. cell.backgroundColor = [UIColor colorWithRed:160/255.0 green:160/255.0 blue:160/255.0 alpha:0.1];
  285. }else
  286. {
  287. cell.backgroundColor = [UIColor clearColor];
  288. }
  289. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  290. return cell;
  291. }
  292. //返回cell的高度
  293. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  294. {
  295. return 55;
  296. }
  297. //当cell被选择(被点击)时调用的函数
  298. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  299. {
  300. DoubleListCell *cell = [_TableArry objectAtIndex:indexPath.row];
  301. {
  302. if (!cell.Open)//如果子菜单是关闭的
  303. {
  304. double delayInSeconds = 0.0f;
  305. if (preCell!=cell && preCell.Open && cell.ChildArray.count!=0) {
  306. delayInSeconds = 0.3;
  307. [self closeWithIndex:[_TableArry indexOfObject:preCell] tableView:tableView isAnimation:NO];
  308. preCell.Open = NO;
  309. [UIView animateWithDuration:0.2 animations:^{
  310. if (preCell.Open) {
  311. preCell.iconView.transform = CGAffineTransformMakeRotation(M_PI);
  312. }
  313. else
  314. {
  315. preCell.iconView.transform = CGAffineTransformMakeRotation(0);
  316. }
  317. } completion:^(BOOL finished) {
  318. }];
  319. }
  320. NSArray * array = [self insertOperation:cell];
  321. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
  322. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  323. //[self openWithIndex:[m_datas indexOfObject:m] tableView:tableView isAnimation:NO];
  324. [self.tableView insertRowsAtIndexPaths: array withRowAnimation:UITableViewRowAnimationBottom ];
  325. //cell.Open = YES;
  326. });
  327. isHadOpen=YES;
  328. }
  329. else//如果子菜单是打开的
  330. {
  331. NSArray *array = [self deleteOperation:cell];
  332. if (array.count > 0 )
  333. {
  334. //从视图中删除
  335. [self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationBottom];
  336. }
  337. }
  338. }
  339. if (cell.ChildArray.count == 0)
  340. {
  341. UIStoryboard *testStoryboard = [UIStoryboard storyboardWithName:@"Test" bundle:[NSBundle mainBundle]];
  342. if ([[cell GetType] intValue] == 1)
  343. {
  344. DataItemCharViewController *dataItemCharView = [[DataItemCharViewController alloc] init];
  345. dataItemCharView.m_id = cell.cellId;
  346. dataItemCharView.m_titile = cell.Name.text;
  347. if ([cell.Name.text isEqualToString:@"销售额按天统计"]) {
  348. dataItemCharView.isDay = @"YES";
  349. }else
  350. {
  351. dataItemCharView.isDay = @"NO";
  352. }
  353. [self.navigationController pushViewController:dataItemCharView animated:YES];
  354. }
  355. else
  356. {
  357. PieCharViewController *pieCharVC = [testStoryboard instantiateViewControllerWithIdentifier:@"pieCharView"];
  358. pieCharVC.m_id = cell.cellId;
  359. pieCharVC.m_title = cell.Name.text;
  360. [self.navigationController pushViewController:pieCharVC animated:YES];
  361. }
  362. }
  363. else
  364. {
  365. [UIView animateWithDuration:0.2 animations:^{
  366. if (cell.Open) {
  367. cell.iconView.transform = CGAffineTransformMakeRotation(M_PI);
  368. }else
  369. {
  370. cell.iconView.transform = CGAffineTransformMakeRotation(0);
  371. }
  372. } completion:^(BOOL finished) {
  373. }];
  374. }
  375. }
  376. -(void)closeWithIndex:(NSInteger)index tableView:(UITableView*)tableView isAnimation:(BOOL)animation
  377. {
  378. DoubleListCell* m = _TableArry[index];
  379. NSMutableArray* indexPathArray = [NSMutableArray array];
  380. for (int i = 1; i <= m.ChildArray.count; i++) {
  381. NSIndexPath* subIndexPath = [NSIndexPath indexPathForRow:index+i inSection:0];
  382. [indexPathArray addObject:subIndexPath];
  383. }
  384. NSRange range;
  385. range.length = m.ChildArray.count;
  386. range.location = index+1;
  387. NSIndexSet* indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
  388. [_TableArry removeObjectsAtIndexes:indexSet];
  389. if (animation) {
  390. [tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationFade];
  391. }
  392. else
  393. [tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationNone];
  394. }
  395. -(NSArray *) insertOperation:(DoubleListCell *)item
  396. {
  397. [_InsertArry removeAllObjects];//将插入菜单清空
  398. NSIndexPath *path = [NSIndexPath indexPathForRow:[_TableArry indexOfObject:item] inSection:0];//获取选取的cell的位置
  399. DoubleListCell *child = [[DoubleListCell alloc]init];
  400. //遍历当前选取cell 的子菜单
  401. for(int i=0;i<item.ChildArray.count;i++)
  402. {
  403. child = [item.ChildArray objectAtIndex:i];
  404. [_TableArry insertObject:child atIndex:path.row + i +1 ];//调用数组函数将其插入其中
  405. [_InsertArry addObject:child];//放入插入数组中
  406. }
  407. item.Open=YES;//设置菜单已经打开
  408. NSMutableArray *PathArray= [NSMutableArray array];//初始化用于存放位置的数组
  409. for(DoubleListCell * cell in _InsertArry)
  410. {
  411. NSIndexPath *path = [NSIndexPath indexPathForRow:[_TableArry indexOfObject:cell] inSection:0];
  412. [PathArray addObject:path];
  413. }
  414. return PathArray;
  415. }
  416. -(NSArray *) deleteOperation:(DoubleListCell *)item
  417. {
  418. [_DeleteArry removeAllObjects];//清空删除数组
  419. DoubleListCell *child =[[DoubleListCell alloc]init];//子菜单
  420. for(int i =0;i<item.ChildArray.count;i++)
  421. {
  422. child = [item.ChildArray objectAtIndex:i];
  423. [_DeleteArry addObject:child];//添加到删除数组
  424. }
  425. item.Open = NO;//设置子视图关闭
  426. NSMutableArray *mutableArry = [NSMutableArray array];
  427. NSMutableIndexSet *set= [NSMutableIndexSet indexSet];//设置用来存放删除的cell的索引
  428. for(DoubleListCell *cell in _DeleteArry)
  429. {
  430. NSIndexPath *path = [NSIndexPath indexPathForRow:[_TableArry indexOfObject:cell] inSection:0];
  431. DLog(@"%ld",(long)path.row);
  432. [mutableArry addObject:path];
  433. [set addIndex:path.row];
  434. }
  435. [_TableArry removeObjectsAtIndexes:set];//调用函数来从数组中删除
  436. return mutableArry;
  437. }
  438. /******************************查询页面*************************************/
  439. -(void)initGridView
  440. {
  441. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  442. _grid = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
  443. _grid.dataSource = self;
  444. _grid.delegate = self;
  445. [self.view addSubview:_grid];
  446. //_grid.backgroundColor = addingCellBackColor;
  447. UIImageView *testd = [[UIImageView alloc]initWithFrame:self.view.bounds];
  448. testd.image = [UIImage imageNamed:@"uu_background_huibai"];
  449. _grid.backgroundView = testd;
  450. [_grid registerClass:[SearchCell class] forCellWithReuseIdentifier:cellID];
  451. }
  452. #pragma mark - UICollectionView 代理
  453. //有多少个单元格
  454. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  455. {
  456. DLog(@"你确定先执行吗?????");
  457. //DLog(@"可以的:%lu",(unsigned long)allSearchMenu.count);
  458. return allSearchMenu.count;
  459. }
  460. //每个item的内容
  461. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  462. {
  463. SearchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  464. cell.nameLbl.text = [NSString stringWithFormat:@"%@",[[allSearchMenu objectAtIndex:indexPath.row] objectForKey:@"mq_title"]];
  465. DLog(@"whatthefuck:%@",[[menuViewDataArray objectAtIndex:indexPath.row] objectForKey:@"mq_title"]);
  466. cell.searchImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",_imageArr[indexPath.row]]];
  467. // cell.layer.borderColor=[UIColor darkGrayColor].CGColor;
  468. // cell.layer.borderWidth=2.0;
  469. // cell.nameLbl.text = @"123";
  470. return cell;
  471. }
  472. //设置每个item的大小
  473. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  474. {
  475. CGFloat width = (collectionView.bounds.size.width - ((_count+1) * 20)) / _count;
  476. CGFloat height = width;
  477. return CGSizeMake(width, height);
  478. }
  479. //设置每个item之间的间距
  480. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  481. {
  482. //return UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
  483. return UIEdgeInsetsMake(5, 15, 5, 15);
  484. }
  485. //选择item
  486. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  487. {
  488. UIStoryboard *testStoryboard = [UIStoryboard storyboardWithName:@"Test" bundle:[NSBundle mainBundle]];
  489. OrderFormTableViewController *orderFormController=(OrderFormTableViewController *)[testStoryboard instantiateViewControllerWithIdentifier:@"orderFormController"];
  490. orderFormController.caller=[[allSearchMenu objectAtIndex:indexPath.row] objectForKey:@"mq_caller"];
  491. orderFormController.titile=[[allSearchMenu objectAtIndex:indexPath.row] objectForKey:@"mq_title"];
  492. orderFormController.isHaveCreatList = @"NO";
  493. orderFormController.is49 = @"NO";
  494. [self.navigationController pushViewController:orderFormController animated:YES];
  495. }
  496. - (void)didReceiveMemoryWarning {
  497. [super didReceiveMemoryWarning];
  498. // Dispose of any resources that can be recreated.
  499. }
  500. @end