MsgSysVC.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // MsgSysVC.m
  3. // YBVideo
  4. //
  5. // Created by YunBao on 2018/8/2.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "MsgSysVC.h"
  9. #import "MsgSysModel.h"
  10. #import "MsgSysCell.h"
  11. #import "PubH5.h"
  12. @interface MsgSysVC ()<UITableViewDelegate,UITableViewDataSource>
  13. {
  14. int _paging;
  15. }
  16. @property(nonatomic,strong)UITableView *tableView;
  17. @property(nonatomic,strong)NSMutableArray *dataArray;
  18. @property(nonatomic,strong)NSArray *sysModels;
  19. @end
  20. @implementation MsgSysVC
  21. - (UIStatusBarStyle)preferredStatusBarStyle {
  22. if (@available(iOS 13.0,*)) {
  23. return UIStatusBarStyleDarkContent;
  24. }
  25. return UIStatusBarStyleDefault;
  26. }
  27. -(void)viewWillAppear:(BOOL)animated{
  28. [super viewWillAppear:animated];
  29. [self pullData];
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. self.view.backgroundColor = [UIColor whiteColor];
  34. self.subNavi.backgroundColor = UIColor.whiteColor;
  35. self.titleL.textColor = UIColor.blackColor;
  36. self.titleL.text = _listModel.unameStr;
  37. [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
  38. self.naviLine.hidden = NO;
  39. self.naviLine.backgroundColor = RGB(245, 245, 245);
  40. self.dataArray = [NSMutableArray array];
  41. self.sysModels = [NSArray array];
  42. _paging = 1;
  43. [self.view addSubview:self.tableView];
  44. }
  45. #pragma mark -
  46. - (NSArray *)sysModels {
  47. NSMutableArray *m_array = [NSMutableArray array];
  48. for (NSDictionary *dic in _dataArray) {
  49. MsgSysModel *model = [MsgSysModel modelWithDic:dic lisModel:_listModel];
  50. [m_array addObject:model];
  51. }
  52. _sysModels = m_array;
  53. return _sysModels;
  54. }
  55. -(void)pullData {
  56. NSString *url;
  57. if ([_listModel.uidStr isEqual:@"dsp_admin_1"]) {
  58. //官方
  59. url = [NSString stringWithFormat:@"Message.officialLists&p=%d",_paging];
  60. }else{
  61. //系统
  62. url = [NSString stringWithFormat:@"Message.systemnotifyLists&uid=%@&token=%@&p=%d",[Config getOwnID],[Config getOwnToken],_paging];
  63. }
  64. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  65. [_tableView.mj_footer endRefreshing];
  66. [_tableView.mj_header endRefreshing];
  67. if (code == 0) {
  68. NSArray *infoA = [NSArray arrayWithArray:info];
  69. if (_paging == 1) {
  70. [_dataArray removeAllObjects];
  71. }
  72. if (infoA.count <=0 ) {
  73. [_tableView.mj_footer endRefreshingWithNoMoreData];
  74. }else{
  75. [_dataArray addObjectsFromArray:infoA];
  76. }
  77. if (_dataArray.count <=0) {
  78. [PublicView showTextNoData:_tableView text1:@"" text2:YZMsg(@"暂无数据") centerY:0.8];
  79. }else{
  80. [PublicView hiddenTextNoData:_tableView];
  81. }
  82. [_tableView reloadData];
  83. }else{
  84. [MBProgressHUD showPop:msg];
  85. }
  86. } Fail:^(id fail) {
  87. [_tableView.mj_footer endRefreshing];
  88. [_tableView.mj_header endRefreshing];
  89. }];
  90. }
  91. -(void)refreshFooter {
  92. _paging +=1;
  93. [self pullData];
  94. }
  95. #pragma mark - UITableViewDelegate、UITableViewDataSource
  96. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  97. return self.sysModels.count;
  98. }
  99. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  100. MsgSysCell *cell = [MsgSysCell cellWithTab:tableView andIndexPath:indexPath];
  101. cell.model = _sysModels[indexPath.row];
  102. cell.isWhiteStyle = _isWhiteStyle;
  103. cell.selectedBackgroundView = [[UIImageView alloc]initWithImage:[PublicObj getImgWithColor:UIColor.whiteColor]];
  104. return cell;
  105. }
  106. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  107. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  108. MsgSysModel *model = _sysModels[indexPath.row];
  109. if ([model.uidStr isEqual:@"dsp_admin_1"]) {
  110. PubH5 *h5 = [[PubH5 alloc]init];
  111. h5.url = model.urlStr;
  112. [self.navigationController pushViewController:h5 animated:YES];
  113. }
  114. }
  115. #pragma mark - set/get
  116. -(UITableView *)tableView {
  117. if (!_tableView) {
  118. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight, _window_width, _window_height - 64-statusbarHeight-ShowDiff)style:UITableViewStylePlain];
  119. _tableView.delegate = self;
  120. _tableView.dataSource = self;
  121. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  122. _tableView.backgroundColor =UIColor.whiteColor;// _isWhiteStyle?[UIColor whiteColor]: Normal_Color;
  123. //先设置预估行高
  124. _tableView.estimatedRowHeight = 200;
  125. //再设置自动计算行高
  126. _tableView.rowHeight = UITableViewAutomaticDimension;
  127. YBWeakSelf;
  128. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  129. _paging = 1;
  130. [weakSelf pullData];
  131. }];
  132. MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(refreshFooter)];
  133. _tableView.mj_footer = footer;
  134. [footer setTitle:YZMsg(@"数据加载中...") forState:MJRefreshStateRefreshing];
  135. [footer setTitle:@"" forState:MJRefreshStateIdle];//YZMsg(@"没有更多了哦~")
  136. [footer setTitle:@"" forState:MJRefreshStateNoMoreData];//YZMsg(@"没有更多了哦~")
  137. footer.stateLabel.font = [UIFont systemFontOfSize:15.0f];
  138. }
  139. return _tableView;
  140. }
  141. #pragma mark - 导航
  142. - (void)didReceiveMemoryWarning {
  143. [super didReceiveMemoryWarning];
  144. }
  145. - (void)reloadSystemView{
  146. [_tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  147. make.width.height.centerX.centerY.equalTo(self.view);
  148. }];
  149. _paging = 1;
  150. [self pullData];
  151. }
  152. - (void)hideSmallView{
  153. if (self.block) {
  154. self.block(0);
  155. }
  156. }
  157. - (void)imSmallViewReload{
  158. /*
  159. UIView *smallNavi = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 35)];
  160. smallNavi.backgroundColor = RGB_COLOR(@"#f9fafb", 1);;
  161. [self.view addSubview:smallNavi];
  162. UIButton *btn = [UIButton buttonWithType:0];
  163. btn.frame = CGRectMake(0, 0, 35, 35);
  164. [btn setImage:[UIImage imageNamed:@"gray_back"] forState:0];
  165. btn.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
  166. [btn addTarget:self action:@selector(hideSmallView) forControlEvents:UIControlEventTouchUpInside];
  167. [smallNavi addSubview:btn];
  168. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(35, 0, _window_width-70, 35)];
  169. titleLabel.font = [UIFont systemFontOfSize:13];
  170. titleLabel.textColor= RGB_COLOR(@"#636464", 1);
  171. titleLabel.textAlignment = NSTextAlignmentCenter;
  172. titleLabel.text = YZMsg(@"系统消息");
  173. [smallNavi addSubview:titleLabel];
  174. _tableView.frame = CGRectMake(0, 35, _window_width, _window_height*0.4-35);
  175. */
  176. [_tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  177. make.width.height.centerX.centerY.equalTo(self.view);
  178. }];
  179. _paging = 1;
  180. [self pullData];
  181. }
  182. @end