YBOnSaleView.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // YBOnSaleView.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2020/8/31.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "YBOnSaleView.h"
  9. @interface YBOnSaleView()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
  10. {
  11. int _paging;
  12. NSString *_titlePre;
  13. }
  14. @property(nonatomic,assign)BOOL isAnchor;
  15. @property(nonatomic,strong)NSString *anchorID;
  16. @property(nonatomic,strong)UIView *bgView;
  17. @property(nonatomic,strong)UILabel *titleL;
  18. @property(nonatomic,strong)UIButton *addGoodsBtn;
  19. @property(nonatomic,strong)UITableView *tableView;
  20. @property(nonatomic,strong)NSMutableArray *dataArray;
  21. @end
  22. @implementation YBOnSaleView
  23. +(instancetype)showSaleWithAnchor:(BOOL)isAnchor andAnchorID:(NSString *)anchorID{
  24. YBOnSaleView *onSaleView = [[YBOnSaleView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
  25. [[UIApplication sharedApplication].delegate.window addSubview:onSaleView];
  26. onSaleView.isAnchor = isAnchor;
  27. onSaleView.anchorID = anchorID;
  28. [onSaleView createUI];
  29. return onSaleView;
  30. }
  31. -(void)createUI {
  32. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dissmissView)];
  33. tap.delegate = self;
  34. [self addGestureRecognizer:tap];
  35. _titlePre = YZMsg(@"在售商品");
  36. _paging = 1;
  37. self.dataArray = [NSMutableArray array];
  38. _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height-280-ShowDiff, _window_width, 280+ShowDiff)];
  39. _bgView.backgroundColor = UIColor.whiteColor;
  40. [self addSubview:_bgView];
  41. UIView *topNav = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 50)];
  42. topNav.backgroundColor = UIColor.whiteColor;
  43. [_bgView addSubview:topNav];
  44. _titleL = [[UILabel alloc]init];
  45. _titleL.font = SYS_Font(14);
  46. _titleL.text = [NSString stringWithFormat:@"%@ 0",_titlePre];
  47. _titleL.textColor =[UIColor blackColor];// RGB_COLOR(@"#323232", 1);
  48. [topNav addSubview:_titleL];
  49. [_titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.centerX.centerY.equalTo(topNav);
  51. }];
  52. UILabel *topLineL = [[UILabel alloc]init];
  53. topLineL.backgroundColor = RGB_COLOR(@"#f5f5f5", 1);
  54. [topNav addSubview:topLineL];
  55. [topLineL mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.width.bottom.centerX.equalTo(topNav);
  57. make.height.mas_equalTo(1);
  58. }];
  59. _addGoodsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  60. [_addGoodsBtn setImage:[UIImage imageNamed:@"在售-加"] forState:0];
  61. [_addGoodsBtn setTitle:YZMsg(@"添加商品") forState:0];
  62. [_addGoodsBtn setTitleColor:Pink_Cor forState:0];
  63. _addGoodsBtn.titleLabel.font = SYS_Font(12);
  64. _addGoodsBtn.contentEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10);
  65. [_addGoodsBtn addTarget:self action:@selector(clickAddBtn) forControlEvents:UIControlEventTouchUpInside];
  66. [topNav addSubview:_addGoodsBtn];
  67. [_addGoodsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.right.equalTo(topNav.mas_right).offset(-5);
  69. make.centerY.equalTo(topNav);
  70. }];
  71. [topNav layoutIfNeeded];
  72. _addGoodsBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
  73. _addGoodsBtn.hidden = YES;
  74. if (_isAnchor) {
  75. _addGoodsBtn.hidden = NO;
  76. }
  77. [_bgView addSubview:self.tableView];
  78. [self pullData];
  79. }
  80. -(void)clickAddBtn {
  81. //10-26调整要求返回消失在售列表,要做展示操作只能手动再次点开[注:注释 [self dissmissView] 添加操作后会刷新]
  82. [self dissmissView];
  83. if (self.onSaleEvent) {
  84. self.onSaleEvent(OnSaleType_addGoods,@{});
  85. }
  86. }
  87. #pragma mark -
  88. -(void)pullData {
  89. if ([PublicObj checkNull:_anchorID]) {
  90. return;
  91. }
  92. [YBNetworking postWithUrl:@"Shop.getSale" Dic:@{@"liveuid":_anchorID,@"p":@(_paging)} Suc:^(int code, id info, NSString *msg) {
  93. [_tableView.mj_header endRefreshing];
  94. [_tableView.mj_footer endRefreshing];
  95. if (code == 0) {
  96. NSDictionary *infoDic = [info firstObject];
  97. _titleL.text = [NSString stringWithFormat:@"%@ %@",_titlePre,minstr([infoDic valueForKey:@"nums"])];;
  98. NSArray *listA = [NSArray arrayWithArray:[infoDic valueForKey:@"list"]];
  99. if (_paging == 1) {
  100. [_dataArray removeAllObjects];
  101. }
  102. if (listA.count <= 0) {
  103. [_tableView.mj_footer endRefreshingWithNoMoreData];
  104. }else{
  105. [_dataArray addObjectsFromArray:listA];
  106. }
  107. if (_dataArray.count <= 0 ) {
  108. [PublicView showTextNoData:_tableView text1:YZMsg(@"当前暂无在售商品") text2:YZMsg(@"点击右上角添加商品到购物车") centerY:0.5];
  109. }else {
  110. [PublicView hiddenTextNoData:_tableView];
  111. }
  112. [_tableView reloadData];
  113. }else {
  114. [MBProgressHUD showPop:msg];
  115. }
  116. } Fail:^(id fail) {
  117. [_tableView.mj_header endRefreshing];
  118. [_tableView.mj_footer endRefreshing];
  119. }];
  120. }
  121. #pragma mark - UITableViewDelegate、UITableViewDataSource
  122. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  123. return nil;
  124. }
  125. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section {
  126. return 0;
  127. }
  128. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  129. return 100;
  130. }
  131. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  132. return _dataArray.count;
  133. }
  134. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  135. YBOnSaleCell *cell = [YBOnSaleCell cellWithTab:tableView index:indexPath];
  136. cell.isAnchor = _isAnchor;
  137. NSDictionary *subDic = _dataArray[indexPath.row];
  138. cell.dataDic = subDic;
  139. YBWeakSelf;
  140. cell.saleCellEnvent = ^(OnSaleType ctrType) {
  141. weakSelf.onSaleEvent(ctrType,subDic);
  142. if (ctrType == OnSaleType_Default || ctrType == OnSaleType_Info) {
  143. [weakSelf dissmissView];
  144. }
  145. };
  146. return cell;
  147. }
  148. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  149. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  150. }
  151. #pragma mark - set/get
  152. -(UITableView *)tableView {
  153. if (!_tableView) {
  154. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,50, _window_width, _bgView.height-50)style:UITableViewStylePlain];
  155. _tableView.delegate = self;
  156. _tableView.dataSource = self;
  157. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  158. _tableView.backgroundColor = UIColor.whiteColor;
  159. YBWeakSelf;
  160. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  161. _paging = 1;
  162. [weakSelf pullData];
  163. }];
  164. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  165. _paging +=1;
  166. [weakSelf pullData];
  167. }];
  168. _tableView.contentInset = UIEdgeInsetsMake(0, 0, ShowDiff, 0);
  169. }
  170. return _tableView;
  171. }
  172. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;{
  173. if ([touch.view isDescendantOfView:self.bgView]) {
  174. return NO;
  175. }
  176. return YES;
  177. }
  178. -(void)dissmissView {
  179. [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  180. [self removeFromSuperview];
  181. }
  182. @end