猎豆优选

LDChildCommissionController.m 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // LDChildCommissionController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/18.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDChildCommissionController.h"
  9. #import "LDChildCommissionCell.h"
  10. #import "LDChildCommissionModel.h"
  11. #import "LDAdWebViewController.h"
  12. #import "LDChildCommissionModel.h"
  13. @interface LDChildCommissionController ()<UITableViewDelegate, UITableViewDataSource,LDChildCommissionCellDelegate>{
  14. NSString *dateStr;
  15. }
  16. @property (nonatomic, strong) NSMutableArray *dataArr;
  17. @property (nonatomic, assign) NSInteger page;
  18. @end
  19. @implementation LDChildCommissionController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. [self configTableView];
  23. [self requestAndRefresh:YES];
  24. }
  25. - (void)configTableView {
  26. self.page = 1;
  27. dateStr = @"";
  28. [self.view addSubview:self.tableView];
  29. }
  30. #pragma mark -------- UITableView Delegate -----
  31. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  32. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  33. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
  34. }
  35. }
  36. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  37. return self.dataArr.count;
  38. }
  39. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  40. LDChildCommissionModel *model=self.dataArr[indexPath.row];
  41. if (model.order_status.integerValue == 1) {
  42. return 140;
  43. }
  44. return 110;
  45. }
  46. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  47. return 0.1;
  48. }
  49. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  50. return 0.1;
  51. }
  52. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  53. LDChildCommissionCell *cell = [LDChildCommissionCell cellWithTableView:tableView];
  54. LDChildCommissionModel *model=self.dataArr[indexPath.row];
  55. cell.model=model;
  56. cell.delegatre =self;
  57. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  58. return cell;
  59. }
  60. #pragma mark ------ scrollView delegate -----
  61. //- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  62. //
  63. // if (!self.childCanScroll) {
  64. // scrollView.contentOffset = CGPointZero;
  65. // }
  66. // if (scrollView.contentOffset.y <= 0) {
  67. // self.childCanScroll = NO;
  68. // scrollView.contentOffset = CGPointZero;
  69. // [[NSNotificationCenter defaultCenter] postNotificationName:@"leaveTop" object:nil];//到顶通知父视图改变状态
  70. // }
  71. //}
  72. #pragma mark -网络请求
  73. #pragma mark - request
  74. - (void)requestAndRefresh:(BOOL)refresh {
  75. if (![self.tableView.mj_footer isRefreshing]) {
  76. [MBProgressHUD showLoadingAddedToView:self.view];
  77. }
  78. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/orderListNew",BaseURL];
  79. NSDictionary *dic=@{
  80. @"type":@(self.type),
  81. @"page":@(self.page),
  82. @"yearMonthDay":dateStr,
  83. @"isDay":@1
  84. };
  85. [LDHttp post:url params:dic success:^(id json) {
  86. if (refresh) {
  87. [self.dataArr removeAllObjects];
  88. }
  89. NSArray *arr = [NSArray yy_modelArrayWithClass:[LDChildCommissionModel class] json:json[@"data"]];
  90. if (arr.count>0) {
  91. [self.dataArr addObjectsFromArray:arr];
  92. [self.tableView.mj_footer endRefreshing];
  93. }else {
  94. [self setUpNoDataView];
  95. [self noMoreDataWithArray:arr];
  96. }
  97. [self.tableView reloadData];
  98. [MBProgressHUD hideHUDForView:self.view];
  99. } failure:^(NSError *error) {
  100. [MBProgressHUD hideHUDForView:self.view];
  101. [self.tableView.mj_footer endRefreshing];
  102. }];
  103. }
  104. - (void)noMoreDataWithArray:(NSArray *)array {
  105. if (array==nil || array.count <= 0) {
  106. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  107. }
  108. }
  109. - (void)setUpNoDataView {
  110. self.tableView.showNoDataView = YES;
  111. self.tableView.noDataImageOffsetY = -70;
  112. self.tableView.defaultNoDataText = @"您还没有订单";
  113. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"no_order"];
  114. }
  115. - (void)refreshWithDate:(NSString *)date {
  116. dateStr = date;
  117. [self requestAndRefresh:YES];
  118. }
  119. #pragma mark ------- layzer ------
  120. - (UITableView *)tableView {
  121. if (!_tableView) {
  122. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-70) style:UITableViewStyleGrouped];
  123. _tableView.estimatedSectionHeaderHeight = 0;
  124. _tableView.estimatedSectionFooterHeight = 0;
  125. _tableView.sectionFooterHeight = 0;
  126. _tableView.sectionHeaderHeight = 0;
  127. _tableView.estimatedRowHeight = 0;
  128. _tableView.delegate = self;
  129. _tableView.dataSource = self;
  130. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  131. _tableView.backgroundColor = [UIColor yhGrayColor];
  132. _tableView.bounces = YES;
  133. _tableView.showsVerticalScrollIndicator = NO;
  134. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  135. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  136. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  137. self.page ++;
  138. [self requestAndRefresh:NO];
  139. }];
  140. }
  141. return _tableView;
  142. }
  143. -(NSMutableArray *)dataArr{
  144. if (!_dataArr) {
  145. _dataArr=[NSMutableArray array];
  146. }
  147. return _dataArr;
  148. }
  149. - (void)didReceiveMemoryWarning {
  150. [super didReceiveMemoryWarning];
  151. // Dispose of any resources that can be recreated.
  152. }
  153. -(void)ClickModel:(LDChildCommissionModel *)model
  154. {
  155. LDAdWebViewController *web = [[LDAdWebViewController alloc] init];
  156. web.url = model.red_url;
  157. [self.navigationController pushViewController:web animated:YES];
  158. }
  159. @end