Files
2025-08-08 11:05:33 +08:00

319 lines
12 KiB
Objective-C
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// YYJYApplyUpView.m
// YaYin
//
// Created by bj_szd on 2023/4/26.
// Copyright © 2023 YaYin. All rights reserved.
//
#import "YYJYApplyUpView.h"
#import "YYJYApplyUpCell.h"
#import "YYApplyUpGiftAlert.h"
#import "YYJYChooseTeamAlert.h"
#import "YYXQPickTimeAlert.h"
@interface YYJYApplyUpView () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (nonatomic, strong) NSArray *vipDataArr;
@property (nonatomic, strong) NSArray *waitDataArr;
@property (nonatomic, strong) YYApplyUpMicModel *model;
@property(nonatomic, assign) NSInteger is_apply;//1在申请 2不在
@property(nonatomic, copy) NSString *apply_id;//申请通道id
@property(nonatomic, assign) BOOL isHost;//主持麦上
@property(nonatomic, assign) BOOL isManager;//管理
@property (nonatomic, strong) YYApplyUpUser *selUserModel;
@end
@implementation YYJYApplyUpView
- (void)awakeFromNib {
[super awakeFromNib];
self.is_apply = 2;
self.apply_id = @"";
[self createUI];
}
- (void)setViewModel:(RCMicRoomViewModel *)viewModel {
_viewModel = viewModel;
[self fetchData];
if ([self.viewModel isRoomHost]) {
self.isHost = YES;
[self.sendBtn setTitle:@"设置" forState:UIControlStateNormal];
}else {
self.isHost = NO;
[self.sendBtn setTitle:@"赠送" forState:UIControlStateNormal];
}
if ([self.viewModel isRoomOwner] || [self.viewModel isRoomAdministrator]) {
self.isManager = YES;
self.refuseBtn.hidden = self.agreeBtn.hidden = self.clearBtn.hidden = NO;
}else {
self.isManager = NO;
self.refuseBtn.hidden = self.agreeBtn.hidden = self.clearBtn.hidden = YES;
}
}
- (void)fetchData {
NSDictionary *params = @{@"rid":_viewModel.roomInfo.roomId};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/room_micro/get_room_micro_list" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
self.model = [YYApplyUpMicModel mj_objectWithKeyValues:responseDic[@"data"]];
[self onUpdateUIWith:self.model];
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)onUpdateUIWith:(YYApplyUpMicModel *)model {
self.vipLab.text = [NSString stringWithFormat:@"优先通道(%@/%@", model.priority_count, model.priority_total_count];
self.vipDataArr = model.priority_aisle;
[self.vipCollectionView reloadData];
self.waitLab.text = [NSString stringWithFormat:@"等待上台(%@/%@", model.common_count, model.common_total_count];
self.waitDataArr = model.common_aisle;
[self.waitCollectionView reloadData];
self.is_apply = 2;
self.apply_id = @"";
for (YYApplyUpUser *obj in self.vipDataArr) {
if ([obj.uid integerValue] == [BJUserManager.userInfo.uid integerValue]) {
self.is_apply = 1;
self.apply_id = obj.id;
}
}
for (YYApplyUpUser *obj in self.waitDataArr) {
if ([obj.uid integerValue] == [BJUserManager.userInfo.uid integerValue]) {
self.is_apply = 1;
self.apply_id = obj.id;
}
}
if (self.is_apply == 1) {
[self.applyBtn setTitle:@"取消申请" forState:UIControlStateNormal];
}else {
[self.applyBtn setTitle:@"申请" forState:UIControlStateNormal];
}
if (model.gift_name.length > 0) {
[self.giftImgV sd_setImageWithURL:[NSURL URLWithString:model.base_image]];
self.giftNameLab.text = [NSString stringWithFormat:@"赠送%@ 插队", model.gift_name];
}else {
self.giftNameLab.text = @"未设置插队礼物";
}
}
- (void)onReceiveSocketWith:(NSDictionary *)dict {
self.model = [YYApplyUpMicModel mj_objectWithKeyValues:dict];
[self onUpdateUIWith:self.model];
}
- (void)createUI {
WEAK_SELF
[self.touchImgV dg_Tapped:^{
[weakSelf removeFromSuperview];
}];
[self.clearBtn styleGradiBlueColor];
[self.agreeBtn styleGradiBlueColor];
[self.applyBtn styleGradiBlueColor];
[self.sendBtn styleGradiBlueColor];
// UIColor *bgColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(ScreenWidth-6*2, 100) direction:FXGradientChangeDirectionHorizontal startColor:HEXCOLOR(0xAE4EFF) endColor:HEXCOLOR(0x403BFF)];
// self.vipCollectionView.backgroundColor = self.waitCollectionView.backgroundColor = [bgColor colorWithAlphaComponent:0.25];
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(70, 105);
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 0;
layout.sectionInset = UIEdgeInsetsMake(0, 8, 0, 8);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
_vipCollectionView.collectionViewLayout = layout;
_vipCollectionView.delegate = self;
_vipCollectionView.dataSource = self;
[_vipCollectionView registerNib:[UINib nibWithNibName:@"YYJYApplyUpCell" bundle:nil] forCellWithReuseIdentifier:@"YYJYApplyUpCell"];
}
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(70, 105);
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 0;
layout.sectionInset = UIEdgeInsetsMake(0, 8, 0, 8);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
_waitCollectionView.collectionViewLayout = layout;
_waitCollectionView.delegate = self;
_waitCollectionView.dataSource = self;
[_waitCollectionView registerNib:[UINib nibWithNibName:@"YYJYApplyUpCell" bundle:nil] forCellWithReuseIdentifier:@"YYJYApplyUpCell"];
}
}
- (IBAction)onClear:(id)sender {
NSDictionary *params = @{@"rid":_viewModel.roomInfo.roomId};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/room_micro/clears_room_micro_list" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
} Failure:^(id _Nonnull errorData) {
}];
}
- (IBAction)onRefuse:(id)sender {
if (_selUserModel == nil) {
[HelpPageDefine showMessage:@"请选择人员"];
return;
}
NSDictionary *params = @{@"rid":_viewModel.roomInfo.roomId, @"id":_selUserModel.id, @"type":@"2"};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/room_micro/operate_user_micro" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
} Failure:^(id _Nonnull errorData) {
}];
}
- (IBAction)onAgreeOrApply:(id)sender {
if (_selUserModel == nil) {
[HelpPageDefine showMessage:@"请选择人员"];
return;
}
if (self.viewModel.roomInfo.is_dating == 1) {
YYJYChooseTeamAlert *alert = LoadNib(@"YYJYChooseTeamAlert");
[alert onPopupWithSize:CGSizeMake(338, 250) parent:KEYWINDOW];
NSDictionary *params = @{@"rid":_viewModel.roomInfo.roomId, @"id":_selUserModel.id, @"type":@"1"};
alert.dict = params;
}else if (self.viewModel.roomInfo.is_blind_date == 1) {
YYXQPickTimeAlert *view = LoadNib(@"YYXQPickTimeAlert");
view.frame = [UIScreen mainScreen].bounds;
[MainWindow() addSubview:view];
view.onConfirmBlock = ^(NSString * _Nonnull time) {
NSDictionary *params = @{@"rid":self.viewModel.roomInfo.roomId, @"id":self.selUserModel.id, @"type":@"1", @"time":time};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/room_micro/operate_user_micro" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
} Failure:^(id _Nonnull errorData) {
}];
};
}else {
NSDictionary *params = @{@"rid":_viewModel.roomInfo.roomId, @"id":_selUserModel.id, @"type":@"1"};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/room_micro/operate_user_micro" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
} Failure:^(id _Nonnull errorData) {
}];
}
}
- (IBAction)onApply:(id)sender {
NSString *urlStr = self.is_apply == 1 ? @"/api/room_micro/unapply_room_micro" : @"/api/room_micro/apply_room_micro";
NSDictionary *params = @{@"rid":_viewModel.roomInfo.roomId, @"id":C_string(self.apply_id)};
[AFNetworkRequset.shared postRequestWithParams:params Path:urlStr Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
} Failure:^(id _Nonnull errorData) {
}];
}
- (IBAction)onSendOrSetGift:(id)sender {
if (self.isHost) {
YYApplyUpGiftAlert *view = LoadNib(@"YYApplyUpGiftAlert");
view.frame = [UIScreen mainScreen].bounds;
[view onShowWith:_viewModel.roomInfo.roomId];
}else {
[self onSendGiftWithHelpUid:BJUserManager.userInfo.uid];
}
}
- (void)onSendGiftWithHelpUid:(NSString *)help_uid {
NSDictionary *params = @{@"rid":_viewModel.roomInfo.roomId, @"help_uid":help_uid, @"gid":self.model.gid, @"num":@"1"};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/room_micro/send_gift_user_micro_help" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
} Failure:^(id _Nonnull errorData) {
}];
}
#pragma mark -------- collectionView代理方法 ------
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (collectionView == _vipCollectionView) {
return self.vipDataArr.count;
}else {
return self.waitDataArr.count;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if (collectionView == _vipCollectionView) {
YYJYApplyUpCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YYJYApplyUpCell" forIndexPath:indexPath];
YYApplyUpUser *model = self.vipDataArr[indexPath.row];
[cell onUpdateYYJYApplyUpCell:model isVip:YES isRoomOwner:self.isManager];
WEAK_SELF
[cell.selBtn buttonAddTaget:^(UIButton *btn) {
[weakSelf onSelWith:model];
} forControlEvents:UIControlEventTouchUpInside];
[cell.chaduiBtn buttonAddTaget:^(UIButton *btn) {
[weakSelf onSendGiftWithHelpUid:model.uid];
} forControlEvents:UIControlEventTouchUpInside];
return cell;
}else {
YYJYApplyUpCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YYJYApplyUpCell" forIndexPath:indexPath];
YYApplyUpUser *model = self.waitDataArr[indexPath.row];
[cell onUpdateYYJYApplyUpCell:model isVip:NO isRoomOwner:self.isManager];
WEAK_SELF
[cell.selBtn buttonAddTaget:^(UIButton *btn) {
[weakSelf onSelWith:model];
} forControlEvents:UIControlEventTouchUpInside];
[cell.chaduiBtn buttonAddTaget:^(UIButton *btn) {
[weakSelf onSendGiftWithHelpUid:model.uid];
} forControlEvents:UIControlEventTouchUpInside];
return cell;
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (collectionView == _vipCollectionView) {
YYApplyUpUser *model = self.vipDataArr[indexPath.row];
if (self.onClickUserBlock) {
self.onClickUserBlock(model.uid);
}
}else {
YYApplyUpUser *model = self.waitDataArr[indexPath.row];
if (self.onClickUserBlock) {
self.onClickUserBlock(model.uid);
}
}
}
- (void)onSelWith:(YYApplyUpUser *)model {
for (YYApplyUpUser *obj in self.vipDataArr) {
obj.is_sel = NO;
}
for (YYApplyUpUser *obj in self.waitDataArr) {
obj.is_sel = NO;
}
model.is_sel = YES;
_selUserModel = model;
[_vipCollectionView reloadData];
[_waitCollectionView reloadData];
}
@end