| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- //
- // SalesAnalysisListNewViewController.m
- // IBOSS
- //
- // Created by Simon on 2019/6/10.
- // Copyright © 2019 elongtian. All rights reserved.
- //
- #import "SalesAnalysisListNewViewController.h"
- #import "SalesAnalysisCell.h"
- #import "SideSlipModel.h"
- #import "SalesAnalysisSearchModel.h"
- #import "DateFormat.h"
- @interface SalesAnalysisListNewViewController ()<UITableViewDataSource,UITableViewDelegate,RefreshTableViewDelegate>{
-
- /**
- 查询参数的Model
- */
- SalesAnalysisSearchModel *_model;
-
- /**
- 页码
- */
- int _pageNumber;
- }
- @end
- @implementation SalesAnalysisListNewViewController
- /**
- 导航数
- */
- static int navcount = 2;
- static int topH = 40;
- #pragma mark - 公共函数
- /**
- viewDidLoad函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self initUI];
- [self setMainSrollView];
- [self sliderWithTag:self.currentIndex+1];
- [self loadNavStyle];
- [self initSlideSlip];
- [self startLoading];
- [self reloadData];
- }
- /**
- 安全区视图发生变化
- */
- -(void)viewSafeAreaInsetsDidChange{
- _mainScrollView.frame = CGRectMake(0,topH, Screen_Width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-topH);
- for (NSInteger i = 0; i < _mainScrollView.subviews.count; i++) {
- _mainScrollView.subviews[i].frame = CGRectMake(Screen_Width * i, 0, Screen_Width,CGRectGetHeight(_mainScrollView.frame));
- }
- [self.chartViewVC viewSafeAreaInsetsDidChange];
- [self.dataListVC viewSafeAreaInsetsDidChange];
- [super viewSafeAreaInsetsDidChange];
- }
- /**
- didReceiveMemoryWarning函数
- */
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- /**
- 初始化畅滞销图表控制器
- @return
- */
- - (SalesAnalysisListNewChartViewController *)chartViewVC{
- if (!_chartViewVC) {
- _chartViewVC = [[SalesAnalysisListNewChartViewController alloc] init];
- }
- return _chartViewVC;
- }
- /**
- 初始化畅滞销列表控制器
- @return
- */
- - (SalesAnalysisListDataViewController *)dataListVC{
- if (!_dataListVC) {
- _dataListVC = [[SalesAnalysisListDataViewController alloc] init];
- }
- return _dataListVC;
- }
- #pragma mark - 自定义方法
- /**
- 分页取数据
- */
- - (void) pagingData{
- //页数
- int maxPages = (int)ceil(_arrAlldataList.count/20);
- //最后一页的个数
- CGFloat numberOfLastPage = _arrAlldataList.count - 20 * maxPages;
- if(_pageNumber < maxPages){
- NSArray *arr = [_arrAlldataList subarrayWithRange:NSMakeRange(20*_pageNumber,20)];
- [_arrDataList addObjectsFromArray:arr];
- _customTableView.mbMoreHidden = NO;
- }else if(_pageNumber == maxPages){
- [_arrDataList addObjectsFromArray:[_arrAlldataList subarrayWithRange:NSMakeRange(20*_pageNumber, numberOfLastPage)]];
- _customTableView.mbMoreHidden = YES;
- }
- [_customTableView FinishLoading];
- [_customTableView reloadData];
- }
- #pragma mark - 委托函数
- /**
- 滑动label位置
- @param scrollView <#scrollView description#>
- */
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
- //实时计算当前位置,实现和titleView上的按钮的联动
- CGFloat contentOffSetX = scrollView.contentOffset.x;
- CGFloat X = contentOffSetX/ navcount;
- CGRect frame = _sliderLabel.frame;
- frame.origin.x = X;
- _sliderLabel.frame = frame;
- }
- /**
- 滑动完成
- @param scrollView <#scrollView description#>
- */
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
- CGFloat contentOffSetX = scrollView.contentOffset.x;
- int index = contentOffSetX/Screen_Width;
- [self sliderWithTag:index + 1];
- }
- #pragma mark - 数据请求回调
- /**
- 加载数据
- */
- - (void)reloadData
- {
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"BestsellersAnalysisIphone" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:_model.strCommodityName forKey:@"GoodsName"];
- [dict setObject:_model.strOnlyCode forKey:@"OnlyCode"];
- [dict setObject:_model.strCommodityBrandID forKeyedSubscript:@"BrandID"];
- [dict setObject:@"" forKeyedSubscript:@"KindCode"];
- [dict setObject:_model.strStartDate forKeyedSubscript:@"OperateDateFrom"];
- [dict setObject:_model.strEndDate forKey:@"OperateDateTo"];
- [dict setObject:_model.strType forKey:@"SortType"];
- [dict setObject:_model.strGrade forKey:@"GradeFlag"];
- [dict setObject:_model.strChannel forKey:@"ChannelFlag"];
- [dict setObject:_model.strAreaColor forKey:@"ColorNoFlag"];
- [dict setObject:_model.strSpecification forKey:@"SpecificationFlag"];
- _downManager = [[ASIDownManager alloc] init];
- _downManager.delegate = self;
- _downManager.onRequestSuccess = @selector(onLoadFinish:);
- _downManager.onRequestFail = @selector(onLoadFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- /**
- 加载列表数据失败回调
-
- @param sender
- */
- - (void)onLoadFail:(ASIDownManager *)sender {
- [self stopLoading];
- [self showAlertViewText:@"网络异常"];
- }
- /**
- 加载列表数据成功回调
-
- @param sender
- */
- - (void)onLoadFinish:(ASIDownManager *)sender {
-
- int iNewCount = 0;
- _customTableView.mTableView.backgroundView = nil;
- // 取消进度条
- [self stopLoading];
- // 服务器返回数据
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- // 服务器返回数据状态值
- int iStatus = resultModel.status;
- // 服务器返回数据消息
- NSString *message = resultModel.message;
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- NSArray * infoArr = (NSArray *)resultModel.result;
- if(infoArr != nil&& infoArr.count > 0)
- {
- // 转换model对象
- [self.arrAlldataList removeAllObjects];
- if(infoArr.count > 0 ){
- for (int i = 0; i < infoArr.count; i++) {
- NSDictionary *str = infoArr[i];
- SalesAnalysisModel *model = [SalesAnalysisModel dk_modelWithDictionary:str];
- model.ranking = [NSString stringWithFormat:@"%d",i+1];
- [self.arrAlldataList addObject:model];
- }
- }
- self.chartViewVC.rankList = self.arrAlldataList;
- self.chartViewVC.sortType = _model.strType;
- [self.chartViewVC refreshData];
- self.dataListVC.rankList = self.arrAlldataList;
- [self.dataListVC refreshData];
- _noDataView.hidden = YES;
- for(UIView *view in [_chartViewVC.view subviews])
- {
-
- if(view.tag != 11){
- view.hidden = NO;
- }
- if(view.tag==1001){
- [view removeFromSuperview];
- }
- }
- }
- else{
- if( _chartViewVC.histogramView!=nil){
- [ _chartViewVC.histogramView removeFromSuperview];
- }
- for(UIView *view in [_chartViewVC.view subviews])
- {
-
- if(view.tag != 11){
- view.hidden = YES;
- }
- if(view.tag==1001){
- [view removeFromSuperview];
- }
-
- _noDataView = [self noDataViewByFrame:CGRectMake(0,0,Screen_Width,Screen_Height-rectNavHeight-rectStatusHeight-160)];
- _noDataView.tag=1001;
- // 有刷新数据的时候
- [_chartViewVC.view addSubview:_noDataView];
-
- }
- [_dataListVC.rankPagingList removeAllObjects];
- [_dataListVC.rankList removeAllObjects];
- [_dataListVC.refreshTableView reloadData];
- // 有刷新数据的时候
- [_dataListVC.view addSubview:_noDataView];
- _dataListVC.refreshTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self showAlertViewBackText:@"未找到匹配结果"];
- }
- }
- // 服务器返回数据状态值异常
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self showReLoginDialog:message];
- }
- else{
- [_customTableView FinishLoading];
- [self showAlertViewText:message];
- }
- }
- #pragma mark - tableView刷新回调
- /**
- 加载更多
-
- @param sender <#sender description#>
- */
- - (void)LoadMoreList:(RefreshTableView *)sender {
- _pageNumber++;
- [self pagingData];
- }
- /**
- 下拉刷新
-
- @param sender <#sender description#>
- */
- - (void)ReloadList:(RefreshTableView *)sender{
- _pageNumber = 0;
- [self.arrDataList removeAllObjects];
- [self.arrAlldataList removeAllObjects];
- [_customTableView reloadData];
- _customTableView.mbMoreHidden=YES;
- [self startLoading];
- [self reloadData];
- }
- #pragma mark - 初始化
- /**
- 初始化ui
- */
- - (void)initUI{
- self.navigationItem.title = @"商品畅滞销分析";
- _arrDataList = [[NSMutableArray alloc]init];
- _arrAlldataList = [[NSMutableArray alloc]init];
- _infoModel = [[SalesAnalysisModel alloc]init];
- _model = [[SalesAnalysisSearchModel alloc] init];
- _model.strCommodityName = @"";
- _model.strEndDate = [DateFormat getCurrentDate];
- _model.strStartDate = [DateFormat getDateBefore:31];
- _model.strOnlyCode = @"";
- _model.strCommodityBrandID = @"";
- _model.strCommodityBrand = @"";
- _model.strType = @"1";
- _model.strAreaColor = @"0";
- _model.strSpecification = @"0";
- _model.strChannel = @"0";
- _model.strGrade = @"0";
- UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 40)];
- [self.view addSubview:navView];
- [self.view setBackgroundColor:[UIColor whiteColor]];
- _chartButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_chartButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
- [_chartButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- _chartButton.frame = CGRectMake(0, 0, Screen_Width/navcount, navView.frame.size.height);
- _chartButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- [_chartButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
- [_chartButton setTitle:@"图形(前10条)" forState:UIControlStateNormal];
- _chartButton.tag = 1;
- _chartButton.selected = YES;
- [navView addSubview:_chartButton];
- _dataButton= [UIButton buttonWithType:UIButtonTypeCustom];
- _dataButton.frame = CGRectMake(CGRectGetMaxX(_chartButton.frame),0, Screen_Width/navcount, navView.frame.size.height);
- [_dataButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
- [_dataButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- _dataButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- [_dataButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
- [ _dataButton setTitle:@"全部列表数据" forState:UIControlStateNormal];
- _dataButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- _dataButton.tag = 2;
- [navView addSubview: _dataButton];
- _sliderLabel = [[UILabel alloc]initWithFrame:CGRectMake(_chartButton.frame.origin.x, 40-2, Screen_Width/navcount, 2)];
- UIView *line = [[UIView alloc] initWithFrame:CGRectMake(((Screen_Width/navcount)-50)/2, 0, 50, 2)];
- line.backgroundColor = [UIColor redColor];
- [_sliderLabel addSubview:line];
- [navView addSubview:_sliderLabel];
-
- }
- /**
- 导航按钮样式
- */
- - (void)loadNavStyle
- {
- //右边
- UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 16)];
-
- UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom];
- [btnfilter addTarget:self action:@selector(search)
- forControlEvents:UIControlEventTouchUpInside];
- btnfilter.frame = CGRectMake(0, 0, 16, 16);
- [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal];
- [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"]
- forState:UIControlStateNormal];
- [v addSubview:btnfilter];
- UIButton *filterLbl = [[UIButton alloc]init];
- filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16);
- [filterLbl setTitle:@"筛选" forState:UIControlStateNormal];
- [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- filterLbl.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- [filterLbl addTarget:self action:@selector(search)
- forControlEvents:UIControlEventTouchUpInside];
- [v addSubview:filterLbl];
- UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v];
-
- self.navigationItem.rightBarButtonItem = menubtnAdd;
-
- //返回
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0,45,22);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- }
- /**
- 按钮点击事件
- @param sender
- */
- - (void)sliderAction:(UIButton *)sender{
- if (self.currentIndex == sender.tag) {
- return;
- }
- [self.view endEditing:YES];
- [self sliderAnimationWithTag:sender.tag];
- [UIView animateWithDuration:0.3 animations:^{
- self.mainScrollView.contentOffset = CGPointMake(Screen_Width * (sender.tag-1), 0);
- } completion:^(BOOL finished) {
-
- }];
- }
- /**
- 滑动tag
- @param tag <#tag description#>
- */
- - (void)sliderWithTag:(NSInteger)tag{
- self.currentIndex = tag;
- _chartButton.selected = NO;
- _dataButton.selected = NO;
- UIButton *sender = [self buttonWithTag:tag];
- sender.selected = YES;
- //动画
- _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
- }
- /**
- 滑动tag
- @param tag <#tag description#>
- */
- - (void)sliderAnimationWithTag:(NSInteger)tag{
- self.currentIndex = tag;
- _chartButton.selected = NO;
- _dataButton.selected = NO;
- UIButton *sender = [self buttonWithTag:tag];
- sender.selected = YES;
- //动画
- [UIView animateWithDuration:0.3 animations:^{
- self.sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, self.sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
-
- } completion:^(BOOL finished) {
-
- }];
-
-
- }
- /**
- 初始化scrollView
- */
- - (void)setMainSrollView{
- _mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, topH, Screen_Width, self.view.frame.size.height)];
- _mainScrollView.delegate = self;
- _mainScrollView.backgroundColor = [UIColor whiteColor];
- _mainScrollView.pagingEnabled = YES;
- _mainScrollView.showsHorizontalScrollIndicator = NO;
- _mainScrollView.showsVerticalScrollIndicator = NO;
- [self.view addSubview:_mainScrollView];
- NSArray *views = @[self.chartViewVC.view,self.dataListVC.view];
- for (NSInteger i = 0; i < views.count; i++) {
- //把三个vc的view依次贴到mainScrollView上面
- UIView *pageView = [[UIView alloc]initWithFrame:CGRectMake(Screen_Width * i, 0, _mainScrollView.frame.size.width, _mainScrollView.frame.size.height - 100)];
- [pageView addSubview:views[i]];
- [_mainScrollView addSubview:pageView];
- }
- _mainScrollView.contentSize = CGSizeMake(Screen_Width*(views.count), 0);
- //滚动到_currentIndex对应的tab
- [_mainScrollView setContentOffset:CGPointMake((_mainScrollView.frame.size.width)*_currentIndex, 0) animated:YES];
- }
- /**
- 抽屉弹出
- */
- - (void)search{
- [_filterController show];
- }
- /**
- 抽屉初始化
- */
- - (void)initSlideSlip{
- // 抽屉对象
- __weak typeof(self) weakself=self;
- self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
- for (SideSlipModel *model in dataList) {
- model.selectedItemList = nil;
- model.customDict = nil;
- }
- } commitBlock:^(NSArray *dataList) {
- //查询条件
- SideSlipModel *serviceRegionModel = dataList[0];
- _model = [serviceRegionModel.customDict objectForKey:SALESANALYSIS_SEARCH_RANGE_MODEL];
-
- if(_model.strStartDate == nil){
- [self showAlertViewText:@"请选择开始日期"];
- return;
- }
- if(_model.strEndDate == nil){
- [self showAlertViewText:@"请选择结束日期"];
- return;
- }
- NSUInteger result = [DateFormat compareDate:_model.strStartDate withDate:_model.strEndDate];
- if(result == -1){
- [self showAlertViewText:@"开始日期不能大于结束日期"];
- return;
- }
- NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
- [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式
-
- NSDate *startD = [dateFormat dateFromString:_model.strStartDate];
- NSDate *endD = [dateFormat dateFromString:_model.strEndDate];
- NSInteger days = [DateFormat calculateDaysFromBegin:startD end:endD];
-
- if(days > 31){
- [self showAlertViewText:@"日期间隔天数不能大于31天"];
- return;
- }
- [weakself.filterController dismiss];
- [self ReloadList:self.customTableView];
- }];
- _filterController.animationDuration = AnimationDuration;
- _filterController.hasHeadView = YES;
- _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
- _filterController.dataList = [self packageDataList];
- }
- /**
- 数据源
-
- @return
- */
- - (NSArray *)packageDataList {
- NSMutableArray *dataArray = [NSMutableArray array];
- SideSlipModel *model = [[SideSlipModel alloc] init];
- model.containerCellClass = @"SalesAnalysisSearchCell";
- model.regionTitle = @"查询条件";
-
- [dataArray addObject:model];
- return [dataArray mutableCopy];
- }
- /*
- 获得导航按钮
- */
- - (UIButton *)buttonWithTag:(NSInteger )tag{
- if (tag == 1) {
- return _chartButton;
- }
- else if (tag == 2){
- return _dataButton;
- }
-
- else{
- return nil;
- }
- }
- @end
|