SalesAnalysisListViewController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. //
  2. // SalesAnalysisListViewController
  3. // IBOSS
  4. //
  5. // Created by apple on 2017/5/15.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:商品畅滞销分析表
  9. //
  10. #import "SalesAnalysisListViewController.h"
  11. #import "SalesAnalysisCell.h"
  12. #import "SideSlipModel.h"
  13. #import "SalesAnalysisSearchModel.h"
  14. #import "DateFormat.h"
  15. @interface SalesAnalysisListViewController ()<UITableViewDataSource, UITableViewDelegate,RefreshTableViewDelegate>{
  16. /**
  17. 查询参数的Model
  18. */
  19. SalesAnalysisSearchModel *_model;
  20. /**
  21. 页码
  22. */
  23. int _pageNumber;
  24. }
  25. @end
  26. @implementation SalesAnalysisListViewController
  27. #pragma mark - 公共函数
  28. /**
  29. viewDidLoad函数
  30. */
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. [self initUI];
  34. [self loadNavStyle];
  35. [self initSlideSlip];
  36. [self startLoading];
  37. [self reloadData];
  38. }
  39. /**
  40. 安全区视图发生变化
  41. */
  42. -(void)viewSafeAreaInsetsDidChange{
  43. self.view.backgroundColor = [UIColor whiteColor];
  44. _customTableView.frame = self.view.safeAreaLayoutGuide.layoutFrame;
  45. [super viewSafeAreaInsetsDidChange];
  46. }
  47. /**
  48. didReceiveMemoryWarning函数
  49. */
  50. - (void)didReceiveMemoryWarning {
  51. [super didReceiveMemoryWarning];
  52. }
  53. #pragma mark - 自定义方法
  54. /**
  55. 分页取数据
  56. */
  57. - (void) pagingData{
  58. //页数
  59. int maxPages = (int)ceil(_arrAlldataList.count/20);
  60. //最后一页的个数
  61. CGFloat numberOfLastPage = _arrAlldataList.count - 20 * maxPages;
  62. if(_pageNumber < maxPages){
  63. NSArray *arr = [_arrAlldataList subarrayWithRange:NSMakeRange(20*_pageNumber,20)];
  64. [_arrDataList addObjectsFromArray:arr];
  65. _customTableView.mbMoreHidden = NO;
  66. }else if(_pageNumber == maxPages){
  67. [_arrDataList addObjectsFromArray:[_arrAlldataList subarrayWithRange:NSMakeRange(20*_pageNumber, numberOfLastPage)]];
  68. _customTableView.mbMoreHidden = YES;
  69. }
  70. [_customTableView FinishLoading];
  71. [_customTableView reloadData];
  72. }
  73. #pragma mark - tableView实现的方法
  74. /**
  75. 单元格cell个数
  76. @param tableView
  77. @param section
  78. @return
  79. */
  80. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  81. {
  82. return [self.arrDataList count];
  83. }
  84. /**
  85. 组数
  86. @param tableView
  87. @return
  88. */
  89. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  90. return 1;
  91. }
  92. /**
  93. 高度
  94. @param tableView
  95. @param indexPath
  96. @return
  97. */
  98. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  99. return 211.5;
  100. }
  101. /**
  102. 每个单元格cell
  103. @param tableView
  104. @param indexPath
  105. @return
  106. */
  107. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  108. {
  109. static NSString *str = @"SalesAnalysisCell";
  110. SalesAnalysisCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
  111. if(cell == nil){
  112. NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"SalesAnalysisCell" owner:nil options:nil];
  113. cell = [nibs lastObject];
  114. } else
  115. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  116. {
  117. while ([cell.contentView.subviews lastObject] != nil) {
  118. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  119. }
  120. }
  121. _infoModel = [_arrDataList objectAtIndex:indexPath.row];
  122. cell.model = _infoModel;
  123. [cell loadView];
  124. return cell;
  125. }
  126. /**
  127. 点击单元格事件
  128. @param tableView
  129. @param indexPath
  130. */
  131. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  132. {
  133. // self.hidesBottomBarWhenPushed=YES;
  134. // InventoryDetailViewController *detailVc = [[InventoryDetailViewController alloc] init];
  135. // _infoModel= [_arrNewdataList objectAtIndex:indexPath.row];
  136. // detailVc.code = _infoModel.code;
  137. // detailVc.onlyCode = _infoModel.onlyCode;
  138. // detailVc.wareHouseName = _infoModel.wareHouseName;
  139. // detailVc.specification = _infoModel.specification;
  140. // detailVc.brandName = _infoModel.brandName;
  141. // detailVc.goodName = _infoModel.goodName;
  142. // detailVc.gradeName = _infoModel.gradeName;
  143. // detailVc.colorNumber = _infoModel.colorNumber;
  144. // detailVc.inventoryQuantity = _infoModel.inventoryQuantity;
  145. // detailVc.canSaleQuantity = _infoModel.canSaleQuantity;
  146. // detailVc.positionNumber = _infoModel.positionNumber;
  147. // detailVc.price = _infoModel.price;
  148. // [self.navigationController pushViewController:detailVc animated:YES];
  149. }
  150. /**
  151. 取消刷新
  152. @param sender sender description
  153. @return return value description
  154. */
  155. - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
  156. return YES;
  157. }
  158. #pragma mark - scrollView回调
  159. /**
  160. 显示下拉更新
  161. @param scrollView
  162. */
  163. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  164. if (scrollView.isDragging) {//显示下拉更新
  165. if (_customTableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [_customTableView CanRefresh]) {
  166. [_customTableView.mRefreshHeader setState:PullRefreshNormal];
  167. }
  168. else if (_customTableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [_customTableView CanRefresh]) {//显示松开更新
  169. [_customTableView.mRefreshHeader setState:PullRefreshPulling];
  170. }
  171. }
  172. }
  173. /**
  174. 隐藏键盘
  175. @param scrollView scrollView description
  176. */
  177. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  178. {
  179. [self.view endEditing:YES];
  180. }
  181. /**
  182. 刷新数据源
  183. */
  184. - (void)refreshTableView
  185. {
  186. [self.customTableView reloadData];
  187. }
  188. #pragma mark - 数据请求回调
  189. /**
  190. 加载数据
  191. */
  192. - (void)reloadData
  193. {
  194. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  195. [dict setObject:@"BestsellersAnalysisIphone" forKey:@"Action"];
  196. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  197. [dict setObject:kkUserCode forKey:@"UserCode"];
  198. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  199. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  200. [dict setObject:_model.strCommodityName forKey:@"GoodsName"];
  201. [dict setObject:_model.strOnlyCode forKey:@"OnlyCode"];
  202. [dict setObject:_model.strCommodityBrandID forKeyedSubscript:@"BrandID"];
  203. [dict setObject:@"" forKeyedSubscript:@"KindCode"];
  204. [dict setObject:_model.strStartDate forKeyedSubscript:@"OperateDateFrom"];
  205. [dict setObject:_model.strEndDate forKey:@"OperateDateTo"];
  206. [dict setObject:_model.strType forKey:@"SortType"];
  207. [dict setObject:_model.strGrade forKey:@"GradeFlag"];
  208. [dict setObject:_model.strChannel forKey:@"ChannelFlag"];
  209. [dict setObject:_model.strAreaColor forKey:@"ColorNoFlag"];
  210. [dict setObject:_model.strSpecification forKey:@"SpecificationFlag"];
  211. _downManager = [[ASIDownManager alloc] init];
  212. _downManager.delegate = self;
  213. _downManager.OnImageDown = @selector(onLoadFinish:);
  214. _downManager.OnImageFail = @selector(onLoadFail:);
  215. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  216. }
  217. /**
  218. 加载列表数据失败回调
  219. @param sender
  220. */
  221. - (void)onLoadFail:(ASIDownManager *)sender {
  222. [self stopLoading];
  223. [self showAlertViewText:@"网络异常"];
  224. }
  225. /**
  226. 加载列表数据成功回调
  227. @param sender
  228. */
  229. - (void)onLoadFinish:(ASIDownManager *)sender {
  230. _customTableView.mTableView.backgroundView = nil;
  231. // 取消进度条
  232. [self stopLoading];
  233. // 服务器返回数据
  234. NSDictionary *dic = [sender.mWebStr JSONValue];
  235. // 服务器返回数据状态值
  236. if (dic && [dic isKindOfClass:[NSDictionary class]])
  237. {
  238. // 服务器返回数据状态值
  239. int iStatus = [[dic objectForKey:@"Status"] intValue];
  240. // 服务器返回数据消息
  241. NSString *message=[dic objectForKey:@"Message"];
  242. // 服务器返回数据状态值正确
  243. if (iStatus == 0) {
  244. NSArray * infoArr = [dic objectForKey:@"Result"];
  245. if(infoArr != nil&& infoArr.count > 0)
  246. {
  247. // 转换model对象
  248. if(infoArr.count > 0 ){
  249. for (int i = 0; i < infoArr.count; i++) {
  250. NSDictionary *str = infoArr[i];
  251. SalesAnalysisModel *model = [SalesAnalysisModel new];
  252. NSString *goodsName= [str objectForKey:@"GoodsName"];
  253. [model setCommodityName:goodsName];
  254. NSString *goodsCode=[str objectForKey:@"Code"];
  255. [model setCommodityCode:goodsCode];
  256. NSString *onlyCode=[str objectForKey:@"OnlyCode"];
  257. [model setOnlyCode:onlyCode];
  258. NSString *brandName=[str objectForKey:@"BrandName"];
  259. [model setCommodityBrand:brandName];
  260. NSString *colorNumber=[str objectForKey:@"ColorNumber"];
  261. [model setColorNumber:colorNumber];
  262. NSString *specification=[str objectForKey:@"Specification"];
  263. [model setSpecifications:specification];
  264. NSString *gradeName=[str objectForKey:@"GradeName"];
  265. [model setCommodityGrade:gradeName];
  266. NSString *kindName=[str objectForKey:@"KindName"];
  267. [model setCommodityCategory:kindName];
  268. NSString *salesQuantity=[NSString stringWithFormat:@"%ld",(long)[[str objectForKey:@"SalesNumber"]integerValue]];
  269. [model setNumber:salesQuantity];
  270. NSString *salesAmount = [NSString stringWithFormat:@"%.2f",
  271. [[str objectForKey:@"SalesAmount"] doubleValue]];
  272. [model setSalesAmount:salesAmount];
  273. NSString *salesTimes=[NSString stringWithFormat:@"%ld",(long)[[str objectForKey:@"SalesTimes"]integerValue]];
  274. [model setSalesTimes:salesTimes];
  275. model.ranking = [NSString stringWithFormat:@"%d",i+1];
  276. [self.arrAlldataList addObject:model];
  277. }
  278. }
  279. [self pagingData];
  280. }
  281. else{
  282. [_customTableView FinishLoading];
  283. _customTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  284. // 无数据
  285. if(self.arrAlldataList.count == 0){
  286. // 无数据的view
  287. UIView *noDataView=[[UIView alloc]init];
  288. noDataView.frame= _customTableView.mTableView.bounds;
  289. UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
  290. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  291. [noDataView addSubview:nodataImgView];
  292. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  293. label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
  294. label.text = @"无数据";
  295. label.numberOfLines = 2;
  296. label.textColor = [UIColor lightGrayColor];
  297. [noDataView addSubview:label];
  298. _customTableView.mTableView.backgroundView =noDataView;
  299. }
  300. if(self.arrAlldataList== nil || self.arrAlldataList.count == 0){
  301. [self showAlertViewBackText:@"未找到匹配结果"];
  302. }
  303. }
  304. }
  305. // 服务器返回数据状态值异常
  306. else if(iStatus == ActionResultStatusAuthError
  307. ||iStatus == ActionResultStatusNoLogin
  308. ||iStatus == ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  309. [self showReLoginDialog:message];
  310. }
  311. else{
  312. [_customTableView FinishLoading];
  313. [self showAlertViewText:message];
  314. }
  315. }
  316. }
  317. #pragma mark - tableView刷新回调
  318. /**
  319. 加载更多
  320. @param sender <#sender description#>
  321. */
  322. - (void)LoadMoreList:(RefreshTableView *)sender {
  323. _pageNumber++;
  324. [self pagingData];
  325. }
  326. /**
  327. 下拉刷新
  328. @param sender <#sender description#>
  329. */
  330. - (void)ReloadList:(RefreshTableView *)sender{
  331. _pageNumber = 0;
  332. [self.arrDataList removeAllObjects];
  333. [self.arrAlldataList removeAllObjects];
  334. [_customTableView reloadData];
  335. _customTableView.mbMoreHidden=YES;
  336. [self startLoading];
  337. [self reloadData];
  338. }
  339. #pragma mark - 初始化
  340. /**
  341. 初始化ui
  342. */
  343. - (void)initUI{
  344. self.navigationItem.title = @"商品畅滞销分析";
  345. _arrDataList = [[NSMutableArray alloc]init];
  346. _arrAlldataList = [[NSMutableArray alloc]init];
  347. _infoModel = [[SalesAnalysisModel alloc]init];
  348. _customTableView = [[RefreshTableView alloc]
  349. initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,
  350. self.view.frame.size.height)];
  351. _customTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  352. _customTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  353. _customTableView.backgroundColor = [UIColor whiteColor];
  354. _customTableView.delegate = self;
  355. [self.view addSubview:_customTableView];
  356. _pageNumber = 0;
  357. _model = [[SalesAnalysisSearchModel alloc] init];
  358. _model.strCommodityName = @"";
  359. _model.strEndDate = [DateFormat getCurrentDate];
  360. _model.strStartDate = [DateFormat getDateBefore:31];
  361. _model.strOnlyCode = @"";
  362. _model.strCommodityBrandID = @"";
  363. _model.strCommodityBrand = @"";
  364. _model.strType = @"0";
  365. _model.strAreaColor = @"0";
  366. _model.strSpecification = @"0";
  367. _model.strChannel = @"0";
  368. _model.strGrade = @"0";
  369. }
  370. /**
  371. 导航按钮样式
  372. */
  373. - (void)loadNavStyle
  374. {
  375. //右边
  376. UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 16)];
  377. UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom];
  378. [btnfilter addTarget:self action:@selector(search)
  379. forControlEvents:UIControlEventTouchUpInside];
  380. btnfilter.frame = CGRectMake(0, 0, 16, 16);
  381. [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  382. [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"]
  383. forState:UIControlStateNormal];
  384. [v addSubview:btnfilter];
  385. UIButton *filterLbl = [[UIButton alloc]init];
  386. filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16);
  387. [filterLbl setTitle:@"筛选" forState:UIControlStateNormal];
  388. [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  389. filterLbl.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  390. [filterLbl addTarget:self action:@selector(search)
  391. forControlEvents:UIControlEventTouchUpInside];
  392. [v addSubview:filterLbl];
  393. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v];
  394. self.navigationItem.rightBarButtonItem = menubtnAdd;
  395. //返回
  396. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  397. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  398. forState:UIControlStateNormal];
  399. [button addTarget:self action:@selector(goBack)
  400. forControlEvents:UIControlEventTouchUpInside];
  401. button.frame = CGRectMake(0, 0, 15, 18);
  402. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  403. self.navigationItem.leftBarButtonItem = menuButton;
  404. }
  405. /**
  406. 抽屉弹出
  407. */
  408. - (void)search{
  409. [_filterController show];
  410. }
  411. /**
  412. 抽屉初始化
  413. */
  414. - (void)initSlideSlip{
  415. // 抽屉对象
  416. __weak typeof(self) weakself=self;
  417. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  418. for (SideSlipModel *model in dataList) {
  419. model.selectedItemList = nil;
  420. model.customDict = nil;
  421. }
  422. } commitBlock:^(NSArray *dataList) {
  423. //查询条件
  424. SideSlipModel *serviceRegionModel = dataList[0];
  425. _model = [serviceRegionModel.customDict objectForKey:SALESANALYSIS_SEARCH_RANGE_MODEL];
  426. if(_model.strStartDate == nil){
  427. [self showAlertViewText:@"请选择开始日期"];
  428. return;
  429. }
  430. if(_model.strEndDate == nil){
  431. [self showAlertViewText:@"请选择结束日期"];
  432. return;
  433. }
  434. NSUInteger result = [DateFormat compareDate:_model.strStartDate withDate:_model.strEndDate];
  435. if(result == -1){
  436. [self showAlertViewText:@"开始日期不能大于结束日期"];
  437. return;
  438. }
  439. NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
  440. [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式
  441. NSDate *startD = [dateFormat dateFromString:_model.strStartDate];
  442. NSDate *endD = [dateFormat dateFromString:_model.strEndDate];
  443. NSInteger days = [DateFormat calculateDaysFromBegin:startD end:endD];
  444. if(days > 31){
  445. [self showAlertViewText:@"日期间隔天数不能大于31天"];
  446. return;
  447. }
  448. [weakself.filterController dismiss];
  449. [self ReloadList:self.customTableView];
  450. }];
  451. _filterController.animationDuration = AnimationDuration;
  452. _filterController.hasHeadView = YES;
  453. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  454. _filterController.dataList = [self packageDataList];
  455. }
  456. /**
  457. 数据源
  458. @return
  459. */
  460. - (NSArray *)packageDataList {
  461. NSMutableArray *dataArray = [NSMutableArray array];
  462. SideSlipModel *model = [[SideSlipModel alloc] init];
  463. model.containerCellClass = @"SalesAnalysisSearchCell";
  464. model.regionTitle = @"查询条件";
  465. [dataArray addObject:model];
  466. return [dataArray mutableCopy];
  467. }
  468. @end