SalesAchievementRankHomeViewController.m 23 KB

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