123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- //
- // LDChildBuyLimitController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/7/6.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDChildBuyLimitController.h"
- #import "LDBuyLimitGoodCell.h"
- #import "DateManager.h"
- #import "LDBuyLimitHeader.h"
- #import "LDBuyLimitGoodModel.h"
- @interface LDChildBuyLimitController ()<UITableViewDelegate, UITableViewDataSource>
- {
- NSInteger _page;
- }
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @property (nonatomic, strong) LDBuyLimitHeader *header;
- @property (nonatomic, strong) NSMutableArray *topArr;
- @end
- @implementation LDChildBuyLimitController
- - (void)dealloc {
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self confitUI];
- [self requestData];
- }
- - (void)confitUI {
- _page = 1;
- self.view.backgroundColor = [UIColor whiteColor];
- self.header = [[LDBuyLimitHeader alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160)];
- __weak typeof(self) weakSelf = self;
- self.header.ClickBlock = ^(LDBuyLimitGoodModel *model) {
- LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
- DetailRequestModel *request = [[DetailRequestModel alloc] initWithBuyLimitModel:model];
- detail.requestModel = request;
- LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:QuickBuyAction];
- detail.eventModel = evevtModel;
- [weakSelf.navigationController pushViewController:detail animated:YES];
- [MobClick event:BuyLimitGoodClick];
- };
- self.header.canBuy = self.canBuy;
- self.tableView.tableHeaderView = self.header;
- [self.view addSubview:self.tableView];
- [MBProgressHUD showLoadingAddedToView:self.view];
- }
- - (void)requestData {
-
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/taoQiangGouDataList",BaseURL];
- NSTimeInterval start = [DateManager timeStrToInterval:self.start_time];
- NSTimeInterval end = [DateManager timeStrToInterval:self.end_time];
- NSDictionary *param = @{@"start_time":@(start),
- @"end_time":@(end),
- @"platform":@"2",
- @"page":@(_page),
- @"page_size":@(20)
- };
-
- [LDHttp post:url params:param success:^(id json) {
- if ([self.tableView.mj_header isRefreshing]) {
- [self.topArr removeAllObjects];
- [self.dataArr removeAllObjects];
- }
- NSArray *topList = [NSArray yy_modelArrayWithClass:[LDBuyLimitGoodModel class] json:json[@"data"][@"top"]];
- NSArray *goodList = [NSArray yy_modelArrayWithClass:[LDBuyLimitGoodModel class] json:json[@"data"][@"list"]];
-
- if (goodList.count>0) {
- [self.topArr addObjectsFromArray:topList];
- [self.dataArr addObjectsFromArray:goodList];
- [self.tableView.mj_footer endRefreshing];;
- }else {
- if (_page==1) {
- [self setUpNoDataView];
- }
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }
-
- [self setHeaderGoodInfo];
-
- [self.tableView.mj_header endRefreshing];
- [MBProgressHUD hideHUDForView:self.view];
- [self.tableView reloadData];
- } failure:^(NSError *error) {
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- [MBProgressHUD hideHUDForView:self.view];
- }];
- }
- - (void)setUpNoDataView {
- self.tableView.showNoDataView = YES;
- self.tableView.defaultNoDataText = @"暂无抢购的商品信息";
- self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
- }
- - (void)setHeaderGoodInfo {
- if (self.topArr.count > 0) {
- LDBuyLimitGoodModel *model = self.topArr.firstObject;
- [self.header setModel:model];
- self.header.canBuy = self.canBuy;
- }
- }
- #pragma mark -------- UITableView Delegate -----
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
- [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
- }
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.dataArr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 124;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return .1;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- LDBuyLimitGoodModel *model = self.dataArr[indexPath.row];
- LDBuyLimitGoodCell *cell = [LDBuyLimitGoodCell cellWithTableView:tableView];
- cell.model = model;
- cell.canBuy = self.canBuy;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- if (!_canBuy) {
- [MBProgressHUD showMessage:@"抢购还未开始"];
- return;
- }
-
- LDBuyLimitGoodModel *model = self.dataArr[indexPath.row];
- if ([model.sale_rate floatValue]/100.0 > 1.f ) {
- [MBProgressHUD showMessage:@"已售空"];
- return;
- }
- LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
- DetailRequestModel *request = [[DetailRequestModel alloc] initWithBuyLimitModel:model];
- detail.requestModel = request;
- LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:QuickBuyAction];
- detail.eventModel = evevtModel;
-
- [self.navigationController pushViewController:detail animated:YES];
-
- [MobClick event:BuyLimitGoodClick];
- }
- #pragma mark ------- layzer ------
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-55) style:UITableViewStyleGrouped];
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.sectionFooterHeight = 0;
- _tableView.sectionHeaderHeight = 0;
- _tableView.estimatedRowHeight = 0;
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- _tableView.backgroundColor = [UIColor yhGrayColor];
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
- _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
- MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
- _page = 1;
- [self requestData];
- }];
- header.lastUpdatedTimeLabel.hidden = YES;
- header.stateLabel.hidden = YES;
-
- //正在刷新的图片
- NSArray *imgArr = @[[UIImage imageNamed:@"ant1"],[UIImage imageNamed:@"ant2"]];
- [header setImages:imgArr duration:0.3 forState:MJRefreshStateRefreshing];
- [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStateWillRefresh];
- [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStatePulling];
- _tableView.mj_header = header;
- _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- _page++;
- [self requestData];
- }];
-
- }
- return _tableView;
- }
- - (NSMutableArray *)dataArr {
- if (!_dataArr) {
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- - (NSMutableArray *)topArr {
- if (!_topArr) {
- _topArr = [NSMutableArray array];
- }
- return _topArr;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|