| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- //
- // InventoryAnalysisViewController.m
- // IBOSS
- //
- // Created by ssl on 2018/1/4.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "SideSlipModel.h"
- #import "DateFormat.h"
- #import "InventoryAnalysisSearchModel.h"
- #import "SalesPaymentRankFrame.h"
- #import "InventoryAnalysisViewController.h"
- #import "InventoryAnalysisDataListController.h"
- #import "InventoryAnalysisViewChartViewController.h"
- @interface InventoryAnalysisViewController (){
- InventoryAnalysisDataListController *_dataListVC;
- InventoryAnalysisViewChartViewController *_chartViewVC;
- UILabel *_lbInventoryQuantity;
- UILabel *_lbCanSaleQuantity;
- NSString *_strOperateType;
- }
- @end
- @implementation InventoryAnalysisViewController
- /**
- 导航数
- */
- static int navcount = 2;
- #pragma mark - 公共函数
- /**
- 视图加载完成函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- //self.navigationController.navigationBar.translucent=NO;
- [self.navigationController.navigationBar setTintColor:NavigationBarTintColor ];
- self.navigationItem.title = @"库存分析表";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:[UIImage imageNamed:@"icon_back.png"] 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;
- 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;
- [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
-
- [self initUI];
- _strOperateType = @"1";
- [self loadData];
- }
- #pragma mark - 委托函数
- /**
- 加载数据成功回调
-
- @param sender <#sender description#>
- */
- - (void)onSalesPaymentFinish:(ASIDownManager *)sender {
-
- for(UIView *view in [_chartViewVC.view subviews])
- {
- if(view.tag==1001){
- [view removeFromSuperview];
- }
- }
- // 服务器返回数据
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- // 服务器返回数据状态值
- int iStatus = resultModel.status;
- [self cancel];
- // 服务器返回数据消息
- NSString *message = resultModel.message;
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- // 服务器返回数据结果
- NSArray * infoArr = (NSArray *)resultModel.result;
- _rankList = [[NSMutableArray alloc]init];
- if(infoArr!=nil && infoArr.count > 0){
- double totalInventoryQuantity = 0;
- for(int i = 0;i < infoArr.count;i++){
- NSDictionary * dic = infoArr[i];
- double inventoryQuantity = [[dic objectForKey:@"SUMInventoryQuantity"] doubleValue];
- totalInventoryQuantity += inventoryQuantity;
- }
- double totalCanSaleQuantity = 0;
- for(int i = 0;i < infoArr.count;i++){
- NSDictionary * dic = infoArr[i];
- double canSaleQuantity = [[dic objectForKey:@"SUMCanSaleQuantity"] doubleValue];
- totalCanSaleQuantity += canSaleQuantity;
- }
- for(int i = 0;i <infoArr.count;i++){
- NSDictionary *dic = infoArr[i];
- double inventoryQuantity = [[dic objectForKey:@"SUMInventoryQuantity"] doubleValue];
- NSString *objectName = [dic objectForKey:@"SUMName"];
- SalesPaymentRankModel *model = [SalesPaymentRankModel new];
- [model setInventoryQuantity:[NSString stringWithFormat:@"%.2f",inventoryQuantity]];
- [model setObjectName:objectName];
- [model setCanSaleQuantity:[NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"SUMCanSaleQuantity"] doubleValue]]];
- double backPercent = inventoryQuantity/totalInventoryQuantity*100;
- NSString *percent = [NSString stringWithFormat:@"%.2f",backPercent];
- [model setBackPercent:percent];
- SalesPaymentRankFrame *frame=[[SalesPaymentRankFrame alloc]init];
- [frame setSalesPaymentListFrame:model];
- [_rankList addObject:frame];
- }
- _lbInventoryQuantity.text = [NSString stringWithFormat:@"%.2f", totalInventoryQuantity];
- _lbCanSaleQuantity.text = [NSString stringWithFormat:@"%.2f", totalCanSaleQuantity];
- _chartViewVC.rankList = _rankList;
- if([_strOperateType intValue] == 1){
- [_chartViewVC refreshData:@"种类"];
- }else{
- [_chartViewVC refreshData:@"品牌"];
- }
-
- _dataListVC.rankList = _rankList;
- [_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{
-
- [self showAlertViewText:message];
- }
- }
- /**
- 数据加载失败回调
- @param sender <#sender description#>
- */
- - (void)onSalesPaymentFail:(ASIDownManager *)sender {
- [self showAlertViewText:@"网络异常"];
- }
- #pragma mark - 私有函数
- /*
- 初始化UI
- */
- - (void)initUI{
- UIView *titleView = [[UIView alloc]init];
- titleView.backgroundColor = NavigationBarTintColor;
- titleView.translatesAutoresizingMaskIntoConstraints = NO;
- [self.view addSubview:titleView];
-
- UILabel *lbTitleInventoryQuantity = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH/2, 35)];
- lbTitleInventoryQuantity.text = @"总结存量";
- lbTitleInventoryQuantity.font = [UIFont systemFontOfSize:15];
- lbTitleInventoryQuantity.textColor =[UIColor whiteColor];
- lbTitleInventoryQuantity.textAlignment = NSTextAlignmentCenter;
- [titleView addSubview:lbTitleInventoryQuantity];
- _lbInventoryQuantity = [[UILabel alloc] initWithFrame:CGRectMake(0, 25, SCREENWIDTH/2, 35)];
- _lbInventoryQuantity.textColor =[UIColor whiteColor];
- _lbInventoryQuantity.font = [UIFont systemFontOfSize:15];
- _lbInventoryQuantity.textAlignment = NSTextAlignmentCenter;
- [titleView addSubview:_lbInventoryQuantity];
-
- UILabel *lbTitleCanSaleQuantity = [[UILabel alloc] initWithFrame:CGRectMake(SCREENWIDTH/2, 0, SCREENWIDTH/2, 35)];
- lbTitleCanSaleQuantity.text = @"总可售量";
- lbTitleCanSaleQuantity.font = [UIFont systemFontOfSize:15];
- lbTitleCanSaleQuantity.textColor =[UIColor whiteColor];
- lbTitleCanSaleQuantity.textAlignment = NSTextAlignmentCenter;
- [titleView addSubview:lbTitleCanSaleQuantity];
- _lbCanSaleQuantity = [[UILabel alloc] initWithFrame:CGRectMake(SCREENWIDTH/2 , 25, SCREENWIDTH/2, 35)];
- _lbCanSaleQuantity.textColor =[UIColor whiteColor];
- _lbCanSaleQuantity.font = [UIFont systemFontOfSize:15];
- _lbCanSaleQuantity.textAlignment = NSTextAlignmentCenter;
- [titleView addSubview:_lbCanSaleQuantity];
-
- UIView *line = [[UIView alloc] initWithFrame:CGRectMake(SCREENWIDTH/2, 10, 1, 40)];
- line.backgroundColor = [UIColor whiteColor];
- [titleView addSubview:line];
-
- self.page = [[PageSwitchView alloc] init];
- [self.view addSubview:self.page];
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[titleView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(titleView)]];
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_page]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_page)]];
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[titleView(60)]-0-[_page]-marg-|" options:0 metrics:@{@"marg":@(SCREENHEIGHT >= 812 ? 34 : 0)} views:NSDictionaryOfVariableBindings(titleView,_page)]];
-
- NSMutableArray *arr = [NSMutableArray array];
- _dataListVC = [[InventoryAnalysisDataListController alloc] init];
- _chartViewVC = [[InventoryAnalysisViewChartViewController alloc] init];
-
- //_dataListVC.nav = self.navigationController;
- //_dataListVC.parentController = self;
- PageSwitchModel *model = [[PageSwitchModel alloc] init];
- model.title = @"图形(前10条)";
- model.controller = _chartViewVC;
- [arr addObject:model];
- model = [[PageSwitchModel alloc] init];
- model.title = @"全部列表数据";
- model.controller = _dataListVC;
- [arr addObject:model];
- self.page.datas = arr;
-
- __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];
- InventoryAnalysisSearchModel *m = [serviceRegionModel.customDict objectForKey:INVENTORY_ANALYSIS_SEARCH];
- _strOperateType = m.OperateType;
- [self loadData];
- [weakself.filterController dismiss];
-
-
- }];
- _filterController.animationDuration = AnimationDuration;
- _filterController.hasHeadView = YES;
- _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
- _filterController.dataList = [self packageDataList];
- }
- /**
- 加载数据
- */
- -(void)loadData{
- [self startLoading];
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetInventoryStatisticsIphone" 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:_strOperateType forKey:@"OperateType"];
- _downManager = [[ASIDownManager alloc] init];
- _downManager.delegate = self;
- _downManager.onRequestSuccess = @selector(onSalesPaymentFinish:);
- _downManager.onRequestFail = @selector(onSalesPaymentFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- /**
- 隐藏进度条
- */
- - (void)cancel {
- [self stopLoading];
- }
- /**
- 数据源
-
- @return <#return value description#>
- */
- - (NSArray *)packageDataList {
- NSMutableArray *dataArray = [NSMutableArray array];
- SideSlipModel *model = [[SideSlipModel alloc] init];
- model.containerCellClass = @"InventoryAnalysisSearchCel";
- model.regionTitle = @"查询条件";
- [dataArray addObject:model];
- return [dataArray mutableCopy];
- }
- /**
- 抽屉弹出
- */
- -(void)search{
- [_filterController show];
- }
- @end
|