YOUPAILZBadgeVC.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // YOUPAILZBadgeVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/8/30.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZBadgeVC.h"
  9. #import "YOUPAILZBadgeCell.h"
  10. #import "YOUPAILZDressModel.h"
  11. @interface YOUPAILZBadgeVC () <UICollectionViewDelegate,UICollectionViewDataSource>
  12. @property (nonatomic, weak) UICollectionView *youpaipcollectionView;
  13. @property (nonatomic, strong) NSArray <YOUPAILZDressModel *>*youpaipdataSource;
  14. @property (nonatomic, strong) YOUPAILZDressModel *youpaipcurrentDressModel;
  15. @end
  16. @implementation YOUPAILZBadgeVC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.title = @"勋章墙";
  20. [self youpaifinitUI];
  21. [self youpaifrequestAvatarDressData];
  22. }
  23. - (void)youpaifinitUI{
  24. UILabel *descL = [[UILabel alloc] init];
  25. descL.textColor = [UIColor whiteColor];
  26. descL.font = LCFont14;
  27. descL.text = @"可选择一个佩戴";
  28. descL.textAlignment = NSTextAlignmentCenter;
  29. [self.view addSubview:descL];
  30. [descL mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.left.right.offset(0.0f);
  32. make.top.offset(NavBarHeight);
  33. }];
  34. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  35. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  36. flowLayout.itemSize = CGSizeMake((KScreenWidth - ScaleSize(42.0f)) / 3.0f, ScaleSize(145.0f));
  37. flowLayout.minimumLineSpacing = ScaleSize(14.0f);
  38. flowLayout.minimumInteritemSpacing = ScaleSize(7.0f);
  39. flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, ScaleSize(14.0f), 0.0f, ScaleSize(14.0f));
  40. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  41. collectionView.backgroundColor = LCBkgColor;
  42. collectionView.alwaysBounceVertical = YES;
  43. collectionView.delegate = self;
  44. collectionView.dataSource = self;
  45. [collectionView registerClass:YOUPAILZBadgeCell.class forCellWithReuseIdentifier:@"cell"];
  46. [self.view addSubview:collectionView];
  47. self.youpaipcollectionView = collectionView;
  48. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.bottom.right.offset(0.0f);
  50. make.top.equalTo(descL.mas_bottom).offset(25.0f);
  51. }];
  52. }
  53. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  54. return 1;
  55. }
  56. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  57. return self.youpaipdataSource.count;
  58. }
  59. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  60. YOUPAILZBadgeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  61. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]];
  62. return cell;
  63. }
  64. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  65. self.youpaipcurrentDressModel.youpaipis_use = @"0";
  66. self.youpaipcurrentDressModel = self.youpaipdataSource[indexPath.item];
  67. self.youpaipcurrentDressModel.youpaipis_use = @"1";
  68. [self.youpaipcollectionView reloadData];
  69. [self youpaifsetupAvatarDressWithModel:self.youpaipcurrentDressModel];
  70. }
  71. - (void)youpaifsetupAvatarDressWithModel:(YOUPAILZDressModel *)dressModel{
  72. [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) {
  73. } failure:^(NSError *error) {
  74. }];
  75. }
  76. /// 获取列表数据
  77. - (void)youpaifrequestAvatarDressData{
  78. @weakify(self);
  79. [LCHttpHelper requestWithURLString:GetDressList parameters:@{@"type":@"badge"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  80. @strongify(self);
  81. NSDictionary* dict = (NSDictionary*)responseObject;
  82. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  83. if (code == 0) {//成功
  84. NSDictionary *data = [dict objectForKey:@"data"];
  85. self.youpaipdataSource = [YOUPAILZDressModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"userDress"]];
  86. for (YOUPAILZDressModel *dressModel in self.youpaipdataSource) {
  87. if ([dressModel.youpaipis_use isEqual:@"1"]) {
  88. self.youpaipcurrentDressModel = dressModel;
  89. }
  90. }
  91. if (self.youpaipdataSource.count != 0) {
  92. [self.youpaipcollectionView lz_hideEmptyView];
  93. }else{
  94. [self.youpaipcollectionView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_badge_data"] content:@"暂无徽章,要努力加油哦~"];
  95. }
  96. [self.youpaipcollectionView reloadData];
  97. }
  98. } failure:^(NSError *error) {
  99. }];
  100. }
  101. @end