MORedPacketDetailView.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. //
  2. // MORedPacketDetailView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/6/13.
  6. //
  7. #import "MORedPacketDetailView.h"
  8. #import "MORedPacketDTopView.h"
  9. //一页的size
  10. #define kPageSize 20
  11. @interface MORedPacketDetailView ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, strong) BigBtn *backBtn;
  13. @property (nonatomic, strong) UIView *bgView;
  14. @property (nonatomic, strong) UIImageView *bgImageView;
  15. @property (nonatomic, strong) UITableView *tableView;
  16. @property (nonatomic, strong) MORedPacketDTopView *headView;
  17. @property (nonatomic, strong) NSMutableArray *dataArr;
  18. @property (nonatomic, assign) BOOL isShowBest;
  19. /** 游标 */
  20. @property (nonatomic, copy) NSString *next;
  21. /** 没有更多的数据视图 */
  22. @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
  23. @end
  24. @implementation MORedPacketDetailView
  25. - (instancetype)init {
  26. if (self = [super init]) {
  27. [self setupUI];
  28. }
  29. return self;
  30. }
  31. - (void)setupUI {
  32. [self addSubview:self.bgView];
  33. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.edges.mas_equalTo(0);
  35. }];
  36. [self addSubview:self.bgImageView];
  37. [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.top.left.mas_equalTo(0);
  39. make.width.mas_equalTo(SCREENWIDTH);
  40. make.height.mas_equalTo(kScaleWidth(143));
  41. }];
  42. CGFloat spacing = KIsiPhoneX ? 10.0 : 40.0;
  43. [self addSubview:self.headView];
  44. [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.mas_equalTo(kTopSafeAreaInset + spacing);
  46. make.left.trailing.mas_equalTo(0);
  47. make.height.equalTo(@340.0);
  48. }];
  49. [self addSubview:self.backBtn];
  50. [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.mas_equalTo(kTopSafeAreaInset + spacing);
  52. make.size.mas_equalTo(CGSizeMake(12, 22));
  53. make.left.mas_equalTo(15);
  54. }];
  55. [self addSubview:self.tableView];
  56. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.top.equalTo(self.headView.mas_bottom);
  58. make.left.right.bottom.mas_equalTo(0);
  59. }];
  60. WEAKSELF
  61. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  62. if(weakSelf.next.length == 0 || weakSelf.receiveData.receivingInfo.redEnvelopeId.length == 0){
  63. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  64. return;
  65. }
  66. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  67. NSDictionary *baseDict = @{@"page":basePage,
  68. @"redEnvelopeId":weakSelf.receiveData.receivingInfo.redEnvelopeId,
  69. @"lastReceivedNum":@(weakSelf.receiveData.lastReceivedNum)};
  70. [weakSelf toGetTheReceivingInfoWith:baseDict];
  71. }];
  72. self.tableView.backgroundView = self.noMoreDataView;
  73. }
  74. - (void)setReceiveData:(MOReceivingBaseData *)receiveData{
  75. _receiveData = receiveData;
  76. [self.dataArr removeAllObjects];
  77. self.headView.redEnvelopInfo = self.redEnvelopInfo;
  78. self.headView.receiveData = receiveData;
  79. self.dataArr = [receiveData.receivingInfo.receivingUserItems mutableCopy];
  80. if(receiveData.receivingInfo.receivedNum == receiveData.receivingInfo.num){
  81. self.isShowBest = YES;
  82. }
  83. else{
  84. self.isShowBest = NO;
  85. }
  86. if(receiveData.next.length == 0){
  87. self.next = @"2";
  88. }
  89. else{
  90. self.next = receiveData.next;
  91. }
  92. [self.tableView reloadData];
  93. }
  94. - (void)toGetTheReceivingInfoWith:(NSDictionary *)dict{
  95. WEAKSELF
  96. [kHttpManager toGetTheRedEnvelopeReceivingInfoWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  97. [weakSelf.tableView.mj_footer endRefreshing];
  98. if(kCode_Success){
  99. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  100. MOReceivingInfo *baseData = [MOReceivingInfo modelObjectWithDictionary:data[@"data"]];
  101. if(baseData.next == nil || baseData.next.length == 0){
  102. if(weakSelf.next == nil || weakSelf.next.length == 0){
  103. if(weakSelf.dataArr.count > 0){
  104. [weakSelf.dataArr removeAllObjects];
  105. }
  106. //第一页
  107. weakSelf.dataArr = [baseData.receivingUserList mutableCopy];
  108. }
  109. else{
  110. //最后一页
  111. [weakSelf.dataArr addObjectsFromArray:baseData.receivingUserList];
  112. }
  113. weakSelf.next = @"";
  114. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  115. }
  116. else{
  117. weakSelf.next = baseData.next;
  118. [weakSelf.dataArr addObjectsFromArray:baseData.receivingUserList];
  119. }
  120. [weakSelf.tableView reloadData];
  121. weakSelf.tableView.mj_footer.hidden = (weakSelf.dataArr.count > 0) ? NO : YES;
  122. weakSelf.noMoreDataView.isHaveData = (weakSelf.dataArr.count > 0) ? YES : NO;
  123. }
  124. else{
  125. MOLogV(@"toGetTheRedEnvelopeReceivingInfoWithParams 接口报错了");
  126. kShowNetError(data)
  127. }
  128. }];
  129. }
  130. #pragma mark - UITableViewDelegate,UITableViewDataSource
  131. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  132. {
  133. return 1;
  134. }
  135. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  136. {
  137. return self.dataArr.count;
  138. }
  139. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  140. MOReceivingUserItems *model = self.dataArr[indexPath.row];
  141. MORedPacketDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:MORedPacketDetailCell_ID];
  142. cell.isShowBest = self.isShowBest;
  143. cell.cellModel = model;
  144. return cell;
  145. }
  146. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  147. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  148. }
  149. - (void)openRedPacketDetailView{
  150. self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
  151. CGRect actionViewRect = self.frame;
  152. actionViewRect.size.height = 200.0;
  153. actionViewRect.origin.y = (SCREENHEIGHT / 2.0) - 100.0;
  154. self.frame = actionViewRect;
  155. WEAKSELF
  156. [UIView animateWithDuration:0.3 animations:^{
  157. CGRect actionViewRect = weakSelf.frame;
  158. actionViewRect.size.height = SCREENHEIGHT;
  159. actionViewRect.origin.y = 0;
  160. weakSelf.frame = actionViewRect;
  161. }];
  162. //不能滑动
  163. SendNotification(@"MOShowLivePagesVCCannotScroll")
  164. }
  165. - (void)pushRedPacketDetailView{
  166. self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
  167. CGRect actionViewRect = self.frame;
  168. actionViewRect.origin.x = SCREENWIDTH;
  169. self.frame = actionViewRect;
  170. WEAKSELF
  171. [UIView animateWithDuration:0.3 animations:^{
  172. CGRect actionViewRect = weakSelf.frame;
  173. actionViewRect.origin.x = 0;
  174. weakSelf.frame = actionViewRect;
  175. }];
  176. //不能滑动
  177. SendNotification(@"MOShowLivePagesVCCannotScroll")
  178. }
  179. - (void)dismissRedPacketDetailView{
  180. if(self.receiveData.receivedAmount > 0){
  181. //抢到了, 刷新一下余额
  182. [[MORefreshViewManage shareManager] toUpdataTheUserInfo];
  183. }
  184. //完成下移动画
  185. WEAKSELF
  186. [UIView animateWithDuration:0.3 animations:^
  187. {
  188. CGRect actionSheetViewRect = weakSelf.frame;
  189. actionSheetViewRect.origin.x = SCREENWIDTH;
  190. weakSelf.frame = actionSheetViewRect;
  191. } completion:^(BOOL finished)
  192. {
  193. [self removeFromSuperview];
  194. }];
  195. //可以滑动
  196. SendNotification(@"MOShowLivePagesVCCanScroll")
  197. }
  198. #pragma mark - Lazy
  199. - (UIView *)bgView {
  200. if (!_bgView) {
  201. _bgView = [[UIView alloc] init];
  202. _bgView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
  203. }
  204. return _bgView;
  205. }
  206. - (UIImageView *)bgImageView {
  207. if (!_bgImageView) {
  208. _bgImageView = [[UIImageView alloc] init];
  209. _bgImageView.image = [UIImage imageNamed:@"icon_red_top_bg"];
  210. }
  211. return _bgImageView;
  212. }
  213. - (MORedPacketDTopView *)headView{
  214. if(!_headView){
  215. _headView = [MORedPacketDTopView moRedPacketDTopView];
  216. _headView.backgroundColor = [UIColor clearColor];
  217. }
  218. return _headView;
  219. }
  220. - (UITableView *)tableView{
  221. if (!_tableView)
  222. {
  223. _tableView= [[UITableView alloc] init];
  224. if (@available(iOS 11.0, *))
  225. {
  226. _tableView.estimatedRowHeight = 0;
  227. _tableView.estimatedSectionFooterHeight = 0;
  228. _tableView.estimatedSectionHeaderHeight = 0;
  229. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  230. }
  231. //iOS15适配
  232. if (@available(iOS 15.0, *))
  233. {
  234. self.tableView.sectionHeaderTopPadding = 0;
  235. }
  236. _tableView.delegate = self;
  237. _tableView.dataSource = self;
  238. _tableView.rowHeight = 64.0;
  239. _tableView.estimatedRowHeight = 0;
  240. _tableView.estimatedSectionHeaderHeight = 0;
  241. _tableView.estimatedSectionFooterHeight = 0;
  242. [_tableView registerNib:[UINib nibWithNibName:@"MORedPacketDetailCell" bundle:nil] forCellReuseIdentifier:MORedPacketDetailCell_ID];
  243. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  244. }
  245. return _tableView;
  246. }
  247. - (NSMutableArray *)dataArr{
  248. if(!_dataArr){
  249. _dataArr = [NSMutableArray array];
  250. }
  251. return _dataArr;
  252. }
  253. - (BigBtn *)backBtn {
  254. if (!_backBtn) {
  255. _backBtn = [[BigBtn alloc] init];
  256. [_backBtn addTarget:self action:@selector(dismissRedPacketDetailView) forControlEvents:UIControlEventTouchUpInside];
  257. [_backBtn setImage:[UIImage imageNamed:@"icon_left_red"] forState:UIControlStateNormal];
  258. }
  259. return _backBtn;
  260. }
  261. @end