statisticsVC.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  1. //
  2. // statisticsVC.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/4/5.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #define KSetxywh initWithFrame:CGRectMake(x, y, w, h)
  9. #define kLineColor [UIColor colorWithWhite:.3 alpha:.1]
  10. #define KTitleColor [UIColor colorWithRed:70/255.0 green:70/255.0 blue:70/255.0 alpha:1]
  11. #define KSubTitleColor [UIColor colorWithWhite:.3 alpha:1]
  12. #define KContentTextColor [UIColor colorWithRed:110/255.0 green:110/255.0 blue:110/255.0 alpha:1]
  13. #import "statisticsVC.h"
  14. #import "DateView.h"
  15. #import "XDBarView.h"
  16. #import "NetworkManager.h"
  17. @interface statisticsVC ()
  18. {
  19. //日历
  20. UILabel *calendarLabel;
  21. UIButton *calendarbtn;
  22. UIView *calendarView;
  23. UIButton *lastDatebtn;
  24. UILabel *numberLabel;
  25. UILabel *compareNumLabel;
  26. //自定义日期
  27. UIView *backView;
  28. UIButton *beginBtn,*endBtn;
  29. NSString *searchStartTime;
  30. NSString *searchEndTime;
  31. NSString *todayString;
  32. NSString *yesterdayString;
  33. NSString *weekNow;
  34. NSString *weekLast;
  35. NSString *monthNow;
  36. NSString *monthLast;
  37. NSString *startDateString;
  38. NSString *endDateString;
  39. // 1代表是日 2代表周 3代表月 4代表年
  40. NSInteger dateType;
  41. //角色权限
  42. NSInteger roleId;//对应登陆信息usertype
  43. NSString *dqbh;
  44. NSString *qxbh;
  45. UIButton *backLastRoleBtn;
  46. NSArray *numDataArray;
  47. //柱状图大小开关
  48. UILabel *rankLabel;
  49. NSInteger rankNum;
  50. }
  51. @property (nonatomic,strong) XDBarView *barview;
  52. @end
  53. @implementation statisticsVC
  54. - (void)viewDidLoad {
  55. [super viewDidLoad];
  56. self.navigationItem.title = @"报名统计";
  57. self.view.backgroundColor = [UIColor whiteColor];
  58. [self myInit];
  59. }
  60. - (void)myInit {
  61. //顶部日历条
  62. CGFloat x, y, w, h, bd;
  63. bd = 10;
  64. x = 0;
  65. y = kNavOffSet;
  66. w = kSize.width;
  67. h = 50;
  68. UIView *view = [[UIView alloc] KSetxywh];
  69. view.backgroundColor = COLOR_THEME;
  70. [self.view addSubview:view];
  71. x = y = bd;
  72. w = h = 30;
  73. UIImageView *imgView = [[UIImageView alloc] KSetxywh];
  74. [imgView setModeAspectFill];
  75. imgView.image = [UIImage imageNamed:@"arrow_left"];
  76. [view addSubview:imgView];
  77. x = kSize.width - w - bd;
  78. imgView = [[UIImageView alloc] KSetxywh];
  79. [imgView setModeAspectFill];
  80. imgView.image = [UIImage imageNamed:@"arrow_right"];
  81. [view addSubview:imgView];
  82. x = y = 0;
  83. w = 70;
  84. h = 50;
  85. UIButton *btn = [[UIButton alloc] KSetxywh];
  86. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  87. btn.tag = 1;
  88. [view addSubview:btn];
  89. x = kSize.width - w;
  90. btn = [[UIButton alloc] KSetxywh];
  91. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  92. btn.tag = 2;
  93. [view addSubview:btn];
  94. x = w;
  95. w = kSize.width - 2*x;
  96. btn = [[UIButton alloc] KSetxywh];
  97. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  98. btn.tag = 3;
  99. [view addSubview:btn];
  100. calendarbtn = btn;
  101. x = 0;
  102. w = kSize.width;
  103. UILabel *label = [[UILabel alloc] KSetxywh];
  104. label.text = @"请选择日期 ▽";
  105. label.textColor = [UIColor whiteColor];
  106. label.font = [UIFont systemFontOfSize:16];
  107. label.textAlignment = NSTextAlignmentCenter;
  108. [view addSubview:label];
  109. calendarLabel = label;
  110. //折线图大小开关
  111. rankNum = 3;
  112. y +=kNavOffSet + h + 4*bd;
  113. w = kSize.width - 10 - 40 - 25 - 40;
  114. h = 25;
  115. label = [[UILabel alloc] KSetxywh];
  116. label.text = @"统计图比例:";
  117. label.textColor = [UIColor grayColor];
  118. label.font = [UIFont systemFontOfSize:16];
  119. label.textAlignment = NSTextAlignmentRight;
  120. [self.view addSubview:label];
  121. x += w;
  122. w = 40;
  123. y -= 5;
  124. h += 10;
  125. btn = [[UIButton alloc] KSetxywh];
  126. [btn setTitle:@"-" forState:UIControlStateNormal];
  127. btn.titleLabel.font = [UIFont systemFontOfSize:22];
  128. [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  129. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  130. btn.tag = 9;
  131. [self.view addSubview:btn];
  132. x += w;
  133. w = 25;
  134. y += 5;
  135. h -= 10;
  136. label = [[UILabel alloc] KSetxywh];
  137. label.text = [NSString stringWithFormat:@"%ld",rankNum];
  138. label.textColor = [UIColor grayColor];
  139. label.font = [UIFont systemFontOfSize:17];
  140. label.textAlignment = NSTextAlignmentCenter;
  141. label.layer.masksToBounds = YES;
  142. label.layer.cornerRadius = h/2;
  143. label.layer.borderWidth = 1;
  144. label.layer.borderColor = COLOR_THEME.CGColor;
  145. [self.view addSubview:label];
  146. rankLabel = label;
  147. x += w;
  148. w = 40;
  149. y -= 5;
  150. h += 10;
  151. btn = [[UIButton alloc] KSetxywh];
  152. [btn setTitle:@"+" forState:UIControlStateNormal];
  153. btn.titleLabel.font = [UIFont systemFontOfSize:21];
  154. [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  155. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  156. btn.tag = 10;
  157. [self.view addSubview:btn];
  158. //折线图
  159. y += h + bd;
  160. x = 0;
  161. w = kSize.width;
  162. h = kSize.height - y - kNavOffSet - kTabBarHeight;
  163. //kSize.width * 0.67
  164. _barview = [[XDBarView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  165. _barview.barWith = 30;
  166. _barview.cellHeight = 60;
  167. _barview.defaultColor = ColorWithHEAL;//ColorWithRGB(218, 218, 218)
  168. _barview.SelectColor = ColorWithHEAL;
  169. [self.view addSubview:_barview];
  170. //柱子被点击的回调
  171. [_barview selectedWithTableViewPathRowBlock:^(NSString *colname, NSInteger row) {
  172. //NSLog(@"%ld点击了柱子colname == %@",(long)row,colname);
  173. if (roleId >= 3) {
  174. //已经是最底层了
  175. return;
  176. }
  177. backLastRoleBtn.hidden = NO;
  178. roleId ++;
  179. if (roleId == 2) {
  180. dqbh = colname;
  181. }else {
  182. qxbh = colname;
  183. }
  184. [self getPeopleNum];
  185. //roleId 1省级 2地市 3区县
  186. }];
  187. roleId = [MYAPPDELEGATE.userDic[@"userType"] integerValue];
  188. dqbh = MYAPPDELEGATE.userDic[@"dqbh"];
  189. qxbh = MYAPPDELEGATE.userDic[@"qxbh"];
  190. searchStartTime = @"";
  191. searchEndTime = @"";
  192. //返回上一级
  193. x = 20;
  194. y = kSize.height-kTabBarHeight-50-(kNavOffSet-50)/2;
  195. w = kSize.width - 2*x;
  196. h = 50;
  197. btn = [[UIButton alloc] KSetxywh];
  198. btn.backgroundColor = COLOR_THEME;
  199. [btn setTitle:@"返回上一级" forState:UIControlStateNormal];
  200. [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  201. btn.layer.masksToBounds = YES;
  202. btn.layer.cornerRadius = 10;
  203. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  204. btn.tag = 8;
  205. [self.view addSubview:btn];
  206. btn.hidden = YES;
  207. backLastRoleBtn = btn;
  208. //隐藏的日期选择
  209. x = 0;
  210. y = kNavOffSet + 50;
  211. w = kSize.width;
  212. h = kSize.height - y;
  213. view = [[UIView alloc] KSetxywh];
  214. view.backgroundColor = [UIColor colorWithWhite:.7 alpha:1.0];
  215. [self.view addSubview:view];
  216. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap)];
  217. [view addGestureRecognizer:tap];
  218. calendarView = view;
  219. y = 0;
  220. h = 170;
  221. view = [[UIView alloc] KSetxywh];
  222. view.backgroundColor = KBackGroundColor;
  223. [calendarView addSubview:view];
  224. x = bd;
  225. w -= 2*x;
  226. h = 40;
  227. label = [[UILabel alloc] KSetxywh];
  228. label.text = @"日期";
  229. label.textColor = [UIColor blackColor];
  230. label.font = [UIFont systemFontOfSize:17];
  231. [view addSubview:label];
  232. y += h;
  233. w = (kSize.width - 40)/3.0;
  234. h = 30;
  235. NSArray *titleArray = @[@"今日",@"昨日",@"本周",@"上周",@"本月",@"上月"];
  236. for (int i = 0; i < titleArray.count; i ++) {
  237. int row = i/3;
  238. int column = i%3;
  239. btn = [[UIButton alloc] initWithFrame:CGRectMake(x + column*(w + bd), y + row*(h + bd), w, h)];
  240. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  241. btn.tag = i-6;
  242. [btn setTitle:titleArray[i] forState:UIControlStateNormal];
  243. [btn setBackgroundColor:kLineColor];
  244. [btn setTitleColor:KSubTitleColor forState:UIControlStateNormal];
  245. [btn setTitleColor:COLOR_THEME forState:UIControlStateSelected];
  246. btn.layer.masksToBounds = YES;
  247. btn.layer.cornerRadius = 5;
  248. [view addSubview:btn];
  249. if (i == 0) {
  250. btn.selected = YES;
  251. btn.backgroundColor = [UIColor whiteColor];
  252. btn.layer.borderWidth = 1;
  253. btn.layer.borderColor = COLOR_THEME.CGColor;
  254. lastDatebtn = btn;
  255. }
  256. }
  257. y += 2*h + 2*bd;
  258. w = kSize.width - 2*x;
  259. btn = [[UIButton alloc] KSetxywh];
  260. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  261. btn.tag = -7;
  262. [btn setTitle:@"自定义日期范围" forState:UIControlStateNormal];
  263. [btn setTitleColor:KSubTitleColor forState:UIControlStateNormal];
  264. [btn setTitleColor:COLOR_THEME forState:UIControlStateSelected];
  265. [btn setBackgroundColor:kLineColor];
  266. btn.layer.masksToBounds = YES;
  267. btn.layer.cornerRadius = 3;
  268. [view addSubview:btn];
  269. calendarView.hidden = YES;
  270. dateType = 1;
  271. [self initDefaultDate]; //设置默认日期
  272. [self getPeopleNum];
  273. }
  274. - (void)btnClick:(UIButton *)sender
  275. {
  276. // NSLog(@"%d",(int)sender.tag);
  277. if (sender.tag == -7) { //自定义日期
  278. if (backView) {
  279. return;
  280. }
  281. calendarView.hidden = YES;
  282. backView = [[UIView alloc] initWithFrame:kFrame];
  283. backView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.5];
  284. [self.view addSubview:backView];
  285. CGFloat x, y, w, h, bd;
  286. x = 20;
  287. y = (kSize.height - 230)/2.0 - kNavOffSet;
  288. w = kSize.width - 40;
  289. h = 230;
  290. UIView *searchView = [[UIView alloc] KSetxywh];
  291. searchView.backgroundColor = KBackGroundColor;
  292. searchView.layer.masksToBounds = YES;
  293. searchView.layer.cornerRadius = 5;
  294. [backView addSubview:searchView];
  295. x = y = bd = 15;
  296. w = searchView.width - 30;
  297. h = 50;
  298. NSArray *imgArray = @[@"beginDate",@"endDate"];
  299. NSString *beginDateStr = @"开始时间";
  300. NSString *endDateStr = @"结束时间";
  301. if (searchStartTime.length > 0) {
  302. beginDateStr = searchStartTime;
  303. }
  304. if (searchEndTime.length > 0) {
  305. endDateStr = searchEndTime;
  306. }
  307. NSArray *titles = @[beginDateStr,endDateStr];
  308. NSMutableArray *btns = [NSMutableArray arrayWithCapacity:3];
  309. for (int i = 0; i < 2; i ++) {
  310. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x + bd, 2*y + i*(h + bd), 20, 20)];
  311. imageView.image = [[UIImage imageNamed:imgArray[i]] tint:COLOR_THEME];
  312. [searchView addSubview:imageView];
  313. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y + i*(h + bd) , w, h)];
  314. [button setTitle:titles[i] forState:UIControlStateNormal];
  315. [button setTitleColor:KContentTextColor forState:UIControlStateNormal];
  316. button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  317. button.titleEdgeInsets = UIEdgeInsetsMake(0, 3*bd, 0, 0);
  318. button.layer.masksToBounds = YES;
  319. button.layer.cornerRadius = 5;
  320. button.layer.borderColor = kLineColor.CGColor;
  321. button.layer.borderWidth = 2;
  322. [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  323. button.tag = i + 4;
  324. [searchView addSubview:button];
  325. [btns addObject:button];
  326. }
  327. beginBtn = btns[0];
  328. endBtn = btns[1];
  329. y += 2*(h + bd);
  330. w = (w - 2*bd)/2.0;
  331. NSArray *titleArrays = @[@"取消",@"查询"];
  332. for (int i = 0; i < 2; i ++) {
  333. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + i*(w + 2*bd), y , w, h)];
  334. [button setTitle:titleArrays[i] forState:UIControlStateNormal];
  335. [button setTitleColor:COLOR_THEME forState:UIControlStateNormal];
  336. button.layer.masksToBounds = YES;
  337. button.layer.cornerRadius = 5;
  338. button.layer.borderColor = kLineColor.CGColor;
  339. button.layer.borderWidth = 2;
  340. [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  341. button.tag = i + 6;
  342. [searchView addSubview:button];
  343. }
  344. return;
  345. }
  346. if (sender.tag < 0 && sender.tag > -7) {
  347. if (lastDatebtn.tag != sender.tag) {
  348. if (sender.tag < -4) {
  349. dateType = 1;
  350. }else if (sender.tag < -2) {
  351. dateType = 2;
  352. }else {
  353. dateType = 3;
  354. }
  355. lastDatebtn.selected = NO;
  356. lastDatebtn.layer.borderWidth = 1;
  357. lastDatebtn.layer.borderColor = kLineColor.CGColor;
  358. lastDatebtn.backgroundColor = kLineColor;
  359. sender.selected = !sender.selected;
  360. sender.backgroundColor = [UIColor whiteColor];
  361. sender.layer.borderWidth = 1;
  362. sender.layer.borderColor = COLOR_THEME.CGColor;
  363. lastDatebtn = sender;
  364. calendarView.hidden = YES;
  365. //逻辑处理 要确定日期 然后调接口
  366. NSArray *dateArray = @[todayString,yesterdayString,weekNow,weekLast,monthNow,monthLast];
  367. NSArray *beginAndEndDate = [dateArray[lastDatebtn.tag + 6] componentsSeparatedByString:@"-"];
  368. startDateString = [beginAndEndDate firstObject];
  369. endDateString = [beginAndEndDate lastObject];
  370. [self getPeopleNum];
  371. }else{
  372. calendarView.hidden = YES;
  373. }
  374. return;
  375. }
  376. if (sender.tag == 1 || sender.tag == 2) {
  377. //更新日期
  378. [self getDateWithtype:sender.tag == 1 ? -1 : 1];
  379. //更改按钮状态 调接口
  380. UIButton *selectBtn;
  381. if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:todayString]) {
  382. //相当于选择当天
  383. selectBtn = (UIButton *)[calendarView viewWithTag:-6];
  384. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:yesterdayString]) {
  385. //相当于选择昨天
  386. selectBtn = (UIButton *)[calendarView viewWithTag:-5];
  387. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekNow]) {
  388. //相当于选择本周
  389. selectBtn = (UIButton *)[calendarView viewWithTag:-4];
  390. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekLast]) {
  391. //相当于选择上周
  392. selectBtn = (UIButton *)[calendarView viewWithTag:-3];
  393. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthNow]) {
  394. //相当于选择本月
  395. selectBtn = (UIButton *)[calendarView viewWithTag:-2];
  396. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthLast]) {
  397. //相当于选择上月
  398. selectBtn = (UIButton *)[calendarView viewWithTag:-1];
  399. }else {
  400. //其他日期
  401. selectBtn = (UIButton *)[calendarView viewWithTag:-7];
  402. }
  403. lastDatebtn.selected = NO;
  404. lastDatebtn.layer.borderWidth = 1;
  405. lastDatebtn.layer.borderColor = kLineColor.CGColor;
  406. lastDatebtn.backgroundColor = kLineColor;
  407. selectBtn.selected = YES;
  408. selectBtn.backgroundColor = [UIColor whiteColor];
  409. selectBtn.layer.borderWidth = 1;
  410. selectBtn.layer.borderColor = COLOR_THEME.CGColor;
  411. lastDatebtn = selectBtn;
  412. if (!calendarView.hidden) {
  413. calendarView.hidden = YES;
  414. }
  415. [self getPeopleNum];
  416. return;
  417. }
  418. if (sender.tag == 3) {
  419. //显示或收起
  420. calendarView.hidden = !calendarView.hidden;
  421. return;
  422. }
  423. if (sender.tag == 4) {//开始时间
  424. DateView *dateV = [[DateView alloc] init];
  425. [dateV setStyle:0];
  426. [dateV showWithComplete:^(NSString * result) {
  427. searchStartTime = result;
  428. [beginBtn setTitle:searchStartTime forState:UIControlStateNormal];
  429. }];
  430. return;
  431. }
  432. if (sender.tag == 5) {//结束时间
  433. DateView *dateV = [[DateView alloc] init];
  434. [dateV setStyle:0];
  435. [dateV showWithComplete:^(NSString * result) {
  436. searchEndTime = result;
  437. [endBtn setTitle:searchEndTime forState:UIControlStateNormal];
  438. }];
  439. return;
  440. }
  441. if (sender.tag == 6) {//取消自定义日期
  442. if (backView) {
  443. [backView removeFromSuperview];
  444. backView = nil;
  445. }
  446. return;
  447. }
  448. if (sender.tag == 7) {//查询自定义日期
  449. if (backView) {
  450. [backView removeFromSuperview];
  451. backView = nil;
  452. }
  453. //更改按钮状态 调接口
  454. UIButton *selectBtn;
  455. if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:todayString]) {
  456. //相当于选择当天
  457. dateType = 1;
  458. selectBtn = (UIButton *)[calendarView viewWithTag:-6];
  459. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:yesterdayString]) {
  460. //相当于选择昨天
  461. dateType = 1;
  462. selectBtn = (UIButton *)[calendarView viewWithTag:-5];
  463. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekNow]) {
  464. //相当于选择本周
  465. dateType = 2;
  466. selectBtn = (UIButton *)[calendarView viewWithTag:-4];
  467. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekLast]) {
  468. //相当于选择上周
  469. dateType = 2;
  470. selectBtn = (UIButton *)[calendarView viewWithTag:-3];
  471. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthNow]) {
  472. //相当于选择本月
  473. dateType = 3;
  474. selectBtn = (UIButton *)[calendarView viewWithTag:-2];
  475. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthLast]) {
  476. //相当于选择上月
  477. dateType = 3;
  478. selectBtn = (UIButton *)[calendarView viewWithTag:-1];
  479. }else {
  480. //其他日期
  481. selectBtn = sender;
  482. dateType = 1;
  483. }
  484. lastDatebtn.selected = NO;
  485. lastDatebtn.layer.masksToBounds = YES;
  486. lastDatebtn.layer.borderWidth = 1;
  487. lastDatebtn.layer.borderColor = kLineColor.CGColor;
  488. lastDatebtn.backgroundColor = kLineColor;
  489. selectBtn.selected = YES;
  490. selectBtn.backgroundColor = [UIColor whiteColor];
  491. selectBtn.layer.masksToBounds = YES;
  492. selectBtn.layer.borderWidth = 1;
  493. selectBtn.layer.borderColor = COLOR_THEME.CGColor;
  494. lastDatebtn = selectBtn;
  495. calendarView.hidden = YES;
  496. [self getPeopleNum];
  497. return;
  498. }
  499. if (sender.tag == 8) { //返回上一级
  500. if (roleId == [MYAPPDELEGATE.userDic[@"userType"] integerValue]) {
  501. //已经到最高权限
  502. backLastRoleBtn.hidden = YES;
  503. return;
  504. }
  505. roleId --;
  506. //只有1,2
  507. if (roleId == 1) {
  508. dqbh = @"";
  509. qxbh = @"";
  510. }else {
  511. //dqbh保持刚刚点进来的值
  512. qxbh = @"";
  513. }
  514. [self getPeopleNum];
  515. }
  516. if (sender.tag == 9) {
  517. if (rankNum == 1) {
  518. [self showMsgByAlertVCWithString:@"图表已放至最小"];
  519. return;
  520. }
  521. rankNum --;
  522. [self changeRank];
  523. }
  524. if (sender.tag == 10) {
  525. if (rankNum == 5) {
  526. [self showMsgByAlertVCWithString:@"图表已放至最大"];
  527. return;
  528. }
  529. rankNum ++;
  530. [self changeRank];
  531. }
  532. }
  533. - (void) changeRank {
  534. rankLabel.text = [NSString stringWithFormat:@"%ld",rankNum];
  535. switch (rankNum) {
  536. case 1:
  537. {
  538. _barview.barWith = 10;
  539. _barview.cellHeight = 20;
  540. }
  541. break;
  542. case 2:
  543. {
  544. _barview.barWith = 20;
  545. _barview.cellHeight = 40;
  546. }
  547. break;
  548. case 3:
  549. {
  550. _barview.barWith = 30;
  551. _barview.cellHeight = 60;
  552. }
  553. break;
  554. case 4:
  555. {
  556. _barview.barWith = 40;
  557. _barview.cellHeight = 80;
  558. }
  559. break;
  560. case 5:
  561. {
  562. _barview.barWith = 50;
  563. _barview.cellHeight = 100;
  564. }
  565. break;
  566. default:
  567. break;
  568. }
  569. [_barview reloadtb];
  570. }
  571. - (void)handleTap
  572. {
  573. calendarView.hidden = YES;
  574. }
  575. - (void)initDefaultDate {
  576. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  577. [dateFormatter setDateFormat:@"yyyy.MM.dd"];
  578. //今天
  579. NSString *dateStr = [dateFormatter stringFromDate:[NSDate date]];
  580. todayString = [NSString stringWithFormat:@"%@-%@",dateStr,dateStr];
  581. //设置默认值
  582. startDateString = endDateString = dateStr;
  583. calendarLabel.text = [NSString stringWithFormat:@"今日(%@) ▽",dateStr];
  584. //昨天
  585. dateStr = [self getDateWithdifferentDay:-1];
  586. yesterdayString =[NSString stringWithFormat:@"%@-%@",dateStr,dateStr];
  587. //本周
  588. [dateFormatter setDateFormat:@"e"];//1-7 这里把周日当作一周的开始
  589. int weekDay = [[dateFormatter stringFromDate:[NSDate date]] intValue] - 1;
  590. if (weekDay == 0) {
  591. weekDay = 7;
  592. }
  593. NSString *beginDate = [self getDateWithdifferentDay: 1-weekDay];
  594. NSString *endDate = [self getDateWithdifferentDay: 7-weekDay];
  595. weekNow = [NSString stringWithFormat:@"%@-%@",beginDate,endDate];
  596. //上周
  597. beginDate = [self getDateWithdifferentDay: -6-weekDay];
  598. endDate = [self getDateWithdifferentDay: -weekDay];
  599. weekLast = [NSString stringWithFormat:@"%@-%@",beginDate,endDate];
  600. //本月
  601. [dateFormatter setDateFormat:@"yyyy.MM"];
  602. dateStr = [dateFormatter stringFromDate:[NSDate date]];
  603. int moneyInt = [[dateStr substringFromIndex:5] intValue];
  604. int yearInt = [[dateStr substringToIndex:4] intValue];
  605. int moneyDay = 31;
  606. if (moneyInt == 2) {
  607. if (yearInt%4 == 0) {
  608. moneyDay = 28;
  609. }else{
  610. moneyDay = 29;
  611. }
  612. }else{
  613. if (moneyInt == 4 || moneyInt == 6 || moneyInt == 9 || moneyInt == 11) {
  614. moneyDay = 30;
  615. }
  616. }
  617. monthNow = [NSString stringWithFormat:@"%@.01-%@.%d",dateStr,dateStr,moneyDay];
  618. //上月
  619. if (moneyInt == 1) {
  620. yearInt -= 1;
  621. moneyInt = 12;
  622. }else{
  623. moneyInt -= 1;
  624. }
  625. moneyDay = 31;
  626. if (moneyInt == 2) {
  627. if (yearInt%4 == 0) {
  628. moneyDay = 28;
  629. }else{
  630. moneyDay = 29;
  631. }
  632. }else{
  633. if (moneyInt == 4 || moneyInt == 6 || moneyInt == 9 || moneyInt == 11) {
  634. moneyDay = 30;
  635. }
  636. }
  637. monthLast = [NSString stringWithFormat:@"%d.%02d.01-%d.%02d.%d",yearInt,moneyInt,yearInt,moneyInt,moneyDay];
  638. // NSLog(@"%@\n%@\n%@\n%@\n%@\n%@",todayString,yesterdayString,weekNow,weekLast,monthNow,monthLast);
  639. }
  640. - (NSString *)getDateWithdifferentDay:(NSInteger)day
  641. {
  642. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  643. [dateFormatter setDateFormat:@"yyyy.MM.dd"];
  644. return [self getDateWithDay:[dateFormatter stringFromDate:[NSDate date]] DifferentDay:day];
  645. }
  646. /**获取指定日期相差某天的日期 格式 yyyy.MM.dd
  647. @param now 指定日期
  648. @param day 相差日期 向后为正 向前为负
  649. @return 返回计算后的日期
  650. */
  651. - (NSString *)getDateWithDay:(NSString *)now DifferentDay:(NSInteger)day
  652. {
  653. if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
  654. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
  655. NSDateComponents *adcomps = [[NSDateComponents alloc] init];
  656. [adcomps setDay:day];
  657. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  658. [dateFormatter setDateFormat:@"yyyy.MM.dd"];
  659. NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:now] options:0];
  660. return [dateFormatter stringFromDate:newdate];
  661. }else{
  662. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  663. NSDateComponents *adcomps = [[NSDateComponents alloc] init];
  664. [adcomps setDay:day];
  665. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  666. [dateFormatter setDateFormat:@"yyyy.MM.dd"];
  667. NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:now] options:0];
  668. return [dateFormatter stringFromDate:newdate];
  669. }
  670. }
  671. /**获取给定时间前或后的日期
  672. @param type 1、向前 2、向后
  673. */
  674. - (void)getDateWithtype:(NSInteger)type
  675. {
  676. if (dateType == 2) {
  677. startDateString = [self getDateWithDay:startDateString DifferentDay:type*7];
  678. endDateString = [self getDateWithDay:endDateString DifferentDay:type*7];
  679. return;
  680. }
  681. if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
  682. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
  683. NSDateComponents *adcomps = [[NSDateComponents alloc] init];
  684. switch (dateType) {
  685. case 1:
  686. [adcomps setDay:type];
  687. break;
  688. case 2:
  689. // [adcomps setWeekday:type];
  690. break;
  691. case 3:
  692. [adcomps setMonth:type];
  693. break;
  694. case 4:
  695. [adcomps setYear:type];
  696. break;
  697. default:
  698. break;
  699. }
  700. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  701. [dateFormatter setDateFormat:@"yyyy.MM.dd"];
  702. NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:startDateString] options:0];
  703. startDateString = [dateFormatter stringFromDate:newdate];
  704. newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:endDateString] options:0];
  705. endDateString = [dateFormatter stringFromDate:newdate];
  706. if (dateType == 3) {
  707. int month = [[endDateString componentsSeparatedByString:@"."][1] intValue];
  708. if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
  709. if ([endDateString containsString:@".30"]) {
  710. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".30" withString:@".31"];
  711. }
  712. if ([endDateString containsString:@".29"]) {
  713. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".31"];
  714. }
  715. if ([endDateString containsString:@".28"]) {
  716. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".31"];
  717. }
  718. }
  719. if (month == 4 || month == 6 || month == 9 || month == 11) {
  720. if ([endDateString containsString:@".31"]) {
  721. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".31" withString:@".30"];
  722. }
  723. if ([endDateString containsString:@".29"]) {
  724. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".30"];
  725. }
  726. if ([endDateString containsString:@".28"]) {
  727. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".30"];
  728. }
  729. }
  730. }
  731. }else{
  732. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  733. NSDateComponents *adcomps = [[NSDateComponents alloc] init];
  734. switch (dateType) {
  735. case 1:
  736. [adcomps setDay:type];
  737. break;
  738. case 2:
  739. // [adcomps setWeekday:type];
  740. break;
  741. case 3:
  742. [adcomps setMonth:type];
  743. break;
  744. case 4:
  745. [adcomps setYear:type];
  746. break;
  747. default:
  748. break;
  749. }
  750. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  751. [dateFormatter setDateFormat:@"yyyy.MM.dd"];
  752. NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:startDateString] options:0];
  753. startDateString = [dateFormatter stringFromDate:newdate];
  754. newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:endDateString] options:0];
  755. endDateString = [dateFormatter stringFromDate:newdate];
  756. if (dateType == 3) {
  757. int month = [[endDateString componentsSeparatedByString:@"."][1] intValue];
  758. if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
  759. if ([endDateString containsString:@".30"]) {
  760. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".30" withString:@".31"];
  761. }
  762. if ([endDateString containsString:@".29"]) {
  763. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".31"];
  764. }
  765. if ([endDateString containsString:@".28"]) {
  766. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".31"];
  767. }
  768. }
  769. if (month == 4 || month == 6 || month == 9 || month == 11) {
  770. if ([endDateString containsString:@".31"]) {
  771. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".31" withString:@".30"];
  772. }
  773. if ([endDateString containsString:@".29"]) {
  774. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".30"];
  775. }
  776. if ([endDateString containsString:@".28"]) {
  777. endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".30"];
  778. }
  779. }
  780. }
  781. }
  782. }
  783. #pragma mark 数据请求
  784. - (void)getPeopleNum {
  785. // NSString *typeString = [NSString stringWithFormat:@"%d",(int)dateType];
  786. // if (lastDatebtn.tag == -7 && ![startDateString isEqualToString:endDateString]) {
  787. // typeString = @"4";
  788. // }
  789. NSMutableDictionary * mdic = [NSMutableDictionary new];
  790. [mdic setValue:dqbh forKey:@"dqbh"];
  791. [mdic setValue:qxbh forKey:@"qxbh"];
  792. [mdic setValue:[startDateString stringByReplacingOccurrencesOfString:@"." withString:@"-"] forKey:@"startTime"];
  793. [mdic setValue:[endDateString stringByReplacingOccurrencesOfString:@"." withString:@"-"] forKey:@"endTime"];
  794. [self getDataWithDic:mdic method:@"getSignReport" block:^(NSDictionary *successDic) {
  795. if (roleId == [MYAPPDELEGATE.userDic[@"userType"] integerValue]) {
  796. backLastRoleBtn.hidden = YES;
  797. }
  798. //根据传过来的时间 改变calendarLabel
  799. NSString *calendarString = calendarString = [NSString stringWithFormat:@"%@-%@ ▽",startDateString,endDateString];
  800. if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:todayString]) {
  801. //相当于选择当天
  802. calendarString = [NSString stringWithFormat:@"今日(%@) ▽",startDateString];
  803. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:yesterdayString]) {
  804. //相当于选择昨天
  805. calendarString = [NSString stringWithFormat:@"昨日(%@) ▽",startDateString];
  806. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekNow]) {
  807. //相当于选择本周
  808. calendarString = [NSString stringWithFormat:@"本周(%@-%@) ▽",startDateString,endDateString];
  809. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekLast]) {
  810. //相当于选择上周
  811. calendarString = [NSString stringWithFormat:@"上周(%@-%@) ▽",startDateString,endDateString];
  812. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthNow]) {
  813. //相当于选择本月
  814. calendarString = [NSString stringWithFormat:@"本月(%@-%@) ▽",startDateString,endDateString];
  815. }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthLast]) {
  816. //相当于选择上月
  817. calendarString = [NSString stringWithFormat:@"上月(%@-%@) ▽",startDateString,endDateString];
  818. }else {
  819. //其他日期
  820. if (lastDatebtn.tag == -7) {
  821. if ([startDateString isEqualToString:endDateString]) {
  822. calendarString = [NSString stringWithFormat:@"%@ ▽",startDateString];
  823. }
  824. }
  825. }
  826. //根据type不同 分为报名和退学
  827. calendarLabel.text = calendarString;
  828. _barview.modelArray = successDic[@"body"];
  829. // NSDictionary *dict = successDic[@"body"];
  830. // NSArray *realArray = dict[@"nums"];
  831. // if (![startDateString isEqualToString:endDateString]) {
  832. // if ([dict[@"nums"] count] > 0) {
  833. //
  834. // }
  835. // }
  836. //
  837. // numberLabel.text = [NSString stringWithFormat:@"%@人",dict[@"CURRENTNUM"]];
  838. //
  839. // int differentNumber = [dict[@"CURRENTNUM"] intValue] - [dict[@"LASTNUM"] intValue];
  840. // NSString *differentString = @"--";
  841. // if (differentNumber < 0) {
  842. // differentString = [NSString stringWithFormat:@"- %d人",-differentNumber];
  843. // }else {
  844. // differentString = [NSString stringWithFormat:@"+ %d人",differentNumber];
  845. // }
  846. }];
  847. }
  848. - (void)didReceiveMemoryWarning {
  849. [super didReceiveMemoryWarning];
  850. // Dispose of any resources that can be recreated.
  851. }
  852. @end