酷店

KDPNoticeViewController.m 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. clearBtn.hidden=YES;
  38. [self.navBar addSubview:clearBtn];
  39. self.clearBtn = clearBtn;
  40. }
  41. - (void)backAction{
  42. if (self.presentingViewController) {
  43. [self dismissViewControllerAnimated:YES completion:nil];
  44. } else{
  45. [self.navigationController popViewControllerAnimated:YES];
  46. }
  47. }
  48. - (void)clearAction{
  49. NSString *clearUrl = [NSString stringWithFormat:@"%@api/message_push/allMessageRead",KDURL];
  50. [KDPNetworkRequestHTTP postURL:clearUrl params:nil success:^(id _Nonnull json) {
  51. if ([json[@"flag"]intValue] == 1) {
  52. for (KDPNoticeModel *model in self.dataSource) {
  53. model.is_view = @"1";
  54. }
  55. [MBProgressHUD showMessage:@"全部已读"];
  56. [self.tableView reloadData];
  57. }
  58. } failure:^(NSError * _Nonnull error) {
  59. }];
  60. }
  61. - (void)requestMessageData{
  62. NSDictionary *params = @{@"page":@(self.page)};
  63. NSString *messageUrl = [NSString stringWithFormat:@"%@api/message_push/messagePushList",KDURL];
  64. [LoadingView show];
  65. [KDPNetworkRequestHTTP postURL:messageUrl params:params success:^(id _Nonnull json) {
  66. [LoadingView dismiss];
  67. NSArray *list = [NSArray yy_modelArrayWithClass:[KDPNoticeModel class] json:json[@"data"]];
  68. if (self.page == 1) {
  69. [self.dataSource removeAllObjects];
  70. }
  71. if (list.count>0) {
  72. [self.dataSource addObjectsFromArray:list];
  73. [self.tableView.mj_footer endRefreshing];
  74. [self.tableView.mj_header endRefreshing];
  75. self.clearBtn.hidden = NO;
  76. }else {
  77. self.clearBtn.hidden = YES;
  78. [self.tableView.mj_header endRefreshing];
  79. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  80. }
  81. [LoadingView dismiss];
  82. [self.tableView reloadData];
  83. } failure:^(NSError * _Nonnull error) {
  84. [LoadingView dismiss];
  85. [self.tableView.mj_header endRefreshing];
  86. [self.tableView.mj_footer endRefreshing];
  87. }];
  88. }
  89. - (UITableView *)tableView{
  90. if (!_tableView) {
  91. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, KDNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight) style:UITableViewStylePlain];
  92. _tableView.showsVerticalScrollIndicator = NO;
  93. _tableView.showsHorizontalScrollIndicator = NO;
  94. _tableView.rowHeight = 121;
  95. _tableView.emptyDataSetDelegate = self;
  96. _tableView.emptyDataSetSource = self;
  97. _tableView.delegate = self;
  98. _tableView.dataSource = self;
  99. _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
  100. _tableView.backgroundColor = [UIColor clearColor];
  101. _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
  102. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  103. [_tableView registerClass:[KDPMessageTableViewCell class] forCellReuseIdentifier:NSStringFromClass([KDPMessageTableViewCell class])];
  104. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  105. self.page = 1;
  106. [self requestMessageData];
  107. }];
  108. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  109. self.page ++;
  110. [self requestMessageData];
  111. }];
  112. [_tableView.mj_header beginRefreshing];
  113. }
  114. return _tableView;
  115. }
  116. - (NSMutableArray *)dataSource{
  117. if (!_dataSource) {
  118. _dataSource = [NSMutableArray array];
  119. }
  120. return _dataSource;
  121. }
  122. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  123. KDPMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPMessageTableViewCell class])];
  124. [cell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
  125. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  126. return cell;
  127. }
  128. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  129. return 1;
  130. }
  131. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  132. return self.dataSource.count;
  133. }
  134. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  135. return [UIImage imageNamed:@"no_order"];
  136. }
  137. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  138. return YES;
  139. }
  140. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  141. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  142. }
  143. - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  144. return 30;
  145. }
  146. @end