ModelFansViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // ModelFansViewController.m
  3. // 千模
  4. //
  5. // Created by Drew on 2018/12/24.
  6. // Copyright © 2018 MUMEI. All rights reserved.
  7. //
  8. #import "ModelFansViewController.h"
  9. #import "ModelFansTableViewCell.h"
  10. #import "Masonry.h"
  11. #import "GroupSendViewController.h"
  12. @interface ModelFansViewController () <UITableViewDelegate, UITableViewDataSource> {
  13. NSInteger page;
  14. }
  15. @property(weak, nonatomic) IBOutlet UITableView *tableView;
  16. @property(nonatomic, strong) NSMutableArray *data;
  17. @property(nonatomic, strong) UIView *headView;
  18. @end
  19. @implementation ModelFansViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. page = 1;
  23. self.navigationItem.title = @"粉丝团";
  24. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)];
  25. self.navigationItem.leftBarButtonItem = leftItem;
  26. self.navigationController.navigationBar.tintColor = [UIColor blackColor];
  27. self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F4F5"];
  28. self.data = [NSMutableArray arrayWithCapacity:0];
  29. self.tableView.backgroundColor = [UIColor clearColor];
  30. self.tableView.delegate = self;
  31. self.tableView.dataSource = self;
  32. self.tableView.contentInset = UIEdgeInsetsMake(5, 0, 5, 0);
  33. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  34. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refresh)];
  35. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
  36. if ([self.modelPK isEqualToString:[ModelUser user].modelpk]) {
  37. self.tableView.tableHeaderView = self.headView;
  38. }
  39. [self getData];
  40. }
  41. - (void)viewWillAppear:(BOOL)animated {
  42. [super viewWillAppear:animated];
  43. self.navigationController.navigationBar.tintColor = [UIColor blackColor];
  44. }
  45. - (void)backClick {
  46. [self.navigationController popViewControllerAnimated:YES];
  47. }
  48. - (void)getData {
  49. NSString *url = [NSString stringWithFormat:@"%@/modelInfo?action=modelfans&modelpk=%@&page=%zd&size=20", PublicUrl, self.modelPK, page];
  50. [[AHHttpManager sharedManager]
  51. POST:url
  52. parameters:nil
  53. success:^(id responseObject) {
  54. if ([@"success" isEqualToString:responseObject[@"msg"]]) {
  55. [self.tableView reloadData];
  56. NSArray *data = responseObject[@"data"];
  57. if (page == 1) {
  58. [self.data removeAllObjects];
  59. }
  60. [self.data addObjectsFromArray:data];
  61. [self.tableView reloadData];
  62. [self.tableView.mj_header endRefreshing];
  63. if (data.count < 20) {
  64. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  65. } else {
  66. [self.tableView.mj_footer endRefreshing];
  67. }
  68. }
  69. }
  70. failure:^(NSError *error) {
  71. }];
  72. }
  73. - (void)refresh {
  74. page = 1;
  75. [self getData];
  76. }
  77. - (void)loadMore {
  78. page++;
  79. [self getData];
  80. }
  81. - (UIView *)headView {
  82. if (!_headView) {
  83. _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
  84. UIButton *button = [[UIButton alloc] init];
  85. button.layer.backgroundColor = [UIColor colorWithRed:1.0 green:64 / 255.f blue:149 / 255.f alpha:1.0].CGColor;
  86. button.layer.cornerRadius = 22;
  87. [button setImage:[UIImage imageNamed:@"icon_liaotian"] forState:UIControlStateNormal];
  88. [button setTitle:@"群发消息" forState:UIControlStateNormal];
  89. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  90. button.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  91. [_headView addSubview:button];
  92. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.equalTo(_headView).offset(20);
  94. make.right.equalTo(_headView).offset(-20);
  95. make.height.mas_equalTo(44);
  96. make.centerY.equalTo(_headView);
  97. }];
  98. [button addTarget:self action:@selector(sendMsgToFans) forControlEvents:UIControlEventTouchUpInside];
  99. }
  100. return _headView;
  101. }
  102. - (void)sendMsgToFans {
  103. GroupSendViewController *vc = [[GroupSendViewController alloc] init];
  104. vc.modelPK = self.modelPK;
  105. [self.navigationController pushViewController:vc animated:YES];
  106. }
  107. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  108. return self.data.count;
  109. }
  110. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  111. ModelFansTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"ModelFansTableViewCell"];
  112. if (!cell) {
  113. NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ModelFansTableViewCell" owner:self options:nil];
  114. cell = nib[0];
  115. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  116. cell.data = self.data[indexPath.row];
  117. }
  118. return cell;
  119. }
  120. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  121. return 70;
  122. }
  123. @end