省钱达人

DRChildCommissionController.m 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // DRChildCommissionController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/18.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRChildCommissionController.h"
  9. #import "DRChildCommissionCell.h"
  10. #import "DRChildCommissionModel.h"
  11. @interface DRChildCommissionController ()<UITableViewDelegate, UITableViewDataSource>
  12. @property (nonatomic, strong) NSMutableArray *dataArr;
  13. @property (nonatomic, assign) NSInteger page;
  14. @end
  15. @implementation DRChildCommissionController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self configTableView];
  19. [self request];
  20. }
  21. - (void)configTableView {
  22. self.page = 1;
  23. [self.view addSubview:self.tableView];
  24. }
  25. #pragma mark -------- UITableView Delegate -----
  26. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  27. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  28. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
  29. }
  30. }
  31. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  32. return self.dataArr.count;
  33. }
  34. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  35. return 110;
  36. }
  37. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  38. return 0.1;
  39. }
  40. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  41. return 0.1;
  42. }
  43. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  44. DRChildCommissionCell *cell = [DRChildCommissionCell cellWithTableView:tableView];
  45. DRChildCommissionModel *model=self.dataArr[indexPath.row];
  46. cell.model=model;
  47. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  48. return cell;
  49. }
  50. #pragma mark ------ scrollView delegate -----
  51. //- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  52. //
  53. // if (!self.childCanScroll) {
  54. // scrollView.contentOffset = CGPointZero;
  55. // }
  56. // if (scrollView.contentOffset.y <= 0) {
  57. // self.childCanScroll = NO;
  58. // scrollView.contentOffset = CGPointZero;
  59. // [[NSNotificationCenter defaultCenter] postNotificationName:@"leaveTop" object:nil];//到顶通知父视图改变状态
  60. // }
  61. //}
  62. #pragma mark -网络请求
  63. #pragma mark - request
  64. - (void)request {
  65. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/orderList",BaseURL];
  66. NSDictionary *dic=@{
  67. @"type":@(self.type),
  68. @"page":@(self.page)
  69. };
  70. [DRHttp post:url params:dic success:^(id json) {
  71. NSArray *arr = [NSArray yy_modelArrayWithClass:[DRChildCommissionModel class] json:json[@"data"]];
  72. if (arr.count>0) {
  73. [self.dataArr addObjectsFromArray:arr];
  74. self.tableView.footRefreshState = MJTableFooterRefreshStateLoadMore;
  75. [self.tableView reloadData];
  76. }else {
  77. [self setUpNoDataView];
  78. [self noMoreDataWithArray:arr];
  79. // self.tableView.footRefreshState = MJTableFooterRefreshStateNoMore;
  80. if (self.page==1) {
  81. [self.tableView reloadData];
  82. }
  83. }
  84. [self.tableView.mj_footer endRefreshing];
  85. } failure:^(NSError *error) {
  86. [self.tableView.mj_footer endRefreshing];
  87. }];
  88. }
  89. - (void)noMoreDataWithArray:(NSArray *)array {
  90. if (array==nil || array.count <= 0) {
  91. MJRefreshBackNormalFooter *foot = (MJRefreshBackNormalFooter *)self.tableView.mj_footer;
  92. [foot setTitle:@"到底啦" forState:MJRefreshStateIdle];
  93. }
  94. }
  95. - (void)setUpNoDataView {
  96. self.tableView.showNoDataView = YES;
  97. self.tableView.noDataImageOffsetY = -70;
  98. self.tableView.defaultNoDataText = @"您还没有任何记录";
  99. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  100. }
  101. #pragma mark ------- layzer ------
  102. - (UITableView *)tableView {
  103. if (!_tableView) {
  104. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-40) style:UITableViewStyleGrouped];
  105. _tableView.estimatedSectionHeaderHeight = 0;
  106. _tableView.estimatedSectionFooterHeight = 0;
  107. _tableView.sectionFooterHeight = 0;
  108. _tableView.sectionHeaderHeight = 0;
  109. _tableView.delegate = self;
  110. _tableView.dataSource = self;
  111. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  112. _tableView.backgroundColor = [UIColor yhGrayColor];
  113. _tableView.bounces = YES;
  114. _tableView.showsVerticalScrollIndicator = NO;
  115. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  116. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  117. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  118. self.page ++;
  119. [self request];
  120. }];
  121. _tableView.footRefreshState = MJTableFooterRefreshStateNormal;
  122. }
  123. return _tableView;
  124. }
  125. -(NSMutableArray *)dataArr{
  126. if (!_dataArr) {
  127. _dataArr=[NSMutableArray array];
  128. }
  129. return _dataArr;
  130. }
  131. - (void)didReceiveMemoryWarning {
  132. [super didReceiveMemoryWarning];
  133. // Dispose of any resources that can be recreated.
  134. }
  135. /*
  136. #pragma mark - Navigation
  137. // In a storyboard-based application, you will often want to do a little preparation before navigation
  138. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  139. // Get the new view controller using [segue destinationViewController].
  140. // Pass the selected object to the new view controller.
  141. }
  142. */
  143. @end