// // SettingViewController.m // IBOSS // // Created by apple on 2017/5/4. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved. // // 功能描述:设置控制器 // #import "MineViewController.h" #import "PWModifyViewController.h" #import "Reachability.h" #import "Util.h" @interface MineViewController (){ UIScrollView *scroll; // 滑动线 UILabel *_sliderLabel; // 滚动条 UIScrollView *_mainScrollView; // 基本信息按钮 UIButton *_lastMonthBtn; // 业绩信息按钮 UIButton *_currentMonthBtn; // 装修信息按钮 UIButton *_currentYearBtn; CurrentStaffLastMonthPerformanceRankVc *lastMonthRankVc; CurrentStaffCurrentMonthPerformanceRankVc *currentMonthRankVc; CurrentStaffCurrentYearPerformanceRankVc *currentYearRankVc; } /** ASIDownManager请求对象 */ @property (nonatomic,strong) ASIDownManager *downManager; @end static int navcount = 3; @implementation MineViewController #pragma mark - 公共函数 /** viewDidLoad */ - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"iBOSS"; UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)]; //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。 tapGestureRecognizer.cancelsTouchesInView = NO; //将触摸事件添加到当前view [self.view addGestureRecognizer:tapGestureRecognizer]; _staffList=[[NSMutableArray alloc]init]; [self initUI]; [self loadStaffData]; } /** didReceiveMemoryWarning */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - 私有函数 /** 初始化ui */ - (void)initUI{ [self.view setBackgroundColor:[UIColor whiteColor]]; UIImage *pic = [UIImage imageNamed:@"banner_setting"]; UIImageView *bannerView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.width*pic.size.height/pic.size.width)]; [bannerView setImage:pic]; [self.view addSubview:bannerView]; UIView *separatorView = [[UIView alloc]init]; [separatorView setBackgroundColor:LineBackgroundColor]; separatorView.frame=CGRectMake(0, CGRectGetMaxY(bannerView.frame), self.view.frame.size.width, 10); [self.view addSubview: separatorView]; CGFloat titleHeight = 50; CGFloat lblx = 20; CGFloat fontsize = 14; CGFloat valuey = 13; CGFloat valueheight = 25; CGFloat heightLine =1; CGFloat height = 350; scroll = [UIScrollView new]; scroll.frame=CGRectZero; [self.view addSubview:scroll]; //头布局 UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(separatorView.frame), Screen_Width, height)]; UIButton *btnHead = [UIButton buttonWithType:UIButtonTypeCustom]; btnHead.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [scroll addSubview: headView]; //名称 ————————— UIView *vname = [UIView new]; vname.frame=CGRectMake(0, 0, Screen_Width, titleHeight); [headView addSubview:vname]; UILabel *lbtotal = [UILabel new]; lbtotal.frame=CGRectMake(lblx, valuey, Screen_Width - 3*lblx, valueheight); lbtotal.font = [UIFont boldSystemFontOfSize:fontsize]; NSString *str = [NSString stringWithFormat:@"用户名:%@(%@)",kkUserName,kkUserCode]; lbtotal.text = str; [vname addSubview:lbtotal]; bannerView = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width - lblx - 18,valuey+4,18,12.5)]; [bannerView setImage:[UIImage imageNamed:@"setting_right"]]; [vname addSubview:bannerView]; //分割线 UIView *viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vname.frame), Screen_Width, 10); viewBackgroud.backgroundColor = LineBackgroundColor; [headView addSubview:viewBackgroud]; UIView *vPerformanceTargetTitle = [UIView new]; vPerformanceTargetTitle.frame=CGRectMake(0,CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [headView addSubview:vPerformanceTargetTitle]; UIImageView *imgview1 = [UIImageView new]; imgview1.frame=CGRectMake(Screen_Width/2-35-17,valuey+3, 14, 19); [imgview1 setImage:[UIImage imageNamed:@"performancerank"]]; [vPerformanceTargetTitle addSubview:imgview1]; UILabel *lblPerformanceTargetTitle = [UILabel new]; lblPerformanceTargetTitle.frame=CGRectMake(Screen_Width/2-35, valuey, 70, valueheight); lblPerformanceTargetTitle.font = [UIFont boldSystemFontOfSize:17]; lblPerformanceTargetTitle.text =@"业绩目标"; [vPerformanceTargetTitle addSubview:lblPerformanceTargetTitle]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vPerformanceTargetTitle.frame), Screen_Width, heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [headView addSubview:viewBackgroud]; UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(viewBackgroud.frame), Screen_Width, 40)]; [headView setBackgroundColor:[UIColor whiteColor]]; [headView addSubview:navView]; _lastMonthBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_lastMonthBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; [_lastMonthBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; _lastMonthBtn.frame = CGRectMake(2, 0, Screen_Width/navcount, navView.frame.size.height); _lastMonthBtn.titleLabel.font = [UIFont systemFontOfSize:TitleFontOfSize]; [_lastMonthBtn addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside]; [_lastMonthBtn setTitle:@"上月" forState:UIControlStateNormal]; _lastMonthBtn.tag = 1; _lastMonthBtn.selected = YES; [navView addSubview:_lastMonthBtn]; _currentMonthBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _currentMonthBtn.frame = CGRectMake(_lastMonthBtn.frame.origin.x+_lastMonthBtn.frame.size.width, _lastMonthBtn.frame.origin.y, Screen_Width/navcount, navView.frame.size.height); [_currentMonthBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; [_currentMonthBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; _currentMonthBtn.titleLabel.font = [UIFont systemFontOfSize:TitleFontOfSize]; [_currentMonthBtn addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside]; [_currentMonthBtn setTitle:@"本月" forState:UIControlStateNormal]; _currentMonthBtn.tag = 2; [navView addSubview:_currentMonthBtn]; // 装修 _currentYearBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _currentYearBtn.frame = CGRectMake(_currentMonthBtn.frame.origin.x+_currentMonthBtn.frame.size.width, _currentMonthBtn.frame.origin.y, Screen_Width/navcount, navView.frame.size.height); [_currentYearBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; [_currentYearBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; _currentYearBtn.titleLabel.font = [UIFont systemFontOfSize:TitleFontOfSize]; [_currentYearBtn addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside]; [_currentYearBtn setTitle:@"本年" forState:UIControlStateNormal]; _currentYearBtn.tag = 3; [navView addSubview:_currentYearBtn]; // 选中后的红线 _sliderLabel = [[UILabel alloc]initWithFrame:CGRectMake(_lastMonthBtn.frame.origin.x, 40-2, Screen_Width/navcount, 2)]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(((Screen_Width/navcount)-75)/2, 0, 75, 2)]; line.backgroundColor = [UIColor redColor]; [_sliderLabel addSubview:line]; [navView addSubview:_sliderLabel]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(navView.frame), Screen_Width, 1); viewBackgroud.backgroundColor = LineBackgroundColor; [headView addSubview:viewBackgroud]; // 滚动view _mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(viewBackgroud.frame), Screen_Width,180)]; _mainScrollView.delegate = self; _mainScrollView.backgroundColor = [UIColor whiteColor]; _mainScrollView.pagingEnabled = YES; _mainScrollView.showsHorizontalScrollIndicator = NO; _mainScrollView.showsVerticalScrollIndicator = NO; [headView addSubview:_mainScrollView]; lastMonthRankVc=[[CurrentStaffLastMonthPerformanceRankVc alloc]init]; currentMonthRankVc=[[CurrentStaffCurrentMonthPerformanceRankVc alloc]init]; currentYearRankVc=[[CurrentStaffCurrentYearPerformanceRankVc alloc]init]; NSArray *views = @[lastMonthRankVc.view,currentMonthRankVc.view , currentYearRankVc.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)]; [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]; [self sliderWithTag:self.currentIndex+1]; [self sliderAction:_currentMonthBtn]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(_mainScrollView.frame), Screen_Width, 10); viewBackgroud.backgroundColor = LineBackgroundColor; [headView addSubview:viewBackgroud]; float margin = 5; CGRect cg = CGRectMake(Screen_Width - lblx - 9,valuey+4,9,15 ); UIView *vPerformanceRank = [UIView new]; vPerformanceRank.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [headView addSubview:vPerformanceRank]; UIImageView *imgview; imgview = [UIImageView new]; imgview.frame=CGRectMake(lblx, valuey + margin, 15, 16); [imgview setImage:[UIImage imageNamed:@"performancerank"]]; [vPerformanceRank addSubview:imgview]; UIButton *btnPerformanceRank= [UIButton buttonWithType:UIButtonTypeCustom]; btnPerformanceRank.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight); btnPerformanceRank.userInteractionEnabled=YES; btnPerformanceRank.titleLabel.font = [UIFont systemFontOfSize:fontsize]; btnPerformanceRank.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [btnPerformanceRank setTitle:@"业绩排行" forState:UIControlStateNormal]; [btnPerformanceRank setTitleColor:NavTitleColor forState:UIControlStateNormal]; [btnPerformanceRank addTarget:self action:@selector(performanceRank) forControlEvents:UIControlEventTouchUpInside]; [vPerformanceRank addSubview:btnPerformanceRank]; bannerView = [[UIImageView alloc] initWithFrame:cg]; [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]]; [vPerformanceRank addSubview:bannerView]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vPerformanceRank.frame), Screen_Width,heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [headView addSubview:viewBackgroud]; UIView *vSetting = [UIView new]; vSetting.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [headView addSubview:vSetting]; imgview = [UIImageView new]; imgview.frame=CGRectMake(lblx, valuey + margin, 15, 15); [imgview setImage:[UIImage imageNamed:@"setting"]]; [vSetting addSubview:imgview]; UIButton *btnSetting= [UIButton buttonWithType:UIButtonTypeCustom]; btnSetting.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight); btnSetting.userInteractionEnabled=YES; btnSetting.titleLabel.font = [UIFont systemFontOfSize:fontsize]; btnSetting.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [btnSetting setTitle:@"设置" forState:UIControlStateNormal]; [btnSetting setTitleColor:NavTitleColor forState:UIControlStateNormal]; [btnSetting addTarget:self action:@selector(setting) forControlEvents:UIControlEventTouchUpInside]; [vSetting addSubview:btnSetting]; cg = CGRectMake(Screen_Width - lblx - 9,valuey+4,9,15 ); bannerView = [[UIImageView alloc] initWithFrame:cg]; [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]]; [vSetting addSubview:bannerView]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vSetting.frame), Screen_Width,10); viewBackgroud.backgroundColor = LineBackgroundColor; [headView addSubview:viewBackgroud]; headView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(viewBackgroud.frame)); scroll.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(headView.frame)+rectStatusHeight+rectNavHeight); scroll.frame=CGRectMake(0, CGRectGetMaxY(separatorView.frame), Screen_Width,self.view.frame.size.height-CGRectGetMaxY(separatorView.frame)-rectStatusHeight-rectNavHeight); // // viewBackgroud = [UIView new]; // viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vPerformanceRank.frame), Screen_Width,heightLine); // viewBackgroud.backgroundColor = LineBackgroundColor; // [headView addSubview:viewBackgroud]; // UIView *vNotification = [UIView new]; // vNotification.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); // [headView addSubview:vNotification]; // // imgview = [UIImageView new]; // imgview.frame=CGRectMake(lblx, valuey + margin, 15, 15); // [imgview setImage:[UIImage imageNamed:@"notification"]]; // [vNotification addSubview:imgview]; // // UIButton *btnNotification= [UIButton buttonWithType:UIButtonTypeCustom]; // btnNotification.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight); // btnNotification.titleLabel.font = [UIFont systemFontOfSize:fontsize]; // btnNotification.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; // [btnNotification setTitle:@"通知公告" forState:UIControlStateNormal]; // [btnNotification setTitleColor:NavTitleColor forState:UIControlStateNormal]; // [btnNotification addTarget:self action:@selector(notification) forControlEvents:UIControlEventTouchUpInside]; // [vNotification addSubview:btnNotification]; // // bannerView = [[UIImageView alloc] initWithFrame:cg]; // [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]]; // [vNotification addSubview:bannerView]; // // viewBackgroud = [UIView new]; // viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vNotification.frame), Screen_Width,heightLine); // viewBackgroud.backgroundColor = LineBackgroundColor; // [headView addSubview:viewBackgroud]; } /** 滑动tag @param tag <#tag description#> */ - (void)sliderWithTag:(NSInteger)tag{ self.currentIndex = tag; _lastMonthBtn.selected = NO; _currentMonthBtn.selected = NO; _currentYearBtn.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); } /** 滑动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; if(X > _sliderLabel.frame.size.width/2){ UIView *line = _sliderLabel.subviews[0]; line.frame = CGRectMake(((Screen_Width/navcount)-40)/2, 0, 40, 2); }else{ UIView *line = _sliderLabel.subviews[0]; line.frame = CGRectMake(((Screen_Width/navcount)-70)/2, 0, 70, 2); } } /** 滑动完成 @param scrollView <#scrollView description#> */ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ CGFloat contentOffSetX = scrollView.contentOffset.x; int index_ = contentOffSetX/Screen_Width; [self sliderWithTag:index_+1]; } /** 返回相应的button @param tag <#tag description#> @return <#return value description#> */ - (UIButton *)buttonWithTag:(NSInteger )tag{ if (tag == 1) { return _lastMonthBtn; }else if (tag == 2){ return _currentMonthBtn; } else if (tag == 3){ return _currentYearBtn; } else{ return nil; } } /** 按钮点击事件 @param sender <#sender description#> */ - (void)sliderAction:(UIButton *)sender{ if (self.currentIndex == sender.tag) { return; } // 切换controller [self.view endEditing:YES]; [self sliderAnimationWithTag:sender.tag]; [UIView animateWithDuration:0.3 animations:^{ _mainScrollView.contentOffset = CGPointMake(Screen_Width*(sender.tag-1), 0); } completion:^(BOOL finished) { }]; } /** 滑动tag @param tag <#tag description#> */ - (void)sliderAnimationWithTag:(NSInteger)tag{ self.currentIndex = tag; _lastMonthBtn.selected = NO; _currentMonthBtn.selected = NO; _currentYearBtn.selected = NO; UIButton *sender = [self buttonWithTag:tag]; sender.selected=YES; [sender sendActionsForControlEvents:(UIControlEventTouchUpInside)]; //动画 [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) { }]; } /** 隐藏键盘 @param tap <#tap description#> */ - (void)keyboardHide:(UITapGestureRecognizer*)tap{ [self.view endEditing:YES]; } -(void)loadStaffData{ NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetStaffRelations" 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:kkUserID forKey:@"UserID"]; self.downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.onRequestSuccess = @selector(onStaffLoadFinish:); _downManager.onRequestFail = @selector(onStaffLoadFail:); [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 加载数据成功回调 @param sender <#sender description#> */ - (void)onStaffLoadFinish:(ASIDownManager *)sender { // 服务器返回数据 RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; // 服务器返回数据状态值 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)onStaffLoadFail:(ASIDownManager *)sender { [self showAlertViewText:@"网络异常"]; } -(void)performanceRank{ PerformanceRankListVc *rankVc=[[PerformanceRankListVc alloc]init]; self.hidesBottomBarWhenPushed=YES; rankVc.staffList=_staffList; [self.navigationController setNavigationBarHidden:NO animated:YES]; [self.navigationController pushViewController:rankVc animated:YES]; self.hidesBottomBarWhenPushed=NO; } -(void)setting{ SettingViewController *setVc=[[SettingViewController alloc]init]; self.hidesBottomBarWhenPushed=YES; [self.navigationController setNavigationBarHidden:NO animated:YES]; [self.navigationController pushViewController:setVc animated:YES]; self.hidesBottomBarWhenPushed=NO; } -(void)notification{ self.hidesBottomBarWhenPushed=YES; NotificationHomeVc *homeVC = [[NotificationHomeVc alloc] init]; [self.navigationController pushViewController:homeVC animated:YES]; [self.navigationController setNavigationBarHidden:NO animated:YES]; self.hidesBottomBarWhenPushed=NO; } @end