// // SalesAnalysisListViewController // IBOSS // // Created by apple on 2017/5/15. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved. // // 功能描述:商品畅滞销分析表 // #import "SalesAnalysisListViewController.h" #import "SalesAnalysisCell.h" #import "SideSlipModel.h" #import "SalesAnalysisSearchModel.h" #import "DateFormat.h" @interface SalesAnalysisListViewController (){ /** 查询参数的Model */ SalesAnalysisSearchModel *_model; /** 页码 */ int _pageNumber; } @end @implementation SalesAnalysisListViewController #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; [self initUI]; [self loadNavStyle]; [self initSlideSlip]; [self startLoading]; [self reloadData]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ self.view.backgroundColor = [UIColor whiteColor]; _customTableView.frame = self.view.safeAreaLayoutGuide.layoutFrame; [super viewSafeAreaInsetsDidChange]; } /** didReceiveMemoryWarning函数 */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #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 - tableView实现的方法 /** 单元格cell个数 @param tableView @param section @return */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.arrDataList count]; } /** 组数 @param tableView @return */ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } /** 高度 @param tableView @param indexPath @return */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 211.5; } /** 每个单元格cell @param tableView @param indexPath @return */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *str = @"SalesAnalysisCell"; SalesAnalysisCell *cell = [tableView dequeueReusableCellWithIdentifier:str]; if(cell == nil){ NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"SalesAnalysisCell" owner:nil options:nil]; cell = [nibs lastObject]; } else //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免 { while ([cell.contentView.subviews lastObject] != nil) { [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview]; } } _infoModel = [_arrDataList objectAtIndex:indexPath.row]; cell.model = _infoModel; [cell loadView]; return cell; } /** 点击单元格事件 @param tableView @param indexPath */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // self.hidesBottomBarWhenPushed=YES; // InventoryDetailViewController *detailVc = [[InventoryDetailViewController alloc] init]; // _infoModel= [_arrNewdataList objectAtIndex:indexPath.row]; // detailVc.code = _infoModel.code; // detailVc.onlyCode = _infoModel.onlyCode; // detailVc.wareHouseName = _infoModel.wareHouseName; // detailVc.specification = _infoModel.specification; // detailVc.brandName = _infoModel.brandName; // detailVc.goodName = _infoModel.goodName; // detailVc.gradeName = _infoModel.gradeName; // detailVc.colorNumber = _infoModel.colorNumber; // detailVc.inventoryQuantity = _infoModel.inventoryQuantity; // detailVc.canSaleQuantity = _infoModel.canSaleQuantity; // detailVc.positionNumber = _infoModel.positionNumber; // detailVc.price = _infoModel.price; // [self.navigationController pushViewController:detailVc animated:YES]; } /** 取消刷新 @param sender sender description @return return value description */ - (BOOL)CanRefreshTableView:(RefreshTableView *)sender { return YES; } #pragma mark - scrollView回调 /** 显示下拉更新 @param scrollView */ - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (scrollView.isDragging) {//显示下拉更新 if (_customTableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [_customTableView CanRefresh]) { [_customTableView.mRefreshHeader setState:PullRefreshNormal]; } else if (_customTableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [_customTableView CanRefresh]) {//显示松开更新 [_customTableView.mRefreshHeader setState:PullRefreshPulling]; } } } /** 隐藏键盘 @param scrollView scrollView description */ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [self.view endEditing:YES]; } /** 刷新数据源 */ - (void)refreshTableView { [self.customTableView reloadData]; } #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.OnImageDown = @selector(onLoadFinish:); _downManager.OnImageFail = @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 { _customTableView.mTableView.backgroundView = nil; // 取消进度条 [self stopLoading]; // 服务器返回数据 NSDictionary *dic = [sender.mWebStr JSONValue]; // 服务器返回数据状态值 if (dic && [dic isKindOfClass:[NSDictionary class]]) { // 服务器返回数据状态值 int iStatus = [[dic objectForKey:@"Status"] intValue]; // 服务器返回数据消息 NSString *message=[dic objectForKey:@"Message"]; // 服务器返回数据状态值正确 if (iStatus == 0) { NSArray * infoArr = [dic objectForKey:@"Result"]; if(infoArr != nil&& infoArr.count > 0) { // 转换model对象 if(infoArr.count > 0 ){ for (int i = 0; i < infoArr.count; i++) { NSDictionary *str = infoArr[i]; SalesAnalysisModel *model = [SalesAnalysisModel new]; NSString *goodsName= [str objectForKey:@"GoodsName"]; [model setCommodityName:goodsName]; NSString *goodsCode=[str objectForKey:@"Code"]; [model setCommodityCode:goodsCode]; NSString *onlyCode=[str objectForKey:@"OnlyCode"]; [model setOnlyCode:onlyCode]; NSString *brandName=[str objectForKey:@"BrandName"]; [model setCommodityBrand:brandName]; NSString *colorNumber=[str objectForKey:@"ColorNumber"]; [model setColorNumber:colorNumber]; NSString *specification=[str objectForKey:@"Specification"]; [model setSpecifications:specification]; NSString *gradeName=[str objectForKey:@"GradeName"]; [model setCommodityGrade:gradeName]; NSString *kindName=[str objectForKey:@"KindName"]; [model setCommodityCategory:kindName]; NSString *salesQuantity=[NSString stringWithFormat:@"%ld",(long)[[str objectForKey:@"SalesNumber"]integerValue]]; [model setNumber:salesQuantity]; NSString *salesAmount = [NSString stringWithFormat:@"%.2f", [[str objectForKey:@"SalesAmount"] doubleValue]]; [model setSalesAmount:salesAmount]; NSString *salesTimes=[NSString stringWithFormat:@"%ld",(long)[[str objectForKey:@"SalesTimes"]integerValue]]; [model setSalesTimes:salesTimes]; model.ranking = [NSString stringWithFormat:@"%d",i+1]; [self.arrAlldataList addObject:model]; } } [self pagingData]; } else{ [_customTableView FinishLoading]; _customTableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 无数据 if(self.arrAlldataList.count == 0){ // 无数据的view UIView *noDataView=[[UIView alloc]init]; noDataView.frame= _customTableView.mTableView.bounds; UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)]; [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]]; [noDataView addSubview:nodataImgView]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)]; label.font=[UIFont systemFontOfSize:NoDataFontOfSize]; label.text = @"无数据"; label.numberOfLines = 2; label.textColor = [UIColor lightGrayColor]; [noDataView addSubview:label]; _customTableView.mTableView.backgroundView =noDataView; } if(self.arrAlldataList== nil || self.arrAlldataList.count == 0){ [self showAlertViewBackText:@"未找到匹配结果"]; } } } // 服务器返回数据状态值异常 else if(iStatus == ActionResultStatusAuthError ||iStatus == ActionResultStatusNoLogin ||iStatus == ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [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]; _customTableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; _customTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _customTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _customTableView.backgroundColor = [UIColor whiteColor]; _customTableView.delegate = self; [self.view addSubview:_customTableView]; _pageNumber = 0; _model = [[SalesAnalysisSearchModel alloc] init]; _model.strCommodityName = @""; _model.strEndDate = [DateFormat getCurrentDate]; _model.strStartDate = [DateFormat getDateBefore:31]; _model.strOnlyCode = @""; _model.strCommodityBrandID = @""; _model.strCommodityBrand = @""; _model.strType = @"0"; _model.strAreaColor = @"0"; _model.strSpecification = @"0"; _model.strChannel = @"0"; _model.strGrade = @"0"; } /** 导航按钮样式 */ - (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 setBackgroundImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0, 15, 18); UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = menuButton; } /** 抽屉弹出 */ - (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]; } @end