AuctionGoodsView.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // AuctionGoodsView.m
  3. // BuguLive
  4. //
  5. // Created by 王珂 on 16/10/11.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "AuctionGoodsView.h"
  9. #import "AuctionGoodsCell.h"
  10. #import "MJRefresh.h"
  11. #import "ShopGoodsModel.h"
  12. @interface AuctionGoodsView()<UITableViewDelegate,UITableViewDataSource,AuctionGoodsCellDelegate>
  13. @property (nonatomic, strong) UITableView * auctionGoodsTable;
  14. @property (nonatomic, strong) NSMutableArray * auctionGoodsArray;
  15. @property (nonatomic, assign) int has_next;
  16. @property (nonatomic, assign) int currentPage;
  17. @end
  18. @implementation AuctionGoodsView
  19. - (instancetype)initWithFrame:(CGRect)frame
  20. {
  21. if (self = [super initWithFrame:frame])
  22. {
  23. if (_auctionGoodsTable == nil)
  24. {
  25. _auctionGoodsTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 300) style:UITableViewStylePlain];
  26. _auctionGoodsTable.delegate = self;
  27. _auctionGoodsTable.dataSource = self;
  28. _auctionGoodsTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  29. _auctionGoodsTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  30. [self addSubview:_auctionGoodsTable];
  31. }
  32. if (_auctionGoodsArray == nil)
  33. {
  34. _auctionGoodsArray = [NSMutableArray array];
  35. }
  36. _currentPage=1;
  37. [BGMJRefreshManager refresh:_auctionGoodsTable target:self headerRereshAction:@selector(headerRefresh) shouldHeaderBeginRefresh:NO footerRereshAction:@selector(footerReresh)];
  38. }
  39. return self;
  40. }
  41. - (void)loadDataWithPage:(int)page
  42. {
  43. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  44. [mDict setObject:@"shop" forKey:@"ctl"];
  45. [mDict setObject:@"pai_goods" forKey:@"act"];
  46. [mDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"page"];
  47. [mDict setObject:@"shop" forKey:@"itype"];
  48. FWWeakify(self)
  49. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  50. FWStrongify(self)
  51. if ([responseJson toInt:@"status"] == 1)
  52. {
  53. NSDictionary * dic = [responseJson objectForKey:@"page"];
  54. if (dic && [dic isKindOfClass:[NSDictionary class]])
  55. {
  56. self.currentPage = [dic toInt:@"page"];
  57. if (self.currentPage == 1 || self.currentPage == 0)
  58. {
  59. [self.auctionGoodsArray removeAllObjects];
  60. }
  61. self.has_next = [dic toInt:@"has_next"];
  62. }
  63. NSArray * dataArray = [responseJson objectForKey:@"list"];
  64. if (dataArray && [dataArray isKindOfClass:[NSArray class]])
  65. {
  66. if(dataArray.count)
  67. {
  68. for (NSDictionary * dic in dataArray)
  69. {
  70. ShopGoodsModel * model = [ShopGoodsModel mj_objectWithKeyValues:dic];
  71. [self.auctionGoodsArray addObject:model];
  72. }
  73. }
  74. [self.auctionGoodsTable reloadData];
  75. }
  76. }
  77. [BGMJRefreshManager endRefresh:self.auctionGoodsTable];
  78. if (!self.auctionGoodsArray.count)
  79. {
  80. [self showNoContentViewOnView:self];
  81. }
  82. else
  83. {
  84. [self hideNoContentViewOnView:self];
  85. }
  86. } FailureBlock:^(NSError *error) {
  87. FWStrongify(self)
  88. [BGMJRefreshManager endRefresh:self.auctionGoodsTable];
  89. }];
  90. }
  91. - (void)headerRefresh
  92. {
  93. [self loadDataWithPage:1];
  94. }
  95. - (void)footerReresh
  96. {
  97. if (_has_next == 1)
  98. {
  99. _currentPage ++;
  100. [self loadDataWithPage:_currentPage];
  101. }
  102. else
  103. {
  104. [BGMJRefreshManager endRefresh:_auctionGoodsTable];
  105. }
  106. }
  107. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  108. {
  109. return self.auctionGoodsArray.count;
  110. }
  111. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  112. {
  113. AuctionGoodsCell * cell = [AuctionGoodsCell cellWithTableView:tableView];
  114. cell.model=_auctionGoodsArray[indexPath.row];
  115. cell.delegate = self;
  116. return cell;
  117. }
  118. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  119. {
  120. }
  121. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  122. {
  123. return 100;
  124. }
  125. - (void)clickAuctionWithAuctionGoodsCell:(AuctionGoodsCell *)cell
  126. {
  127. NSIndexPath * indexPath = [_auctionGoodsTable indexPathForCell:cell];
  128. self.model = _auctionGoodsArray[indexPath.row];
  129. if (_delegate && [_delegate respondsToSelector:@selector(closeAuctionGoodsView)])
  130. {
  131. [_delegate closeAuctionGoodsView];
  132. }
  133. }
  134. @end