MOLiveCenterView.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. //
  2. // MOLiveCenterView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/12/5.
  6. //
  7. //一页的size
  8. #define kPageSize 15
  9. #import "MOLiveCenterView.h"
  10. #import "MOLiveCenterTableView.h"
  11. #import "MOLiveCenterRecordListView.h"
  12. #import "MOCenterDataModels.h"
  13. @interface MOLiveCenterView ()
  14. @property (weak, nonatomic) IBOutlet UIView *bgView;
  15. @property (weak, nonatomic) IBOutlet UILabel *topTitleLab;
  16. @property (weak, nonatomic) IBOutlet UIView *allIncomeView;
  17. @property (weak, nonatomic) IBOutlet UIButton *incomeTitleBtn;
  18. @property (weak, nonatomic) IBOutlet UIButton *goldNumBtn;
  19. @property (weak, nonatomic) IBOutlet UIView *fanView;
  20. @property (weak, nonatomic) IBOutlet UIButton *fanTitleBtn;
  21. @property (weak, nonatomic) IBOutlet UIButton *fanUpNumBtn;
  22. @property (weak, nonatomic) IBOutlet UIView *memberView;
  23. @property (weak, nonatomic) IBOutlet UIButton *memberTitleBtn;
  24. @property (weak, nonatomic) IBOutlet UIButton *memberNumBtn;
  25. @property (weak, nonatomic) IBOutlet UIView *populartyView;
  26. @property (weak, nonatomic) IBOutlet UIButton *populartyTitleBtn;
  27. @property (weak, nonatomic) IBOutlet UIButton *populartyNumBtn;
  28. @property (weak, nonatomic) IBOutlet BigBtn *giftBtn;
  29. @property (weak, nonatomic) IBOutlet BigBtn *ticketBtn;
  30. @property (weak, nonatomic) IBOutlet BigBtn *otherBtn;
  31. @property (weak, nonatomic) IBOutlet UILabel *totalLab;
  32. /** 当前选中的下标 */
  33. @property (nonatomic, assign) NSInteger selectIndex;
  34. @property (nonatomic, strong) MOLiveCenterTableView *giftTableView;
  35. @property (nonatomic, strong) MOLiveCenterTableView *ticketTableView;
  36. @property (nonatomic, strong) MOLiveCenterTableView *otherTableView;
  37. @property (nonatomic, copy) NSString *giftNext;
  38. @property (nonatomic, copy) NSString *ticketNext;
  39. @property (nonatomic, strong) MOLiveCenterData *baseModel;
  40. @property (nonatomic, strong) MOLiveCenterRecordListView *recordView;
  41. @end
  42. @implementation MOLiveCenterView
  43. + (instancetype)moLiveCenterView{
  44. return [[[NSBundle mainBundle] loadNibNamed:@"MOLiveCenterView" owner:self options:nil] firstObject];
  45. }
  46. - (void)awakeFromNib{
  47. [super awakeFromNib];
  48. self.topTitleLab.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalTitleFontStr];
  49. self.giftBtn.font = [MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr];
  50. self.ticketBtn.font = [MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr];
  51. self.otherBtn.font = [MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr];
  52. self.bgView.layer.cornerRadius = 12.0;
  53. self.bgView.layer.masksToBounds = YES;
  54. self.bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMinXMaxYCorner;
  55. self.allIncomeView.layer.cornerRadius = 10.0;
  56. self.allIncomeView.layer.masksToBounds = YES;
  57. self.incomeTitleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
  58. self.goldNumBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
  59. self.fanView.layer.cornerRadius = 10.0;
  60. self.fanView.layer.masksToBounds = YES;
  61. self.fanTitleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
  62. self.fanUpNumBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  63. self.fanUpNumBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 8);
  64. self.memberView.layer.cornerRadius = 10.0;
  65. self.memberView.layer.masksToBounds = YES;
  66. self.memberTitleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
  67. self.memberNumBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  68. self.memberNumBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 8);
  69. self.populartyView.layer.cornerRadius = 10.0;
  70. self.populartyView.layer.masksToBounds = YES;
  71. self.populartyTitleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
  72. self.populartyNumBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  73. self.populartyNumBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 8);
  74. self.giftBtn.layer.cornerRadius = 24.0 / 2.0;
  75. self.giftBtn.layer.masksToBounds = YES;
  76. self.ticketBtn.layer.cornerRadius = 24.0 / 2.0;
  77. self.ticketBtn.layer.masksToBounds = YES;
  78. self.otherBtn.layer.cornerRadius = 24.0 / 2.0;
  79. self.otherBtn.layer.masksToBounds = YES;
  80. CGFloat bgWidth = SCREENWIDTH - 90.0;
  81. CGFloat btnWidth = (bgWidth - 15.0 * 2 - 12.0 * 2) / 3.0;
  82. CGFloat btnHeight = 24.0;
  83. NSArray *normalColorArr = @[[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0],[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0]];
  84. UIImage *normalImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 36.0 * 2), 50.0) Colors:normalColorArr GradientType:0];
  85. NSArray *selectColorArr = @[kBaseBtnBgColor,kBaseBtnBgColor];
  86. UIImage *selectImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 36.0 * 2), 50.0) Colors:selectColorArr GradientType:0];
  87. [self.giftBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
  88. [self.giftBtn setBackgroundImage:selectImage forState:UIControlStateSelected];
  89. [self.ticketBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
  90. [self.ticketBtn setBackgroundImage:selectImage forState:UIControlStateSelected];
  91. [self.otherBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
  92. [self.otherBtn setBackgroundImage:selectImage forState:UIControlStateSelected];
  93. [self.bgView addSubview:self.giftTableView];
  94. [self.giftTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.top.equalTo(self.totalLab.mas_bottom).offset(6.0);
  96. make.left.bottom.right.equalTo(self.bgView);
  97. }];
  98. [self.bgView addSubview:self.ticketTableView];
  99. [self.ticketTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.top.equalTo(self.totalLab.mas_bottom).offset(6.0);
  101. make.left.bottom.right.equalTo(self.bgView);
  102. }];
  103. [self.bgView addSubview:self.otherTableView];
  104. [self.otherTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.top.equalTo(self.totalLab.mas_bottom).offset(6.0);
  106. make.left.bottom.right.equalTo(self.bgView);
  107. }];
  108. [self setTableViewBlock];
  109. self.selectIndex = 0;
  110. self.giftNext = @"";
  111. self.ticketNext = @"";
  112. }
  113. - (void)setTableViewBlock{
  114. WEAKSELF
  115. //MARK: 礼物Cell点击
  116. self.giftTableView.cellClickBlock = ^(MOPersonList * _Nonnull cellModel) {
  117. [weakSelf showLiveCenterRecordWith:cellModel.userBase isWish:NO];
  118. };
  119. self.otherTableView.wishCellClickBlock = ^{
  120. [weakSelf showLiveCenterRecordWith:nil isWish:YES];
  121. };
  122. }
  123. - (void)showLiveCenterRecordWith:(MOUserBase *)userModel isWish:(BOOL)isWish{
  124. CGFloat width = SCREENWIDTH - 90.0;
  125. [self addSubview:self.recordView];
  126. [self.recordView mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.left.equalTo(self).offset(90.0);
  128. make.width.equalTo(@(width));
  129. make.top.bottom.equalTo(self);
  130. }];
  131. self.recordView.roomId = self.roomId;
  132. if(isWish){
  133. self.recordView.cellType = MOLiveCenterRecordWishCellType;
  134. }
  135. else{
  136. self.recordView.cellType = MOLiveCenterRecordGiftCellType;
  137. self.recordView.userInfo = userModel;
  138. }
  139. [self.recordView showLiveCenterRecordListView];
  140. [self.recordView getHttpFirstData];
  141. }
  142. - (void)getAllHttpData{
  143. NSString *roomId = self.roomId;
  144. if(roomId.length == 0){
  145. return;
  146. }
  147. [self getHttpDataAboutCentenInfoWith:roomId];
  148. NSDictionary *giftPage = @{@"size":@(kPageSize),@"next":self.giftNext};
  149. NSDictionary *giftDict = @{@"page":giftPage,
  150. @"roomId":roomId};
  151. [self getHttpDataAboutGiftListWisthDict:giftDict];
  152. NSDictionary *ticketPage = @{@"size":@(kPageSize),@"next":self.ticketNext};
  153. NSDictionary *ticketDict = @{@"page":ticketPage,
  154. @"roomId":roomId};
  155. [self getHttpDataAboutTicketListWisthDict:ticketDict];
  156. }
  157. - (void)getHttpDataAboutCentenInfoWith:(NSString *)roomId{
  158. WEAKSELF
  159. NSDictionary *dict = @{@"id":roomId};
  160. [kHttpManager theLiveCenterInfoWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  161. if(kCode_Success){
  162. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  163. weakSelf.baseModel = [MOLiveCenterData modelObjectWithDictionary:data[@"data"]];
  164. [weakSelf setUIProperty];
  165. }
  166. else{
  167. kShowNetError(data)
  168. }
  169. }];
  170. }
  171. - (void)setUIProperty{
  172. CGFloat allGoldNum = self.baseModel.giftGoldenBean + self.baseModel.ticketGoldenBean + self.baseModel.otherGoldenBean + self.baseModel.likeGoldenBean + self.baseModel.divideGoldenBean;
  173. [self.goldNumBtn setTitle:[NSString stringWithFormat:@"%.f",allGoldNum] forState:UIControlStateNormal];
  174. [self.fanUpNumBtn setTitle:[NSString stringWithFormat:@"%.f",self.baseModel.fans] forState:UIControlStateNormal];
  175. [self.memberNumBtn setTitle:[NSString stringWithFormat:@"%.f",self.baseModel.members] forState:UIControlStateNormal];
  176. [self.populartyNumBtn setTitle:[NSString stringWithFormat:@"%.f",self.baseModel.popularity] forState:UIControlStateNormal];
  177. self.totalLab.text = [NSString stringWithFormat:@"Total %.f",self.baseModel.giftGoldenBean];
  178. self.otherTableView.otherGoldenBean = self.baseModel.otherGoldenBean;
  179. self.otherTableView.likeGoldenBean = self.baseModel.likeGoldenBean;
  180. self.otherTableView.divideGoldenBean = self.baseModel.divideGoldenBean;
  181. [self.otherTableView reloadData];
  182. }
  183. - (void)getHttpDataAboutGiftListWisthDict:(NSDictionary *)dict{
  184. WEAKSELF
  185. [kHttpManager theLiveCenterAboutGiftUserWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  186. __strong typeof(weakSelf) self = weakSelf;
  187. [self.giftTableView.mj_footer endRefreshing];
  188. if(kCode_Success){
  189. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  190. MOPersonData *personModel = [MOPersonData modelObjectWithDictionary:data[@"data"]];
  191. if(personModel.next == nil || personModel.next.length == 0){
  192. if(self.giftNext == nil || self.giftNext.length == 0){
  193. //第一页
  194. self.giftTableView.dataArr = [personModel.personList mutableCopy];
  195. }
  196. else{
  197. //最后一页
  198. [self.giftTableView.dataArr addObjectsFromArray:personModel.personList];
  199. }
  200. self.giftNext = @"";
  201. [self.giftTableView.mj_footer endRefreshingWithNoMoreData];
  202. }
  203. else{
  204. self.giftNext = personModel.next;
  205. [self.giftTableView.dataArr addObjectsFromArray:personModel.personList];
  206. }
  207. [self.giftTableView reloadData];
  208. self.giftTableView.mj_footer.hidden = (self.giftTableView.dataArr.count > 0) ? NO : YES;
  209. }
  210. else{
  211. kShowNetError(data)
  212. }
  213. }];
  214. }
  215. - (void)getHttpDataAboutTicketListWisthDict:(NSDictionary *)dict{
  216. WEAKSELF
  217. [kHttpManager theLiveCenterAboutTicketWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  218. __strong typeof(weakSelf) self = weakSelf;
  219. [self.ticketTableView.mj_footer endRefreshing];
  220. if(kCode_Success){
  221. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  222. MOPersonData *personModel = [MOPersonData modelObjectWithDictionary:data[@"data"]];
  223. if(personModel.next == nil || personModel.next.length == 0){
  224. if(self.ticketNext == nil || self.ticketNext.length == 0){
  225. //第一页
  226. self.ticketTableView.dataArr = [personModel.personList mutableCopy];
  227. }
  228. else{
  229. //最后一页
  230. [self.ticketTableView.dataArr addObjectsFromArray:personModel.personList];
  231. }
  232. self.ticketNext = @"";
  233. [self.ticketTableView.mj_footer endRefreshingWithNoMoreData];
  234. }
  235. else{
  236. self.ticketNext = personModel.next;
  237. [self.ticketTableView.dataArr addObjectsFromArray:personModel.personList];
  238. }
  239. [self.ticketTableView reloadData];
  240. self.ticketTableView.mj_footer.hidden = (self.ticketTableView.dataArr.count > 0) ? NO : YES;
  241. }
  242. else{
  243. kShowNetError(data)
  244. }
  245. }];
  246. }
  247. //关闭 视图
  248. - (IBAction)closeBtnClick:(id)sender {
  249. [self dismissLiveCenterView];
  250. }
  251. - (IBAction)typeChangeBtnClick:(BigBtn *)sender {
  252. if(sender == self.giftBtn){
  253. self.selectIndex = 0;
  254. }
  255. else if (sender == self.ticketBtn){
  256. self.selectIndex = 1;
  257. }
  258. else{
  259. self.selectIndex = 2;
  260. }
  261. }
  262. - (void)setSelectIndex:(NSInteger)selectIndex{
  263. _selectIndex = selectIndex;
  264. if(selectIndex == 0){
  265. self.giftBtn.selected = YES;
  266. self.ticketBtn.selected = NO;
  267. self.otherBtn.selected = NO;
  268. self.giftTableView.hidden = NO;
  269. self.ticketTableView.hidden = YES;
  270. self.otherTableView.hidden = YES;
  271. self.totalLab.text = [NSString stringWithFormat:@"Total %.f",self.baseModel.giftGoldenBean];
  272. }
  273. else if (selectIndex == 1){
  274. self.giftBtn.selected = NO;
  275. self.ticketBtn.selected = YES;
  276. self.otherBtn.selected = NO;
  277. self.giftTableView.hidden = YES;
  278. self.ticketTableView.hidden = NO;
  279. self.otherTableView.hidden = YES;
  280. self.totalLab.text = [NSString stringWithFormat:@"Total %.f",self.baseModel.ticketGoldenBean];
  281. }
  282. else{
  283. self.giftBtn.selected = NO;
  284. self.ticketBtn.selected = NO;
  285. self.otherBtn.selected = YES;
  286. self.giftTableView.hidden = YES;
  287. self.ticketTableView.hidden = YES;
  288. self.otherTableView.hidden = NO;
  289. self.otherTableView.otherGoldenBean = self.baseModel.otherGoldenBean;
  290. self.otherTableView.likeGoldenBean = self.baseModel.likeGoldenBean;
  291. CGFloat otherTotalNum = self.baseModel.otherGoldenBean + self.baseModel.likeGoldenBean + self.baseModel.divideGoldenBean;
  292. self.totalLab.text = [NSString stringWithFormat:@"Total %.f",otherTotalNum];
  293. }
  294. }
  295. #pragma mark - Show
  296. - (void)showLiveCenterView{
  297. self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
  298. CGRect actionViewRect = self.bgView.frame;
  299. actionViewRect.origin.x = SCREENWIDTH;
  300. self.bgView.frame = actionViewRect;
  301. WEAKSELF
  302. [UIView animateWithDuration:0.3 animations:^{
  303. CGRect actionViewRect = weakSelf.bgView.frame;
  304. actionViewRect.origin.x = 90.0;
  305. weakSelf.bgView.frame = actionViewRect;
  306. }];
  307. //不能滑动
  308. SendNotification(@"MOShowLivePagesVCCannotScroll")
  309. }
  310. - (void)dismissLiveCenterView{
  311. WEAKSELF
  312. [UIView animateWithDuration:0.3 animations:^
  313. {
  314. CGRect actionSheetViewRect = weakSelf.bgView.frame;
  315. actionSheetViewRect.origin.x = SCREENWIDTH;
  316. weakSelf.bgView.frame = actionSheetViewRect;
  317. } completion:^(BOOL finished)
  318. {
  319. [self removeFromSuperview];
  320. }];
  321. //可以滑动
  322. SendNotification(@"MOShowLivePagesVCCanScroll")
  323. }
  324. #pragma mark - Lazy
  325. - (MOLiveCenterTableView *)giftTableView{
  326. if(!_giftTableView){
  327. _giftTableView = [[MOLiveCenterTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  328. _giftTableView.backgroundColor = [UIColor clearColor];
  329. _giftTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  330. _giftTableView.separatorInset = UIEdgeInsetsZero;
  331. _giftTableView.cellType = MOLiveCenterUserCellType;
  332. _giftTableView.rowHeight = 65.0;
  333. WEAKSELF
  334. _giftTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  335. if(weakSelf.giftNext.length == 0){
  336. return;
  337. }
  338. NSString *roomId = weakSelf.roomId;
  339. if(roomId.length == 0){
  340. return;
  341. }
  342. NSDictionary *giftPage = @{@"size":@(kPageSize),@"next":weakSelf.giftNext};
  343. NSDictionary *giftDict = @{@"page":giftPage,
  344. @"roomId":roomId};
  345. [weakSelf getHttpDataAboutGiftListWisthDict:giftDict];
  346. }];
  347. _giftTableView.mj_footer.hidden = YES;
  348. }
  349. return _giftTableView;
  350. }
  351. - (MOLiveCenterTableView *)ticketTableView{
  352. if(!_ticketTableView){
  353. _ticketTableView = [[MOLiveCenterTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  354. _ticketTableView.backgroundColor = [UIColor clearColor];
  355. _ticketTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  356. _ticketTableView.separatorInset = UIEdgeInsetsZero;
  357. _ticketTableView.cellType = MOLiveCenterUserCellType;
  358. _ticketTableView.rowHeight = 65.0;
  359. WEAKSELF
  360. _ticketTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  361. if(weakSelf.giftNext.length == 0){
  362. return;
  363. }
  364. NSString *roomId = weakSelf.roomId;
  365. if(roomId.length == 0){
  366. return;
  367. }
  368. NSDictionary *ticketPage = @{@"size":@(kPageSize),@"next":weakSelf.ticketNext};
  369. NSDictionary *ticketDict = @{@"page":ticketPage,
  370. @"roomId":roomId};
  371. [weakSelf getHttpDataAboutTicketListWisthDict:ticketDict];
  372. }];
  373. _ticketTableView.mj_footer.hidden = YES;
  374. }
  375. return _ticketTableView;
  376. }
  377. - (MOLiveCenterTableView *)otherTableView{
  378. if(!_otherTableView){
  379. _otherTableView = [[MOLiveCenterTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  380. _otherTableView.backgroundColor = [UIColor clearColor];
  381. _otherTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  382. _otherTableView.separatorInset = UIEdgeInsetsZero;
  383. _otherTableView.cellType = MOLiveCenterWishListCellType;
  384. _otherTableView.rowHeight = 65.0;
  385. }
  386. return _otherTableView;
  387. }
  388. - (MOLiveCenterRecordListView *)recordView{
  389. if(!_recordView){
  390. _recordView = [MOLiveCenterRecordListView moLiveCenterRecordListView];
  391. }
  392. return _recordView;
  393. }
  394. @end