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

DRChildBuyLimitController.m 8.4KB

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