// // YOUPAILCBigCastSkillVC.m // LiveChat // // Created by 张灿 on 2018/8/31. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCBigCastSkillVC.h" #import "YOUPAILCSkillCollectionCell.h" @interface YOUPAILCBigCastSkillVC () @property (nonatomic,strong)UICollectionView *youpaipcollectionView; @property (nonatomic,strong)NSMutableArray* youpaipskillArray; @property (nonatomic,strong)NSIndexPath* youpaipcurrentIndexPath; @property (nonatomic,strong)UIButton* youpaipuploadBtn; @property (nonatomic,assign)BOOL youpaipcanSelect; @end @implementation YOUPAILCBigCastSkillVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"我的女神技能"; self.view.backgroundColor = [UIColor whiteColor]; self.youpaipcanSelect = YES; self.youpaipskillArray = [NSMutableArray array]; [self youpaifsetupView]; [self youpaifinitData]; } - (void)youpaifsetupView{ UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; CGFloat margin = 5; CGFloat itemWH = (KScreenWidth-10)/3.0; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.itemSize = CGSizeMake(itemWH, itemWH); layout.minimumInteritemSpacing = margin; layout.minimumLineSpacing = margin; _youpaipcollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) collectionViewLayout:layout]; _youpaipcollectionView.backgroundColor = [UIColor clearColor]; _youpaipcollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); _youpaipcollectionView.layer.masksToBounds = NO; _youpaipcollectionView.dataSource = self; _youpaipcollectionView.delegate = self; _youpaipcollectionView.scrollEnabled = NO; [_youpaipcollectionView registerClass:[YOUPAILCSkillCollectionCell class] forCellWithReuseIdentifier:@"YOUPAILCSkillCollectionCell"]; [_youpaipcollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"]; [self.view addSubview:_youpaipcollectionView]; } - (void)youpaifinitData{ [LCHttpHelper requestWithURLString:BigCastSkill parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) { self.youpaipskillArray = [YOUPAILCSkillModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]]; for (YOUPAILCSkillModel* model in self.youpaipskillArray) { if (model.youpaipis_add ==1) { self.youpaipcanSelect = NO; } } [self.youpaipcollectionView reloadData]; } } failure:^(NSError *error) { }]; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.youpaipskillArray.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { YOUPAILCSkillCollectionCell *cell = (YOUPAILCSkillCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAILCSkillCollectionCell" forIndexPath:indexPath]; return cell; } - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILCSkillCollectionCell *serviceCell = (YOUPAILCSkillCollectionCell*)cell; YOUPAILCSkillModel *model = self.youpaipskillArray[indexPath.row]; serviceCell.youpaipskillModel = model; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (!self.youpaipcanSelect) { return ; } YOUPAILCSkillCollectionCell* cell = (YOUPAILCSkillCollectionCell*)[self.youpaipcollectionView cellForItemAtIndexPath:indexPath]; if (cell.youpaipskillModel.youpaipis_add==0 && cell.youpaipskillModel.youpaipstatus==0) { cell.youpaipselectImgView.hidden = NO; cell.youpaipiconImgView.alpha = 1.0; cell.youpaipskillNameLabel.alpha = 1.0; if (self.youpaipcurrentIndexPath) { YOUPAILCSkillCollectionCell* oldCell = (YOUPAILCSkillCollectionCell*)[self.youpaipcollectionView cellForItemAtIndexPath:self.youpaipcurrentIndexPath]; oldCell.youpaipselectImgView.hidden = YES; oldCell.youpaipiconImgView.alpha = 0.3; oldCell.youpaipskillNameLabel.alpha = 0.3; } self.youpaipcurrentIndexPath = indexPath; [self updateBtn]; } } -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{ return CGSizeMake(KScreenWidth, 150); } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind: UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath]; UIButton* uploadBtn = [[UIButton alloc]initWithFrame:CGRectMake(30, 50, KScreenWidth-60, 50)]; uploadBtn.backgroundColor = LCGray; uploadBtn.layer.cornerRadius = 25.0; uploadBtn.layer.masksToBounds = YES; if (self.youpaipcanSelect) { [uploadBtn setTitle:@"请选择技能" forState:(UIControlStateNormal)]; }else{ [uploadBtn setTitle:@"你已提交了女神技能" forState:(UIControlStateNormal)]; } [uploadBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [uploadBtn addTarget:self action:@selector(uploadClick) forControlEvents:(UIControlEventTouchUpInside)]; self.youpaipuploadBtn = uploadBtn; [footerView addSubview:uploadBtn]; footerView.backgroundColor = [UIColor clearColor]; return footerView; } - (void)updateBtn{ if (self.youpaipcurrentIndexPath) { [self.youpaipuploadBtn setBackgroundImage:[UIImage imageWithColor:LCYellowColor size:self.youpaipuploadBtn.frame.size] forState:(UIControlStateNormal)]; self.youpaipuploadBtn.userInteractionEnabled = YES; [self.youpaipuploadBtn setTitle:@"提交申请" forState:(UIControlStateNormal)]; }else{ [self.youpaipuploadBtn setBackgroundImage:nil forState:(UIControlStateNormal)]; self.youpaipuploadBtn.userInteractionEnabled = NO; [self.youpaipuploadBtn setTitle:@"请选择技能" forState:(UIControlStateNormal)]; } } - (void)uploadClick{ YOUPAILCSkillCollectionCell* cell = (YOUPAILCSkillCollectionCell*)[self.youpaipcollectionView cellForItemAtIndexPath:self.youpaipcurrentIndexPath]; [LCHttpHelper requestWithURLString:AddSkill parameters:@{@"skills":@(cell.youpaipskillModel.youpaipid)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) { self.youpaipcurrentIndexPath = nil; [self youpaifinitData]; } } failure:^(NSError *error) { }]; } @end