YOUPAILCBigCastSkillVC.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // YOUPAILCBigCastSkillVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/8/31.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCBigCastSkillVC.h"
  9. #import "YOUPAILCSkillCollectionCell.h"
  10. @interface YOUPAILCBigCastSkillVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
  11. @property (nonatomic,strong)UICollectionView *youpaipcollectionView;
  12. @property (nonatomic,strong)NSMutableArray* youpaipskillArray;
  13. @property (nonatomic,strong)NSIndexPath* youpaipcurrentIndexPath;
  14. @property (nonatomic,strong)UIButton* youpaipuploadBtn;
  15. @property (nonatomic,assign)BOOL youpaipcanSelect;
  16. @end
  17. @implementation YOUPAILCBigCastSkillVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.title = @"我的女神技能";
  21. self.view.backgroundColor = [UIColor whiteColor];
  22. self.youpaipcanSelect = YES;
  23. self.youpaipskillArray = [NSMutableArray array];
  24. [self youpaifsetupView];
  25. [self youpaifinitData];
  26. }
  27. - (void)youpaifsetupView{
  28. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  29. CGFloat margin = 5;
  30. CGFloat itemWH = (KScreenWidth-10)/3.0;
  31. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  32. layout.itemSize = CGSizeMake(itemWH, itemWH);
  33. layout.minimumInteritemSpacing = margin;
  34. layout.minimumLineSpacing = margin;
  35. _youpaipcollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) collectionViewLayout:layout];
  36. _youpaipcollectionView.backgroundColor = [UIColor clearColor];
  37. _youpaipcollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
  38. _youpaipcollectionView.layer.masksToBounds = NO;
  39. _youpaipcollectionView.dataSource = self;
  40. _youpaipcollectionView.delegate = self;
  41. _youpaipcollectionView.scrollEnabled = NO;
  42. [_youpaipcollectionView registerClass:[YOUPAILCSkillCollectionCell class] forCellWithReuseIdentifier:@"YOUPAILCSkillCollectionCell"];
  43. [_youpaipcollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
  44. [self.view addSubview:_youpaipcollectionView];
  45. }
  46. - (void)youpaifinitData{
  47. [LCHttpHelper requestWithURLString:BigCastSkill parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  48. NSDictionary* dict = (NSDictionary*)responseObject;
  49. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  50. if (code==0) {
  51. self.youpaipskillArray = [YOUPAILCSkillModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  52. for (YOUPAILCSkillModel* model in self.youpaipskillArray) {
  53. if (model.youpaipis_add ==1) {
  54. self.youpaipcanSelect = NO;
  55. }
  56. }
  57. [self.youpaipcollectionView reloadData];
  58. }
  59. } failure:^(NSError *error) {
  60. }];
  61. }
  62. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  63. return self.youpaipskillArray.count;
  64. }
  65. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  66. YOUPAILCSkillCollectionCell *cell = (YOUPAILCSkillCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAILCSkillCollectionCell" forIndexPath:indexPath];
  67. return cell;
  68. }
  69. - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
  70. YOUPAILCSkillCollectionCell *serviceCell = (YOUPAILCSkillCollectionCell*)cell;
  71. YOUPAILCSkillModel *model = self.youpaipskillArray[indexPath.row];
  72. serviceCell.youpaipskillModel = model;
  73. }
  74. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  75. if (!self.youpaipcanSelect) {
  76. return ;
  77. }
  78. YOUPAILCSkillCollectionCell* cell = (YOUPAILCSkillCollectionCell*)[self.youpaipcollectionView cellForItemAtIndexPath:indexPath];
  79. if (cell.youpaipskillModel.youpaipis_add==0 && cell.youpaipskillModel.youpaipstatus==0) {
  80. cell.youpaipselectImgView.hidden = NO;
  81. cell.youpaipiconImgView.alpha = 1.0;
  82. cell.youpaipskillNameLabel.alpha = 1.0;
  83. if (self.youpaipcurrentIndexPath) {
  84. YOUPAILCSkillCollectionCell* oldCell = (YOUPAILCSkillCollectionCell*)[self.youpaipcollectionView cellForItemAtIndexPath:self.youpaipcurrentIndexPath];
  85. oldCell.youpaipselectImgView.hidden = YES;
  86. oldCell.youpaipiconImgView.alpha = 0.3;
  87. oldCell.youpaipskillNameLabel.alpha = 0.3;
  88. }
  89. self.youpaipcurrentIndexPath = indexPath;
  90. [self updateBtn];
  91. }
  92. }
  93. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
  94. return CGSizeMake(KScreenWidth, 150);
  95. }
  96. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  97. {
  98. UICollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:
  99. UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath];
  100. UIButton* uploadBtn = [[UIButton alloc]initWithFrame:CGRectMake(30, 50, KScreenWidth-60, 50)];
  101. uploadBtn.backgroundColor = LCGray;
  102. uploadBtn.layer.cornerRadius = 25.0;
  103. uploadBtn.layer.masksToBounds = YES;
  104. if (self.youpaipcanSelect) {
  105. [uploadBtn setTitle:@"请选择技能" forState:(UIControlStateNormal)];
  106. }else{
  107. [uploadBtn setTitle:@"你已提交了女神技能" forState:(UIControlStateNormal)];
  108. }
  109. [uploadBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  110. [uploadBtn addTarget:self action:@selector(uploadClick) forControlEvents:(UIControlEventTouchUpInside)];
  111. self.youpaipuploadBtn = uploadBtn;
  112. [footerView addSubview:uploadBtn];
  113. footerView.backgroundColor = [UIColor clearColor];
  114. return footerView;
  115. }
  116. - (void)updateBtn{
  117. if (self.youpaipcurrentIndexPath) {
  118. [self.youpaipuploadBtn setBackgroundImage:[UIImage imageWithColor:LCYellowColor size:self.youpaipuploadBtn.frame.size] forState:(UIControlStateNormal)];
  119. self.youpaipuploadBtn.userInteractionEnabled = YES;
  120. [self.youpaipuploadBtn setTitle:@"提交申请" forState:(UIControlStateNormal)];
  121. }else{
  122. [self.youpaipuploadBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
  123. self.youpaipuploadBtn.userInteractionEnabled = NO;
  124. [self.youpaipuploadBtn setTitle:@"请选择技能" forState:(UIControlStateNormal)];
  125. }
  126. }
  127. - (void)uploadClick{
  128. YOUPAILCSkillCollectionCell* cell = (YOUPAILCSkillCollectionCell*)[self.youpaipcollectionView cellForItemAtIndexPath:self.youpaipcurrentIndexPath];
  129. [LCHttpHelper requestWithURLString:AddSkill parameters:@{@"skills":@(cell.youpaipskillModel.youpaipid)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  130. NSDictionary* dict = (NSDictionary*)responseObject;
  131. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  132. if (code==0) {
  133. self.youpaipcurrentIndexPath = nil;
  134. [self youpaifinitData];
  135. }
  136. } failure:^(NSError *error) {
  137. }];
  138. }
  139. @end