XYRedPacketDrawResultView.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // XYRedPacketDrawResult.m
  3. // Timi
  4. //
  5. // Created by gy on 2021/11/22.
  6. //
  7. #import "XYRedPacketDrawResultView.h"
  8. #import "XYRedPacketDrawResultCell.h"
  9. #import "XYLotteryGameAPIManager.h"
  10. #import "XYRedPacketManager.h"
  11. @interface XYRedPacketDrawResultView()<UICollectionViewDataSource, UICollectionViewDelegate>{
  12. }
  13. @property (nonatomic, strong) UIView *contentView;
  14. @property (nonatomic, strong) UILabel *titleLab;
  15. @property (nonatomic, strong) UICollectionView *collectionView;
  16. @property (nonatomic, strong) UILabel *discLab;
  17. @property (nonatomic, strong) UIButton *closeBtn;
  18. @property (nonatomic, strong) NSMutableArray *dataArrs;
  19. @property (nonatomic, strong) UILabel *withoutLab;
  20. @end
  21. @implementation XYRedPacketDrawResultView
  22. - (void)setup{
  23. self.alpha = 0;
  24. self.backgroundColor = [UIColor colorWithHexString:@"#1D1C1F" alpha:0.35];
  25. [self contentView];
  26. [self titleLab];
  27. [self collectionView];
  28. [self discLab];
  29. [self closeBtn];
  30. [self dataArrs];
  31. [self reload];
  32. }
  33. - (void)reload{
  34. self.titleLab.text = @"结果";
  35. }
  36. - (void)show{
  37. [UIView animateWithDuration:0.2 animations:^{
  38. self.alpha = 1;
  39. } completion:^(BOOL finished) {
  40. }];
  41. [self getResultByRedBag];
  42. }
  43. - (void)hide{
  44. [UIView animateWithDuration:0.2 animations:^{
  45. self.alpha = 0;
  46. } completion:^(BOOL finished) {
  47. }];
  48. }
  49. - (void)clear{
  50. }
  51. - (void)closeBtnAction{
  52. [self hide];
  53. }
  54. /// 获取红包开奖结果
  55. - (void)getResultByRedBag{
  56. XYLiveRoomMessageInfo *info = [[XYRedPacketManager sharedInstance].redPacketQueueArrs lastObject];
  57. NSMutableDictionary *parm = [[NSMutableDictionary alloc] init];
  58. [parm setObject:info.snapId forKey:@"snapId"];
  59. [[XYLotteryGameAPIManager new] getResultByRedBag:parm successHandler:^(ZYLResponseModel *responseModel) {
  60. BOOL isHaveSelf = NO;
  61. [self.dataArrs removeAllObjects];
  62. NSArray *list = (NSArray *)responseModel.data[@"list"];
  63. for (NSDictionary *dict in list) {
  64. YQLiveCoinGiftCoinModel *info = [[YQLiveCoinGiftCoinModel alloc] init];
  65. info.tag_id = dict[@"userId"];
  66. info.image = dict[@"userAvatar"];
  67. info.name = dict[@"userName"];
  68. info.giftPriceTypeName = dict[@"prizeName"];
  69. info.image_type = dict[@"prizeIcon"];
  70. [self.dataArrs addObject:info];
  71. if ([info.tag_id isEqualToString:[XYUserInfoManager nowUser].userId]) {
  72. isHaveSelf = YES;
  73. info.select = YES;
  74. }
  75. }
  76. [self reloadTableView:nil];
  77. if (isHaveSelf) {
  78. self.titleLab.text = @"恭喜中奖";
  79. }else{
  80. self.titleLab.text = @"很遗憾未中奖";
  81. }
  82. self.discLab.text = [NSString stringWithFormat:@"等%@名用户中奖",responseModel.data[@"winCount"]];
  83. } failureHandler:^(ZYLNetworkError *error) {
  84. [self reloadTableView:error.domain];
  85. }];
  86. }
  87. - (void)reloadTableView:(NSString *)content{
  88. //[self.collectionView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:content errorInfo:@"" offsetTop:100 hasData:self.dataArrs.count>0 hasError:NO reloadBlock:nil];
  89. if (!content.length) { content = @"无数据"; }
  90. self.withoutLab.text = content;
  91. [self.collectionView.mj_header endRefreshing];
  92. [self.collectionView.mj_footer endRefreshing];
  93. [self.collectionView reloadData];
  94. if (self.dataArrs.count) {
  95. self.withoutLab.hidden = YES;
  96. }else{
  97. self.withoutLab.hidden = NO;
  98. }
  99. }
  100. #pragma mark — lazy
  101. - (NSMutableArray *)dataArrs{
  102. if (_dataArrs == nil) {
  103. _dataArrs = [[NSMutableArray alloc] init];
  104. }
  105. return _dataArrs;
  106. }
  107. - (UIView *)contentView{
  108. if (_contentView == nil) {
  109. _contentView = [[UIView alloc] initWithFrame:CGRectZero];
  110. _contentView.backgroundColor = [UIColor whiteColor];
  111. [self addSubview:_contentView];
  112. [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {;
  113. make.centerX.equalTo(self.mas_centerX).offset(0);
  114. make.centerY.equalTo(self.mas_centerY).offset(0);
  115. make.width.offset(280);
  116. make.height.offset(440);
  117. }];
  118. kViewRadius(_contentView, 12);
  119. }
  120. return _contentView;
  121. }
  122. - (UILabel *)titleLab{
  123. if (_titleLab == nil) {
  124. _titleLab = [[UILabel alloc] init];
  125. _titleLab.text = @"";
  126. _titleLab.textAlignment = NSTextAlignmentCenter;
  127. _titleLab.textColor = [UIColor colorWithHexString:@"#1D1C1F" alpha:1];
  128. _titleLab.font = [UIFont fontWithName:kPFSCMediumFont size:16];
  129. [_titleLab sizeToFit];
  130. [self.contentView addSubview:_titleLab];
  131. [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.centerX.equalTo(self.contentView.mas_centerX).offset(0);
  133. make.top.equalTo(self.contentView.mas_top).offset(16);
  134. }];
  135. }
  136. return _titleLab;
  137. }
  138. - (UILabel *)discLab{
  139. if (_discLab == nil) {
  140. _discLab = [[UILabel alloc] init];
  141. _discLab.text = @"";
  142. _discLab.textAlignment = NSTextAlignmentCenter;
  143. _discLab.textColor = [UIColor colorWithHexString:@"#909399" alpha:1];
  144. _discLab.font = [UIFont fontWithName:kPFSCFont size:12];
  145. [_discLab sizeToFit];
  146. [self.contentView addSubview:_discLab];
  147. [_discLab mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.centerX.equalTo(self.contentView.mas_centerX).offset(0);
  149. make.bottom.equalTo(self.contentView.mas_bottom).offset(-16);
  150. }];
  151. }
  152. return _discLab;
  153. }
  154. - (UIButton *)closeBtn{
  155. if (_closeBtn == nil) {
  156. _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  157. [_closeBtn setImage:[UIImage imageNamed:@"icon_popup_close"] forState:UIControlStateNormal];
  158. [_closeBtn addTarget:self action:@selector(closeBtnAction) forControlEvents:UIControlEventTouchUpInside];
  159. [self addSubview:_closeBtn];
  160. [_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {;
  161. make.top.equalTo(self.contentView.mas_bottom).offset(24);
  162. make.centerX.equalTo(self.contentView.mas_centerX).offset(0);
  163. make.width.offset(32);
  164. make.height.offset(32);
  165. }];
  166. }
  167. return _closeBtn;
  168. }
  169. - (UICollectionView *)collectionView{
  170. if (_collectionView == nil) {
  171. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  172. flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  173. flowLayout.itemSize = CGSizeMake(280, 35);
  174. flowLayout.minimumLineSpacing = 0;
  175. flowLayout.minimumInteritemSpacing = 0;
  176. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  177. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  178. _collectionView.backgroundColor = [UIColor clearColor];
  179. _collectionView.alwaysBounceVertical = YES;
  180. _collectionView.delegate = self;
  181. _collectionView.dataSource = self;
  182. [_collectionView registerCell:NSStringFromClass([XYRedPacketDrawResultCell class])];
  183. [self.contentView addSubview:_collectionView];
  184. [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  185. make.left.equalTo(self.contentView.mas_left).offset(0);
  186. make.top.equalTo(self.contentView.mas_top).offset(50);
  187. make.right.equalTo(self.contentView.mas_right).offset(0);
  188. make.bottom.equalTo(self.contentView.mas_bottom).offset(-50);
  189. }];
  190. }
  191. return _collectionView;
  192. }
  193. - (UILabel *)withoutLab{
  194. if (_withoutLab == nil) {
  195. _withoutLab = [[UILabel alloc] init];
  196. _withoutLab.text = @"";
  197. _withoutLab.textAlignment = NSTextAlignmentCenter;
  198. _withoutLab.font = Font_B(14);
  199. _withoutLab.textColor = Color_TextGray;
  200. [_withoutLab sizeToFit];
  201. [self.collectionView addSubview:_withoutLab];
  202. [_withoutLab mas_makeConstraints:^(MASConstraintMaker *make) {
  203. make.centerX.equalTo(self.collectionView.mas_centerX).offset(0);
  204. make.centerY.equalTo(self.collectionView.mas_centerY).offset(0);
  205. }];
  206. }
  207. return _withoutLab;
  208. }
  209. #pragma mark - delegate
  210. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  211. return self.dataArrs.count;
  212. }
  213. -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  214. XYRedPacketDrawResultCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XYRedPacketDrawResultCell class]) forIndexPath:indexPath];
  215. [cell reload:self.dataArrs[indexPath.row]];
  216. cell.contentView.backgroundColor = [UIColor clearColor];
  217. return cell;
  218. }
  219. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  220. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  221. }
  222. /*
  223. // Only override drawRect: if you perform custom drawing.
  224. // An empty implementation adversely affects performance during animation.
  225. - (void)drawRect:(CGRect)rect {
  226. // Drawing code
  227. }
  228. */
  229. @end