YOUPAILZChatRoomSetterBgImgWindow.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // YOUPAILZChatRoomSetterBgImgWindow.m
  3. // MSYOUPAI
  4. //
  5. // Created by CY on 2022/1/8.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZChatRoomSetterBgImgWindow.h"
  9. #import "YOUPAILZChatRoomBgImgCell.h"
  10. @interface YOUPAILZChatRoomSetterBgImgWindow ()<UICollectionViewDelegate,UICollectionViewDataSource>
  11. @property (nonatomic, weak) UICollectionView *youpaipcollectionView;
  12. @property (nonatomic, strong) NSMutableArray <YOUPAILZChatRoomBgImgModel *>*youpaipdataSource;
  13. @property (nonatomic, strong) YOUPAILZChatRoomBgImgModel *youpaipSelectedModel;
  14. @property (nonatomic,weak)UIButton *youpaipdefineBtn;
  15. @end
  16. @implementation YOUPAILZChatRoomSetterBgImgWindow
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.baseView.hidden = YES;
  20. [self youpaifinitUI];
  21. [self youpaifrequestBackgoundImageList];
  22. }
  23. - (void)youpaifinitUI{
  24. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, ScaleSize(406.0f))];
  25. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(ScaleSize(20.0f), ScaleSize(20.0f))];
  26. bgV.backgroundColor = LCBkgColor;
  27. [self.view addSubview:bgV];
  28. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.left.right.bottom.offset(0.0f);
  30. make.height.offset(ScaleSize(406.0f));
  31. }];
  32. UILabel *titleL = [[UILabel alloc] init];
  33. titleL.font = LCBoldFont(ScaleSize(17.0f));
  34. titleL.textColor = [UIColor whiteColor];
  35. titleL.textAlignment = NSTextAlignmentCenter;
  36. titleL.text = @"选择背景";
  37. [bgV addSubview:titleL];
  38. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.left.top.right.offset(0.0f);
  40. make.height.offset(ScaleSize(58.0f));
  41. }];
  42. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  43. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  44. layout.minimumLineSpacing = ScaleSize(8.0f);
  45. layout.minimumInteritemSpacing = ScaleSize(8.0f);
  46. layout.sectionInset = UIEdgeInsetsMake(0.0f, ScaleSize(14.0f), SafeHeight + ScaleSize(16.0f) + 48.0f, ScaleSize(14.0f));
  47. CGFloat width = (KScreenWidth - ScaleSize(44.0f)) / 3.0f;
  48. layout.itemSize = CGSizeMake(width, ScaleSize(141.0f)/width*ScaleSize(141.0f));
  49. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  50. collectionView.alwaysBounceVertical = YES;
  51. collectionView.backgroundColor = LCBkgColor;
  52. collectionView.dataSource = self;
  53. collectionView.delegate = self;
  54. collectionView.scrollEnabled = YES;
  55. collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  56. [collectionView registerClass:[YOUPAILZChatRoomBgImgCell class] forCellWithReuseIdentifier:NSStringFromClass(YOUPAILZChatRoomBgImgCell.class)];
  57. [self.view addSubview:collectionView];
  58. self.youpaipcollectionView = collectionView;
  59. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.equalTo(titleL.mas_bottom).offset(0.0f);
  61. make.left.right.bottom.offset(0.0f);
  62. }];
  63. UIButton *youpaipdefineBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  64. [youpaipdefineBtn setTitle:@"确定" forState:UIControlStateNormal];
  65. [youpaipdefineBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  66. youpaipdefineBtn.titleLabel.font = LCFont16;
  67. youpaipdefineBtn.layer.cornerRadius = 24.0f;
  68. youpaipdefineBtn.layer.masksToBounds = YES;
  69. youpaipdefineBtn.userInteractionEnabled = NO;
  70. [youpaipdefineBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  71. [youpaipdefineBtn addTarget:self action:@selector(youpaipdefineBtnClick) forControlEvents:UIControlEventTouchUpInside];
  72. [self.view addSubview:youpaipdefineBtn];
  73. self.youpaipdefineBtn = youpaipdefineBtn;
  74. [youpaipdefineBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.offset(40.0f);
  76. make.right.offset(-40.0f);
  77. make.bottom.offset(-ScaleSize(8.0f)-SafeHeight);
  78. make.height.offset(48.0f);
  79. }];
  80. }
  81. #pragma mark - UICollectionViewDataSource
  82. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  83. return self.youpaipdataSource.count;
  84. }
  85. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  86. YOUPAILZChatRoomBgImgCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(YOUPAILZChatRoomBgImgCell.class) forIndexPath:indexPath];
  87. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]];
  88. return cell;
  89. }
  90. #pragma mark - UICollectionViewDelegate
  91. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  92. if (self.youpaipSelectedModel != nil) {
  93. self.youpaipSelectedModel.isSelected = NO;
  94. if ([self.youpaipdataSource containsObject:self.youpaipSelectedModel]) {
  95. NSInteger item = [self.youpaipdataSource indexOfObject:self.youpaipSelectedModel];
  96. [self.youpaipcollectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:item inSection:0]]];
  97. }
  98. }
  99. self.youpaipSelectedModel = self.youpaipdataSource[indexPath.item];
  100. self.youpaipSelectedModel.isSelected = YES;
  101. if ([self.youpaipdataSource containsObject:self.youpaipSelectedModel]) {
  102. NSInteger item = [self.youpaipdataSource indexOfObject:self.youpaipSelectedModel];
  103. [self.youpaipcollectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:item inSection:0]]];
  104. }
  105. [self youpaifReloadButtonStyle];
  106. }
  107. - (void)youpaifrequestBackgoundImageList{
  108. @weakify(self);
  109. [LCHttpHelper requestWithURLString:ChatRoomBackgoundImageList parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  110. NSDictionary* dict = (NSDictionary*)responseObject;
  111. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  112. if (code==0) {//成功
  113. @strongify(self);
  114. self.youpaipdataSource = [YOUPAILZChatRoomBgImgModel mj_objectArrayWithKeyValuesArray:dict[@"data"]];
  115. YOUPAILZChatRoomBgImgModel *model = nil;
  116. for (NSInteger i = 0; i < self.youpaipdataSource.count; i ++) {
  117. YOUPAILZChatRoomBgImgModel *f_model = self.youpaipdataSource[i];
  118. if ([f_model.youpaipid isEqual:self.youpaipSelectedModel.youpaipid]) {
  119. f_model.isSelected = YES;
  120. model = f_model;
  121. break;
  122. }
  123. }
  124. self.youpaipSelectedModel = model;
  125. [self youpaifReloadButtonStyle];
  126. [self.youpaipcollectionView reloadData];
  127. }
  128. } failure:^(NSError *error) {
  129. }];
  130. }
  131. - (void)youpaipdefineBtnClick{
  132. @weakify(self);
  133. [LCHttpHelper requestWithURLString:ChatRoomSelectedBackgoundImage parameters:@{@"room_id":self.youpaipchatroomModel.youpaiproom_id,@"id":self.youpaipSelectedModel.youpaipid} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  134. @strongify(self);
  135. NSDictionary* dict = (NSDictionary*)responseObject;
  136. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  137. if (code==0) {//成功
  138. [self dismissViewControllerAnimated:YES completion:^{}];
  139. }
  140. } failure:^(NSError *error) {
  141. }];
  142. }
  143. - (void)youpaifReloadButtonStyle{
  144. if (self.youpaipSelectedModel == nil) {
  145. self.youpaipdefineBtn.userInteractionEnabled = NO;
  146. [self.youpaipdefineBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  147. }else{
  148. self.youpaipdefineBtn.userInteractionEnabled = YES;
  149. [self.youpaipdefineBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  150. }
  151. }
  152. @end