InventoryAnalysisViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. //
  2. // InventoryAnalysisViewController.m
  3. // IBOSS
  4. //
  5. // Created by ssl on 2018/1/4.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "SideSlipModel.h"
  9. #import "DateFormat.h"
  10. #import "InventoryAnalysisSearchModel.h"
  11. #import "SalesPaymentRankFrame.h"
  12. #import "InventoryAnalysisViewController.h"
  13. #import "InventoryAnalysisDataListController.h"
  14. #import "InventoryAnalysisViewChartViewController.h"
  15. @interface InventoryAnalysisViewController (){
  16. InventoryAnalysisDataListController *_dataListVC;
  17. InventoryAnalysisViewChartViewController *_chartViewVC;
  18. UILabel *_lbInventoryQuantity;
  19. UILabel *_lbCanSaleQuantity;
  20. NSString *_strOperateType;
  21. }
  22. @end
  23. @implementation InventoryAnalysisViewController
  24. /**
  25. 导航数
  26. */
  27. static int navcount = 2;
  28. #pragma mark - 公共函数
  29. /**
  30. 视图加载完成函数
  31. */
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. //self.navigationController.navigationBar.translucent=NO;
  35. [self.navigationController.navigationBar setTintColor:NavigationBarTintColor ];
  36. self.navigationItem.title = @"库存分析表";
  37. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  38. [button setImage:[UIImage imageNamed:@"icon_back.png"] forState:UIControlStateNormal];
  39. [button addTarget:self action:@selector(goBack)
  40. forControlEvents:UIControlEventTouchUpInside];
  41. button.frame = CGRectMake(0, 0,45,22);
  42. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  43. self.navigationItem.leftBarButtonItem = menuButton;
  44. UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 16)];
  45. UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom];
  46. [btnfilter addTarget:self action:@selector(search)
  47. forControlEvents:UIControlEventTouchUpInside];
  48. btnfilter.frame = CGRectMake(0, 0, 16, 16);
  49. [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  50. [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"]
  51. forState:UIControlStateNormal];
  52. [v addSubview:btnfilter];
  53. UIButton *filterLbl = [[UIButton alloc]init];
  54. filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16);
  55. [filterLbl setTitle:@"筛选" forState:UIControlStateNormal];
  56. [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  57. filterLbl.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  58. [filterLbl addTarget:self action:@selector(search)
  59. forControlEvents:UIControlEventTouchUpInside];
  60. [v addSubview:filterLbl];
  61. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v];
  62. self.navigationItem.rightBarButtonItem = menubtnAdd;
  63. [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  64. [self initUI];
  65. _strOperateType = @"1";
  66. [self loadData];
  67. }
  68. #pragma mark - 委托函数
  69. /**
  70. 加载数据成功回调
  71. @param sender <#sender description#>
  72. */
  73. - (void)onSalesPaymentFinish:(ASIDownManager *)sender {
  74. for(UIView *view in [_chartViewVC.view subviews])
  75. {
  76. if(view.tag==1001){
  77. [view removeFromSuperview];
  78. }
  79. }
  80. // 服务器返回数据
  81. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  82. // 服务器返回数据状态值
  83. int iStatus = resultModel.status;
  84. [self cancel];
  85. // 服务器返回数据消息
  86. NSString *message = resultModel.message;
  87. // 服务器返回数据状态值正确
  88. if (iStatus == 0) {
  89. // 服务器返回数据结果
  90. NSArray * infoArr = (NSArray *)resultModel.result;
  91. _rankList = [[NSMutableArray alloc]init];
  92. if(infoArr!=nil && infoArr.count > 0){
  93. double totalInventoryQuantity = 0;
  94. for(int i = 0;i < infoArr.count;i++){
  95. NSDictionary * dic = infoArr[i];
  96. double inventoryQuantity = [[dic objectForKey:@"SUMInventoryQuantity"] doubleValue];
  97. totalInventoryQuantity += inventoryQuantity;
  98. }
  99. double totalCanSaleQuantity = 0;
  100. for(int i = 0;i < infoArr.count;i++){
  101. NSDictionary * dic = infoArr[i];
  102. double canSaleQuantity = [[dic objectForKey:@"SUMCanSaleQuantity"] doubleValue];
  103. totalCanSaleQuantity += canSaleQuantity;
  104. }
  105. for(int i = 0;i <infoArr.count;i++){
  106. NSDictionary *dic = infoArr[i];
  107. double inventoryQuantity = [[dic objectForKey:@"SUMInventoryQuantity"] doubleValue];
  108. NSString *objectName = [dic objectForKey:@"SUMName"];
  109. SalesPaymentRankModel *model = [SalesPaymentRankModel new];
  110. [model setInventoryQuantity:[NSString stringWithFormat:@"%.2f",inventoryQuantity]];
  111. [model setObjectName:objectName];
  112. [model setCanSaleQuantity:[NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"SUMCanSaleQuantity"] doubleValue]]];
  113. double backPercent = inventoryQuantity/totalInventoryQuantity*100;
  114. NSString *percent = [NSString stringWithFormat:@"%.2f",backPercent];
  115. [model setBackPercent:percent];
  116. SalesPaymentRankFrame *frame=[[SalesPaymentRankFrame alloc]init];
  117. [frame setSalesPaymentListFrame:model];
  118. [_rankList addObject:frame];
  119. }
  120. _lbInventoryQuantity.text = [NSString stringWithFormat:@"%.2f", totalInventoryQuantity];
  121. _lbCanSaleQuantity.text = [NSString stringWithFormat:@"%.2f", totalCanSaleQuantity];
  122. _chartViewVC.rankList = _rankList;
  123. if([_strOperateType intValue] == 1){
  124. [_chartViewVC refreshData:@"种类"];
  125. }else{
  126. [_chartViewVC refreshData:@"品牌"];
  127. }
  128. _dataListVC.rankList = _rankList;
  129. [_dataListVC refreshData];
  130. _noDataView.hidden = YES;
  131. for(UIView *view in [_chartViewVC.view subviews])
  132. {
  133. if(view.tag != 11){
  134. view.hidden = NO;
  135. }
  136. if(view.tag==1001){
  137. [view removeFromSuperview];
  138. }
  139. }}
  140. else{
  141. if( _chartViewVC.histogramView!=nil){
  142. [ _chartViewVC.histogramView removeFromSuperview];
  143. }
  144. for(UIView *view in [_chartViewVC.view subviews])
  145. {
  146. if(view.tag != 11){
  147. view.hidden = YES;
  148. }
  149. if(view.tag==1001){
  150. [view removeFromSuperview];
  151. }
  152. _noDataView = [self noDataViewByFrame:CGRectMake(0,0,Screen_Width,Screen_Height-rectNavHeight-rectStatusHeight-160)];
  153. _noDataView.tag=1001;
  154. // 有刷新数据的时候
  155. [_chartViewVC.view addSubview:_noDataView];
  156. }
  157. [_dataListVC.rankPagingList removeAllObjects];
  158. [_dataListVC.rankList removeAllObjects];
  159. [_dataListVC.refreshTableView reloadData];
  160. // 有刷新数据的时候
  161. [_dataListVC.view addSubview:_noDataView];
  162. _dataListVC.refreshTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  163. [self showAlertViewBackText:@"未找到匹配结果"];
  164. }
  165. }
  166. // 服务器返回数据状态值异常
  167. else if(iStatus == ActionResultStatusAuthError
  168. ||iStatus == ActionResultStatusNoLogin
  169. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  170. [self showReLoginDialog:message];
  171. }
  172. else{
  173. [self showAlertViewText:message];
  174. }
  175. }
  176. /**
  177. 数据加载失败回调
  178. @param sender <#sender description#>
  179. */
  180. - (void)onSalesPaymentFail:(ASIDownManager *)sender {
  181. [self showAlertViewText:@"网络异常"];
  182. }
  183. #pragma mark - 私有函数
  184. /*
  185. 初始化UI
  186. */
  187. - (void)initUI{
  188. UIView *titleView = [[UIView alloc]init];
  189. titleView.backgroundColor = NavigationBarTintColor;
  190. titleView.translatesAutoresizingMaskIntoConstraints = NO;
  191. [self.view addSubview:titleView];
  192. UILabel *lbTitleInventoryQuantity = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH/2, 35)];
  193. lbTitleInventoryQuantity.text = @"总结存量";
  194. lbTitleInventoryQuantity.font = [UIFont systemFontOfSize:15];
  195. lbTitleInventoryQuantity.textColor =[UIColor whiteColor];
  196. lbTitleInventoryQuantity.textAlignment = NSTextAlignmentCenter;
  197. [titleView addSubview:lbTitleInventoryQuantity];
  198. _lbInventoryQuantity = [[UILabel alloc] initWithFrame:CGRectMake(0, 25, SCREENWIDTH/2, 35)];
  199. _lbInventoryQuantity.textColor =[UIColor whiteColor];
  200. _lbInventoryQuantity.font = [UIFont systemFontOfSize:15];
  201. _lbInventoryQuantity.textAlignment = NSTextAlignmentCenter;
  202. [titleView addSubview:_lbInventoryQuantity];
  203. UILabel *lbTitleCanSaleQuantity = [[UILabel alloc] initWithFrame:CGRectMake(SCREENWIDTH/2, 0, SCREENWIDTH/2, 35)];
  204. lbTitleCanSaleQuantity.text = @"总可售量";
  205. lbTitleCanSaleQuantity.font = [UIFont systemFontOfSize:15];
  206. lbTitleCanSaleQuantity.textColor =[UIColor whiteColor];
  207. lbTitleCanSaleQuantity.textAlignment = NSTextAlignmentCenter;
  208. [titleView addSubview:lbTitleCanSaleQuantity];
  209. _lbCanSaleQuantity = [[UILabel alloc] initWithFrame:CGRectMake(SCREENWIDTH/2 , 25, SCREENWIDTH/2, 35)];
  210. _lbCanSaleQuantity.textColor =[UIColor whiteColor];
  211. _lbCanSaleQuantity.font = [UIFont systemFontOfSize:15];
  212. _lbCanSaleQuantity.textAlignment = NSTextAlignmentCenter;
  213. [titleView addSubview:_lbCanSaleQuantity];
  214. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(SCREENWIDTH/2, 10, 1, 40)];
  215. line.backgroundColor = [UIColor whiteColor];
  216. [titleView addSubview:line];
  217. self.page = [[PageSwitchView alloc] init];
  218. [self.view addSubview:self.page];
  219. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[titleView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(titleView)]];
  220. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_page]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_page)]];
  221. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[titleView(60)]-0-[_page]-marg-|" options:0 metrics:@{@"marg":@(SCREENHEIGHT >= 812 ? 34 : 0)} views:NSDictionaryOfVariableBindings(titleView,_page)]];
  222. NSMutableArray *arr = [NSMutableArray array];
  223. _dataListVC = [[InventoryAnalysisDataListController alloc] init];
  224. _chartViewVC = [[InventoryAnalysisViewChartViewController alloc] init];
  225. //_dataListVC.nav = self.navigationController;
  226. //_dataListVC.parentController = self;
  227. PageSwitchModel *model = [[PageSwitchModel alloc] init];
  228. model.title = @"图形(前10条)";
  229. model.controller = _chartViewVC;
  230. [arr addObject:model];
  231. model = [[PageSwitchModel alloc] init];
  232. model.title = @"全部列表数据";
  233. model.controller = _dataListVC;
  234. [arr addObject:model];
  235. self.page.datas = arr;
  236. __weak typeof(self) weakself=self;
  237. // 抽屉对象
  238. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  239. for (SideSlipModel *model in dataList) {
  240. model.selectedItemList = nil;
  241. model.customDict = nil;
  242. }
  243. } commitBlock:^(NSArray *dataList) {
  244. // 查询条件
  245. SideSlipModel *serviceRegionModel = dataList[0];
  246. InventoryAnalysisSearchModel *m = [serviceRegionModel.customDict objectForKey:INVENTORY_ANALYSIS_SEARCH];
  247. _strOperateType = m.OperateType;
  248. [self loadData];
  249. [weakself.filterController dismiss];
  250. }];
  251. _filterController.animationDuration = AnimationDuration;
  252. _filterController.hasHeadView = YES;
  253. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  254. _filterController.dataList = [self packageDataList];
  255. }
  256. /**
  257. 加载数据
  258. */
  259. -(void)loadData{
  260. [self startLoading];
  261. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  262. [dict setObject:@"GetInventoryStatisticsIphone" forKey:@"Action"];
  263. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  264. [dict setObject:kkUserCode forKey:@"UserCode"];
  265. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  266. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  267. [dict setObject:_strOperateType forKey:@"OperateType"];
  268. _downManager = [[ASIDownManager alloc] init];
  269. _downManager.delegate = self;
  270. _downManager.onRequestSuccess = @selector(onSalesPaymentFinish:);
  271. _downManager.onRequestFail = @selector(onSalesPaymentFail:);
  272. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  273. }
  274. /**
  275. 隐藏进度条
  276. */
  277. - (void)cancel {
  278. [self stopLoading];
  279. }
  280. /**
  281. 数据源
  282. @return <#return value description#>
  283. */
  284. - (NSArray *)packageDataList {
  285. NSMutableArray *dataArray = [NSMutableArray array];
  286. SideSlipModel *model = [[SideSlipModel alloc] init];
  287. model.containerCellClass = @"InventoryAnalysisSearchCel";
  288. model.regionTitle = @"查询条件";
  289. [dataArray addObject:model];
  290. return [dataArray mutableCopy];
  291. }
  292. /**
  293. 抽屉弹出
  294. */
  295. -(void)search{
  296. [_filterController show];
  297. }
  298. @end