酷店

KDPNoticeViewController.m 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // KDPNoticeViewController.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/11.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPNoticeViewController.h"
  9. #import "KDPNoticeModel.h"
  10. #import "KDPMessageTableViewCell.h"
  11. @interface KDPNoticeViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, strong) NSMutableArray *dataSource;
  14. @property (nonatomic, assign) NSInteger page;
  15. @property (nonatomic, strong) UIButton *clearBtn;
  16. @end
  17. @implementation KDPNoticeViewController
  18. -(void)viewWillAppear:(BOOL)animated
  19. {
  20. [super viewWillAppear:animated];
  21. self.tabBarController.tabBar.hidden=YES;
  22. }
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. [self setUpNav];
  27. self.view.backgroundColor = [UIColor colorWithHex:0xF2F2F2];
  28. [self.view addSubview:self.tableView];
  29. }
  30. - (void)setUpNav{
  31. self.navBar.navTitleLabel.text = @"我的消息";
  32. [self.navBar addleftReturnButton:self selector:@selector(backAction)];
  33. UIButton *clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  34. [clearBtn setImage:[UIImage imageNamed:@"clear_icon"] forState:UIControlStateNormal];
  35. clearBtn.frame = CGRectMake(SCREEN_WIDTH-17-16, KDNavBarHeight-16-17, 17, 17);
  36. [clearBtn addTarget:self action:@selector(clearAction) forControlEvents:UIControlEventTouchUpInside];
  37. [self.navBar addSubview:clearBtn];
  38. self.clearBtn = clearBtn;
  39. }
  40. - (void)backAction{
  41. if (self.presentingViewController) {
  42. [self dismissViewControllerAnimated:YES completion:nil];
  43. } else{
  44. [self.navigationController popViewControllerAnimated:YES];
  45. }
  46. }
  47. - (void)clearAction{
  48. NSString *clearUrl = [NSString stringWithFormat:@"%@api/message_push/allMessageRead",KDURL];
  49. [KDPNetworkRequestHTTP postURL:clearUrl params:nil success:^(id _Nonnull json) {
  50. if ([json[@"flag"]intValue] == 1) {
  51. for (KDPNoticeModel *model in self.dataSource) {
  52. model.is_view = @"1";
  53. }
  54. [MBProgressHUD showMessage:@"全部已读"];
  55. [self.tableView reloadData];
  56. }
  57. } failure:^(NSError * _Nonnull error) {
  58. }];
  59. }
  60. - (void)requestMessageData{
  61. NSDictionary *params = @{@"page":@(self.page)};
  62. NSString *messageUrl = [NSString stringWithFormat:@"%@api/message_push/messagePushList",KDURL];
  63. [LoadingView show];
  64. [KDPNetworkRequestHTTP postURL:messageUrl params:params success:^(id _Nonnull json) {
  65. [LoadingView dismiss];
  66. NSArray *list = [NSArray yy_modelArrayWithClass:[KDPNoticeModel class] json:json[@"data"]];
  67. if (self.page == 1) {
  68. [self.dataSource removeAllObjects];
  69. }
  70. if (list.count>0) {
  71. [self.dataSource addObjectsFromArray:list];
  72. [self.tableView.mj_footer endRefreshing];
  73. [self.tableView.mj_header endRefreshing];
  74. self.clearBtn.hidden = NO;
  75. }else {
  76. self.clearBtn.hidden = YES;
  77. [self.tableView.mj_header endRefreshing];
  78. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  79. }
  80. [LoadingView dismiss];
  81. [self.tableView reloadData];
  82. } failure:^(NSError * _Nonnull error) {
  83. [LoadingView dismiss];
  84. [self.tableView.mj_header endRefreshing];
  85. [self.tableView.mj_footer endRefreshing];
  86. }];
  87. }
  88. - (UITableView *)tableView{
  89. if (!_tableView) {
  90. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, KDNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight) style:UITableViewStylePlain];
  91. _tableView.showsVerticalScrollIndicator = NO;
  92. _tableView.showsHorizontalScrollIndicator = NO;
  93. _tableView.rowHeight = 121;
  94. _tableView.emptyDataSetDelegate = self;
  95. _tableView.emptyDataSetSource = self;
  96. _tableView.delegate = self;
  97. _tableView.dataSource = self;
  98. _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
  99. _tableView.backgroundColor = [UIColor clearColor];
  100. _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
  101. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  102. [_tableView registerClass:[KDPMessageTableViewCell class] forCellReuseIdentifier:NSStringFromClass([KDPMessageTableViewCell class])];
  103. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  104. self.page = 1;
  105. [self requestMessageData];
  106. }];
  107. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  108. self.page ++;
  109. [self requestMessageData];
  110. }];
  111. [_tableView.mj_header beginRefreshing];
  112. }
  113. return _tableView;
  114. }
  115. - (NSMutableArray *)dataSource{
  116. if (!_dataSource) {
  117. _dataSource = [NSMutableArray array];
  118. }
  119. return _dataSource;
  120. }
  121. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  122. KDPMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPMessageTableViewCell class])];
  123. [cell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
  124. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  125. return cell;
  126. }
  127. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  128. return 1;
  129. }
  130. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  131. return self.dataSource.count;
  132. }
  133. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  134. return [UIImage imageNamed:@"no_order"];
  135. }
  136. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  137. return YES;
  138. }
  139. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  140. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  141. }
  142. - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  143. return 30;
  144. }
  145. @end