// // YYRoomBgAlert.m // SweetParty // // Created by bj_szd on 2022/6/9. // #import "YYRoomBgAlert.h" #import "MSRoomSetBgCell.h" @interface YYRoomBgAlert () //房间背景相关 @property (nonatomic, strong) NSArray *bgArr; @property (nonatomic, copy) NSString *currentBid; @end @implementation YYRoomBgAlert - (void)awakeFromNib { [super awakeFromNib]; [self createUI]; [self fetchBgData]; } - (void)fetchBgData { NSDictionary *params = @{}; [AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/room/get_room_background_list" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) { self.bgArr = [responseDic safeArrayForKey:@"data"]; [self.collectionView reloadData]; } Failure:^(id _Nonnull errorData) { }]; } - (void)createUI { [self.confirmBtn setJianBianWithCGSize:CGSizeMake(ScreenWidth-32*2, 45)]; WEAK_SELF [self.touchImgV dg_Tapped:^{ [weakSelf removeFromSuperview]; }]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; CGFloat itemW = (ScreenWidth-30*2-7*2)/3; layout.itemSize = CGSizeMake(itemW, 120); layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 8; layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); _collectionView.collectionViewLayout = layout; _collectionView.delegate = self; _collectionView.dataSource = self; [_collectionView registerNib:[UINib nibWithNibName:@"MSRoomSetBgCell" bundle:nil] forCellWithReuseIdentifier:@"MSRoomSetBgCell"]; } - (void)setModel:(YYRoomSetModel *)model { _model = model; self.currentBid = model.room_background_id; [self.collectionView reloadData]; } - (IBAction)onConfirm:(id)sender { if (self.currentBid.length <= 0) { [HelpPageDefine showMessage:@"请选择房间背景"]; return; } NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.model.mj_JSONObject]; [params setObject:self.currentBid forKey:@"room_background_id"]; [[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/room/modify_room_info" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) { if (self.onCompleteBlock) { self.onCompleteBlock(); } [self removeFromSuperview]; } Failure:^(id _Nonnull errorData) { }]; } #pragma mark -------- collectionView代理方法 ------ - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.bgArr.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { MSRoomSetBgCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MSRoomSetBgCell" forIndexPath:indexPath]; NSDictionary *dict = self.bgArr[indexPath.row]; [cell.bgImgV sd_setImageWithURL:[NSURL URLWithString:[dict safeStringForKey:@"image_url"]]]; if ([[dict safeStringForKey:@"bid"] isEqualToString:self.currentBid]) { cell.selImgV.hidden = NO; }else { cell.selImgV.hidden = YES; } return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dict = self.bgArr[indexPath.row]; self.currentBid = [dict safeStringForKey:@"bid"]; [self.collectionView reloadData]; } @end