猎豆优选

LDChildBuyLimitController.m 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // LDChildBuyLimitController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/6.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDChildBuyLimitController.h"
  9. #import "LDBuyLimitGoodCell.h"
  10. #import "DateManager.h"
  11. #import "LDBuyLimitHeader.h"
  12. #import "LDBuyLimitGoodModel.h"
  13. @interface LDChildBuyLimitController ()<UITableViewDelegate, UITableViewDataSource>
  14. {
  15. NSInteger _page;
  16. }
  17. @property (nonatomic, strong) UITableView *tableView;
  18. @property (nonatomic, strong) NSMutableArray *dataArr;
  19. @property (nonatomic, strong) LDBuyLimitHeader *header;
  20. @property (nonatomic, strong) NSMutableArray *topArr;
  21. @end
  22. @implementation LDChildBuyLimitController
  23. - (void)dealloc {
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self confitUI];
  28. [self requestData];
  29. }
  30. - (void)confitUI {
  31. _page = 1;
  32. self.view.backgroundColor = [UIColor whiteColor];
  33. self.header = [[LDBuyLimitHeader alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160)];
  34. __weak typeof(self) weakSelf = self;
  35. self.header.ClickBlock = ^(LDBuyLimitGoodModel *model) {
  36. LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  37. DetailRequestModel *request = [[DetailRequestModel alloc] initWithBuyLimitModel:model];
  38. detail.requestModel = request;
  39. LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:QuickBuyAction];
  40. detail.eventModel = evevtModel;
  41. [weakSelf.navigationController pushViewController:detail animated:YES];
  42. [MobClick event:BuyLimitGoodClick];
  43. };
  44. self.header.canBuy = self.canBuy;
  45. self.tableView.tableHeaderView = self.header;
  46. [self.view addSubview:self.tableView];
  47. [MBProgressHUD showLoadingAddedToView:self.view];
  48. }
  49. - (void)requestData {
  50. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/taoQiangGouDataList",BaseURL];
  51. NSTimeInterval start = [DateManager timeStrToInterval:self.start_time];
  52. NSTimeInterval end = [DateManager timeStrToInterval:self.end_time];
  53. NSDictionary *param = @{@"start_time":@(start),
  54. @"end_time":@(end),
  55. @"platform":@"2",
  56. @"page":@(_page),
  57. @"page_size":@(20)
  58. };
  59. [LDHttp post:url params:param success:^(id json) {
  60. if ([self.tableView.mj_header isRefreshing]) {
  61. [self.topArr removeAllObjects];
  62. [self.dataArr removeAllObjects];
  63. }
  64. NSArray *topList = [NSArray yy_modelArrayWithClass:[LDBuyLimitGoodModel class] json:json[@"data"][@"top"]];
  65. NSArray *goodList = [NSArray yy_modelArrayWithClass:[LDBuyLimitGoodModel class] json:json[@"data"][@"list"]];
  66. if (goodList.count>0) {
  67. [self.topArr addObjectsFromArray:topList];
  68. [self.dataArr addObjectsFromArray:goodList];
  69. [self.tableView.mj_footer endRefreshing];;
  70. }else {
  71. if (_page==1) {
  72. [self setUpNoDataView];
  73. }
  74. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  75. }
  76. [self setHeaderGoodInfo];
  77. [self.tableView.mj_header endRefreshing];
  78. [MBProgressHUD hideHUDForView:self.view];
  79. [self.tableView reloadData];
  80. } failure:^(NSError *error) {
  81. [self.tableView.mj_header endRefreshing];
  82. [self.tableView.mj_footer endRefreshing];
  83. [MBProgressHUD hideHUDForView:self.view];
  84. }];
  85. }
  86. - (void)setUpNoDataView {
  87. self.tableView.showNoDataView = YES;
  88. self.tableView.defaultNoDataText = @"暂无抢购的商品信息";
  89. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  90. }
  91. - (void)setHeaderGoodInfo {
  92. if (self.topArr.count > 0) {
  93. LDBuyLimitGoodModel *model = self.topArr.firstObject;
  94. [self.header setModel:model];
  95. self.header.canBuy = self.canBuy;
  96. }
  97. }
  98. #pragma mark -------- UITableView Delegate -----
  99. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  100. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  101. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
  102. }
  103. }
  104. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  105. return self.dataArr.count;
  106. }
  107. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  108. return 124;
  109. }
  110. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  111. return .1;
  112. }
  113. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  114. return 0.1;
  115. }
  116. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  117. LDBuyLimitGoodModel *model = self.dataArr[indexPath.row];
  118. LDBuyLimitGoodCell *cell = [LDBuyLimitGoodCell cellWithTableView:tableView];
  119. cell.model = model;
  120. cell.canBuy = self.canBuy;
  121. return cell;
  122. }
  123. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  124. if (!_canBuy) {
  125. [MBProgressHUD showMessage:@"抢购还未开始"];
  126. return;
  127. }
  128. LDBuyLimitGoodModel *model = self.dataArr[indexPath.row];
  129. if ([model.sale_rate floatValue]/100.0 > 1.f ) {
  130. [MBProgressHUD showMessage:@"已售空"];
  131. return;
  132. }
  133. LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  134. DetailRequestModel *request = [[DetailRequestModel alloc] initWithBuyLimitModel:model];
  135. detail.requestModel = request;
  136. LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:QuickBuyAction];
  137. detail.eventModel = evevtModel;
  138. [self.navigationController pushViewController:detail animated:YES];
  139. [MobClick event:BuyLimitGoodClick];
  140. }
  141. #pragma mark ------- layzer ------
  142. - (UITableView *)tableView {
  143. if (!_tableView) {
  144. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-55) style:UITableViewStyleGrouped];
  145. _tableView.estimatedSectionHeaderHeight = 0;
  146. _tableView.estimatedSectionFooterHeight = 0;
  147. _tableView.sectionFooterHeight = 0;
  148. _tableView.sectionHeaderHeight = 0;
  149. _tableView.estimatedRowHeight = 0;
  150. _tableView.delegate = self;
  151. _tableView.dataSource = self;
  152. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  153. _tableView.backgroundColor = [UIColor yhGrayColor];
  154. _tableView.showsVerticalScrollIndicator = NO;
  155. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  156. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  157. MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
  158. _page = 1;
  159. [self requestData];
  160. }];
  161. header.lastUpdatedTimeLabel.hidden = YES;
  162. header.stateLabel.hidden = YES;
  163. //正在刷新的图片
  164. NSArray *imgArr = @[[UIImage imageNamed:@"ant1"],[UIImage imageNamed:@"ant2"]];
  165. [header setImages:imgArr duration:0.3 forState:MJRefreshStateRefreshing];
  166. [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStateWillRefresh];
  167. [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStatePulling];
  168. _tableView.mj_header = header;
  169. _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  170. _page++;
  171. [self requestData];
  172. }];
  173. }
  174. return _tableView;
  175. }
  176. - (NSMutableArray *)dataArr {
  177. if (!_dataArr) {
  178. _dataArr = [NSMutableArray array];
  179. }
  180. return _dataArr;
  181. }
  182. - (NSMutableArray *)topArr {
  183. if (!_topArr) {
  184. _topArr = [NSMutableArray array];
  185. }
  186. return _topArr;
  187. }
  188. - (void)didReceiveMemoryWarning {
  189. [super didReceiveMemoryWarning];
  190. // Dispose of any resources that can be recreated.
  191. }
  192. /*
  193. #pragma mark - Navigation
  194. // In a storyboard-based application, you will often want to do a little preparation before navigation
  195. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  196. // Get the new view controller using [segue destinationViewController].
  197. // Pass the selected object to the new view controller.
  198. }
  199. */
  200. @end