// // LogListViewController.m // IBOSSmini // // Created by guan hong hou on 2017/5/5. // Copyright © 2017年 elongtian. All rights reserved. // #import "LogListViewController.h" #import "SideSlipModel.h" #import "LogSearchModel.h" @interface LogListViewController () @end static int navcount = 4; @implementation LogListViewController #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title=@"日志"; [self initUI]; [self setMainSrollView]; [self sliderWithTag:self.currentIndex+1]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0, 15, 18); UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = menuButton; //保存 UIButton* btnAdd = [UIButton buttonWithType:UIButtonTypeCustom]; [btnAdd setBackgroundImage:[UIImage imageNamed:@"title_add.png"] forState:UIControlStateNormal]; [btnAdd addTarget:self action:@selector(newLog) forControlEvents:UIControlEventTouchUpInside]; // UIImage *pic =[UIImage imageNamed:@"title_add"]; btnAdd.frame = CGRectMake(0, 0,18,18); UIBarButtonItem* _menuButton2 = [[UIBarButtonItem alloc] initWithCustomView:btnAdd]; self.navigationItem.rightBarButtonItem = _menuButton2; __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]; LogSearchModel *m = [serviceRegionModel.customDict objectForKey:SEARCH_RANGE_MODEL]; if(self.currentIndex==1){ _allVC.recordStatus=@""; _allVC.startDate=m.startDate; _allVC.endDate=m.endDate; _allVC.createUserIds=m.createUserId; [ _allVC.dataList removeAllObjects]; [_allVC refresh]; } else if(self.currentIndex==2){ _noCommentVC.recordStatus=@"0"; _noCommentVC.startDate=m.startDate; _noCommentVC.endDate=m.endDate; _noCommentVC.createUserIds=m.createUserId; [_noCommentVC.dataList removeAllObjects]; [_noCommentVC refresh]; } else if(self.currentIndex==3){ _haveCommentVC.recordStatus=@"1"; _haveCommentVC.startDate=m.startDate; _haveCommentVC.endDate=m.endDate; [_haveCommentVC.dataList removeAllObjects]; _haveCommentVC.createUserIds=m.createUserId; [_haveCommentVC refresh]; } [weakself.filterController dismiss]; }]; _filterController.animationDuration = AnimationDuration; _filterController.hasHeadView = YES; _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width; _filterController.dataList = [self packageDataList]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ self.view.backgroundColor = [UIColor whiteColor]; _mainScrollView.frame = CGRectMake(0, 40, Screen_Width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40); for (NSInteger i = 0; i < _mainScrollView.subviews.count; i++) { _mainScrollView.subviews[i].frame = CGRectMake(Screen_Width * i, 0, Screen_Width,CGRectGetHeight(_mainScrollView.frame)); } [self.allVC viewSafeAreaInsetsDidChange]; [self.noCommentVC viewSafeAreaInsetsDidChange]; [self.haveCommentVC viewSafeAreaInsetsDidChange]; [super viewSafeAreaInsetsDidChange]; } #pragma mark - 委托函数 -(void)refreshData{ if(self.currentIndex==1){ _allVC.recordStatus=@""; [ _allVC.dataList removeAllObjects]; [_allVC refresh]; } else if(self.currentIndex==2){ _noCommentVC.recordStatus=@"0"; [_noCommentVC.dataList removeAllObjects]; [_noCommentVC refresh]; } else if(self.currentIndex==3){ _haveCommentVC.recordStatus=@"1"; [_haveCommentVC.dataList removeAllObjects]; [_haveCommentVC refresh]; } } #pragma mark - 私有函数 - (void)searchLogData{ [_filterController show]; } /** 数据源 @return <#return value description#> */ - (NSArray *)packageDataList { NSMutableArray *dataArray = [NSMutableArray array]; SideSlipModel *model = [[SideSlipModel alloc] init]; model.containerCellClass = @"LogSearchTableViewCell"; model.regionTitle = @"查询条件"; [dataArray addObject:model]; return [dataArray mutableCopy]; } /** * 新增日志 */ -(void)newLog{ self.hidesBottomBarWhenPushed=YES; LogAddViewController *newVC=[[LogAddViewController alloc] init]; newVC.refreshDelegate=self; [self.navigationController pushViewController:newVC animated:YES]; } /** * 返回函数 */ -(void)goBack { [self.navigationController popViewControllerAnimated:YES]; } -(void)initUI{ UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 40)]; [self.view addSubview:navView]; [self.view setBackgroundColor:[UIColor whiteColor]]; _allButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_allButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; [_allButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; _allButton.frame = CGRectMake(0, 0, Screen_Width/navcount, navView.frame.size.height); _allButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize]; [_allButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside]; [_allButton setTitle:@"全部" forState:UIControlStateNormal]; _allButton.tag = 1; _allButton.selected = YES; [navView addSubview:_allButton]; _noCommentButton= [UIButton buttonWithType:UIButtonTypeCustom]; _noCommentButton.frame = CGRectMake(CGRectGetMaxX(_allButton.frame),0, Screen_Width/navcount, navView.frame.size.height); [ _noCommentButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; [ _noCommentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; _noCommentButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize]; [ _noCommentButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside]; [_noCommentButton setTitle:@"未点评" forState:UIControlStateNormal]; _noCommentButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize]; _noCommentButton.tag = 2; [navView addSubview:_noCommentButton]; _haveCommentButton= [UIButton buttonWithType:UIButtonTypeCustom]; _haveCommentButton.frame = CGRectMake(CGRectGetMaxX(_noCommentButton.frame),0, Screen_Width/navcount, navView.frame.size.height); [_haveCommentButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; [_haveCommentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [ _haveCommentButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside]; [_haveCommentButton setTitle:@"已点评" forState:UIControlStateNormal]; _haveCommentButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize]; _haveCommentButton.tag = 3; [navView addSubview:_haveCommentButton]; _sliderLabel = [[UILabel alloc]initWithFrame:CGRectMake(_allButton.frame.origin.x, 40-2, Screen_Width/navcount, 2)]; _sliderLabel.backgroundColor = [UIColor redColor]; [navView addSubview:_sliderLabel]; _filterButton=[UIButton buttonWithType:UIButtonTypeCustom]; _filterButton.frame=CGRectMake(CGRectGetMaxX(_haveCommentButton.frame),0,Screen_Width/navcount, navView.frame.size.height); UIImageView *filterImg=[[UIImageView alloc] initWithFrame:CGRectMake(_filterButton.bounds.size.width/2-25,15,10, 10)]; [filterImg setImage:[UIImage imageNamed:@"icon_filter"]]; [_filterButton addSubview:filterImg]; filterImg.userInteractionEnabled=NO; UILabel *filterLbl=[[UILabel alloc]init]; filterLbl.frame=CGRectMake(CGRectGetMaxX(filterImg.frame)+3,10,50, 20); filterLbl.text=@"筛选"; filterLbl.font=[UIFont systemFontOfSize:ButtonFontOfSize]; [_filterButton addSubview:filterLbl]; [_filterButton addTarget:self action:@selector(searchLogData) forControlEvents:UIControlEventTouchUpInside]; [navView addSubview:_filterButton]; } /** 全部vc @return <#return value description#> */ - (LogAllViewController *)allVC{ if (_allVC==nil) { _allVC = [[LogAllViewController alloc] init]; _allVC.cNav=self.navigationController; } return _allVC; } /** 未点评vc @return <#return value description#> */ - (LogAllViewController *)noCommentVC{ if (_noCommentVC==nil) { _noCommentVC = [[LogAllViewController alloc] init]; _noCommentVC.cNav=self.navigationController; } return _noCommentVC; } /** 装修信息vc @return <#return value description#> */ - (LogAllViewController *)haveCommentVC{ if (_haveCommentVC==nil) { _haveCommentVC = [[LogAllViewController alloc] init]; _haveCommentVC.cNav=self.navigationController; } return _haveCommentVC; } /** 按钮点击事件 @param sender <#sender description#> */ - (void)sliderAction:(UIButton *)sender{ if (self.currentIndex==sender.tag) { return; } [self sliderAnimationWithTag:sender.tag]; [UIView animateWithDuration:0.3 animations:^{ _mainScrollView.contentOffset = CGPointMake(Screen_Width*(sender.tag-1), 0); } completion:^(BOOL finished) { }]; if(_currentIndex==1){ self.allVC.recordStatus=@""; [_allVC refresh]; } else if(_currentIndex==2){ self.noCommentVC.recordStatus=@"0"; [_noCommentVC refresh]; } else if(_currentIndex==3){ self.haveCommentVC.recordStatus=@"1"; [_haveCommentVC refresh]; } } /** 滑动tag @param tag <#tag description#> */ - (void)sliderWithTag:(NSInteger)tag{ self.currentIndex = tag; _allButton.selected = NO; _noCommentButton.selected = NO; _haveCommentButton.selected = NO; UIButton *sender = [self buttonWithTag:tag]; sender.selected = YES; //动画 _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height); if(_currentIndex==1){ self.allVC.recordStatus=@""; [_allVC refresh]; } else if(_currentIndex==2){ self.noCommentVC.recordStatus=@"0"; [_noCommentVC refresh]; } else if(_currentIndex==3){ self.haveCommentVC.recordStatus=@"1"; [_haveCommentVC refresh]; } } /** 滑动tag @param tag <#tag description#> */ - (void)sliderAnimationWithTag:(NSInteger)tag{ self.currentIndex = tag; _allButton.selected = NO; _noCommentButton.selected = NO; _haveCommentButton.selected = NO; UIButton *sender = [self buttonWithTag:tag]; sender.selected = YES; //动画 [UIView animateWithDuration:0.3 animations:^{ _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height); } completion:^(BOOL finished) { }]; } - (UIButton *)buttonWithTag:(NSInteger )tag{ if (tag==1) { return _allButton; }else if (tag==2){ return _noCommentButton; } else if (tag==3){ return _haveCommentButton; } else{ return nil; } } /** 初始化srollView */ - (void)setMainSrollView{ _mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 40, Screen_Width, self.view.frame.size.height)]; _mainScrollView.delegate = self; _mainScrollView.backgroundColor = [UIColor whiteColor]; _mainScrollView.pagingEnabled = YES; _mainScrollView.showsHorizontalScrollIndicator = NO; _mainScrollView.showsVerticalScrollIndicator = NO; [self.view addSubview:_mainScrollView]; NSArray *views = @[self.allVC.view,self.noCommentVC.view , self.haveCommentVC.view]; for (NSInteger i = 0; i< views.count; i++) { //把三个vc的view依次贴到mainScrollView上面 UIView *pageView = [[UIView alloc]initWithFrame:CGRectMake(Screen_Width * i, 0, _mainScrollView.frame.size.width, _mainScrollView.frame.size.height-100)]; //将子view的高度与父view的高度相同 ((UIView*)views[i]).frame = CGRectMake(0,0,self.view.frame.size.width,pageView.frame.size.height); [pageView addSubview:views[i]]; [_mainScrollView addSubview:pageView]; } _mainScrollView.contentSize = CGSizeMake(Screen_Width*(views.count), 0); //滚动到_currentIndex对应的tab [_mainScrollView setContentOffset:CGPointMake((_mainScrollView.frame.size.width)*_currentIndex, 0) animated:YES]; } /** 滑动label位置 @param scrollView <#scrollView description#> */ - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ //实时计算当前位置,实现和titleView上的按钮的联动 CGFloat contentOffSetX = scrollView.contentOffset.x; CGFloat X = contentOffSetX/ navcount; CGRect frame = _sliderLabel.frame; frame.origin.x = X; _sliderLabel.frame = frame; [self.allVC closeKeyboard]; [self.noCommentVC closeKeyboard]; [self.haveCommentVC closeKeyboard]; } /** 滑动完成 @param scrollView <#scrollView description#> */ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ CGFloat contentOffSetX = scrollView.contentOffset.x; int index_ = contentOffSetX/Screen_Width; [self sliderWithTag:index_+1]; } @end