123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- //
- // XYRedPacketDrawResult.m
- // Timi
- //
- // Created by gy on 2021/11/22.
- //
- #import "XYRedPacketDrawResultView.h"
- #import "XYRedPacketDrawResultCell.h"
- #import "XYLotteryGameAPIManager.h"
- #import "XYRedPacketManager.h"
- @interface XYRedPacketDrawResultView()<UICollectionViewDataSource, UICollectionViewDelegate>{
-
- }
- @property (nonatomic, strong) UIView *contentView;
- @property (nonatomic, strong) UILabel *titleLab;
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, strong) UILabel *discLab;
- @property (nonatomic, strong) UIButton *closeBtn;
- @property (nonatomic, strong) NSMutableArray *dataArrs;
- @property (nonatomic, strong) UILabel *withoutLab;
- @end
- @implementation XYRedPacketDrawResultView
- - (void)setup{
- self.alpha = 0;
- self.backgroundColor = [UIColor colorWithHexString:@"#1D1C1F" alpha:0.35];
-
- [self contentView];
- [self titleLab];
- [self collectionView];
- [self discLab];
- [self closeBtn];
- [self dataArrs];
-
- [self reload];
- }
- - (void)reload{
- self.titleLab.text = @"结果";
- }
- - (void)show{
- [UIView animateWithDuration:0.2 animations:^{
- self.alpha = 1;
- } completion:^(BOOL finished) {
- }];
- [self getResultByRedBag];
- }
- - (void)hide{
- [UIView animateWithDuration:0.2 animations:^{
- self.alpha = 0;
- } completion:^(BOOL finished) {
- }];
- }
- - (void)clear{
-
- }
- - (void)closeBtnAction{
- [self hide];
- }
- /// 获取红包开奖结果
- - (void)getResultByRedBag{
- XYLiveRoomMessageInfo *info = [[XYRedPacketManager sharedInstance].redPacketQueueArrs lastObject];
- NSMutableDictionary *parm = [[NSMutableDictionary alloc] init];
- [parm setObject:info.snapId forKey:@"snapId"];
- [[XYLotteryGameAPIManager new] getResultByRedBag:parm successHandler:^(ZYLResponseModel *responseModel) {
- BOOL isHaveSelf = NO;
- [self.dataArrs removeAllObjects];
- NSArray *list = (NSArray *)responseModel.data[@"list"];
- for (NSDictionary *dict in list) {
- YQLiveCoinGiftCoinModel *info = [[YQLiveCoinGiftCoinModel alloc] init];
- info.tag_id = dict[@"userId"];
- info.image = dict[@"userAvatar"];
- info.name = dict[@"userName"];
- info.giftPriceTypeName = dict[@"prizeName"];
- info.image_type = dict[@"prizeIcon"];
- [self.dataArrs addObject:info];
- if ([info.tag_id isEqualToString:[XYUserInfoManager nowUser].userId]) {
- isHaveSelf = YES;
- info.select = YES;
- }
- }
- [self reloadTableView:nil];
-
- if (isHaveSelf) {
- self.titleLab.text = @"恭喜中奖";
- }else{
- self.titleLab.text = @"很遗憾未中奖";
- }
- self.discLab.text = [NSString stringWithFormat:@"等%@名用户中奖",responseModel.data[@"winCount"]];
-
- } failureHandler:^(ZYLNetworkError *error) {
- [self reloadTableView:error.domain];
-
- }];
- }
- - (void)reloadTableView:(NSString *)content{
- //[self.collectionView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:content errorInfo:@"" offsetTop:100 hasData:self.dataArrs.count>0 hasError:NO reloadBlock:nil];
- if (!content.length) { content = @"无数据"; }
- self.withoutLab.text = content;
- [self.collectionView.mj_header endRefreshing];
- [self.collectionView.mj_footer endRefreshing];
- [self.collectionView reloadData];
- if (self.dataArrs.count) {
- self.withoutLab.hidden = YES;
- }else{
- self.withoutLab.hidden = NO;
- }
- }
- #pragma mark — lazy
- - (NSMutableArray *)dataArrs{
- if (_dataArrs == nil) {
- _dataArrs = [[NSMutableArray alloc] init];
- }
- return _dataArrs;
- }
- - (UIView *)contentView{
- if (_contentView == nil) {
- _contentView = [[UIView alloc] initWithFrame:CGRectZero];
- _contentView.backgroundColor = [UIColor whiteColor];
- [self addSubview:_contentView];
- [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {;
- make.centerX.equalTo(self.mas_centerX).offset(0);
- make.centerY.equalTo(self.mas_centerY).offset(0);
- make.width.offset(280);
- make.height.offset(440);
- }];
- kViewRadius(_contentView, 12);
- }
- return _contentView;
- }
- - (UILabel *)titleLab{
- if (_titleLab == nil) {
- _titleLab = [[UILabel alloc] init];
- _titleLab.text = @"";
- _titleLab.textAlignment = NSTextAlignmentCenter;
- _titleLab.textColor = [UIColor colorWithHexString:@"#1D1C1F" alpha:1];
- _titleLab.font = [UIFont fontWithName:kPFSCMediumFont size:16];
- [_titleLab sizeToFit];
- [self.contentView addSubview:_titleLab];
- [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.contentView.mas_centerX).offset(0);
- make.top.equalTo(self.contentView.mas_top).offset(16);
- }];
- }
- return _titleLab;
- }
- - (UILabel *)discLab{
- if (_discLab == nil) {
- _discLab = [[UILabel alloc] init];
- _discLab.text = @"";
- _discLab.textAlignment = NSTextAlignmentCenter;
- _discLab.textColor = [UIColor colorWithHexString:@"#909399" alpha:1];
- _discLab.font = [UIFont fontWithName:kPFSCFont size:12];
- [_discLab sizeToFit];
- [self.contentView addSubview:_discLab];
- [_discLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.contentView.mas_centerX).offset(0);
- make.bottom.equalTo(self.contentView.mas_bottom).offset(-16);
- }];
- }
- return _discLab;
- }
- - (UIButton *)closeBtn{
- if (_closeBtn == nil) {
- _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_closeBtn setImage:[UIImage imageNamed:@"icon_popup_close"] forState:UIControlStateNormal];
- [_closeBtn addTarget:self action:@selector(closeBtnAction) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:_closeBtn];
- [_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {;
- make.top.equalTo(self.contentView.mas_bottom).offset(24);
- make.centerX.equalTo(self.contentView.mas_centerX).offset(0);
- make.width.offset(32);
- make.height.offset(32);
- }];
- }
- return _closeBtn;
- }
- - (UICollectionView *)collectionView{
- if (_collectionView == nil) {
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
- flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
- flowLayout.itemSize = CGSizeMake(280, 35);
- flowLayout.minimumLineSpacing = 0;
- flowLayout.minimumInteritemSpacing = 0;
- flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
-
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
- _collectionView.backgroundColor = [UIColor clearColor];
- _collectionView.alwaysBounceVertical = YES;
- _collectionView.delegate = self;
- _collectionView.dataSource = self;
- [_collectionView registerCell:NSStringFromClass([XYRedPacketDrawResultCell class])];
- [self.contentView addSubview:_collectionView];
- [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView.mas_left).offset(0);
- make.top.equalTo(self.contentView.mas_top).offset(50);
- make.right.equalTo(self.contentView.mas_right).offset(0);
- make.bottom.equalTo(self.contentView.mas_bottom).offset(-50);
- }];
- }
- return _collectionView;
- }
- - (UILabel *)withoutLab{
- if (_withoutLab == nil) {
- _withoutLab = [[UILabel alloc] init];
- _withoutLab.text = @"";
- _withoutLab.textAlignment = NSTextAlignmentCenter;
- _withoutLab.font = Font_B(14);
- _withoutLab.textColor = Color_TextGray;
- [_withoutLab sizeToFit];
- [self.collectionView addSubview:_withoutLab];
- [_withoutLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.collectionView.mas_centerX).offset(0);
- make.centerY.equalTo(self.collectionView.mas_centerY).offset(0);
- }];
- }
- return _withoutLab;
- }
- #pragma mark - delegate
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.dataArrs.count;
- }
- -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- XYRedPacketDrawResultCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XYRedPacketDrawResultCell class]) forIndexPath:indexPath];
- [cell reload:self.dataArrs[indexPath.row]];
- cell.contentView.backgroundColor = [UIColor clearColor];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
-
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|