SalesAnalysisListViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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 setBackgroundColor:[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.onRequestSuccess = @selector(onLoadFinish:);
  214. _downManager.onRequestFail = @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. int iNewCount = 0;
  231. _customTableView.mTableView.backgroundView = nil;
  232. // 取消进度条
  233. [self stopLoading];
  234. // 服务器返回数据
  235. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  236. // 服务器返回数据状态值
  237. int iStatus = resultModel.status;
  238. // 服务器返回数据消息
  239. NSString *message = resultModel.message;
  240. // 服务器返回数据状态值正确
  241. if (iStatus == 0) {
  242. NSArray * infoArr = (NSArray *)resultModel.result;
  243. if(infoArr != nil&& infoArr.count > 0)
  244. {
  245. // 转换model对象
  246. if(infoArr.count > 0 ){
  247. for (int i = 0; i < infoArr.count; i++) {
  248. NSDictionary *str = infoArr[i];
  249. SalesAnalysisModel *model = [SalesAnalysisModel dk_modelWithDictionary:str];
  250. model.ranking = [NSString stringWithFormat:@"%d",i+1];
  251. [self.arrAlldataList addObject:model];
  252. }
  253. }
  254. [self pagingData];
  255. }
  256. else{
  257. [_customTableView FinishLoading];
  258. _customTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  259. // 无数据
  260. if(self.arrAlldataList.count == 0){
  261. // 无数据的view
  262. UIView *noDataView = [self noDataViewByFrame:_customTableView.mTableView.bounds];
  263. _customTableView.mTableView.backgroundView =noDataView;
  264. }
  265. if(self.arrAlldataList== nil || self.arrAlldataList.count == 0){
  266. [self showAlertViewBackText:@"未找到匹配结果"];
  267. }
  268. }
  269. }
  270. // 服务器返回数据状态值异常
  271. else if(iStatus == ActionResultStatusAuthError
  272. ||iStatus == ActionResultStatusNoLogin
  273. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  274. [self showReLoginDialog:message];
  275. }
  276. else{
  277. [_customTableView FinishLoading];
  278. [self showAlertViewText:message];
  279. }
  280. }
  281. #pragma mark - tableView刷新回调
  282. /**
  283. 加载更多
  284. @param sender <#sender description#>
  285. */
  286. - (void)LoadMoreList:(RefreshTableView *)sender {
  287. _pageNumber++;
  288. [self pagingData];
  289. }
  290. /**
  291. 下拉刷新
  292. @param sender <#sender description#>
  293. */
  294. - (void)ReloadList:(RefreshTableView *)sender{
  295. _pageNumber = 0;
  296. [self.arrDataList removeAllObjects];
  297. [self.arrAlldataList removeAllObjects];
  298. [_customTableView reloadData];
  299. _customTableView.mbMoreHidden=YES;
  300. [self startLoading];
  301. [self reloadData];
  302. }
  303. #pragma mark - 初始化
  304. /**
  305. 初始化ui
  306. */
  307. - (void)initUI{
  308. self.navigationItem.title = @"商品畅滞销分析";
  309. _arrDataList = [[NSMutableArray alloc]init];
  310. _arrAlldataList = [[NSMutableArray alloc]init];
  311. _infoModel = [[SalesAnalysisModel alloc]init];
  312. _customTableView = [[RefreshTableView alloc]
  313. initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,
  314. self.view.frame.size.height)];
  315. _customTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  316. _customTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  317. _customTableView.backgroundColor = [UIColor whiteColor];
  318. _customTableView.delegate = self;
  319. [self.view addSubview:_customTableView];
  320. _pageNumber = 0;
  321. _model = [[SalesAnalysisSearchModel alloc] init];
  322. _model.strCommodityName = @"";
  323. _model.strEndDate = [DateFormat getCurrentDate];
  324. _model.strStartDate = [DateFormat getDateBefore:31];
  325. _model.strOnlyCode = @"";
  326. _model.strCommodityBrandID = @"";
  327. _model.strCommodityBrand = @"";
  328. _model.strType = @"0";
  329. _model.strAreaColor = @"0";
  330. _model.strSpecification = @"0";
  331. _model.strChannel = @"0";
  332. _model.strGrade = @"0";
  333. }
  334. /**
  335. 导航按钮样式
  336. */
  337. - (void)loadNavStyle
  338. {
  339. //右边
  340. UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 16)];
  341. UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom];
  342. [btnfilter addTarget:self action:@selector(search)
  343. forControlEvents:UIControlEventTouchUpInside];
  344. btnfilter.frame = CGRectMake(0, 0, 16, 16);
  345. [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  346. [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"]
  347. forState:UIControlStateNormal];
  348. [v addSubview:btnfilter];
  349. UIButton *filterLbl = [[UIButton alloc]init];
  350. filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16);
  351. [filterLbl setTitle:@"筛选" forState:UIControlStateNormal];
  352. [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  353. filterLbl.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  354. [filterLbl addTarget:self action:@selector(search)
  355. forControlEvents:UIControlEventTouchUpInside];
  356. [v addSubview:filterLbl];
  357. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v];
  358. self.navigationItem.rightBarButtonItem = menubtnAdd;
  359. //返回
  360. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  361. [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
  362. [button addTarget:self action:@selector(goBack)
  363. forControlEvents:UIControlEventTouchUpInside];
  364. button.frame = CGRectMake(0, 0,45,22);
  365. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  366. self.navigationItem.leftBarButtonItem = menuButton;
  367. }
  368. /**
  369. 抽屉弹出
  370. */
  371. - (void)search{
  372. [_filterController show];
  373. }
  374. /**
  375. 抽屉初始化
  376. */
  377. - (void)initSlideSlip{
  378. // 抽屉对象
  379. __weak typeof(self) weakself=self;
  380. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  381. for (SideSlipModel *model in dataList) {
  382. model.selectedItemList = nil;
  383. model.customDict = nil;
  384. }
  385. } commitBlock:^(NSArray *dataList) {
  386. //查询条件
  387. SideSlipModel *serviceRegionModel = dataList[0];
  388. _model = [serviceRegionModel.customDict objectForKey:SALESANALYSIS_SEARCH_RANGE_MODEL];
  389. if(_model.strStartDate == nil){
  390. [self showAlertViewText:@"请选择开始日期"];
  391. return;
  392. }
  393. if(_model.strEndDate == nil){
  394. [self showAlertViewText:@"请选择结束日期"];
  395. return;
  396. }
  397. NSUInteger result = [DateFormat compareDate:_model.strStartDate withDate:_model.strEndDate];
  398. if(result == -1){
  399. [self showAlertViewText:@"开始日期不能大于结束日期"];
  400. return;
  401. }
  402. NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
  403. [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式
  404. NSDate *startD = [dateFormat dateFromString:_model.strStartDate];
  405. NSDate *endD = [dateFormat dateFromString:_model.strEndDate];
  406. NSInteger days = [DateFormat calculateDaysFromBegin:startD end:endD];
  407. if(days > 31){
  408. [self showAlertViewText:@"日期间隔天数不能大于31天"];
  409. return;
  410. }
  411. [weakself.filterController dismiss];
  412. [self ReloadList:self.customTableView];
  413. }];
  414. _filterController.animationDuration = AnimationDuration;
  415. _filterController.hasHeadView = YES;
  416. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  417. _filterController.dataList = [self packageDataList];
  418. }
  419. /**
  420. 数据源
  421. @return
  422. */
  423. - (NSArray *)packageDataList {
  424. NSMutableArray *dataArray = [NSMutableArray array];
  425. SideSlipModel *model = [[SideSlipModel alloc] init];
  426. model.containerCellClass = @"SalesAnalysisSearchCell";
  427. model.regionTitle = @"查询条件";
  428. [dataArray addObject:model];
  429. return [dataArray mutableCopy];
  430. }
  431. @end