SalesAnalysisListNewViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. //
  2. // SalesAnalysisListNewViewController.m
  3. // IBOSS
  4. //
  5. // Created by Simon on 2019/6/10.
  6. // Copyright © 2019 elongtian. All rights reserved.
  7. //
  8. #import "SalesAnalysisListNewViewController.h"
  9. #import "SalesAnalysisCell.h"
  10. #import "SideSlipModel.h"
  11. #import "SalesAnalysisSearchModel.h"
  12. #import "DateFormat.h"
  13. @interface SalesAnalysisListNewViewController ()<UITableViewDataSource,UITableViewDelegate,RefreshTableViewDelegate>{
  14. /**
  15. 查询参数的Model
  16. */
  17. SalesAnalysisSearchModel *_model;
  18. /**
  19. 页码
  20. */
  21. int _pageNumber;
  22. }
  23. @end
  24. @implementation SalesAnalysisListNewViewController
  25. /**
  26. 导航数
  27. */
  28. static int navcount = 2;
  29. static int topH = 40;
  30. #pragma mark - 公共函数
  31. /**
  32. viewDidLoad函数
  33. */
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. [self initUI];
  37. [self setMainSrollView];
  38. [self sliderWithTag:self.currentIndex+1];
  39. [self loadNavStyle];
  40. [self initSlideSlip];
  41. [self startLoading];
  42. [self reloadData];
  43. }
  44. /**
  45. 安全区视图发生变化
  46. */
  47. -(void)viewSafeAreaInsetsDidChange{
  48. _mainScrollView.frame = CGRectMake(0,topH, Screen_Width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-topH);
  49. for (NSInteger i = 0; i < _mainScrollView.subviews.count; i++) {
  50. _mainScrollView.subviews[i].frame = CGRectMake(Screen_Width * i, 0, Screen_Width,CGRectGetHeight(_mainScrollView.frame));
  51. }
  52. [self.chartViewVC viewSafeAreaInsetsDidChange];
  53. [self.dataListVC viewSafeAreaInsetsDidChange];
  54. [super viewSafeAreaInsetsDidChange];
  55. }
  56. /**
  57. didReceiveMemoryWarning函数
  58. */
  59. - (void)didReceiveMemoryWarning {
  60. [super didReceiveMemoryWarning];
  61. }
  62. /**
  63. 初始化畅滞销图表控制器
  64. @return
  65. */
  66. - (SalesAnalysisListNewChartViewController *)chartViewVC{
  67. if (!_chartViewVC) {
  68. _chartViewVC = [[SalesAnalysisListNewChartViewController alloc] init];
  69. }
  70. return _chartViewVC;
  71. }
  72. /**
  73. 初始化畅滞销列表控制器
  74. @return
  75. */
  76. - (SalesAnalysisListDataViewController *)dataListVC{
  77. if (!_dataListVC) {
  78. _dataListVC = [[SalesAnalysisListDataViewController alloc] init];
  79. }
  80. return _dataListVC;
  81. }
  82. #pragma mark - 自定义方法
  83. /**
  84. 分页取数据
  85. */
  86. - (void) pagingData{
  87. //页数
  88. int maxPages = (int)ceil(_arrAlldataList.count/20);
  89. //最后一页的个数
  90. CGFloat numberOfLastPage = _arrAlldataList.count - 20 * maxPages;
  91. if(_pageNumber < maxPages){
  92. NSArray *arr = [_arrAlldataList subarrayWithRange:NSMakeRange(20*_pageNumber,20)];
  93. [_arrDataList addObjectsFromArray:arr];
  94. _customTableView.mbMoreHidden = NO;
  95. }else if(_pageNumber == maxPages){
  96. [_arrDataList addObjectsFromArray:[_arrAlldataList subarrayWithRange:NSMakeRange(20*_pageNumber, numberOfLastPage)]];
  97. _customTableView.mbMoreHidden = YES;
  98. }
  99. [_customTableView FinishLoading];
  100. [_customTableView reloadData];
  101. }
  102. #pragma mark - 委托函数
  103. /**
  104. 滑动label位置
  105. @param scrollView <#scrollView description#>
  106. */
  107. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  108. //实时计算当前位置,实现和titleView上的按钮的联动
  109. CGFloat contentOffSetX = scrollView.contentOffset.x;
  110. CGFloat X = contentOffSetX/ navcount;
  111. CGRect frame = _sliderLabel.frame;
  112. frame.origin.x = X;
  113. _sliderLabel.frame = frame;
  114. }
  115. /**
  116. 滑动完成
  117. @param scrollView <#scrollView description#>
  118. */
  119. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  120. CGFloat contentOffSetX = scrollView.contentOffset.x;
  121. int index = contentOffSetX/Screen_Width;
  122. [self sliderWithTag:index + 1];
  123. }
  124. #pragma mark - 数据请求回调
  125. /**
  126. 加载数据
  127. */
  128. - (void)reloadData
  129. {
  130. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  131. [dict setObject:@"BestsellersAnalysisIphone" forKey:@"Action"];
  132. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  133. [dict setObject:kkUserCode forKey:@"UserCode"];
  134. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  135. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  136. [dict setObject:_model.strCommodityName forKey:@"GoodsName"];
  137. [dict setObject:_model.strOnlyCode forKey:@"OnlyCode"];
  138. [dict setObject:_model.strCommodityBrandID forKeyedSubscript:@"BrandID"];
  139. [dict setObject:@"" forKeyedSubscript:@"KindCode"];
  140. [dict setObject:_model.strStartDate forKeyedSubscript:@"OperateDateFrom"];
  141. [dict setObject:_model.strEndDate forKey:@"OperateDateTo"];
  142. [dict setObject:_model.strType forKey:@"SortType"];
  143. [dict setObject:_model.strGrade forKey:@"GradeFlag"];
  144. [dict setObject:_model.strChannel forKey:@"ChannelFlag"];
  145. [dict setObject:_model.strAreaColor forKey:@"ColorNoFlag"];
  146. [dict setObject:_model.strSpecification forKey:@"SpecificationFlag"];
  147. _downManager = [[ASIDownManager alloc] init];
  148. _downManager.delegate = self;
  149. _downManager.onRequestSuccess = @selector(onLoadFinish:);
  150. _downManager.onRequestFail = @selector(onLoadFail:);
  151. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  152. }
  153. /**
  154. 加载列表数据失败回调
  155. @param sender
  156. */
  157. - (void)onLoadFail:(ASIDownManager *)sender {
  158. [self stopLoading];
  159. [self showAlertViewText:@"网络异常"];
  160. }
  161. /**
  162. 加载列表数据成功回调
  163. @param sender
  164. */
  165. - (void)onLoadFinish:(ASIDownManager *)sender {
  166. int iNewCount = 0;
  167. _customTableView.mTableView.backgroundView = nil;
  168. // 取消进度条
  169. [self stopLoading];
  170. // 服务器返回数据
  171. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  172. // 服务器返回数据状态值
  173. int iStatus = resultModel.status;
  174. // 服务器返回数据消息
  175. NSString *message = resultModel.message;
  176. // 服务器返回数据状态值正确
  177. if (iStatus == 0) {
  178. NSArray * infoArr = (NSArray *)resultModel.result;
  179. if(infoArr != nil&& infoArr.count > 0)
  180. {
  181. // 转换model对象
  182. [self.arrAlldataList removeAllObjects];
  183. if(infoArr.count > 0 ){
  184. for (int i = 0; i < infoArr.count; i++) {
  185. NSDictionary *str = infoArr[i];
  186. SalesAnalysisModel *model = [SalesAnalysisModel dk_modelWithDictionary:str];
  187. model.ranking = [NSString stringWithFormat:@"%d",i+1];
  188. [self.arrAlldataList addObject:model];
  189. }
  190. }
  191. self.chartViewVC.rankList = self.arrAlldataList;
  192. self.chartViewVC.sortType = _model.strType;
  193. [self.chartViewVC refreshData];
  194. self.dataListVC.rankList = self.arrAlldataList;
  195. [self.dataListVC refreshData];
  196. _noDataView.hidden = YES;
  197. for(UIView *view in [_chartViewVC.view subviews])
  198. {
  199. if(view.tag != 11){
  200. view.hidden = NO;
  201. }
  202. if(view.tag==1001){
  203. [view removeFromSuperview];
  204. }
  205. }
  206. }
  207. else{
  208. if( _chartViewVC.histogramView!=nil){
  209. [ _chartViewVC.histogramView removeFromSuperview];
  210. }
  211. for(UIView *view in [_chartViewVC.view subviews])
  212. {
  213. if(view.tag != 11){
  214. view.hidden = YES;
  215. }
  216. if(view.tag==1001){
  217. [view removeFromSuperview];
  218. }
  219. _noDataView = [self noDataViewByFrame:CGRectMake(0,0,Screen_Width,Screen_Height-rectNavHeight-rectStatusHeight-160)];
  220. _noDataView.tag=1001;
  221. // 有刷新数据的时候
  222. [_chartViewVC.view addSubview:_noDataView];
  223. }
  224. [_dataListVC.rankPagingList removeAllObjects];
  225. [_dataListVC.rankList removeAllObjects];
  226. [_dataListVC.refreshTableView reloadData];
  227. // 有刷新数据的时候
  228. [_dataListVC.view addSubview:_noDataView];
  229. _dataListVC.refreshTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  230. [self showAlertViewBackText:@"未找到匹配结果"];
  231. }
  232. }
  233. // 服务器返回数据状态值异常
  234. else if(iStatus == ActionResultStatusAuthError
  235. ||iStatus == ActionResultStatusNoLogin
  236. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  237. [self showReLoginDialog:message];
  238. }
  239. else{
  240. [_customTableView FinishLoading];
  241. [self showAlertViewText:message];
  242. }
  243. }
  244. #pragma mark - tableView刷新回调
  245. /**
  246. 加载更多
  247. @param sender <#sender description#>
  248. */
  249. - (void)LoadMoreList:(RefreshTableView *)sender {
  250. _pageNumber++;
  251. [self pagingData];
  252. }
  253. /**
  254. 下拉刷新
  255. @param sender <#sender description#>
  256. */
  257. - (void)ReloadList:(RefreshTableView *)sender{
  258. _pageNumber = 0;
  259. [self.arrDataList removeAllObjects];
  260. [self.arrAlldataList removeAllObjects];
  261. [_customTableView reloadData];
  262. _customTableView.mbMoreHidden=YES;
  263. [self startLoading];
  264. [self reloadData];
  265. }
  266. #pragma mark - 初始化
  267. /**
  268. 初始化ui
  269. */
  270. - (void)initUI{
  271. self.navigationItem.title = @"商品畅滞销分析";
  272. _arrDataList = [[NSMutableArray alloc]init];
  273. _arrAlldataList = [[NSMutableArray alloc]init];
  274. _infoModel = [[SalesAnalysisModel alloc]init];
  275. _model = [[SalesAnalysisSearchModel alloc] init];
  276. _model.strCommodityName = @"";
  277. _model.strEndDate = [DateFormat getCurrentDate];
  278. _model.strStartDate = [DateFormat getDateBefore:31];
  279. _model.strOnlyCode = @"";
  280. _model.strCommodityBrandID = @"";
  281. _model.strCommodityBrand = @"";
  282. _model.strType = @"1";
  283. _model.strAreaColor = @"0";
  284. _model.strSpecification = @"0";
  285. _model.strChannel = @"0";
  286. _model.strGrade = @"0";
  287. UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 40)];
  288. [self.view addSubview:navView];
  289. [self.view setBackgroundColor:[UIColor whiteColor]];
  290. _chartButton = [UIButton buttonWithType:UIButtonTypeCustom];
  291. [_chartButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
  292. [_chartButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  293. _chartButton.frame = CGRectMake(0, 0, Screen_Width/navcount, navView.frame.size.height);
  294. _chartButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  295. [_chartButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
  296. [_chartButton setTitle:@"图形(前10条)" forState:UIControlStateNormal];
  297. _chartButton.tag = 1;
  298. _chartButton.selected = YES;
  299. [navView addSubview:_chartButton];
  300. _dataButton= [UIButton buttonWithType:UIButtonTypeCustom];
  301. _dataButton.frame = CGRectMake(CGRectGetMaxX(_chartButton.frame),0, Screen_Width/navcount, navView.frame.size.height);
  302. [_dataButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
  303. [_dataButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  304. _dataButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  305. [_dataButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
  306. [ _dataButton setTitle:@"全部列表数据" forState:UIControlStateNormal];
  307. _dataButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  308. _dataButton.tag = 2;
  309. [navView addSubview: _dataButton];
  310. _sliderLabel = [[UILabel alloc]initWithFrame:CGRectMake(_chartButton.frame.origin.x, 40-2, Screen_Width/navcount, 2)];
  311. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(((Screen_Width/navcount)-50)/2, 0, 50, 2)];
  312. line.backgroundColor = [UIColor redColor];
  313. [_sliderLabel addSubview:line];
  314. [navView addSubview:_sliderLabel];
  315. }
  316. /**
  317. 导航按钮样式
  318. */
  319. - (void)loadNavStyle
  320. {
  321. //右边
  322. UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 16)];
  323. UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom];
  324. [btnfilter addTarget:self action:@selector(search)
  325. forControlEvents:UIControlEventTouchUpInside];
  326. btnfilter.frame = CGRectMake(0, 0, 16, 16);
  327. [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  328. [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"]
  329. forState:UIControlStateNormal];
  330. [v addSubview:btnfilter];
  331. UIButton *filterLbl = [[UIButton alloc]init];
  332. filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16);
  333. [filterLbl setTitle:@"筛选" forState:UIControlStateNormal];
  334. [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  335. filterLbl.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  336. [filterLbl addTarget:self action:@selector(search)
  337. forControlEvents:UIControlEventTouchUpInside];
  338. [v addSubview:filterLbl];
  339. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v];
  340. self.navigationItem.rightBarButtonItem = menubtnAdd;
  341. //返回
  342. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  343. [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
  344. [button addTarget:self action:@selector(goBack)
  345. forControlEvents:UIControlEventTouchUpInside];
  346. button.frame = CGRectMake(0, 0,45,22);
  347. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  348. self.navigationItem.leftBarButtonItem = menuButton;
  349. }
  350. /**
  351. 按钮点击事件
  352. @param sender
  353. */
  354. - (void)sliderAction:(UIButton *)sender{
  355. if (self.currentIndex == sender.tag) {
  356. return;
  357. }
  358. [self.view endEditing:YES];
  359. [self sliderAnimationWithTag:sender.tag];
  360. [UIView animateWithDuration:0.3 animations:^{
  361. self.mainScrollView.contentOffset = CGPointMake(Screen_Width * (sender.tag-1), 0);
  362. } completion:^(BOOL finished) {
  363. }];
  364. }
  365. /**
  366. 滑动tag
  367. @param tag <#tag description#>
  368. */
  369. - (void)sliderWithTag:(NSInteger)tag{
  370. self.currentIndex = tag;
  371. _chartButton.selected = NO;
  372. _dataButton.selected = NO;
  373. UIButton *sender = [self buttonWithTag:tag];
  374. sender.selected = YES;
  375. //动画
  376. _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
  377. }
  378. /**
  379. 滑动tag
  380. @param tag <#tag description#>
  381. */
  382. - (void)sliderAnimationWithTag:(NSInteger)tag{
  383. self.currentIndex = tag;
  384. _chartButton.selected = NO;
  385. _dataButton.selected = NO;
  386. UIButton *sender = [self buttonWithTag:tag];
  387. sender.selected = YES;
  388. //动画
  389. [UIView animateWithDuration:0.3 animations:^{
  390. self.sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, self.sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
  391. } completion:^(BOOL finished) {
  392. }];
  393. }
  394. /**
  395. 初始化scrollView
  396. */
  397. - (void)setMainSrollView{
  398. _mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, topH, Screen_Width, self.view.frame.size.height)];
  399. _mainScrollView.delegate = self;
  400. _mainScrollView.backgroundColor = [UIColor whiteColor];
  401. _mainScrollView.pagingEnabled = YES;
  402. _mainScrollView.showsHorizontalScrollIndicator = NO;
  403. _mainScrollView.showsVerticalScrollIndicator = NO;
  404. [self.view addSubview:_mainScrollView];
  405. NSArray *views = @[self.chartViewVC.view,self.dataListVC.view];
  406. for (NSInteger i = 0; i < views.count; i++) {
  407. //把三个vc的view依次贴到mainScrollView上面
  408. UIView *pageView = [[UIView alloc]initWithFrame:CGRectMake(Screen_Width * i, 0, _mainScrollView.frame.size.width, _mainScrollView.frame.size.height - 100)];
  409. [pageView addSubview:views[i]];
  410. [_mainScrollView addSubview:pageView];
  411. }
  412. _mainScrollView.contentSize = CGSizeMake(Screen_Width*(views.count), 0);
  413. //滚动到_currentIndex对应的tab
  414. [_mainScrollView setContentOffset:CGPointMake((_mainScrollView.frame.size.width)*_currentIndex, 0) animated:YES];
  415. }
  416. /**
  417. 抽屉弹出
  418. */
  419. - (void)search{
  420. [_filterController show];
  421. }
  422. /**
  423. 抽屉初始化
  424. */
  425. - (void)initSlideSlip{
  426. // 抽屉对象
  427. __weak typeof(self) weakself=self;
  428. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  429. for (SideSlipModel *model in dataList) {
  430. model.selectedItemList = nil;
  431. model.customDict = nil;
  432. }
  433. } commitBlock:^(NSArray *dataList) {
  434. //查询条件
  435. SideSlipModel *serviceRegionModel = dataList[0];
  436. _model = [serviceRegionModel.customDict objectForKey:SALESANALYSIS_SEARCH_RANGE_MODEL];
  437. if(_model.strStartDate == nil){
  438. [self showAlertViewText:@"请选择开始日期"];
  439. return;
  440. }
  441. if(_model.strEndDate == nil){
  442. [self showAlertViewText:@"请选择结束日期"];
  443. return;
  444. }
  445. NSUInteger result = [DateFormat compareDate:_model.strStartDate withDate:_model.strEndDate];
  446. if(result == -1){
  447. [self showAlertViewText:@"开始日期不能大于结束日期"];
  448. return;
  449. }
  450. NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
  451. [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式
  452. NSDate *startD = [dateFormat dateFromString:_model.strStartDate];
  453. NSDate *endD = [dateFormat dateFromString:_model.strEndDate];
  454. NSInteger days = [DateFormat calculateDaysFromBegin:startD end:endD];
  455. if(days > 31){
  456. [self showAlertViewText:@"日期间隔天数不能大于31天"];
  457. return;
  458. }
  459. [weakself.filterController dismiss];
  460. [self ReloadList:self.customTableView];
  461. }];
  462. _filterController.animationDuration = AnimationDuration;
  463. _filterController.hasHeadView = YES;
  464. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  465. _filterController.dataList = [self packageDataList];
  466. }
  467. /**
  468. 数据源
  469. @return
  470. */
  471. - (NSArray *)packageDataList {
  472. NSMutableArray *dataArray = [NSMutableArray array];
  473. SideSlipModel *model = [[SideSlipModel alloc] init];
  474. model.containerCellClass = @"SalesAnalysisSearchCell";
  475. model.regionTitle = @"查询条件";
  476. [dataArray addObject:model];
  477. return [dataArray mutableCopy];
  478. }
  479. /*
  480. 获得导航按钮
  481. */
  482. - (UIButton *)buttonWithTag:(NSInteger )tag{
  483. if (tag == 1) {
  484. return _chartButton;
  485. }
  486. else if (tag == 2){
  487. return _dataButton;
  488. }
  489. else{
  490. return nil;
  491. }
  492. }
  493. @end