《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRChildCommissionController.m 5.8KB

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