123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026 |
- //
- // statisticsVC.m
- // LN_School
- //
- // Created by apple on 2017/4/5.
- // Copyright © 2017年 Danson. All rights reserved.
- //
- #define KSetxywh initWithFrame:CGRectMake(x, y, w, h)
- #define kLineColor [UIColor colorWithWhite:.3 alpha:.1]
- #define KTitleColor [UIColor colorWithRed:70/255.0 green:70/255.0 blue:70/255.0 alpha:1]
- #define KSubTitleColor [UIColor colorWithWhite:.3 alpha:1]
- #define KContentTextColor [UIColor colorWithRed:110/255.0 green:110/255.0 blue:110/255.0 alpha:1]
- #import "statisticsVC.h"
- #import "DateView.h"
- #import "XDBarView.h"
- #import "NetworkManager.h"
- @interface statisticsVC ()
- {
- //日历
- UILabel *calendarLabel;
- UIButton *calendarbtn;
- UIView *calendarView;
- UIButton *lastDatebtn;
- UILabel *numberLabel;
- UILabel *compareNumLabel;
- //自定义日期
- UIView *backView;
- UIButton *beginBtn,*endBtn;
- NSString *searchStartTime;
- NSString *searchEndTime;
-
- NSString *todayString;
- NSString *yesterdayString;
- NSString *weekNow;
- NSString *weekLast;
- NSString *monthNow;
- NSString *monthLast;
-
- NSString *startDateString;
- NSString *endDateString;
-
- // 1代表是日 2代表周 3代表月 4代表年
- NSInteger dateType;
-
-
- //角色权限
- NSInteger roleId;//对应登陆信息usertype
- NSString *dqbh;
- NSString *qxbh;
- UIButton *backLastRoleBtn;
- NSArray *numDataArray;
-
- //柱状图大小开关
- UILabel *rankLabel;
- NSInteger rankNum;
- }
- @property (nonatomic,strong) XDBarView *barview;
- @end
- @implementation statisticsVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title = @"报名统计";
- self.view.backgroundColor = [UIColor whiteColor];
-
- [self myInit];
- }
- - (void)myInit {
-
- //顶部日历条
- CGFloat x, y, w, h, bd;
- bd = 10;
- x = 0;
- y = kNavOffSet;
- w = kSize.width;
- h = 50;
-
- UIView *view = [[UIView alloc] KSetxywh];
- view.backgroundColor = COLOR_THEME;
- [self.view addSubview:view];
-
- x = y = bd;
- w = h = 30;
- UIImageView *imgView = [[UIImageView alloc] KSetxywh];
- [imgView setModeAspectFill];
- imgView.image = [UIImage imageNamed:@"arrow_left"];
- [view addSubview:imgView];
-
- x = kSize.width - w - bd;
- imgView = [[UIImageView alloc] KSetxywh];
- [imgView setModeAspectFill];
- imgView.image = [UIImage imageNamed:@"arrow_right"];
- [view addSubview:imgView];
-
- x = y = 0;
- w = 70;
- h = 50;
- UIButton *btn = [[UIButton alloc] KSetxywh];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- btn.tag = 1;
- [view addSubview:btn];
-
- x = kSize.width - w;
- btn = [[UIButton alloc] KSetxywh];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- btn.tag = 2;
- [view addSubview:btn];
-
- x = w;
- w = kSize.width - 2*x;
- btn = [[UIButton alloc] KSetxywh];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- btn.tag = 3;
- [view addSubview:btn];
- calendarbtn = btn;
-
- x = 0;
- w = kSize.width;
- UILabel *label = [[UILabel alloc] KSetxywh];
- label.text = @"请选择日期 ▽";
- label.textColor = [UIColor whiteColor];
- label.font = [UIFont systemFontOfSize:16];
- label.textAlignment = NSTextAlignmentCenter;
- [view addSubview:label];
- calendarLabel = label;
-
-
- //折线图大小开关
- rankNum = 3;
-
- y +=kNavOffSet + h + 4*bd;
- w = kSize.width - 10 - 40 - 25 - 40;
- h = 25;
- label = [[UILabel alloc] KSetxywh];
- label.text = @"统计图比例:";
- label.textColor = [UIColor grayColor];
- label.font = [UIFont systemFontOfSize:16];
- label.textAlignment = NSTextAlignmentRight;
- [self.view addSubview:label];
-
- x += w;
- w = 40;
- y -= 5;
- h += 10;
- btn = [[UIButton alloc] KSetxywh];
- [btn setTitle:@"-" forState:UIControlStateNormal];
- btn.titleLabel.font = [UIFont systemFontOfSize:22];
- [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- btn.tag = 9;
- [self.view addSubview:btn];
-
- x += w;
- w = 25;
- y += 5;
- h -= 10;
- label = [[UILabel alloc] KSetxywh];
- label.text = [NSString stringWithFormat:@"%ld",rankNum];
- label.textColor = [UIColor grayColor];
- label.font = [UIFont systemFontOfSize:17];
- label.textAlignment = NSTextAlignmentCenter;
- label.layer.masksToBounds = YES;
- label.layer.cornerRadius = h/2;
- label.layer.borderWidth = 1;
- label.layer.borderColor = COLOR_THEME.CGColor;
- [self.view addSubview:label];
- rankLabel = label;
-
- x += w;
- w = 40;
- y -= 5;
- h += 10;
- btn = [[UIButton alloc] KSetxywh];
- [btn setTitle:@"+" forState:UIControlStateNormal];
- btn.titleLabel.font = [UIFont systemFontOfSize:21];
- [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- btn.tag = 10;
- [self.view addSubview:btn];
-
-
-
- //折线图
- y += h + bd;
- x = 0;
- w = kSize.width;
- h = kSize.height - y - kNavOffSet - kTabBarHeight;
-
- //kSize.width * 0.67
- _barview = [[XDBarView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- _barview.barWith = 30;
- _barview.cellHeight = 60;
- _barview.defaultColor = ColorWithHEAL;//ColorWithRGB(218, 218, 218)
- _barview.SelectColor = ColorWithHEAL;
- [self.view addSubview:_barview];
- //柱子被点击的回调
- [_barview selectedWithTableViewPathRowBlock:^(NSString *colname, NSInteger row) {
-
- //NSLog(@"%ld点击了柱子colname == %@",(long)row,colname);
- if (roleId >= 3) {
- //已经是最底层了
- return;
- }
- backLastRoleBtn.hidden = NO;
- roleId ++;
-
- if (roleId == 2) {
- dqbh = colname;
- }else {
- qxbh = colname;
- }
-
- [self getPeopleNum];
- //roleId 1省级 2地市 3区县
- }];
-
-
- roleId = [MYAPPDELEGATE.userDic[@"userType"] integerValue];
- dqbh = MYAPPDELEGATE.userDic[@"dqbh"];
- qxbh = MYAPPDELEGATE.userDic[@"qxbh"];
-
- searchStartTime = @"";
- searchEndTime = @"";
-
-
- //返回上一级
- x = 20;
- y = kSize.height-kTabBarHeight-50-(kNavOffSet-50)/2;
- w = kSize.width - 2*x;
- h = 50;
- btn = [[UIButton alloc] KSetxywh];
- btn.backgroundColor = COLOR_THEME;
- [btn setTitle:@"返回上一级" forState:UIControlStateNormal];
- [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- btn.layer.masksToBounds = YES;
- btn.layer.cornerRadius = 10;
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- btn.tag = 8;
- [self.view addSubview:btn];
- btn.hidden = YES;
- backLastRoleBtn = btn;
-
-
- //隐藏的日期选择
- x = 0;
- y = kNavOffSet + 50;
- w = kSize.width;
- h = kSize.height - y;
- view = [[UIView alloc] KSetxywh];
- view.backgroundColor = [UIColor colorWithWhite:.7 alpha:1.0];
- [self.view addSubview:view];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap)];
- [view addGestureRecognizer:tap];
- calendarView = view;
-
- y = 0;
- h = 170;
- view = [[UIView alloc] KSetxywh];
- view.backgroundColor = KBackGroundColor;
- [calendarView addSubview:view];
-
- x = bd;
- w -= 2*x;
- h = 40;
- label = [[UILabel alloc] KSetxywh];
- label.text = @"日期";
- label.textColor = [UIColor blackColor];
- label.font = [UIFont systemFontOfSize:17];
- [view addSubview:label];
-
- y += h;
- w = (kSize.width - 40)/3.0;
- h = 30;
- NSArray *titleArray = @[@"今日",@"昨日",@"本周",@"上周",@"本月",@"上月"];
- for (int i = 0; i < titleArray.count; i ++) {
-
- int row = i/3;
- int column = i%3;
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x + column*(w + bd), y + row*(h + bd), w, h)];
-
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- btn.tag = i-6;
- [btn setTitle:titleArray[i] forState:UIControlStateNormal];
- [btn setBackgroundColor:kLineColor];
- [btn setTitleColor:KSubTitleColor forState:UIControlStateNormal];
- [btn setTitleColor:COLOR_THEME forState:UIControlStateSelected];
- btn.layer.masksToBounds = YES;
- btn.layer.cornerRadius = 5;
- [view addSubview:btn];
-
- if (i == 0) {
- btn.selected = YES;
- btn.backgroundColor = [UIColor whiteColor];
- btn.layer.borderWidth = 1;
- btn.layer.borderColor = COLOR_THEME.CGColor;
- lastDatebtn = btn;
- }
- }
-
- y += 2*h + 2*bd;
- w = kSize.width - 2*x;
- btn = [[UIButton alloc] KSetxywh];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- btn.tag = -7;
- [btn setTitle:@"自定义日期范围" forState:UIControlStateNormal];
- [btn setTitleColor:KSubTitleColor forState:UIControlStateNormal];
- [btn setTitleColor:COLOR_THEME forState:UIControlStateSelected];
- [btn setBackgroundColor:kLineColor];
- btn.layer.masksToBounds = YES;
- btn.layer.cornerRadius = 3;
- [view addSubview:btn];
-
- calendarView.hidden = YES;
- dateType = 1;
- [self initDefaultDate]; //设置默认日期
- [self getPeopleNum];
- }
- - (void)btnClick:(UIButton *)sender
- {
- // NSLog(@"%d",(int)sender.tag);
-
- if (sender.tag == -7) { //自定义日期
-
- if (backView) {
- return;
- }
-
- calendarView.hidden = YES;
-
- backView = [[UIView alloc] initWithFrame:kFrame];
- backView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.5];
- [self.view addSubview:backView];
-
- CGFloat x, y, w, h, bd;
- x = 20;
- y = (kSize.height - 230)/2.0 - kNavOffSet;
- w = kSize.width - 40;
- h = 230;
-
- UIView *searchView = [[UIView alloc] KSetxywh];
- searchView.backgroundColor = KBackGroundColor;
- searchView.layer.masksToBounds = YES;
- searchView.layer.cornerRadius = 5;
- [backView addSubview:searchView];
-
- x = y = bd = 15;
- w = searchView.width - 30;
- h = 50;
-
- NSArray *imgArray = @[@"beginDate",@"endDate"];
- NSString *beginDateStr = @"开始时间";
- NSString *endDateStr = @"结束时间";
-
- if (searchStartTime.length > 0) {
- beginDateStr = searchStartTime;
- }
-
- if (searchEndTime.length > 0) {
- endDateStr = searchEndTime;
- }
-
- NSArray *titles = @[beginDateStr,endDateStr];
-
- NSMutableArray *btns = [NSMutableArray arrayWithCapacity:3];
- for (int i = 0; i < 2; i ++) {
-
- UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x + bd, 2*y + i*(h + bd), 20, 20)];
- imageView.image = [[UIImage imageNamed:imgArray[i]] tint:COLOR_THEME];
-
- [searchView addSubview:imageView];
-
- UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y + i*(h + bd) , w, h)];
- [button setTitle:titles[i] forState:UIControlStateNormal];
- [button setTitleColor:KContentTextColor forState:UIControlStateNormal];
- button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- button.titleEdgeInsets = UIEdgeInsetsMake(0, 3*bd, 0, 0);
- button.layer.masksToBounds = YES;
- button.layer.cornerRadius = 5;
- button.layer.borderColor = kLineColor.CGColor;
- button.layer.borderWidth = 2;
- [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- button.tag = i + 4;
- [searchView addSubview:button];
- [btns addObject:button];
- }
-
- beginBtn = btns[0];
- endBtn = btns[1];
-
- y += 2*(h + bd);
- w = (w - 2*bd)/2.0;
- NSArray *titleArrays = @[@"取消",@"查询"];
- for (int i = 0; i < 2; i ++) {
-
- UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + i*(w + 2*bd), y , w, h)];
-
- [button setTitle:titleArrays[i] forState:UIControlStateNormal];
- [button setTitleColor:COLOR_THEME forState:UIControlStateNormal];
- button.layer.masksToBounds = YES;
- button.layer.cornerRadius = 5;
- button.layer.borderColor = kLineColor.CGColor;
- button.layer.borderWidth = 2;
- [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- button.tag = i + 6;
- [searchView addSubview:button];
- }
-
- return;
- }
-
- if (sender.tag < 0 && sender.tag > -7) {
-
- if (lastDatebtn.tag != sender.tag) {
-
- if (sender.tag < -4) {
- dateType = 1;
- }else if (sender.tag < -2) {
- dateType = 2;
- }else {
- dateType = 3;
- }
-
- lastDatebtn.selected = NO;
- lastDatebtn.layer.borderWidth = 1;
- lastDatebtn.layer.borderColor = kLineColor.CGColor;
- lastDatebtn.backgroundColor = kLineColor;
-
- sender.selected = !sender.selected;
- sender.backgroundColor = [UIColor whiteColor];
- sender.layer.borderWidth = 1;
- sender.layer.borderColor = COLOR_THEME.CGColor;
-
- lastDatebtn = sender;
- calendarView.hidden = YES;
-
- //逻辑处理 要确定日期 然后调接口
- NSArray *dateArray = @[todayString,yesterdayString,weekNow,weekLast,monthNow,monthLast];
- NSArray *beginAndEndDate = [dateArray[lastDatebtn.tag + 6] componentsSeparatedByString:@"-"];
- startDateString = [beginAndEndDate firstObject];
- endDateString = [beginAndEndDate lastObject];
-
- [self getPeopleNum];
- }else{
- calendarView.hidden = YES;
- }
- return;
- }
-
- if (sender.tag == 1 || sender.tag == 2) {
- //更新日期
- [self getDateWithtype:sender.tag == 1 ? -1 : 1];
-
- //更改按钮状态 调接口
- UIButton *selectBtn;
- if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:todayString]) {
- //相当于选择当天
- selectBtn = (UIButton *)[calendarView viewWithTag:-6];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:yesterdayString]) {
- //相当于选择昨天
- selectBtn = (UIButton *)[calendarView viewWithTag:-5];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekNow]) {
- //相当于选择本周
- selectBtn = (UIButton *)[calendarView viewWithTag:-4];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekLast]) {
- //相当于选择上周
- selectBtn = (UIButton *)[calendarView viewWithTag:-3];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthNow]) {
- //相当于选择本月
- selectBtn = (UIButton *)[calendarView viewWithTag:-2];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthLast]) {
- //相当于选择上月
- selectBtn = (UIButton *)[calendarView viewWithTag:-1];
- }else {
- //其他日期
- selectBtn = (UIButton *)[calendarView viewWithTag:-7];
- }
-
- lastDatebtn.selected = NO;
-
- lastDatebtn.layer.borderWidth = 1;
- lastDatebtn.layer.borderColor = kLineColor.CGColor;
- lastDatebtn.backgroundColor = kLineColor;
-
- selectBtn.selected = YES;
- selectBtn.backgroundColor = [UIColor whiteColor];
- selectBtn.layer.borderWidth = 1;
- selectBtn.layer.borderColor = COLOR_THEME.CGColor;
-
- lastDatebtn = selectBtn;
-
-
- if (!calendarView.hidden) {
- calendarView.hidden = YES;
- }
-
- [self getPeopleNum];
- return;
- }
-
- if (sender.tag == 3) {
- //显示或收起
- calendarView.hidden = !calendarView.hidden;
- return;
- }
-
- if (sender.tag == 4) {//开始时间
-
- DateView *dateV = [[DateView alloc] init];
- [dateV setStyle:0];
- [dateV showWithComplete:^(NSString * result) {
-
- searchStartTime = result;
- [beginBtn setTitle:searchStartTime forState:UIControlStateNormal];
- }];
- return;
- }
-
- if (sender.tag == 5) {//结束时间
-
- DateView *dateV = [[DateView alloc] init];
- [dateV setStyle:0];
- [dateV showWithComplete:^(NSString * result) {
-
- searchEndTime = result;
- [endBtn setTitle:searchEndTime forState:UIControlStateNormal];
- }];
- return;
- }
- if (sender.tag == 6) {//取消自定义日期
-
- if (backView) {
- [backView removeFromSuperview];
- backView = nil;
- }
- return;
- }
-
- if (sender.tag == 7) {//查询自定义日期
-
- if (backView) {
- [backView removeFromSuperview];
- backView = nil;
- }
- //更改按钮状态 调接口
- UIButton *selectBtn;
-
- if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:todayString]) {
- //相当于选择当天
- dateType = 1;
- selectBtn = (UIButton *)[calendarView viewWithTag:-6];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:yesterdayString]) {
- //相当于选择昨天
- dateType = 1;
- selectBtn = (UIButton *)[calendarView viewWithTag:-5];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekNow]) {
- //相当于选择本周
- dateType = 2;
- selectBtn = (UIButton *)[calendarView viewWithTag:-4];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekLast]) {
- //相当于选择上周
- dateType = 2;
- selectBtn = (UIButton *)[calendarView viewWithTag:-3];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthNow]) {
- //相当于选择本月
- dateType = 3;
- selectBtn = (UIButton *)[calendarView viewWithTag:-2];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthLast]) {
- //相当于选择上月
- dateType = 3;
- selectBtn = (UIButton *)[calendarView viewWithTag:-1];
- }else {
- //其他日期
- selectBtn = sender;
- dateType = 1;
- }
-
- lastDatebtn.selected = NO;
- lastDatebtn.layer.masksToBounds = YES;
- lastDatebtn.layer.borderWidth = 1;
- lastDatebtn.layer.borderColor = kLineColor.CGColor;
- lastDatebtn.backgroundColor = kLineColor;
-
- selectBtn.selected = YES;
- selectBtn.backgroundColor = [UIColor whiteColor];
- selectBtn.layer.masksToBounds = YES;
- selectBtn.layer.borderWidth = 1;
- selectBtn.layer.borderColor = COLOR_THEME.CGColor;
- lastDatebtn = selectBtn;
-
- calendarView.hidden = YES;
-
- [self getPeopleNum];
- return;
- }
-
- if (sender.tag == 8) { //返回上一级
-
- if (roleId == [MYAPPDELEGATE.userDic[@"userType"] integerValue]) {
- //已经到最高权限
- backLastRoleBtn.hidden = YES;
- return;
- }
-
- roleId --;
- //只有1,2
- if (roleId == 1) {
- dqbh = @"";
- qxbh = @"";
- }else {
- //dqbh保持刚刚点进来的值
- qxbh = @"";
- }
-
- [self getPeopleNum];
- }
-
- if (sender.tag == 9) {
-
- if (rankNum == 1) {
- [self showMsgByAlertVCWithString:@"图表已放至最小"];
- return;
- }
- rankNum --;
- [self changeRank];
- }
-
- if (sender.tag == 10) {
-
- if (rankNum == 5) {
- [self showMsgByAlertVCWithString:@"图表已放至最大"];
- return;
- }
- rankNum ++;
- [self changeRank];
- }
-
- }
- - (void) changeRank {
-
- rankLabel.text = [NSString stringWithFormat:@"%ld",rankNum];
-
- switch (rankNum) {
- case 1:
- {
- _barview.barWith = 10;
- _barview.cellHeight = 20;
- }
- break;
- case 2:
- {
- _barview.barWith = 20;
- _barview.cellHeight = 40;
- }
- break;
- case 3:
- {
- _barview.barWith = 30;
- _barview.cellHeight = 60;
- }
- break;
- case 4:
- {
- _barview.barWith = 40;
- _barview.cellHeight = 80;
- }
- break;
- case 5:
- {
- _barview.barWith = 50;
- _barview.cellHeight = 100;
- }
- break;
- default:
- break;
- }
- [_barview reloadtb];
- }
- - (void)handleTap
- {
- calendarView.hidden = YES;
- }
- - (void)initDefaultDate {
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
-
- //今天
- NSString *dateStr = [dateFormatter stringFromDate:[NSDate date]];
- todayString = [NSString stringWithFormat:@"%@-%@",dateStr,dateStr];
- //设置默认值
- startDateString = endDateString = dateStr;
- calendarLabel.text = [NSString stringWithFormat:@"今日(%@) ▽",dateStr];
-
- //昨天
- dateStr = [self getDateWithdifferentDay:-1];
- yesterdayString =[NSString stringWithFormat:@"%@-%@",dateStr,dateStr];
-
- //本周
- [dateFormatter setDateFormat:@"e"];//1-7 这里把周日当作一周的开始
- int weekDay = [[dateFormatter stringFromDate:[NSDate date]] intValue] - 1;
- if (weekDay == 0) {
- weekDay = 7;
- }
- NSString *beginDate = [self getDateWithdifferentDay: 1-weekDay];
- NSString *endDate = [self getDateWithdifferentDay: 7-weekDay];
- weekNow = [NSString stringWithFormat:@"%@-%@",beginDate,endDate];
-
- //上周
- beginDate = [self getDateWithdifferentDay: -6-weekDay];
- endDate = [self getDateWithdifferentDay: -weekDay];
- weekLast = [NSString stringWithFormat:@"%@-%@",beginDate,endDate];
-
- //本月
- [dateFormatter setDateFormat:@"yyyy.MM"];
- dateStr = [dateFormatter stringFromDate:[NSDate date]];
-
- int moneyInt = [[dateStr substringFromIndex:5] intValue];
- int yearInt = [[dateStr substringToIndex:4] intValue];
- int moneyDay = 31;
- if (moneyInt == 2) {
- if (yearInt%4 == 0) {
- moneyDay = 28;
- }else{
- moneyDay = 29;
- }
- }else{
- if (moneyInt == 4 || moneyInt == 6 || moneyInt == 9 || moneyInt == 11) {
- moneyDay = 30;
- }
- }
- monthNow = [NSString stringWithFormat:@"%@.01-%@.%d",dateStr,dateStr,moneyDay];
-
- //上月
- if (moneyInt == 1) {
- yearInt -= 1;
- moneyInt = 12;
- }else{
- moneyInt -= 1;
- }
-
- moneyDay = 31;
- if (moneyInt == 2) {
- if (yearInt%4 == 0) {
- moneyDay = 28;
- }else{
- moneyDay = 29;
- }
- }else{
- if (moneyInt == 4 || moneyInt == 6 || moneyInt == 9 || moneyInt == 11) {
- moneyDay = 30;
- }
- }
- monthLast = [NSString stringWithFormat:@"%d.%02d.01-%d.%02d.%d",yearInt,moneyInt,yearInt,moneyInt,moneyDay];
-
- // NSLog(@"%@\n%@\n%@\n%@\n%@\n%@",todayString,yesterdayString,weekNow,weekLast,monthNow,monthLast);
- }
- - (NSString *)getDateWithdifferentDay:(NSInteger)day
- {
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
- return [self getDateWithDay:[dateFormatter stringFromDate:[NSDate date]] DifferentDay:day];
- }
- /**获取指定日期相差某天的日期 格式 yyyy.MM.dd
- @param now 指定日期
- @param day 相差日期 向后为正 向前为负
- @return 返回计算后的日期
- */
- - (NSString *)getDateWithDay:(NSString *)now DifferentDay:(NSInteger)day
- {
- if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
- NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
-
- NSDateComponents *adcomps = [[NSDateComponents alloc] init];
-
- [adcomps setDay:day];
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
-
- NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:now] options:0];
- return [dateFormatter stringFromDate:newdate];
- }else{
- NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
-
- NSDateComponents *adcomps = [[NSDateComponents alloc] init];
-
- [adcomps setDay:day];
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
-
- NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:now] options:0];
- return [dateFormatter stringFromDate:newdate];
- }
- }
- /**获取给定时间前或后的日期
- @param type 1、向前 2、向后
- */
- - (void)getDateWithtype:(NSInteger)type
- {
- if (dateType == 2) {
-
- startDateString = [self getDateWithDay:startDateString DifferentDay:type*7];
- endDateString = [self getDateWithDay:endDateString DifferentDay:type*7];
- return;
- }
-
-
- if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
- NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
-
- NSDateComponents *adcomps = [[NSDateComponents alloc] init];
-
- switch (dateType) {
- case 1:
- [adcomps setDay:type];
- break;
- case 2:
- // [adcomps setWeekday:type];
- break;
- case 3:
- [adcomps setMonth:type];
- break;
- case 4:
- [adcomps setYear:type];
- break;
- default:
- break;
- }
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
-
- NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:startDateString] options:0];
- startDateString = [dateFormatter stringFromDate:newdate];
-
- newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:endDateString] options:0];
- endDateString = [dateFormatter stringFromDate:newdate];
-
- if (dateType == 3) {
- int month = [[endDateString componentsSeparatedByString:@"."][1] intValue];
- if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
- if ([endDateString containsString:@".30"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".30" withString:@".31"];
- }
- if ([endDateString containsString:@".29"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".31"];
- }
- if ([endDateString containsString:@".28"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".31"];
- }
- }
- if (month == 4 || month == 6 || month == 9 || month == 11) {
- if ([endDateString containsString:@".31"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".31" withString:@".30"];
- }
- if ([endDateString containsString:@".29"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".30"];
- }
- if ([endDateString containsString:@".28"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".30"];
- }
- }
- }
-
- }else{
- NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
-
- NSDateComponents *adcomps = [[NSDateComponents alloc] init];
-
- switch (dateType) {
- case 1:
- [adcomps setDay:type];
- break;
- case 2:
- // [adcomps setWeekday:type];
- break;
- case 3:
- [adcomps setMonth:type];
- break;
- case 4:
- [adcomps setYear:type];
- break;
- default:
- break;
- }
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
-
- NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:startDateString] options:0];
- startDateString = [dateFormatter stringFromDate:newdate];
-
- newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:endDateString] options:0];
- endDateString = [dateFormatter stringFromDate:newdate];
-
- if (dateType == 3) {
- int month = [[endDateString componentsSeparatedByString:@"."][1] intValue];
- if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
- if ([endDateString containsString:@".30"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".30" withString:@".31"];
- }
- if ([endDateString containsString:@".29"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".31"];
- }
- if ([endDateString containsString:@".28"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".31"];
- }
- }
- if (month == 4 || month == 6 || month == 9 || month == 11) {
- if ([endDateString containsString:@".31"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".31" withString:@".30"];
- }
- if ([endDateString containsString:@".29"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".30"];
- }
- if ([endDateString containsString:@".28"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".30"];
- }
- }
- }
- }
- }
- #pragma mark 数据请求
- - (void)getPeopleNum {
-
- // NSString *typeString = [NSString stringWithFormat:@"%d",(int)dateType];
- // if (lastDatebtn.tag == -7 && ![startDateString isEqualToString:endDateString]) {
- // typeString = @"4";
- // }
-
- NSMutableDictionary * mdic = [NSMutableDictionary new];
-
- [mdic setValue:dqbh forKey:@"dqbh"];
- [mdic setValue:qxbh forKey:@"qxbh"];
- [mdic setValue:[startDateString stringByReplacingOccurrencesOfString:@"." withString:@"-"] forKey:@"startTime"];
- [mdic setValue:[endDateString stringByReplacingOccurrencesOfString:@"." withString:@"-"] forKey:@"endTime"];
-
-
- [self getDataWithDic:mdic method:@"getSignReport" block:^(NSDictionary *successDic) {
-
- if (roleId == [MYAPPDELEGATE.userDic[@"userType"] integerValue]) {
- backLastRoleBtn.hidden = YES;
- }
-
- //根据传过来的时间 改变calendarLabel
- NSString *calendarString = calendarString = [NSString stringWithFormat:@"%@-%@ ▽",startDateString,endDateString];
-
- if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:todayString]) {
- //相当于选择当天
- calendarString = [NSString stringWithFormat:@"今日(%@) ▽",startDateString];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:yesterdayString]) {
- //相当于选择昨天
- calendarString = [NSString stringWithFormat:@"昨日(%@) ▽",startDateString];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekNow]) {
- //相当于选择本周
- calendarString = [NSString stringWithFormat:@"本周(%@-%@) ▽",startDateString,endDateString];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekLast]) {
- //相当于选择上周
- calendarString = [NSString stringWithFormat:@"上周(%@-%@) ▽",startDateString,endDateString];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthNow]) {
- //相当于选择本月
- calendarString = [NSString stringWithFormat:@"本月(%@-%@) ▽",startDateString,endDateString];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthLast]) {
- //相当于选择上月
- calendarString = [NSString stringWithFormat:@"上月(%@-%@) ▽",startDateString,endDateString];
- }else {
- //其他日期
- if (lastDatebtn.tag == -7) {
- if ([startDateString isEqualToString:endDateString]) {
- calendarString = [NSString stringWithFormat:@"%@ ▽",startDateString];
- }
- }
- }
- //根据type不同 分为报名和退学
- calendarLabel.text = calendarString;
-
-
- _barview.modelArray = successDic[@"body"];
-
- // NSDictionary *dict = successDic[@"body"];
- // NSArray *realArray = dict[@"nums"];
- // if (![startDateString isEqualToString:endDateString]) {
- // if ([dict[@"nums"] count] > 0) {
- //
- // }
- // }
- //
- // numberLabel.text = [NSString stringWithFormat:@"%@人",dict[@"CURRENTNUM"]];
- //
- // int differentNumber = [dict[@"CURRENTNUM"] intValue] - [dict[@"LASTNUM"] intValue];
- // NSString *differentString = @"--";
- // if (differentNumber < 0) {
- // differentString = [NSString stringWithFormat:@"- %d人",-differentNumber];
- // }else {
- // differentString = [NSString stringWithFormat:@"+ %d人",differentNumber];
- // }
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|