123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //
- // YOUPAILZBadgeVC.m
- // VQU
- //
- // Created by CY on 2021/8/30.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAILZBadgeVC.h"
- #import "YOUPAILZBadgeCell.h"
- #import "YOUPAILZDressModel.h"
- @interface YOUPAILZBadgeVC () <UICollectionViewDelegate,UICollectionViewDataSource>
- @property (nonatomic, weak) UICollectionView *youpaipcollectionView;
- @property (nonatomic, strong) NSArray <YOUPAILZDressModel *>*youpaipdataSource;
- @property (nonatomic, strong) YOUPAILZDressModel *youpaipcurrentDressModel;
- @end
- @implementation YOUPAILZBadgeVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"勋章墙";
- [self youpaifinitUI];
- [self youpaifrequestAvatarDressData];
- }
- - (void)youpaifinitUI{
- UILabel *descL = [[UILabel alloc] init];
- descL.textColor = [UIColor whiteColor];
- descL.font = LCFont14;
- descL.text = @"可选择一个佩戴";
- descL.textAlignment = NSTextAlignmentCenter;
- [self.view addSubview:descL];
- [descL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.offset(0.0f);
- make.top.offset(NavBarHeight);
- }];
-
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
- flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
- flowLayout.itemSize = CGSizeMake((KScreenWidth - ScaleSize(42.0f)) / 3.0f, ScaleSize(145.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 = LCBkgColor;
- collectionView.alwaysBounceVertical = YES;
- collectionView.delegate = self;
- collectionView.dataSource = self;
- [collectionView registerClass:YOUPAILZBadgeCell.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(descL.mas_bottom).offset(25.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{
- YOUPAILZBadgeCell *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.youpaipcollectionView reloadData];
- [self youpaifsetupAvatarDressWithModel:self.youpaipcurrentDressModel];
- }
- - (void)youpaifsetupAvatarDressWithModel:(YOUPAILZDressModel *)dressModel{
- [LCHttpHelper requestWithURLString:UpdateDress parameters:@{@"type":@"badge",@"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)youpaifrequestAvatarDressData{
- @weakify(self);
- [LCHttpHelper requestWithURLString:GetDressList parameters:@{@"type":@"badge"} 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;
- }
- }
- if (self.youpaipdataSource.count != 0) {
- [self.youpaipcollectionView lz_hideEmptyView];
- }else{
- [self.youpaipcollectionView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_badge_data"] content:@"暂无徽章,要努力加油哦~"];
- }
- [self.youpaipcollectionView reloadData];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- @end
|