SocietyDetailVC.m 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. //
  2. // SocietyDetailVC.m
  3. // BuguLive
  4. //
  5. // Created by 杨仁伟 on 2017/8/21.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "SocietyDetailVC.h"
  9. #import "AnchorCell.h"
  10. #import "SocietyHeaderView.h"
  11. #import "FansCell.h"
  12. #import "ApplicantCell.h"
  13. #import "SociatyDetailModel.h"
  14. #import "EditSocietyViewController.h"
  15. #import "NoCotentCell.h"
  16. @interface SocietyDetailVC () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,FansCellDelegate,ApplicantCellDelegate, UIScrollViewDelegate>
  17. {
  18. HMSegmentedControl *segmentControl;
  19. SocietyHeaderView *head; //区头
  20. CGFloat _lblShowH; //点击更多按钮时候label的高度
  21. BOOL _isFirst;
  22. BOOL _isShow; //是否展开
  23. NSInteger _showRow; //默认展开行数
  24. CGFloat _showHeight; //默认公告高度
  25. UIBlurEffect *_frostedEffect; //毛玻璃效果
  26. }
  27. @property (nonatomic, strong) NSMutableArray *sociatyDetailArray;
  28. @property (nonatomic, assign) int currentPage;
  29. @property (nonatomic, assign) int has_next;
  30. @property (nonatomic, copy) NSString *tianTuanHeadImg; // 公会头像
  31. @property (nonatomic, assign) NSInteger open_society_code; // 是否开启邀请码
  32. @property (nonatomic, strong) UICollectionView *detailCollectionView;
  33. @property (nonatomic, strong) UICollectionViewFlowLayout *layout;
  34. @end
  35. static NSString *const anchor = @"Anchor";
  36. static NSString *const headerFlag = @"SocietyHeader";
  37. static NSString *const fans = @"Fans";
  38. static NSString *const applicant = @"applicant";
  39. static NSString *const noContent = @"NOCotent";
  40. static NSString *const mySociety = @"MySociety";
  41. static CGFloat const fixationH = 308; //表头除去label高度
  42. static CGFloat const slideH = 50; //滑块高度
  43. static CGFloat const margin5 = 5; //单元格间距
  44. @implementation SocietyDetailVC
  45. - (NSMutableArray *)sociatyDetailArray
  46. {
  47. if (!_sociatyDetailArray)
  48. {
  49. _sociatyDetailArray = [NSMutableArray arrayWithCapacity:0];
  50. }
  51. return _sociatyDetailArray;
  52. }
  53. - (void)initFWUI
  54. {
  55. [super initFWUI];
  56. self.automaticallyAdjustsScrollViewInsets = NO;
  57. if (isIOS11())
  58. {
  59. self.detailCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, -54, kScreenW, kScreenH+54) collectionViewLayout:[self judgeUsageWhichOne]];
  60. }
  61. else
  62. {
  63. self.detailCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, -64, kScreenW, kScreenH+64) collectionViewLayout:[self judgeUsageWhichOne]];
  64. }
  65. self.detailCollectionView.delegate = self;
  66. self.detailCollectionView.dataSource = self;
  67. self.detailCollectionView.backgroundColor = kAppSpaceColor3;
  68. [self.view addSubview:self.detailCollectionView];
  69. _isFirst = YES;
  70. [self createSegmentControler];
  71. [self.detailCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([AnchorCell class]) bundle:nil] forCellWithReuseIdentifier:anchor];
  72. [self.detailCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([FansCell class]) bundle:nil] forCellWithReuseIdentifier:fans];
  73. [self.detailCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([ApplicantCell class]) bundle:nil] forCellWithReuseIdentifier:applicant];
  74. [self.detailCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([SocietyHeaderView class]) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerFlag];
  75. [self.detailCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([NoCotentCell class]) bundle:nil] forCellWithReuseIdentifier:noContent];
  76. [BGMJRefreshManager refresh:self.detailCollectionView target:self headerRereshAction:@selector(headerNew) footerRereshAction:@selector(footerNew)];
  77. }
  78. #pragma mark ------------------------------------ 表头:根据成员类型设置 -------------------------------------------
  79. - (void)tableViewHeadMsgSetup
  80. {
  81. if (self.type == 1)
  82. { //会长
  83. head.OperationBtn.hidden = NO;
  84. if (self.open_society_code == 0)
  85. {
  86. head.OperationBtn.hidden = YES;
  87. }
  88. if (!self.flagStr && self.open_society_code == 1)
  89. {
  90. head.operationBtnW.constant = 100;
  91. }
  92. }
  93. else
  94. {
  95. if (self.type == 0)
  96. { //该公会成员
  97. [self operationWithWidth:24 title:@"" imageStr:@"me_quit_society"];
  98. }
  99. else if (self.type == 2)
  100. {//其他公会成员
  101. head.OperationBtn.hidden = YES;
  102. }
  103. else if (self.type == 3)
  104. { //无公会成员
  105. [self operationWithWidth:20 title:@"" imageStr:@"me_join_society"];
  106. }
  107. else if (self.type == 4)
  108. {
  109. [self operationWithWidth:100 title:ASLocalizedString(@"入会申请中")imageStr:@""];
  110. }
  111. else if (self.type == 5)
  112. {
  113. [self operationWithWidth:100 title:ASLocalizedString(@"退会申请中")imageStr:@""];
  114. }
  115. }
  116. //从个人中心界面跳转过来执行以下逻辑
  117. if ([self.flagStr isEqualToString:mySociety] && self.type == 1)
  118. {
  119. //审核状态判断
  120. if (self.mygh_status == 0)
  121. { //公会未审核
  122. [self propertyWithBtnEnable:NO btnTitle:ASLocalizedString(@"状态:审核中")];
  123. }
  124. else if (self.mygh_status == 1)
  125. { //审核通过,展示公会邀请码
  126. head.operationBtnW.constant = 100;
  127. head.OperationBtn.enabled = YES;
  128. }
  129. else if (self.mygh_status == 2)
  130. { //公会审核被拒绝
  131. [self propertyWithBtnEnable:YES btnTitle:ASLocalizedString(@"重新申请")];
  132. }
  133. }
  134. }
  135. /**
  136. 是否隐藏,操作按钮是否可编辑,标题,背景颜色
  137. @param enable 是否可编辑
  138. @param title 标题
  139. */
  140. - (void)propertyWithBtnEnable:(BOOL)enable btnTitle:(NSString *)title
  141. {
  142. head.OperationBtn.hidden = NO;
  143. head.OperationBtn.enabled = enable;
  144. [head.OperationBtn setTitle:title forState:UIControlStateNormal];
  145. }
  146. - (void)operationWithWidth:(CGFloat)width title:(NSString *)title imageStr:(NSString *)imageStr
  147. {
  148. head.OperationBtn.hidden = NO;
  149. head.operationBtnW.constant = width;
  150. [head.OperationBtn setBackgroundImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
  151. [head.OperationBtn setTitle:title forState:UIControlStateNormal];
  152. }
  153. #pragma mark ------------------------------------- 请求数据 ----------------------------------------
  154. //头部刷新
  155. - (void)headerNew
  156. {
  157. [self requestDataWithPage:1 withDetailType:(int)segmentControl.selectedSegmentIndex];
  158. }
  159. //尾部刷新
  160. - (void)footerNew
  161. {
  162. if (self.has_next == 1)
  163. {
  164. self.currentPage += 1;
  165. [self requestDataWithPage:1 withDetailType:(int)segmentControl.selectedSegmentIndex];
  166. }
  167. else
  168. {
  169. [self.detailCollectionView.mj_footer endRefreshingWithNoMoreData];
  170. }
  171. }
  172. - (void)requestDataWithPage:(int)page withDetailType:(int)detailType
  173. {
  174. NSMutableDictionary *paramDict = [NSMutableDictionary dictionary];
  175. [paramDict setObject:@"society_app" forKey:@"ctl"];
  176. [paramDict setObject:@"society_details" forKey:@"act"];
  177. [paramDict setObject:[NSNumber numberWithInt:self.mySocietyID] forKey:@"society_id"];
  178. [paramDict setObject:[NSNumber numberWithInt:detailType] forKey:@"society_status"];
  179. [paramDict setObject:[NSNumber numberWithInt:page] forKey:@"page"];
  180. MMWeakify(self)
  181. [self.httpsManager POSTWithParameters:paramDict SuccessBlock:^(NSDictionary *responseJson)
  182. {
  183. MMStrongify(self)
  184. if ([responseJson toInt:@"status"] == 1)
  185. {
  186. if (page == 1)
  187. {
  188. [_sociatyDetailArray removeAllObjects];
  189. }
  190. NSArray *listArray = responseJson[@"list"];
  191. if (listArray && listArray.count > 0)
  192. {
  193. SociatyDetailModel *spModel;
  194. for (NSDictionary *sociatyDetailDict in listArray)
  195. {
  196. SociatyDetailModel *detailM = [SociatyDetailModel mj_objectWithKeyValues:sociatyDetailDict];
  197. //判断是否公会长
  198. if ([detailM.user_position intValue] == 1)
  199. {
  200. spModel = detailM;
  201. }
  202. else
  203. {
  204. [_sociatyDetailArray addObject:detailM];
  205. }
  206. }
  207. //将其插入到数组第一个元素中
  208. if (spModel)
  209. {
  210. [_sociatyDetailArray insertObject:spModel atIndex:0];
  211. }
  212. }
  213. [self configurationResponseJson:responseJson];
  214. if (self.type == 1)
  215. {
  216. //1、如果从我的个人中心进来,并且公会通过审核,展示公会邀请码;2、从首页进来是公会会长展示邀请码
  217. if (([self.flagStr isEqualToString:mySociety] && self.mygh_status == 1) || !self.flagStr)
  218. {
  219. NSString *inviteCodeStr = [NSString stringWithFormat:ASLocalizedString(@"邀请码:%@"),responseJson[@"society_code"]];
  220. if (inviteCodeStr)
  221. {
  222. [head.OperationBtn setTitle:inviteCodeStr forState:UIControlStateNormal];
  223. }
  224. }
  225. }
  226. [self tableViewHeadMsgSetup];
  227. [self judgeUsageWhichOne];
  228. [self.detailCollectionView reloadData];
  229. }
  230. } FailureBlock:^(NSError *error)
  231. {
  232. [BGMJRefreshManager endRefresh:self.detailCollectionView];
  233. }];
  234. [BGMJRefreshManager endRefresh:self.detailCollectionView];
  235. }
  236. - (void)configurationResponseJson:(NSDictionary *)responseJson
  237. {
  238. head.societyNameLbl.text = responseJson[@"society_name"];
  239. head.presidentLbl.text = [NSString stringWithFormat:ASLocalizedString(@"会长:%@"),[responseJson toString:@"society_chairman"]];
  240. head.declarationLbl.text = responseJson[@"society_explain"];
  241. [self societyTotalNumberOfPeople:[responseJson toInt:@"user_count"] + [responseJson toInt:@"fans_count"]];
  242. self.tianTuanHeadImg = responseJson[@"society_image"];
  243. self.type = [responseJson toInt:@"type"];
  244. self.mygh_status = [responseJson toInt:@"gh_status"];
  245. self.open_society_code = [responseJson toInt:@"open_society_code"];
  246. [self showMoreBtnWithNumberOfLines:_showRow height:_showHeight isShow:NO angle:0.0];
  247. segmentControl.sectionTitles = [self configSegmentSectionTitle];
  248. [head.societyBgBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:responseJson[@"society_image"]] forState:UIControlStateNormal placeholderImage:kDefaultPreloadImgSquare];
  249. [self frostedGlassEffectWithImage:head.tblHeadImg url:responseJson[@"society_image"]];
  250. NSDictionary *pageDict = responseJson[@"page"];
  251. self.has_next = [pageDict toInt:@"has_next"];
  252. self.currentPage = [pageDict toInt:@"page"];
  253. }
  254. - (void)societyTotalNumberOfPeople:(int)number
  255. {
  256. //如果总的行数大于1,刚开始显示两行;等于1显示一行
  257. NSInteger row = [self takeOutNumberOfRowWithString:head.declarationLbl.text];
  258. head.declarationLbl.numberOfLines = row > 1 ? 2 : 1;
  259. _showRow = head.declarationLbl.numberOfLines;
  260. _showHeight = head.declarationLbl.font.lineHeight*_showRow+5;
  261. head.societyTotalLbl.text = [NSString stringWithFormat:ASLocalizedString(@"公会人数:%d"),number];
  262. head.moreBtn.hidden = row == 1 ? YES : NO;
  263. }
  264. #pragma mark ------------------------------------ 设置 layout -------------------------------------------
  265. - (UICollectionViewFlowLayout *)judgeUsageWhichOne
  266. {
  267. if (!_layout) {
  268. _layout = [[UICollectionViewFlowLayout alloc] init];
  269. }
  270. if (self.sociatyDetailArray.count) {
  271. if (segmentControl.selectedSegmentIndex == 0)
  272. {
  273. CGFloat layoutW = (kScreenW - margin5 * 4) / 3.0;
  274. _layout.minimumInteritemSpacing = 0;
  275. _layout.minimumLineSpacing = 5;
  276. _layout.itemSize = CGSizeMake(layoutW, layoutW + 25);
  277. }
  278. else
  279. {
  280. _layout.itemSize = CGSizeMake(kScreenW, 60);
  281. _layout.minimumLineSpacing = 0.5;
  282. }
  283. }
  284. else
  285. {
  286. _layout.itemSize = CGSizeMake(150, 300);
  287. }
  288. return _layout;
  289. }
  290. #pragma mark ------------------------------------------ 设置毛玻璃效果 --------------------------------------------------
  291. - (void)frostedGlassEffectWithImage:(UIImageView *)image url:(NSString *)url
  292. {
  293. [image sd_setImageWithURL:[NSURL URLWithString:url] completed:nil];
  294. if (!_frostedEffect)
  295. {
  296. _frostedEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  297. [UIImage frostedGlassEffectWithView:image effect:_frostedEffect];
  298. }
  299. }
  300. /**
  301. 根据label的宽高、字体获取行数
  302. @param string 文本
  303. @return 返回的行数
  304. */
  305. - (NSInteger)takeOutNumberOfRowWithString:(NSString *)string
  306. {
  307. head.declarationLbl.numberOfLines = 0;
  308. head.declarationLbl.text = string;
  309. CGSize size = [head.declarationLbl.text boundingRectWithSize:CGSizeMake(kScreenW-30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:head.declarationLbl.font} context:nil].size;
  310. head.declarationLbl.size = CGSizeMake(kScreenW-30, size.height);
  311. CGFloat labelHeight = [head.declarationLbl sizeThatFits:CGSizeMake(kScreenW-30, size.height)].height;
  312. NSInteger count = (NSInteger)(labelHeight / head.declarationLbl.font.lineHeight);
  313. return count;
  314. }
  315. #pragma mark ---------------------------------------------- 收起或更多 ----------------------------------------------
  316. - (void)showOrHide:(UIButton *)sender
  317. {
  318. if (_isShow == NO)
  319. {
  320. _lblShowH = [self resetLineSpacing:5 text:head.declarationLbl.text];
  321. [self showMoreBtnWithNumberOfLines:0 height:_lblShowH isShow:YES angle:M_PI];
  322. }
  323. else
  324. {
  325. [self resetLineSpacing:5 text:head.declarationLbl.text];
  326. [self showMoreBtnWithNumberOfLines:_showRow height:_showHeight isShow:NO angle:0.0];
  327. }
  328. [self.detailCollectionView reloadData];
  329. }
  330. - (void)showMoreBtnWithNumberOfLines:(NSInteger)num height:(CGFloat)height isShow:(BOOL)isShow angle:(CGFloat)angle
  331. {
  332. CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
  333. head.moreBtn.transform = transform;
  334. _isShow = isShow;
  335. head.declarationLbl.numberOfLines = num;
  336. [head.declarationLbl lblHeight:height];
  337. }
  338. - (void)configurationWithNumberOfLines:(NSInteger)numberOfLines headTblSize:(CGSize)size
  339. {
  340. head.declarationLbl.numberOfLines = numberOfLines;
  341. head.size = size;
  342. }
  343. - (CGFloat)resetLineSpacing:(NSInteger)lineSpacing text:(NSString *)text
  344. {
  345. return [head.declarationLbl takeLblHeight:text withTextFontSize:14.0 lineSpaceing:lineSpacing size:CGSizeMake(kScreenW-30.0, MAXFLOAT)];
  346. }
  347. - (void)createSegmentControler
  348. {
  349. segmentControl = [[HMSegmentedControl alloc] initWithSectionTitles:[self configSegmentSectionTitle]];
  350. segmentControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName:kAppMainColor};
  351. segmentControl.titleTextAttributes = @{NSForegroundColorAttributeName:kAppGrayColor3,NSFontAttributeName:kAppMiddleTextFont_1};
  352. segmentControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
  353. segmentControl.selectionIndicatorColor = kAppMainColor;
  354. segmentControl.selectionIndicatorHeight = 3;
  355. segmentControl.borderType = HMSegmentedControlBorderTypeBottom;
  356. [segmentControl addTarget:self action:@selector(memberClick:) forControlEvents:UIControlEventValueChanged];
  357. segmentControl.borderColor = kAppSpaceColor3;
  358. }
  359. #pragma mark ---------------------------------------------- 切换列表 ----------------------------------------------
  360. - (void)memberClick:(HMSegmentedControl *)selectSegment
  361. {
  362. [self requestDataWithPage:1 withDetailType:(int)selectSegment.selectedSegmentIndex];
  363. }
  364. - (NSArray *)configSegmentSectionTitle
  365. {
  366. NSArray *arrayTitle;
  367. NSString *anchorStr = [NSString stringWithFormat:ASLocalizedString(@"主播")];
  368. NSString *fansStr = [NSString stringWithFormat:ASLocalizedString(@"粉丝")];
  369. NSString *joinStr = [NSString stringWithFormat:ASLocalizedString(@"成员申请")];
  370. NSString *outStr = [NSString stringWithFormat:ASLocalizedString(@"退出申请")];
  371. arrayTitle = self.type == 1 ? @[anchorStr, fansStr, joinStr, outStr] : @[anchorStr, fansStr];
  372. return arrayTitle;
  373. }
  374. #pragma mark -------------------------- CollectionView delegate and dataSource ------------------------
  375. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  376. {
  377. if (self.sociatyDetailArray.count)
  378. {
  379. return self.sociatyDetailArray.count;
  380. }
  381. else
  382. {
  383. return 1;
  384. }
  385. }
  386. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath
  387. {
  388. if (self.sociatyDetailArray.count)
  389. {
  390. SociatyDetailModel *model = self.sociatyDetailArray[indexPath.row];
  391. if (segmentControl.selectedSegmentIndex == 0)
  392. {
  393. AnchorCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:anchor forIndexPath:indexPath];
  394. [cell configCellMsg:model];
  395. return cell;
  396. }
  397. else if (segmentControl.selectedSegmentIndex == 1)
  398. {
  399. FansCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:fans forIndexPath:indexPath];
  400. [cell configCellMsg:model memberType:self.type];
  401. cell.delegate = self;
  402. return cell;
  403. }
  404. else
  405. {
  406. ApplicantCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:applicant forIndexPath:indexPath];
  407. [cell configCellMsg:model];
  408. cell.delegate = self;
  409. return cell;
  410. }
  411. }
  412. else
  413. {
  414. NoCotentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:noContent forIndexPath:indexPath];
  415. return cell;
  416. }
  417. return nil;
  418. }
  419. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  420. {
  421. if (self.sociatyDetailArray.count) {
  422. if (segmentControl.selectedSegmentIndex == 0)
  423. {
  424. return UIEdgeInsetsMake(margin5, margin5, 0, margin5);
  425. }
  426. return UIEdgeInsetsZero;
  427. }
  428. else
  429. {
  430. return UIEdgeInsetsMake(0, (kScreenW-150)/2, 0, (kScreenW-150)/2);
  431. }
  432. }
  433. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  434. {
  435. head = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerFlag forIndexPath:indexPath];
  436. if (_isShow == NO)
  437. {
  438. segmentControl.frame = CGRectMake(0, fixationH+_showHeight, kScreenW, slideH);
  439. }
  440. else if (_isShow == YES)
  441. {
  442. segmentControl.frame = CGRectMake(0, fixationH+_lblShowH, kScreenW, slideH);
  443. }
  444. if (_isFirst == YES)
  445. {
  446. _isFirst = NO;
  447. [head addSubview:segmentControl];
  448. head.declarationLbl.textColor = kAppGrayColor1;
  449. [head.societyBgBtn addTarget:self action:@selector(societyBgClick) forControlEvents:UIControlEventTouchUpInside];
  450. [head.OperationBtn addTarget:self action:@selector(tiantuanOperationClick) forControlEvents:UIControlEventTouchUpInside];
  451. [head.moreBtn addTarget:self action:@selector(showOrHide:) forControlEvents:UIControlEventTouchUpInside];
  452. }
  453. [self tableViewHeadMsgSetup];
  454. return head;
  455. }
  456. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  457. {
  458. if (_isShow == NO)
  459. {
  460. return CGSizeMake(kScreenW, fixationH+_showHeight+slideH);
  461. }
  462. else
  463. {
  464. return CGSizeMake(kScreenW, fixationH+_lblShowH+slideH);
  465. }
  466. }
  467. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  468. {
  469. SociatyDetailModel *model = self.sociatyDetailArray[indexPath.row];
  470. if (segmentControl.selectedSegmentIndex == 0)
  471. {
  472. NSArray *items;
  473. //会长、正在直播
  474. if (self.type == 1)//查看的人身份是会长
  475. {
  476. //会长、没直播
  477. if (model.user_position.intValue == 1 && model.live_in.intValue == 0) {
  478. items = @[MMItemMake(ASLocalizedString(@"查看详情"), MMItemTypeNormal, ^(NSInteger index)
  479. {
  480. [self jumpOffToHomePageWithModel:model];
  481. })];
  482. }
  483. //普通主播
  484. else if (model.user_position.intValue == 0)
  485. {
  486. if (model.live_in.intValue == 1)
  487. {
  488. items = @[MMItemMake(ASLocalizedString(@"观看直播"), MMItemTypeNormal, ^(NSInteger index)
  489. {
  490. [self viewLivingWithIndex:indexPath.row];
  491. }),MMItemMake(ASLocalizedString(@"查看详情"), MMItemTypeNormal, ^(NSInteger index)
  492. {
  493. [self jumpOffToHomePageWithModel:model];
  494. }),MMItemMake(ASLocalizedString(@"踢出公会"), MMItemTypeNormal, ^(NSInteger index)
  495. {
  496. [self pleaseGoOutOfSocietyWithIndex:indexPath];
  497. })];
  498. }
  499. else if (model.live_in.intValue == 0)
  500. {
  501. items = @[MMItemMake(ASLocalizedString(@"查看详情"), MMItemTypeNormal, ^(NSInteger index)
  502. {
  503. [self jumpOffToHomePageWithModel:model];
  504. }),MMItemMake(ASLocalizedString(@"踢出公会"), MMItemTypeNormal, ^(NSInteger index)
  505. {
  506. [self pleaseGoOutOfSocietyWithIndex:indexPath];
  507. })];
  508. }
  509. }
  510. }
  511. else { //查看者不是会长
  512. if (model.live_in.intValue == 0)
  513. {
  514. items = @[MMItemMake(ASLocalizedString(@"查看详情"), MMItemTypeNormal, ^(NSInteger index)
  515. {
  516. [self jumpOffToHomePageWithModel:model];
  517. })];
  518. }
  519. else if (model.live_in.intValue == 1)
  520. {
  521. items = @[MMItemMake(ASLocalizedString(@"观看直播"), MMItemTypeNormal, ^(NSInteger index)
  522. {
  523. [self viewLivingWithIndex:indexPath.row];
  524. }),MMItemMake(ASLocalizedString(@"查看详情"), MMItemTypeNormal, ^(NSInteger index)
  525. {
  526. [self jumpOffToHomePageWithModel:model];
  527. })];
  528. }
  529. }
  530. [MMPopupWindow sharedWindow].touchWildToHide = YES;
  531. if (items.count > 0)
  532. {
  533. MMSheetView *alert = [[MMSheetView alloc] initWithTitle:nil items:items];
  534. [alert show];
  535. }
  536. }
  537. else
  538. {
  539. if (self.sociatyDetailArray.count > 0 && indexPath.row < self.sociatyDetailArray.count)
  540. {
  541. [self jumpOffToHomePageWithModel:model];
  542. }
  543. }
  544. }
  545. - (void)jumpOffToHomePageWithModel:(SociatyDetailModel *)model
  546. {
  547. SHomePageVC *homeVC = [[SHomePageVC alloc]init];
  548. homeVC.user_id = model.user_id;
  549. // homeVC.user_nickname = model.user_name;
  550. homeVC.type = 0;
  551. [[AppDelegate sharedAppDelegate]pushViewController:homeVC animated:YES];
  552. }
  553. #pragma mark ---------------------------------------------- 点击公会头像 ----------------------------------------------
  554. - (void)societyBgClick
  555. {
  556. if (!(self.type == 1))
  557. {
  558. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"你没有操作权限")];
  559. return;
  560. }
  561. else if (self.type == 1 && self.mygh_status == 0 && [self.flagStr isEqualToString:mySociety])
  562. {
  563. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"公会正在审核中")];
  564. return;
  565. }
  566. EditSocietyViewController * editSocietyVC = [[EditSocietyViewController alloc] init];
  567. editSocietyVC.type = 1;
  568. editSocietyVC.sociatyID = self.mySocietyID;
  569. editSocietyVC.sociatyName = head.societyNameLbl.text;
  570. editSocietyVC.sociatyManifasto = head.declarationLbl.text;
  571. editSocietyVC.sociaHead = self.tianTuanHeadImg;
  572. [self.navigationController pushViewController:editSocietyVC animated:YES];
  573. }
  574. #pragma mark ------------------------------------------------ 根据偏移量设置状态栏颜色 ----------------------------------------------
  575. //表头背景图片高度固定256,减去状态栏和导航栏高度 = 192,当偏移量 <= 192 状态栏为白色,反之为黑色
  576. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  577. {
  578. if (isIOS11()) {
  579. if (scrollView.contentOffset.y >= -59 && scrollView.contentOffset.y <= 187.0 )
  580. {
  581. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  582. }
  583. else
  584. {
  585. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  586. }
  587. }
  588. else {
  589. if (scrollView.contentOffset.y >= -64 && scrollView.contentOffset.y <= 192.0 )
  590. {
  591. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  592. }
  593. else
  594. {
  595. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  596. }
  597. }
  598. }
  599. #pragma mark ------------------------------------------------ 加入、退出公会 ----------------------------------------------
  600. - (void)tiantuanOperationClick
  601. {
  602. if (self.type == 0)
  603. {
  604. FWWeakify(self)
  605. [FanweMessage alert:ASLocalizedString(@"退出公会")message:[NSString stringWithFormat:ASLocalizedString(@"是否退出公会:%@?"),head.societyNameLbl.text] destructiveAction:^{
  606. FWStrongify(self)
  607. NSMutableDictionary *parmDict = [self parmDictWithCtlValue:@"society_app" actValue:@"society_out" isAgree:@"" forId:@"" model:nil parmType:0];
  608. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  609. if ([responseJson toInt:@"status"]==1)
  610. {
  611. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"退会申请已提交")];
  612. [self operationWithWidth:100 title:ASLocalizedString(@"退会申请中")imageStr:@""];
  613. self.type = 5;
  614. }
  615. } FailureBlock:^(NSError *error) {
  616. }];
  617. } cancelAction:^{
  618. }];
  619. return;
  620. }
  621. else if (self.type == 3)
  622. {
  623. NSMutableDictionary *parmDict = [self parmDictWithCtlValue:@"society_app" actValue:@"society_join" isAgree:@"" forId:@"" model:nil parmType:0];
  624. FWWeakify(self)
  625. [FanweMessage alert:ASLocalizedString(@"加入公会")message:[NSString stringWithFormat:ASLocalizedString(@"是否加入公会:%@?"),head.societyNameLbl.text] destructiveAction:^{
  626. FWStrongify(self)
  627. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  628. if ([responseJson toInt:@"status"]==1)
  629. {
  630. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"入会申请已提交")];
  631. [self operationWithWidth:100 title:ASLocalizedString(@"入会申请中")imageStr:@""];
  632. self.type = 4;
  633. }
  634. } FailureBlock:^(NSError *error) {
  635. }];
  636. } cancelAction:^{
  637. }];
  638. return;
  639. }
  640. else if (self.type == 4)
  641. {
  642. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"入会申请中")];
  643. return;
  644. }
  645. else if (self.type == 5)
  646. {
  647. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"退会申请中")];
  648. return;
  649. }
  650. if (self.mygh_status == 2)
  651. {
  652. NSMutableDictionary *parmDict = [self parmDictWithCtlValue:@"society_app" actValue:@"society_agree" isAgree:@"" forId:@"" model:nil parmType:0];
  653. FWWeakify(self)
  654. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  655. if ([responseJson toInt:@"status"] == 1)
  656. {
  657. FWStrongify(self)
  658. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"申请已提交")];
  659. [self propertyWithBtnEnable:NO btnTitle:ASLocalizedString(@"状态:审核中")];
  660. head.operationBtnW.constant = 100;
  661. self.mygh_status = 0;
  662. }
  663. } FailureBlock:^(NSError *error) {
  664. }];
  665. }
  666. //邀请码从第四位开始取
  667. if (head.OperationBtn.currentTitle.length > 3)
  668. {
  669. UIPasteboard *pab = [UIPasteboard generalPasteboard];
  670. [pab setString:[head.OperationBtn.currentTitle substringFromIndex:4]];
  671. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"已复制")];
  672. }
  673. }
  674. #pragma mark ----------------------------------- 踢出公会 -----------------------------------
  675. - (void)pleaseLeaveWithSocietyMember:(FansCell *)cell
  676. {
  677. NSIndexPath *index = [self.detailCollectionView indexPathForCell:cell];
  678. [self pleaseGoOutOfSocietyWithIndex:index];
  679. }
  680. - (void)pleaseGoOutOfSocietyWithIndex:(NSIndexPath *)index
  681. {
  682. FWWeakify(self)
  683. [FanweMessage alert:ASLocalizedString(@"踢出成员")message:ASLocalizedString(@"是否踢出该成员?")destructiveAction:^{
  684. FWStrongify(self)
  685. SociatyDetailModel *model = self.sociatyDetailArray[index.row];
  686. NSMutableDictionary *parmDict = [self parmDictWithCtlValue:@"society_app" actValue:@"member_del" isAgree:@"1" forId:@"member_id" model:model parmType:1];
  687. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  688. if ([responseJson toInt:@"status"]==1)
  689. {
  690. [self deleteSelectRowWithNSIndexPath:index];
  691. }
  692. } FailureBlock:^(NSError *error) {
  693. }];
  694. } cancelAction:^{
  695. }];
  696. }
  697. #pragma mark ------------------------------- 观看直播 ----------------------------------
  698. - (void)viewLiving:(ApplicantCell *)cell
  699. {
  700. NSIndexPath *index = [self.detailCollectionView indexPathForCell:cell];
  701. [self viewLivingWithIndex:index.row];
  702. }
  703. - (void)fansViewLiving:(FansCell *)cell
  704. {
  705. NSIndexPath *index = [self.detailCollectionView indexPathForCell:cell];
  706. [self viewLivingWithIndex:index.row];
  707. }
  708. - (void)viewLivingWithIndex:(NSInteger)index
  709. {
  710. SociatyDetailModel *model = self.sociatyDetailArray[index];
  711. NSMutableDictionary *paramDict = [NSMutableDictionary dictionary];
  712. [paramDict setObject:@"society_app" forKey:@"ctl"];
  713. [paramDict setObject:@"join_zb" forKey:@"act"];
  714. [paramDict setObject:[NSNumber numberWithInt:[model.user_id intValue]]forKey:@"member_id"];
  715. if (![BGUtils isNetConnected])
  716. {
  717. return;
  718. }
  719. if ([self checkUser:[IMAPlatform sharedInstance].host])
  720. {
  721. TCShowLiveListItem *item = [[TCShowLiveListItem alloc]init];
  722. item.chatRoomId = model.group_id;
  723. item.avRoomId = [model.room_id intValue];
  724. item.title = model.room_id;
  725. item.vagueImgUrl = model.user_image;
  726. TCShowUser *showUser = [[TCShowUser alloc]init];
  727. showUser.uid = model.user_id;
  728. showUser.avatar = model.user_image;
  729. item.host = showUser;
  730. if ([model.live_in intValue] == FW_LIVE_STATE_ING)
  731. {
  732. item.liveType = FW_LIVE_TYPE_AUDIENCE;
  733. }
  734. // else if ([model.live_in intValue] == FW_LIVE_STATE_RELIVE)
  735. // {
  736. // item.liveType = FW_LIVE_TYPE_RELIVE;
  737. // }
  738. //2020-1-7 小直播变大
  739. [LiveCenterManager sharedInstance].itemModel=item;
  740. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  741. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:item modelArr:self.sociatyDetailArray isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL isFinished) {
  742. }];
  743. }
  744. else
  745. {
  746. [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
  747. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  748. } completion:^{
  749. }];
  750. }
  751. }
  752. - (BOOL)checkUser:(id<IMHostAble>)user
  753. {
  754. if (![user conformsToProtocol:@protocol(AVUserAble)])
  755. {
  756. return NO;
  757. }
  758. return YES;
  759. }
  760. #pragma mark ------------------------------------- 拒绝申请 ----------------------------------------
  761. - (void)refuseOfSociety:(ApplicantCell *)cell
  762. {
  763. NSIndexPath *index = [self.detailCollectionView indexPathForCell:cell];
  764. SociatyDetailModel *model = self.sociatyDetailArray[index.row];
  765. //拒绝加入公会
  766. if (segmentControl.selectedSegmentIndex == 2)
  767. {
  768. FWWeakify(self)
  769. [FanweMessage alert:ASLocalizedString(@"拒绝加入公会")message:ASLocalizedString(@"是否拒绝该成员加入公会?")destructiveAction:^{
  770. FWStrongify(self)
  771. NSMutableDictionary *parmDict = [self parmDictWithCtlValue:@"society_app" actValue:@"join_check" isAgree:@"0" forId:@"applyFor_id" model:model parmType:2];
  772. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  773. if ([responseJson toInt:@"status"] == 1)
  774. {
  775. [self deleteSelectRowWithNSIndexPath:index];
  776. }
  777. } FailureBlock:^(NSError *error) {
  778. }];
  779. } cancelAction:^{
  780. }];
  781. }
  782. //拒绝退出公会
  783. else if (segmentControl.selectedSegmentIndex == 3)
  784. {
  785. FWWeakify(self)
  786. [FanweMessage alert:ASLocalizedString(@"拒绝退出公会")message:ASLocalizedString(@"是否拒绝该成员退出公会?")destructiveAction:^{
  787. FWStrongify(self)
  788. NSMutableDictionary *parmDict = [self parmDictWithCtlValue:@"society_app" actValue:@"out_check" isAgree:@"0" forId:@"applyFor_id" model:model parmType:2];
  789. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  790. if ([responseJson toInt:@"status"] == 1)
  791. {
  792. [self deleteSelectRowWithNSIndexPath:index];
  793. }
  794. } FailureBlock:^(NSError *error) {
  795. }];
  796. } cancelAction:^{
  797. }];
  798. }
  799. }
  800. #pragma mark ------------------------------------- 同意申请 ----------------------------------------
  801. - (void)agreeOfSociety:(ApplicantCell *)cell
  802. {
  803. NSIndexPath *index = [self.detailCollectionView indexPathForCell:cell];
  804. SociatyDetailModel *model = self.sociatyDetailArray[index.row];
  805. if (segmentControl.selectedSegmentIndex == 2)
  806. {
  807. FWWeakify(self)
  808. [FanweMessage alert:ASLocalizedString(@"同意加入公会")message:ASLocalizedString(@"是否同意该成员加入公会?")destructiveAction:^{
  809. FWStrongify(self)
  810. NSMutableDictionary *parmDict = [self parmDictWithCtlValue:@"society_app" actValue:@"join_check" isAgree:@"1" forId:@"applyFor_id" model:model parmType:2];
  811. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  812. if ([responseJson toInt:@"status"]==1)
  813. {
  814. [self deleteSelectRowWithNSIndexPath:index];
  815. }
  816. } FailureBlock:^(NSError *error) {
  817. }];
  818. } cancelAction:^{
  819. }];
  820. }
  821. else if (segmentControl.selectedSegmentIndex == 3)
  822. {
  823. FWWeakify(self)
  824. [FanweMessage alert:ASLocalizedString(@"同意退出公会")message:ASLocalizedString(@"是否同意该成员退出公会?")destructiveAction:^{
  825. FWStrongify(self)
  826. NSMutableDictionary *parmDict = [self parmDictWithCtlValue:@"society_app" actValue:@"out_check" isAgree:@"1" forId:@"applyFor_id" model:model parmType:2];
  827. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  828. if ([responseJson toInt:@"status"]==1)
  829. {
  830. [self deleteSelectRowWithNSIndexPath:index];
  831. }
  832. } FailureBlock:^(NSError *error) {
  833. }];
  834. } cancelAction:^{
  835. }];
  836. }
  837. }
  838. - (NSMutableDictionary *)parmDictWithCtlValue:(NSString *)ctlValue actValue:(NSString *)actValue isAgree:(NSString *)isAgree forId:(NSString *)forId model:(SociatyDetailModel *)model parmType:(int)type
  839. {
  840. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  841. [parmDict setObject:ctlValue forKey:@"ctl"];
  842. [parmDict setObject:actValue forKey:@"act"];
  843. if (type == 1)
  844. {
  845. [parmDict setObject:[NSNumber numberWithInt:[model.user_id intValue]] forKey:forId];
  846. }
  847. else if (type == 2)
  848. {
  849. [parmDict setObject:[NSNumber numberWithInt:[model.user_id intValue]] forKey:forId];
  850. [parmDict setObject:isAgree forKey:@"is_agree"];
  851. }
  852. [parmDict setObject:[NSNumber numberWithInt:self.mySocietyID] forKey:@"society_id"];
  853. return parmDict;
  854. }
  855. - (void)deleteSelectRowWithNSIndexPath:(NSIndexPath *)index
  856. {
  857. [self.sociatyDetailArray removeObjectAtIndex:index.row];
  858. [self judgeUsageWhichOne];
  859. [self.detailCollectionView reloadData];
  860. }
  861. - (void)viewDidLoad
  862. {
  863. [super viewDidLoad];
  864. }
  865. - (void)viewWillAppear:(BOOL)animated
  866. {
  867. [super viewWillAppear:animated];
  868. [self.navigationController setNavigationBarHidden:YES animated:NO];
  869. [self requestDataWithPage:1 withDetailType:(int)segmentControl.selectedSegmentIndex];
  870. }
  871. - (void)viewWillDisappear:(BOOL)animated
  872. {
  873. [super viewWillDisappear:animated];
  874. [self.navigationController setNavigationBarHidden:NO animated:NO];
  875. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  876. }
  877. @end