SalesPaymentRankHomeViewController.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. //
  2. // SalesPaymentRankHomeViewController.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 2017/8/23.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. // 功能描述:销售回款排行主页控制器
  9. #import "SalesPaymentRankHomeViewController.h"
  10. #import "SideSlipModel.h"
  11. #import "DateFormat.h"
  12. #import "SalesAchievementSearchModel.h"
  13. #import "SalesPaymentRankFrame.h"
  14. @interface SalesPaymentRankHomeViewController ()
  15. @end
  16. @implementation SalesPaymentRankHomeViewController
  17. /**
  18. 导航数
  19. */
  20. static int navcount = 2;
  21. #pragma mark - 公共函数
  22. /**
  23. 视图加载完成函数
  24. */
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.navigationItem.title = @"销售回款排行";
  28. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  29. [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"]
  30. forState:UIControlStateNormal];
  31. [button addTarget:self action:@selector(goBack)
  32. forControlEvents:UIControlEventTouchUpInside];
  33. button.frame = CGRectMake(0, 0, 15, 18);
  34. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  35. self.navigationItem.leftBarButtonItem = menuButton;
  36. UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 16)];
  37. UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom];
  38. [btnfilter addTarget:self action:@selector(search)
  39. forControlEvents:UIControlEventTouchUpInside];
  40. btnfilter.frame = CGRectMake(0, 0, 16, 16);
  41. [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  42. [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"]
  43. forState:UIControlStateNormal];
  44. [v addSubview:btnfilter];
  45. UIButton *filterLbl = [[UIButton alloc]init];
  46. filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16);
  47. [filterLbl setTitle:@"筛选" forState:UIControlStateNormal];
  48. [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  49. filterLbl.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  50. [filterLbl addTarget:self action:@selector(search)
  51. forControlEvents:UIControlEventTouchUpInside];
  52. [v addSubview:filterLbl];
  53. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v];
  54. self.navigationItem.rightBarButtonItem = menubtnAdd;
  55. _rankType=@"1";
  56. _mEndDate= [DateFormat getCurrentDate];
  57. _mStartDate = [DateFormat getDateBefore:31];
  58. [self initUI];
  59. [self setMainSrollView];
  60. [self sliderWithTag:self.currentIndex+1];
  61. [self loadData];
  62. }
  63. /**
  64. 初始化销售回款图表控制器
  65. @return <#return value description#>
  66. */
  67. - (SalesPaymentRankChartViewController *)chartViewVC{
  68. if (_chartViewVC == nil) {
  69. _chartViewVC = [[SalesPaymentRankChartViewController alloc] init];
  70. }
  71. return _chartViewVC ;
  72. }
  73. /**
  74. 初始化销售回款列表控制器
  75. @return <#return value description#>
  76. */
  77. - (SalesPaymentRankDataListViewController *)dataListVC{
  78. if (_dataListVC == nil) {
  79. _dataListVC = [[SalesPaymentRankDataListViewController alloc] init];
  80. }
  81. return _dataListVC;
  82. }
  83. #pragma mark - 委托函数
  84. /**
  85. 加载数据成功回调
  86. @param sender <#sender description#>
  87. */
  88. - (void)onSalesPaymentFinish:(ASIDownManager *)sender {
  89. for(UIView *view in [_chartViewVC.view subviews])
  90. {
  91. if(view.tag==1001){
  92. [view removeFromSuperview];
  93. }
  94. }
  95. // 服务器返回数据
  96. NSDictionary *dic = [sender.mWebStr JSONValue];
  97. // 服务器返回数据状态值
  98. if (dic && [dic isKindOfClass:[NSDictionary class]])
  99. {
  100. // 服务器返回数据状态值
  101. int iStatus = [[dic objectForKey:@"Status"] intValue];;
  102. [self cancel];
  103. // 服务器返回数据消息
  104. NSString *message = [dic objectForKey:@"Message"];
  105. // 服务器返回数据状态值正确
  106. if (iStatus == 0) {
  107. // 服务器返回数据结果
  108. NSArray * infoArr = [dic objectForKey:@"Result"];
  109. double totalAmount = 0;
  110. _rankList = [[NSMutableArray alloc]init];
  111. _dataListVC.refreshTableView.mTableView.backgroundView = nil;
  112. if(infoArr!=nil && infoArr.count > 0){
  113. double totalAmount = 0;
  114. for(int i = 0;i < infoArr.count;i++){
  115. NSDictionary * dic = infoArr[i];
  116. double backAmount = [[dic objectForKey:@"BackAmount"] doubleValue];
  117. totalAmount += backAmount;
  118. }
  119. for(int i = 0;i <infoArr.count;i++){
  120. NSDictionary *dic = infoArr[i];
  121. double backAmount = [[dic objectForKey:@"BackAmount"] doubleValue];
  122. NSString *objectName = [dic objectForKey:@"ObjectName"];
  123. NSInteger orderSort = i+1;
  124. SalesPaymentRankModel *model = [SalesPaymentRankModel new];
  125. [model setPaymentAmount:backAmount];
  126. [model setObjectName:objectName];
  127. [model setOrderSort:orderSort];
  128. double backPercent = backAmount/totalAmount*100;
  129. NSString *percent = [NSString stringWithFormat:@"%.2f",backPercent];
  130. [model setBackPercent:percent];
  131. SalesPaymentRankFrame *frame=[[SalesPaymentRankFrame alloc]init];
  132. [frame setSalesPaymentListFrame:model];
  133. [_rankList addObject:frame];
  134. }
  135. NSString *totalAmountStr = [NSString stringWithFormat:@"¥%.2f", totalAmount];
  136. _paymentAmountLabel.text=totalAmountStr;
  137. if(_currentIndex == 1){
  138. _chartViewVC.rankList = _rankList;
  139. [_chartViewVC refreshData];
  140. }
  141. else if(_currentIndex == 2){
  142. _dataListVC.rankList = _rankList;
  143. [_dataListVC refreshData];
  144. }
  145. }
  146. else{
  147. if(_currentIndex == 1){
  148. if( _chartViewVC.histogramView!=nil){
  149. [ _chartViewVC.histogramView removeFromSuperview];
  150. }
  151. _noDataView = [self noDataViewByFrame:CGRectMake(0,CGRectGetMaxY(_chartViewVC.bottomSeparatorView.frame),Screen_Width,Screen_Height-rectNavHeight-rectStatusHeight-160)];
  152. _noDataView.tag=1001;
  153. [_chartViewVC.view addSubview:_noDataView];
  154. }
  155. else if(_currentIndex == 2){
  156. [_dataListVC.rankPagingList removeAllObjects];
  157. [_dataListVC.rankList removeAllObjects];
  158. [_dataListVC.refreshTableView reloadData];
  159. _noDataView=[[UIView alloc]init];
  160. _noDataView.frame= _dataListVC.refreshTableView.bounds;
  161. UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(_noDataView.frame.size.width/2-16,_noDataView.frame.size.height/2-16,32,32)];
  162. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  163. [_noDataView addSubview:nodataImgView];
  164. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(_noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  165. label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
  166. label.text = @"无数据";
  167. label.numberOfLines = 2;
  168. label.textColor = [UIColor lightGrayColor];
  169. [_noDataView addSubview:label];
  170. // 有刷新数据的时候
  171. _dataListVC.refreshTableView.mTableView.backgroundView = _noDataView;
  172. _dataListVC.refreshTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  173. }
  174. }
  175. }
  176. // 服务器返回数据状态值异常
  177. else if(iStatus == ActionResultStatusAuthError
  178. ||iStatus == ActionResultStatusNoLogin
  179. ||iStatus == ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  180. [self showReLoginDialog:message];
  181. }
  182. else{
  183. [self showAlertViewText:message];
  184. }
  185. }
  186. }
  187. /**
  188. 数据加载失败回调
  189. @param sender <#sender description#>
  190. */
  191. - (void)onSalesPaymentFail:(ASIDownManager *)sender {
  192. [self showAlertViewText:@"网络异常"];
  193. }
  194. /**
  195. 滑动label位置
  196. @param scrollView <#scrollView description#>
  197. */
  198. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  199. //实时计算当前位置,实现和titleView上的按钮的联动
  200. CGFloat contentOffSetX = scrollView.contentOffset.x;
  201. CGFloat X = contentOffSetX/ navcount;
  202. CGRect frame = _sliderLabel.frame;
  203. frame.origin.x = X;
  204. _sliderLabel.frame = frame;
  205. }
  206. /**
  207. 滑动完成
  208. @param scrollView <#scrollView description#>
  209. */
  210. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  211. CGFloat contentOffSetX = scrollView.contentOffset.x;
  212. int index = contentOffSetX/Screen_Width;
  213. [self sliderWithTag:index + 1];
  214. }
  215. #pragma mark - 私有函数
  216. /*
  217. 初始化UI
  218. */
  219. - (void)initUI{
  220. [self.navigationController.navigationBar setShadowImage:[UIImage new]];
  221. self.edgesForExtendedLayout = UIRectEdgeNone;
  222. UIView *titleView = [[UIView alloc]init];
  223. titleView.backgroundColor = self.navigationController.navigationBar.barTintColor;
  224. titleView.frame = CGRectMake(0, 0, Screen_Width, 40);
  225. UILabel *titlePaymentAmount = [[UILabel alloc]init];
  226. titlePaymentAmount.frame = CGRectMake(20, 10, 100, 25);
  227. titlePaymentAmount.text = @"回款总额(元)";
  228. titlePaymentAmount.textColor = [UIColor whiteColor];
  229. titlePaymentAmount.font = [UIFont systemFontOfSize:16];
  230. [titleView addSubview:titlePaymentAmount];
  231. [self.view addSubview:titleView];
  232. _paymentAmountLabel = [[UILabel alloc]init];
  233. _paymentAmountLabel.frame = CGRectMake(CGRectGetMaxX(titlePaymentAmount.frame),10, 200, 25);
  234. _paymentAmountLabel.textColor = [UIColor whiteColor];
  235. _paymentAmountLabel.font = [UIFont systemFontOfSize:16];
  236. [titleView addSubview:_paymentAmountLabel];
  237. UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 40, Screen_Width, 40)];
  238. [self.view addSubview:navView];
  239. [self.view setBackgroundColor:[UIColor whiteColor]];
  240. _chartButton = [UIButton buttonWithType:UIButtonTypeCustom];
  241. [_chartButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
  242. [_chartButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  243. _chartButton.frame = CGRectMake(0, 0, Screen_Width/navcount, navView.frame.size.height);
  244. _chartButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  245. [_chartButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
  246. [_chartButton setTitle:@"图形(前10条)" forState:UIControlStateNormal];
  247. _chartButton.tag = 1;
  248. _chartButton.selected = YES;
  249. [navView addSubview:_chartButton];
  250. _dataButton = [UIButton buttonWithType:UIButtonTypeCustom];
  251. _dataButton.frame = CGRectMake(CGRectGetMaxX(_chartButton.frame),0, Screen_Width/navcount, navView.frame.size.height);
  252. [_dataButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
  253. [_dataButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  254. _dataButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  255. [_dataButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
  256. [ _dataButton setTitle:@"全部列表数据" forState:UIControlStateNormal];
  257. _dataButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  258. _dataButton.tag = 2;
  259. [navView addSubview: _dataButton];
  260. _sliderLabel = [[UILabel alloc]initWithFrame:CGRectMake(_chartButton.frame.origin.x, 40-2, Screen_Width/navcount, 2)];
  261. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(((Screen_Width/navcount)-50)/2, 0, 50, 2)];
  262. line.backgroundColor = [UIColor redColor];
  263. [_sliderLabel addSubview:line];
  264. [navView addSubview:_sliderLabel];
  265. __weak typeof(self) weakself=self;
  266. // 抽屉对象
  267. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  268. for (SideSlipModel *model in dataList) {
  269. model.selectedItemList = nil;
  270. model.customDict = nil;
  271. }
  272. } commitBlock:^(NSArray *dataList) {
  273. // 查询条件
  274. SideSlipModel *serviceRegionModel = dataList[0];
  275. SalesAchievementSearchModel *m = [serviceRegionModel.customDict objectForKey:SEARCH_RANGE_MODEL];
  276. _rankType = m.rankType;
  277. _mStartDate = m.startDate;
  278. _mEndDate = m.endDate;
  279. if(_rankType == nil){
  280. [self showAlertViewText:@"请选择排行类型"];
  281. return;
  282. }
  283. if(_mStartDate == nil){
  284. [self showAlertViewText:@"请选择开始日期"];
  285. return;
  286. }
  287. if(_mEndDate == nil){
  288. [self showAlertViewText:@"请选择结束日期"];
  289. return;
  290. }
  291. NSUInteger result = [DateFormat compareDate:_mStartDate withDate:_mEndDate];
  292. if(result == -1){
  293. [self showAlertViewText:@"开始日期不能大于结束日期"];
  294. return;
  295. }
  296. NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
  297. [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式
  298. NSDate *startD = [dateFormat dateFromString:_mStartDate];
  299. NSDate *endD = [dateFormat dateFromString:_mEndDate];
  300. NSInteger days = [DateFormat calculateDaysFromBegin:startD end:endD];
  301. if(days > 31){
  302. [self showAlertViewText:@"日期间隔天数不能大于31天"];
  303. return;
  304. }
  305. _paymentAmountLabel.text=@"";
  306. [self loadData];
  307. [weakself.filterController dismiss];
  308. }];
  309. _filterController.animationDuration = AnimationDuration;
  310. _filterController.hasHeadView = YES;
  311. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  312. _filterController.dataList = [self packageDataList];
  313. }
  314. /**
  315. 无数据的view
  316. @param frame <#frame description#>
  317. @return <#return value description#>
  318. */
  319. - (UIView *)noDataViewByFrame:(CGRect)frame{
  320. UIView *noDataView = [[UIView alloc]init];
  321. noDataView.frame = frame;
  322. UIImageView *nodataImgView = [[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
  323. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  324. [noDataView addSubview:nodataImgView];
  325. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  326. label.font = [UIFont systemFontOfSize:NoDataFontOfSize];
  327. label.text = @"无数据";
  328. label.numberOfLines = 2;
  329. label.textColor = [UIColor lightGrayColor];
  330. [noDataView addSubview:label];
  331. return noDataView;
  332. }
  333. /**
  334. 加载数据
  335. */
  336. -(void)loadData{
  337. [self startLoading];
  338. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  339. [dict setObject:@"SalesBackAmountRankingIphone" forKey:@"Action"];
  340. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  341. [dict setObject:kkUserCode forKey:@"UserCode"];
  342. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  343. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  344. [dict setObject:_mStartDate forKey:@"AccountDateFrom"];
  345. [dict setObject:_mEndDate forKey:@"AccountDateTo"];
  346. [dict setObject:_rankType forKey:@"SortType"];
  347. _downManager = [[ASIDownManager alloc] init];
  348. _downManager.delegate = self;
  349. _downManager.OnImageDown = @selector(onSalesPaymentFinish:);
  350. _downManager.OnImageFail = @selector(onSalesPaymentFail:);
  351. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  352. }
  353. /**
  354. 隐藏进度条
  355. */
  356. - (void)cancel {
  357. [self stopLoading];
  358. }
  359. /**
  360. 数据源
  361. @return <#return value description#>
  362. */
  363. - (NSArray *)packageDataList {
  364. NSMutableArray *dataArray = [NSMutableArray array];
  365. SideSlipModel *model = [[SideSlipModel alloc] init];
  366. model.containerCellClass = @"SalesAchievementSearchCell";
  367. model.regionTitle = @"查询条件";
  368. [dataArray addObject:model];
  369. return [dataArray mutableCopy];
  370. }
  371. -(void)search{
  372. [_filterController show];
  373. }
  374. /**
  375. 初始化scrollView
  376. */
  377. - (void)setMainSrollView{
  378. _mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 80, Screen_Width, self.view.frame.size.height)];
  379. _mainScrollView.delegate = self;
  380. _mainScrollView.backgroundColor = [UIColor whiteColor];
  381. _mainScrollView.pagingEnabled = YES;
  382. _mainScrollView.showsHorizontalScrollIndicator = NO;
  383. _mainScrollView.showsVerticalScrollIndicator = NO;
  384. [self.view addSubview:_mainScrollView];
  385. NSArray *views = @[self.chartViewVC.view,self.dataListVC.view];
  386. for (NSInteger i = 0; i< views.count; i++) {
  387. //把三个vc的view依次贴到mainScrollView上面
  388. UIView *pageView = [[UIView alloc]initWithFrame:CGRectMake(Screen_Width * i, 0, _mainScrollView.frame.size.width, _mainScrollView.frame.size.height - 100)];
  389. [pageView addSubview:views[i]];
  390. [_mainScrollView addSubview:pageView];
  391. }
  392. _mainScrollView.contentSize = CGSizeMake(Screen_Width*(views.count), 0);
  393. //滚动到_currentIndex对应的tab
  394. [_mainScrollView setContentOffset:CGPointMake((_mainScrollView.frame.size.width)*_currentIndex, 0) animated:YES];
  395. }
  396. /**
  397. 滑动tag
  398. @param tag <#tag description#>
  399. */
  400. - (void)sliderWithTag:(NSInteger)tag{
  401. self.currentIndex = tag;
  402. _chartButton.selected = NO;
  403. _dataButton.selected = NO;
  404. UIButton *sender = [self buttonWithTag:tag];
  405. sender.selected = YES;
  406. if(_rankList!=nil&&_rankList.count>0){
  407. if(_currentIndex == 1){
  408. _chartViewVC.rankList = _rankList;
  409. [_chartViewVC refreshData];
  410. }
  411. else if(_currentIndex == 2){
  412. _dataListVC.rankList = _rankList;
  413. [_dataListVC refreshData];
  414. }
  415. }
  416. else{
  417. if(_currentIndex == 1){
  418. if( _chartViewVC.histogramView!=nil){
  419. [ _chartViewVC.histogramView removeFromSuperview];
  420. }
  421. _noDataView = [self noDataViewByFrame:CGRectMake(0,CGRectGetMaxY(_chartViewVC.bottomSeparatorView.frame),Screen_Width,Screen_Height-rectNavHeight-rectStatusHeight-160)];
  422. _noDataView.tag=1001;
  423. [_chartViewVC.view addSubview:_noDataView];
  424. }
  425. else if(_currentIndex == 2){
  426. [_dataListVC.rankList removeAllObjects];
  427. [_dataListVC.rankPagingList removeAllObjects];
  428. [_dataListVC.refreshTableView reloadData];
  429. UIView *noDataView = [self noDataViewByFrame:_dataListVC.refreshTableView.mTableView.bounds];
  430. // 有刷新数据的时候
  431. _dataListVC.refreshTableView.mTableView.backgroundView = noDataView;
  432. _dataListVC.refreshTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  433. }
  434. }
  435. //动画
  436. _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
  437. }
  438. /*
  439. 获得导航按钮
  440. */
  441. - (UIButton *)buttonWithTag:(NSInteger )tag{
  442. if (tag == 1) {
  443. return _chartButton;
  444. }
  445. else if (tag == 2){
  446. return _dataButton;
  447. }
  448. else{
  449. return nil;
  450. }
  451. }
  452. /**
  453. 按钮点击事件
  454. @param sender <#sender description#>
  455. */
  456. - (void)sliderAction:(UIButton *)sender{
  457. if (self.currentIndex == sender.tag) {
  458. return;
  459. }
  460. [self.view endEditing:YES];
  461. [self sliderAnimationWithTag:sender.tag];
  462. [UIView animateWithDuration:0.3 animations:^{
  463. _mainScrollView.contentOffset = CGPointMake(Screen_Width * (sender.tag-1), 0);
  464. } completion:^(BOOL finished) {
  465. }];
  466. if(_rankList!=nil&&_rankList.count>0){
  467. if(_currentIndex == 1){
  468. _chartViewVC.rankList = _rankList;
  469. [_chartViewVC refreshData];
  470. }
  471. else if(_currentIndex == 2){
  472. _dataListVC.rankList = _rankList;
  473. [_dataListVC refreshData];
  474. }
  475. }
  476. else{
  477. if(_currentIndex == 1){
  478. if( _chartViewVC.histogramView!=nil){
  479. [ _chartViewVC.histogramView removeFromSuperview];
  480. }
  481. for(UIView *view in [_chartViewVC.view subviews])
  482. {
  483. if(view.tag==1001){
  484. [view removeFromSuperview];
  485. }
  486. }
  487. _noDataView = [self noDataViewByFrame:CGRectMake(0,CGRectGetMaxY(_chartViewVC.bottomSeparatorView.frame),Screen_Width,Screen_Height-rectNavHeight-rectStatusHeight-160)];
  488. _noDataView.tag=1001;
  489. [_chartViewVC.view addSubview:_noDataView];
  490. }
  491. else if(_currentIndex == 2){
  492. [_dataListVC.rankList removeAllObjects];
  493. [_dataListVC.rankPagingList removeAllObjects];
  494. [_dataListVC.refreshTableView reloadData];
  495. UIView *noDataView = [self noDataViewByFrame:_dataListVC.refreshTableView.mTableView.bounds];
  496. // 有刷新数据的时候
  497. _dataListVC.refreshTableView.mTableView.backgroundView = noDataView;
  498. _dataListVC.refreshTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  499. }
  500. }
  501. }
  502. /**
  503. 安全区视图发生变化
  504. */
  505. -(void)viewSafeAreaInsetsDidChange{
  506. self.view.backgroundColor = [UIColor whiteColor];
  507. _mainScrollView.frame = CGRectMake(0, 80, Screen_Width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-80);
  508. for (NSInteger i = 0; i < _mainScrollView.subviews.count; i++) {
  509. _mainScrollView.subviews[i].frame = CGRectMake(Screen_Width * i, 0, Screen_Width,CGRectGetHeight(_mainScrollView.frame));
  510. }
  511. [self.chartViewVC viewSafeAreaInsetsDidChange];
  512. [self.dataListVC viewSafeAreaInsetsDidChange];
  513. [super viewSafeAreaInsetsDidChange];
  514. }
  515. /**
  516. 滑动tag
  517. @param tag <#tag description#>
  518. */
  519. - (void)sliderAnimationWithTag:(NSInteger)tag{
  520. self.currentIndex = tag;
  521. _chartButton.selected = NO;
  522. _dataButton.selected = NO;
  523. UIButton *sender = [self buttonWithTag:tag];
  524. sender.selected = YES;
  525. //动画
  526. [UIView animateWithDuration:0.3 animations:^{
  527. _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
  528. } completion:^(BOOL finished) {
  529. }];
  530. }
  531. @end