YOUPAILZCardDressVC.m 5.4 KB

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