// // YOUPAILZBubbleDressVC.m // VQU // // Created by CY on 2021/8/18. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZBubbleDressVC.h" #import "YOUPAILZBubbleDressHeaderView.h" #import "YOUPAILZDressModel.h" #import "YOUPAILZBubbleDressCell.h" @interface YOUPAILZBubbleDressVC () @property (nonatomic, weak) YOUPAILZBubbleDressHeaderView *youpaipheaderView; @property (nonatomic, weak) UICollectionView *youpaipcollectionView; @property (nonatomic, strong) NSArray *youpaipdataSource; @property (nonatomic, strong) YOUPAILZDressModel *youpaipcurrentDressModel; @end @implementation YOUPAILZBubbleDressVC - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = HexColorFromRGB(0x21232E); [self youpaifinitUI]; [self youpaifrequestBubbleDressData]; } - (void)youpaifinitUI{ YOUPAILZBubbleDressHeaderView *headerView = [[YOUPAILZBubbleDressHeaderView alloc] init]; [self.view addSubview:headerView]; self.youpaipheaderView = headerView; [headerView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.offset(0.0f); make.height.offset(158.0f); }]; UILabel *titleL = [[UILabel alloc] init]; titleL.textColor = [UIColor whiteColor]; titleL.font = LCFont(15.0f); titleL.text = @"已拥有"; [self.view addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.right.offset(-14.0f); make.top.equalTo(headerView.mas_bottom).offset(28.0f); }]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; flowLayout.itemSize = CGSizeMake((KScreenWidth - ScaleSize(42.0f)) / 3.0f, ScaleSize(131.0f)); flowLayout.minimumLineSpacing = ScaleSize(14.0f); flowLayout.minimumInteritemSpacing = ScaleSize(7.0f); flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, ScaleSize(14.0f), 0.0f, ScaleSize(14.0f)); UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; collectionView.backgroundColor = HexColorFromRGB(0x21232E); collectionView.alwaysBounceVertical = YES; collectionView.delegate = self; collectionView.dataSource = self; [collectionView registerClass:YOUPAILZBubbleDressCell.class forCellWithReuseIdentifier:@"cell"]; [self.view addSubview:collectionView]; self.youpaipcollectionView = collectionView; [collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.offset(0.0f); make.top.equalTo(titleL.mas_bottom).offset(20.0f); }]; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.youpaipdataSource.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILZBubbleDressCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]]; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ self.youpaipcurrentDressModel.youpaipis_use = @"0"; self.youpaipcurrentDressModel = self.youpaipdataSource[indexPath.item]; self.youpaipcurrentDressModel.youpaipis_use = @"1"; [self.youpaipheaderView youpaifreloadWithModel:self.youpaipcurrentDressModel]; [self.youpaipcollectionView reloadData]; [self youpaifsetupBubbleDressWithModel:self.youpaipcurrentDressModel]; } - (void)youpaifsetupBubbleDressWithModel:(YOUPAILZDressModel *)dressModel{ [LCHttpHelper requestWithURLString:UpdateDress parameters:@{@"type":@"bubble",@"u_dress_id":dressModel.youpaipu_dress_id.length == 0 ? @"0" : dressModel.youpaipu_dress_id} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { } failure:^(NSError *error) { }]; } /// 获取列表数据 - (void)youpaifrequestBubbleDressData{ @weakify(self); [LCHttpHelper requestWithURLString:GetDressList parameters:@{@"type":@"bubble"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) {//成功 NSDictionary *data = [dict objectForKey:@"data"]; self.youpaipdataSource = [YOUPAILZDressModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"userDress"]]; for (YOUPAILZDressModel *dressModel in self.youpaipdataSource) { if ([dressModel.youpaipis_use isEqual:@"1"]) { self.youpaipcurrentDressModel = dressModel; [self.youpaipheaderView youpaifreloadWithModel:self.youpaipcurrentDressModel]; } } [self.youpaipcollectionView reloadData]; } } failure:^(NSError *error) { }]; } #pragma mark - JXCategoryListContentViewDelegate - (UIView *)listView{ return self.view; } @end