123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- //
- // NotifyMessageViewController.m
- // MusicGradeExam
- //
- // Created by Kyle on 2020/7/10.
- // Copyright © 2020 DayaMusic. All rights reserved.
- //
- #import "NotifyMessageViewController.h"
- #import "MessageListModel.h"
- #import "NotifyMessageCell.h"
- #import "KSBaseWKWebViewController.h"
- #import "ExamDisplayViewController.h"
- #import "WaitExamViewController.h"
- @interface NotifyMessageViewController ()<UITableViewDelegate, UITableViewDataSource>
- @property (nonatomic, strong) UITableView *tableView;
- @end
- @implementation NotifyMessageViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"通知中心"];
- [self configUI];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
- if(@available(iOS 13.0, *)){
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
- }
- [self resetParamenter];
- [self requestData];
- }
- - (void)requestData {
- [self showhud];
- [KSRequestManager sysMessageRequest:KS_GET page:[NSString stringWithFormat:@"%zd", self.pages] rows:[NSString stringWithFormat:@"%zd",self.rows] success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- // 赋值
- NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
- for (NSDictionary *parm in sourceArray) {
- MessageListModel *model = [[MessageListModel alloc] initWithDictionary:parm];
- [self.dataArray addObject:model];
- }
- if (sourceArray.count < self.rows) {
- self.isLoadMore = NO;
- }
- [self.tableView reloadData];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- [self changeEmptyStatus];
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- if (self.networkAvaiable == NO) {
- MJWeakSelf;
- [self setPromptString:@"网络开小差,再刷新看看" imageName:@"networking_error" actionTitle:@"刷新一下" inView:self.tableView actionBlock:^{
- [weakSelf resetParamenter];
- [weakSelf requestData];
- }];
- }
- [self.dataArray removeAllObjects];
- [self.tableView reloadData];
- [self changeEmptyStatus];
- }];
- }
- - (void)configUI {
- [self.view addSubview:self.tableView];
- MJWeakSelf;
- self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [weakSelf resetParamenter];
- [weakSelf requestData];
- }];
- self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- if (weakSelf.isLoadMore) {
- weakSelf.pages += 1;
- [weakSelf requestData];
- }
- else {
- [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- }];
- }
- - (void)resetParamenter {
- self.isLoadMore = YES;
- self.pages = 1;
- self.rows = 20;
- self.dataArray = [NSMutableArray array];
- [self.tableView.mj_footer resetNoMoreData];
- MJWeakSelf;
- [self setPromptString:@"暂无消息" imageName:@"empty_message" actionTitle:@"返回" inView:self.tableView actionBlock:^{
- [weakSelf.navigationController popViewControllerAnimated:YES];
- }];
- [self.tableView reloadData];
- }
- #pragma mark --- table data soure
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- MessageListModel *model = self.dataArray[indexPath.row];
- NotifyMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NotifyMessageCell"];
- [cell configCellWithSource:model];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- MessageListModel *model = self.dataArray[indexPath.row];
- if (model.readStatus == 0) {
- NotifyMessageCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- [self readMessage:model baseCell:cell];
- }
- else {
- // 跳转页面
- [self toDetailViewWithTypeString:model.memo];
- }
- }
- - (void)readMessage:(MessageListModel *)model baseCell:(NotifyMessageCell *)cell {
-
- [KSRequestManager sysMessageSetReadRequest:KS_POST messageId:[NSString stringWithFormat:@"%.0f", model.messageId] success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- model.readStatus = 1;
- cell.isRead = YES;
- // 跳转页面
- [self toDetailViewWithTypeString:model.memo];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)toDetailViewWithTypeString:(NSString *)memo {
- if (![NSString isEmptyString:memo]) {
- NSString *headStr = [[memo componentsSeparatedByString:@"?"] firstObject];
- if ([headStr isEqualToString:@"1"]) { // 报考详情
- NSRange range = [memo rangeOfString:@"?"];
- if (range.location != NSNotFound) {
- NSString *url = [memo substringFromIndex:(range.location+range.length)];
-
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = url;
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- else if ([headStr isEqualToString:@"2"]) { // 准考证
- NSString *valueStr = [[memo componentsSeparatedByString:@"?"] lastObject];
- NSArray *parmArray = [valueStr componentsSeparatedByString:@"&"];
- for (NSString *subStr in parmArray) {
- if ([subStr containsString:@"examRegistrationId"]) {
- ExamDisplayViewController *displayVC = [[ExamDisplayViewController alloc] init];
- displayVC.examRegistrationId = [[subStr componentsSeparatedByString:@"="] lastObject];
- [self.navigationController pushViewController:displayVC animated:YES];
- }
- }
- }
- else if ([headStr isEqualToString:@"3"]) { // 待考
- NSString *valueStr = [[memo componentsSeparatedByString:@"?"] lastObject];
- NSArray *parmArray = [valueStr componentsSeparatedByString:@"&"];
- for (NSString *subStr in parmArray) {
- if ([subStr containsString:@"examRegistrationId"]) {
- WaitExamViewController *waitCtrl = [[WaitExamViewController alloc] init];
- waitCtrl.examRegistrationId = [[subStr componentsSeparatedByString:@"="] lastObject];
- [self.navigationController pushViewController:waitCtrl animated:YES];
- }
- }
- }
- else if ([headStr isEqualToString:@"4"]) { // 跳转考试记录
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/examRecord"];
- ctrl.hiddenNavBar = NO;
- ctrl.headTitle = @"考试记录";
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else {
- NSRange range = [memo rangeOfString:@"?"];
- if (range.location != NSNotFound) {
- NSString *url = [memo substringFromIndex:(range.location+range.length)];
-
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = url;
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- }
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin) style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.rowHeight = UITableViewAutomaticDimension;
- _tableView.estimatedRowHeight = 88;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = HexRGB(0xf3f4f8);
- _tableView.showsVerticalScrollIndicator = NO;
- [_tableView registerNib:[UINib nibWithNibName:@"NotifyMessageCell" bundle:nil] forCellReuseIdentifier:@"NotifyMessageCell"];
- UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
- bottomView.backgroundColor = HexRGB(0xf3f4f8);
- _tableView.tableFooterView = bottomView;
- }
- return _tableView;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|