| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- //
- // MORedPacketDetailView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/6/13.
- //
- #import "MORedPacketDetailView.h"
- #import "MORedPacketDTopView.h"
- //一页的size
- #define kPageSize 20
- @interface MORedPacketDetailView ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) BigBtn *backBtn;
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UIImageView *bgImageView;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) MORedPacketDTopView *headView;
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @property (nonatomic, assign) BOOL isShowBest;
- /** 游标 */
- @property (nonatomic, copy) NSString *next;
- /** 没有更多的数据视图 */
- @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
- @end
- @implementation MORedPacketDetailView
- - (instancetype)init {
- if (self = [super init]) {
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI {
- [self addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- [self addSubview:self.bgImageView];
- [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.mas_equalTo(0);
- make.width.mas_equalTo(SCREENWIDTH);
- make.height.mas_equalTo(kScaleWidth(143));
- }];
-
- CGFloat spacing = KIsiPhoneX ? 10.0 : 40.0;
- [self addSubview:self.headView];
- [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(kTopSafeAreaInset + spacing);
- make.left.trailing.mas_equalTo(0);
- make.height.equalTo(@340.0);
- }];
-
- [self addSubview:self.backBtn];
- [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(kTopSafeAreaInset + spacing);
- make.size.mas_equalTo(CGSizeMake(12, 22));
- make.left.mas_equalTo(15);
- }];
-
- [self addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.headView.mas_bottom);
- make.left.right.bottom.mas_equalTo(0);
- }];
-
- WEAKSELF
- self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
-
- if(weakSelf.next.length == 0 || weakSelf.receiveData.receivingInfo.redEnvelopeId.length == 0){
- [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
- return;
- }
-
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"page":basePage,
- @"redEnvelopeId":weakSelf.receiveData.receivingInfo.redEnvelopeId,
- @"lastReceivedNum":@(weakSelf.receiveData.lastReceivedNum)};
-
- [weakSelf toGetTheReceivingInfoWith:baseDict];
- }];
- self.tableView.backgroundView = self.noMoreDataView;
- }
- - (void)setReceiveData:(MOReceivingBaseData *)receiveData{
- _receiveData = receiveData;
-
- [self.dataArr removeAllObjects];
-
- self.headView.redEnvelopInfo = self.redEnvelopInfo;
- self.headView.receiveData = receiveData;
- self.dataArr = [receiveData.receivingInfo.receivingUserItems mutableCopy];
-
- if(receiveData.receivingInfo.receivedNum == receiveData.receivingInfo.num){
- self.isShowBest = YES;
- }
- else{
- self.isShowBest = NO;
- }
-
- if(receiveData.next.length == 0){
- self.next = @"2";
- }
- else{
- self.next = receiveData.next;
- }
-
-
- [self.tableView reloadData];
- }
- - (void)toGetTheReceivingInfoWith:(NSDictionary *)dict{
- WEAKSELF
- [kHttpManager toGetTheRedEnvelopeReceivingInfoWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- [weakSelf.tableView.mj_footer endRefreshing];
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MOReceivingInfo *baseData = [MOReceivingInfo modelObjectWithDictionary:data[@"data"]];
- if(baseData.next == nil || baseData.next.length == 0){
- if(weakSelf.next == nil || weakSelf.next.length == 0){
-
- if(weakSelf.dataArr.count > 0){
- [weakSelf.dataArr removeAllObjects];
- }
-
- //第一页
- weakSelf.dataArr = [baseData.receivingUserList mutableCopy];
- }
- else{
- //最后一页
- [weakSelf.dataArr addObjectsFromArray:baseData.receivingUserList];
- }
- weakSelf.next = @"";
-
- [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- else{
- weakSelf.next = baseData.next;
- [weakSelf.dataArr addObjectsFromArray:baseData.receivingUserList];
- }
- [weakSelf.tableView reloadData];
-
- weakSelf.tableView.mj_footer.hidden = (weakSelf.dataArr.count > 0) ? NO : YES;
- weakSelf.noMoreDataView.isHaveData = (weakSelf.dataArr.count > 0) ? YES : NO;
- }
- else{
- MOLogV(@"toGetTheRedEnvelopeReceivingInfoWithParams 接口报错了");
- kShowNetError(data)
- }
- }];
- }
- #pragma mark - UITableViewDelegate,UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.dataArr.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- MOReceivingUserItems *model = self.dataArr[indexPath.row];
- MORedPacketDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:MORedPacketDetailCell_ID];
- cell.isShowBest = self.isShowBest;
- cell.cellModel = model;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
- - (void)openRedPacketDetailView{
- self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
-
- CGRect actionViewRect = self.frame;
- actionViewRect.size.height = 200.0;
- actionViewRect.origin.y = (SCREENHEIGHT / 2.0) - 100.0;
- self.frame = actionViewRect;
-
- WEAKSELF
- [UIView animateWithDuration:0.3 animations:^{
- CGRect actionViewRect = weakSelf.frame;
- actionViewRect.size.height = SCREENHEIGHT;
- actionViewRect.origin.y = 0;
- weakSelf.frame = actionViewRect;
- }];
-
- //不能滑动
- SendNotification(@"MOShowLivePagesVCCannotScroll")
- }
- - (void)pushRedPacketDetailView{
- self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
-
- CGRect actionViewRect = self.frame;
- actionViewRect.origin.x = SCREENWIDTH;
- self.frame = actionViewRect;
-
- WEAKSELF
- [UIView animateWithDuration:0.3 animations:^{
- CGRect actionViewRect = weakSelf.frame;
- actionViewRect.origin.x = 0;
- weakSelf.frame = actionViewRect;
- }];
-
- //不能滑动
- SendNotification(@"MOShowLivePagesVCCannotScroll")
- }
- - (void)dismissRedPacketDetailView{
-
- if(self.receiveData.receivedAmount > 0){
- //抢到了, 刷新一下余额
- [[MORefreshViewManage shareManager] toUpdataTheUserInfo];
- }
-
- //完成下移动画
- WEAKSELF
- [UIView animateWithDuration:0.3 animations:^
- {
- CGRect actionSheetViewRect = weakSelf.frame;
- actionSheetViewRect.origin.x = SCREENWIDTH;
- weakSelf.frame = actionSheetViewRect;
- } completion:^(BOOL finished)
- {
- [self removeFromSuperview];
- }];
-
- //可以滑动
- SendNotification(@"MOShowLivePagesVCCanScroll")
- }
- #pragma mark - Lazy
- - (UIView *)bgView {
- if (!_bgView) {
- _bgView = [[UIView alloc] init];
- _bgView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
- }
- return _bgView;
- }
- - (UIImageView *)bgImageView {
- if (!_bgImageView) {
- _bgImageView = [[UIImageView alloc] init];
- _bgImageView.image = [UIImage imageNamed:@"icon_red_top_bg"];
- }
- return _bgImageView;
- }
- - (MORedPacketDTopView *)headView{
- if(!_headView){
- _headView = [MORedPacketDTopView moRedPacketDTopView];
- _headView.backgroundColor = [UIColor clearColor];
- }
- return _headView;
- }
- - (UITableView *)tableView{
- if (!_tableView)
- {
- _tableView= [[UITableView alloc] init];
- if (@available(iOS 11.0, *))
- {
- _tableView.estimatedRowHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
-
- //iOS15适配
- if (@available(iOS 15.0, *))
- {
- self.tableView.sectionHeaderTopPadding = 0;
- }
-
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.rowHeight = 64.0;
- _tableView.estimatedRowHeight = 0;
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- [_tableView registerNib:[UINib nibWithNibName:@"MORedPacketDetailCell" bundle:nil] forCellReuseIdentifier:MORedPacketDetailCell_ID];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
-
- }
- return _tableView;
- }
- - (NSMutableArray *)dataArr{
- if(!_dataArr){
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- - (BigBtn *)backBtn {
- if (!_backBtn) {
- _backBtn = [[BigBtn alloc] init];
- [_backBtn addTarget:self action:@selector(dismissRedPacketDetailView) forControlEvents:UIControlEventTouchUpInside];
- [_backBtn setImage:[UIImage imageNamed:@"icon_left_red"] forState:UIControlStateNormal];
- }
- return _backBtn;
- }
- @end
|