YOUPAILZAvatarDressVC.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // YOUPAILZAvatarDressVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/8/17.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZAvatarDressVC.h"
  9. #import "YOUPAILZAvatarDressHeaderView.h"
  10. #import "YOUPAILZAvatarDressCell.h"
  11. #import "YOUPAILZDressModel.h"
  12. @interface YOUPAILZAvatarDressVC () <UICollectionViewDelegate,UICollectionViewDataSource>
  13. @property (nonatomic, weak) YOUPAILZAvatarDressHeaderView *youpaipheaderView;
  14. @property (nonatomic, weak) UICollectionView *youpaipcollectionView;
  15. @property (nonatomic, strong) NSArray <YOUPAILZDressModel *>*youpaipdataSource;
  16. @property (nonatomic, strong) YOUPAILZDressModel *youpaipcurrentDressModel;
  17. @end
  18. @implementation YOUPAILZAvatarDressVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.view.backgroundColor = HexColorFromRGB(0x21232E);
  22. [self youpaifinitUI];
  23. [self youpaifrequestAvatarDressData];
  24. }
  25. - (void)youpaifinitUI{
  26. YOUPAILZAvatarDressHeaderView *headerView = [[YOUPAILZAvatarDressHeaderView alloc] init];
  27. [self.view addSubview:headerView];
  28. self.youpaipheaderView = headerView;
  29. [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.right.top.offset(0.0f);
  31. make.height.offset(ScaleSize(158.0f));
  32. }];
  33. UILabel *titleL = [[UILabel alloc] init];
  34. titleL.textColor = [UIColor whiteColor];
  35. titleL.font = LCFont(15.0f);
  36. titleL.text = @"已拥有";
  37. [self.view addSubview:titleL];
  38. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.left.offset(14.0f);
  40. make.right.offset(-14.0f);
  41. make.top.equalTo(headerView.mas_bottom).offset(28.0f);
  42. }];
  43. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  44. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  45. flowLayout.itemSize = CGSizeMake((KScreenWidth - ScaleSize(42.0f)) / 3.0f, ScaleSize(131.0f));
  46. flowLayout.minimumLineSpacing = ScaleSize(14.0f);
  47. flowLayout.minimumInteritemSpacing = ScaleSize(7.0f);
  48. flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, ScaleSize(14.0f), 0.0f, ScaleSize(14.0f));
  49. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  50. collectionView.backgroundColor = HexColorFromRGB(0x21232E);
  51. collectionView.alwaysBounceVertical = YES;
  52. collectionView.delegate = self;
  53. collectionView.dataSource = self;
  54. [collectionView registerClass:YOUPAILZAvatarDressCell.class forCellWithReuseIdentifier:@"cell"];
  55. [self.view addSubview:collectionView];
  56. self.youpaipcollectionView = collectionView;
  57. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.bottom.right.offset(0.0f);
  59. make.top.equalTo(titleL.mas_bottom).offset(20.0f);
  60. }];
  61. }
  62. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  63. return 1;
  64. }
  65. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  66. return self.youpaipdataSource.count;
  67. }
  68. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  69. YOUPAILZAvatarDressCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  70. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]];
  71. return cell;
  72. }
  73. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  74. self.youpaipcurrentDressModel.youpaipis_use = @"0";
  75. self.youpaipcurrentDressModel = self.youpaipdataSource[indexPath.item];
  76. self.youpaipcurrentDressModel.youpaipis_use = @"1";
  77. [self.youpaipheaderView youpaifreloadWithModel:self.youpaipcurrentDressModel];
  78. [self.youpaipcollectionView reloadData];
  79. [self youpaifsetupAvatarDressWithModel:self.youpaipcurrentDressModel];
  80. }
  81. - (void)youpaifsetupAvatarDressWithModel:(YOUPAILZDressModel *)dressModel{
  82. [LCHttpHelper requestWithURLString:UpdateDress parameters:@{@"type":@"avatar_frame",@"u_dress_id":dressModel.youpaipu_dress_id.length == 0 ? @"0" : dressModel.youpaipu_dress_id} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  83. } failure:^(NSError *error) {
  84. }];
  85. }
  86. /// 获取列表数据
  87. - (void)youpaifrequestAvatarDressData{
  88. @weakify(self);
  89. [LCHttpHelper requestWithURLString:GetDressList parameters:@{@"type":@"avatar_frame"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  90. @strongify(self);
  91. NSDictionary* dict = (NSDictionary*)responseObject;
  92. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  93. if (code == 0) {//成功
  94. NSDictionary *data = [dict objectForKey:@"data"];
  95. self.youpaipdataSource = [YOUPAILZDressModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"userDress"]];
  96. for (YOUPAILZDressModel *dressModel in self.youpaipdataSource) {
  97. if ([dressModel.youpaipis_use isEqual:@"1"]) {
  98. self.youpaipcurrentDressModel = dressModel;
  99. [self.youpaipheaderView youpaifreloadWithModel:self.youpaipcurrentDressModel];
  100. }
  101. }
  102. [self.youpaipcollectionView reloadData];
  103. }
  104. } failure:^(NSError *error) {
  105. }];
  106. }
  107. #pragma mark - JXCategoryListContentViewDelegate
  108. - (UIView *)listView{
  109. return self.view;
  110. }
  111. @end