省钱达人

DRChildOrderController.m 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // DRChildOrderController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/18.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRChildOrderController.h"
  9. #import "DRChildOrderCell.h"
  10. #import "DRChildOrderModel.h"
  11. @interface DRChildOrderController ()<UITableViewDelegate, UITableViewDataSource>
  12. @property (nonatomic, strong) NSMutableArray *dataArr;
  13. @property (nonatomic) NSInteger page;
  14. @end
  15. @implementation DRChildOrderController
  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 67;
  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. DRChildOrderCell *cell = [DRChildOrderCell cellWithTableView:tableView];
  45. DRChildOrderModel *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. //
  58. // self.childCanScroll = NO;
  59. // scrollView.contentOffset = CGPointZero;
  60. // [[NSNotificationCenter defaultCenter] postNotificationName:@"leaveTop" object:nil];//到顶通知父视图改变状态
  61. // }
  62. //}
  63. //
  64. //
  65. #pragma mark - request
  66. - (void)request {
  67. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/commissionList",BaseURL];
  68. NSDictionary *dic=@{
  69. @"type":@(self.type),
  70. @"page":@(self.page)
  71. };
  72. [DRHttp post:url params:dic success:^(id json) {
  73. NSArray *arr = [NSArray yy_modelArrayWithClass:[DRChildOrderModel class] json:json[@"data"]];
  74. if (arr.count>0) {
  75. [self.dataArr addObjectsFromArray:arr];
  76. self.tableView.footRefreshState = MJTableFooterRefreshStateLoadMore;
  77. }else {
  78. self.tableView.footRefreshState = MJTableFooterRefreshStateNoMore;
  79. [self setUpNoDataView];
  80. }
  81. [self.tableView reloadData];
  82. } failure:^(NSError *error) {
  83. [self.tableView.mj_footer endRefreshing];
  84. }];
  85. }
  86. - (void)setUpNoDataView {
  87. self.tableView.showNoDataView = YES;
  88. self.tableView.noDataImageOffsetY = -70;
  89. self.tableView.defaultNoDataText = @"您还没有任何记录";
  90. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  91. }
  92. #pragma mark ------- layzer ------
  93. - (UITableView *)tableView {
  94. if (!_tableView) {
  95. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-40) style:UITableViewStyleGrouped];
  96. _tableView.estimatedSectionHeaderHeight = 0;
  97. _tableView.estimatedSectionFooterHeight = 0;
  98. _tableView.sectionFooterHeight = 0;
  99. _tableView.sectionHeaderHeight = 0;
  100. _tableView.delegate = self;
  101. _tableView.dataSource = self;
  102. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  103. _tableView.backgroundColor = [UIColor yhGrayColor];
  104. _tableView.bounces = YES;
  105. _tableView.showsVerticalScrollIndicator = NO;
  106. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  107. _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  108. self.page ++;
  109. [self request];
  110. }];
  111. _tableView.footRefreshState = MJTableFooterRefreshStateNormal;
  112. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  113. }
  114. return _tableView;
  115. }
  116. -(NSMutableArray *)dataArr{
  117. if (!_dataArr) {
  118. _dataArr=[NSMutableArray array];
  119. }
  120. return _dataArr;
  121. }
  122. @end