123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- //
- // KDPNoticeViewController.m
- // KuDianProject
- //
- // Created by admin on 2019/7/11.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPNoticeViewController.h"
- #import "KDPNoticeModel.h"
- #import "KDPMessageTableViewCell.h"
- @interface KDPNoticeViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *dataSource;
- @property (nonatomic, assign) NSInteger page;
- @property (nonatomic, strong) UIButton *clearBtn;
- @end
- @implementation KDPNoticeViewController
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- self.tabBarController.tabBar.hidden=YES;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self setUpNav];
- self.view.backgroundColor = [UIColor colorWithHex:0xF2F2F2];
- [self.view addSubview:self.tableView];
- }
- - (void)setUpNav{
- self.navBar.navTitleLabel.text = @"我的消息";
- [self.navBar addleftReturnButton:self selector:@selector(backAction)];
-
- UIButton *clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [clearBtn setImage:[UIImage imageNamed:@"clear_icon"] forState:UIControlStateNormal];
- clearBtn.frame = CGRectMake(SCREEN_WIDTH-17-16, KDNavBarHeight-16-17, 17, 17);
- [clearBtn addTarget:self action:@selector(clearAction) forControlEvents:UIControlEventTouchUpInside];
- clearBtn.hidden=YES;
- [self.navBar addSubview:clearBtn];
- self.clearBtn = clearBtn;
- }
- - (void)backAction{
- if (self.presentingViewController) {
- [self dismissViewControllerAnimated:YES completion:nil];
- } else{
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- - (void)clearAction{
- NSString *clearUrl = [NSString stringWithFormat:@"%@api/message_push/allMessageRead",KDURL];
- [KDPNetworkRequestHTTP postURL:clearUrl params:nil success:^(id _Nonnull json) {
- if ([json[@"flag"]intValue] == 1) {
- for (KDPNoticeModel *model in self.dataSource) {
- model.is_view = @"1";
- }
- [MBProgressHUD showMessage:@"全部已读"];
-
- [self.tableView reloadData];
- }
- } failure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)requestMessageData{
- NSDictionary *params = @{@"page":@(self.page)};
- NSString *messageUrl = [NSString stringWithFormat:@"%@api/message_push/messagePushList",KDURL];
- [LoadingView show];
- [KDPNetworkRequestHTTP postURL:messageUrl params:params success:^(id _Nonnull json) {
- [LoadingView dismiss];
- NSArray *list = [NSArray yy_modelArrayWithClass:[KDPNoticeModel class] json:json[@"data"]];
- if (self.page == 1) {
- [self.dataSource removeAllObjects];
- }
- if (list.count>0) {
- [self.dataSource addObjectsFromArray:list];
- [self.tableView.mj_footer endRefreshing];
- [self.tableView.mj_header endRefreshing];
- self.clearBtn.hidden = NO;
- }else {
- self.clearBtn.hidden = YES;
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }
-
- [LoadingView dismiss];
- [self.tableView reloadData];
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- }];
- }
- - (UITableView *)tableView{
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, KDNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight) style:UITableViewStylePlain];
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.rowHeight = 121;
- _tableView.emptyDataSetDelegate = self;
- _tableView.emptyDataSetSource = self;
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- [_tableView registerClass:[KDPMessageTableViewCell class] forCellReuseIdentifier:NSStringFromClass([KDPMessageTableViewCell class])];
- _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- self.page = 1;
- [self requestMessageData];
- }];
- _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- self.page ++;
- [self requestMessageData];
- }];
- [_tableView.mj_header beginRefreshing];
- }
- return _tableView;
- }
- - (NSMutableArray *)dataSource{
- if (!_dataSource) {
- _dataSource = [NSMutableArray array];
- }
- return _dataSource;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- KDPMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPMessageTableViewCell class])];
- [cell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- return cell;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.dataSource.count;
- }
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
- return [UIImage imageNamed:@"no_order"];
- }
- - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
- return YES;
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
- return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
- }
- - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
- return 30;
- }
- @end
|