NotifyMessageViewController.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // NotifyMessageViewController.m
  3. // MusicGradeExam
  4. //
  5. // Created by Kyle on 2020/7/10.
  6. // Copyright © 2020 DayaMusic. All rights reserved.
  7. //
  8. #import "NotifyMessageViewController.h"
  9. #import "MessageListModel.h"
  10. #import "NotifyMessageCell.h"
  11. #import "KSBaseWKWebViewController.h"
  12. #import "ExamDisplayViewController.h"
  13. #import "WaitExamViewController.h"
  14. @interface NotifyMessageViewController ()<UITableViewDelegate, UITableViewDataSource>
  15. @property (nonatomic, strong) UITableView *tableView;
  16. @end
  17. @implementation NotifyMessageViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. [self allocTitle:@"通知中心"];
  22. [self configUI];
  23. }
  24. - (void)viewWillAppear:(BOOL)animated {
  25. [super viewWillAppear:animated];
  26. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  27. if(@available(iOS 13.0, *)){
  28. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
  29. }
  30. [self resetParamenter];
  31. [self requestData];
  32. }
  33. - (void)requestData {
  34. [self showhud];
  35. [KSRequestManager sysMessageRequest:KS_GET page:[NSString stringWithFormat:@"%zd", self.pages] rows:[NSString stringWithFormat:@"%zd",self.rows] success:^(NSDictionary * _Nonnull dic) {
  36. [self removehub];
  37. [self.tableView.mj_header endRefreshing];
  38. [self.tableView.mj_footer endRefreshing];
  39. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  40. // 赋值
  41. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  42. for (NSDictionary *parm in sourceArray) {
  43. MessageListModel *model = [[MessageListModel alloc] initWithDictionary:parm];
  44. [self.dataArray addObject:model];
  45. }
  46. if (sourceArray.count < self.rows) {
  47. self.isLoadMore = NO;
  48. }
  49. [self.tableView reloadData];
  50. }
  51. else {
  52. [self MBPShow:MESSAGEKEY];
  53. }
  54. [self changeEmptyStatus];
  55. } faliure:^(NSError * _Nonnull error) {
  56. [self removehub];
  57. [self.tableView.mj_header endRefreshing];
  58. [self.tableView.mj_footer endRefreshing];
  59. if (self.networkAvaiable == NO) {
  60. MJWeakSelf;
  61. [self setPromptString:@"网络开小差,再刷新看看" imageName:@"networking_error" actionTitle:@"刷新一下" inView:self.tableView actionBlock:^{
  62. [weakSelf resetParamenter];
  63. [weakSelf requestData];
  64. }];
  65. }
  66. [self.dataArray removeAllObjects];
  67. [self.tableView reloadData];
  68. [self changeEmptyStatus];
  69. }];
  70. }
  71. - (void)configUI {
  72. [self.view addSubview:self.tableView];
  73. MJWeakSelf;
  74. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  75. [weakSelf resetParamenter];
  76. [weakSelf requestData];
  77. }];
  78. self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  79. if (weakSelf.isLoadMore) {
  80. weakSelf.pages += 1;
  81. [weakSelf requestData];
  82. }
  83. else {
  84. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  85. }
  86. }];
  87. }
  88. - (void)resetParamenter {
  89. self.isLoadMore = YES;
  90. self.pages = 1;
  91. self.rows = 20;
  92. self.dataArray = [NSMutableArray array];
  93. [self.tableView.mj_footer resetNoMoreData];
  94. MJWeakSelf;
  95. [self setPromptString:@"暂无消息" imageName:@"empty_message" actionTitle:@"返回" inView:self.tableView actionBlock:^{
  96. [weakSelf.navigationController popViewControllerAnimated:YES];
  97. }];
  98. [self.tableView reloadData];
  99. }
  100. #pragma mark --- table data soure
  101. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  102. return self.dataArray.count;
  103. }
  104. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  105. MessageListModel *model = self.dataArray[indexPath.row];
  106. NotifyMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NotifyMessageCell"];
  107. [cell configCellWithSource:model];
  108. return cell;
  109. }
  110. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  111. MessageListModel *model = self.dataArray[indexPath.row];
  112. if (model.readStatus == 0) {
  113. NotifyMessageCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  114. [self readMessage:model baseCell:cell];
  115. }
  116. else {
  117. // 跳转页面
  118. [self toDetailViewWithTypeString:model.memo];
  119. }
  120. }
  121. - (void)readMessage:(MessageListModel *)model baseCell:(NotifyMessageCell *)cell {
  122. [KSRequestManager sysMessageSetReadRequest:KS_POST messageId:[NSString stringWithFormat:@"%.0f", model.messageId] success:^(NSDictionary * _Nonnull dic) {
  123. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  124. model.readStatus = 1;
  125. cell.isRead = YES;
  126. // 跳转页面
  127. [self toDetailViewWithTypeString:model.memo];
  128. }
  129. } faliure:^(NSError * _Nonnull error) {
  130. }];
  131. }
  132. - (void)toDetailViewWithTypeString:(NSString *)memo {
  133. if (![NSString isEmptyString:memo]) {
  134. NSString *headStr = [[memo componentsSeparatedByString:@"?"] firstObject];
  135. if ([headStr isEqualToString:@"1"]) { // 报考详情
  136. NSRange range = [memo rangeOfString:@"?"];
  137. if (range.location != NSNotFound) {
  138. NSString *url = [memo substringFromIndex:(range.location+range.length)];
  139. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  140. webCtrl.url = url;
  141. [self.navigationController pushViewController:webCtrl animated:YES];
  142. }
  143. }
  144. else if ([headStr isEqualToString:@"2"]) { // 准考证
  145. NSString *valueStr = [[memo componentsSeparatedByString:@"?"] lastObject];
  146. NSArray *parmArray = [valueStr componentsSeparatedByString:@"&"];
  147. for (NSString *subStr in parmArray) {
  148. if ([subStr containsString:@"examRegistrationId"]) {
  149. ExamDisplayViewController *displayVC = [[ExamDisplayViewController alloc] init];
  150. displayVC.examRegistrationId = [[subStr componentsSeparatedByString:@"="] lastObject];
  151. [self.navigationController pushViewController:displayVC animated:YES];
  152. }
  153. }
  154. }
  155. else if ([headStr isEqualToString:@"3"]) { // 待考
  156. NSString *valueStr = [[memo componentsSeparatedByString:@"?"] lastObject];
  157. NSArray *parmArray = [valueStr componentsSeparatedByString:@"&"];
  158. for (NSString *subStr in parmArray) {
  159. if ([subStr containsString:@"examRegistrationId"]) {
  160. WaitExamViewController *waitCtrl = [[WaitExamViewController alloc] init];
  161. waitCtrl.examRegistrationId = [[subStr componentsSeparatedByString:@"="] lastObject];
  162. [self.navigationController pushViewController:waitCtrl animated:YES];
  163. }
  164. }
  165. }
  166. else if ([headStr isEqualToString:@"4"]) { // 跳转考试记录
  167. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  168. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/examRecord"];
  169. ctrl.hiddenNavBar = NO;
  170. ctrl.headTitle = @"考试记录";
  171. [self.navigationController pushViewController:ctrl animated:YES];
  172. }
  173. else {
  174. NSRange range = [memo rangeOfString:@"?"];
  175. if (range.location != NSNotFound) {
  176. NSString *url = [memo substringFromIndex:(range.location+range.length)];
  177. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  178. webCtrl.url = url;
  179. [self.navigationController pushViewController:webCtrl animated:YES];
  180. }
  181. }
  182. }
  183. }
  184. - (UITableView *)tableView {
  185. if (!_tableView) {
  186. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin) style:UITableViewStylePlain];
  187. _tableView.delegate = self;
  188. _tableView.dataSource = self;
  189. _tableView.rowHeight = UITableViewAutomaticDimension;
  190. _tableView.estimatedRowHeight = 88;
  191. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  192. _tableView.backgroundColor = HexRGB(0xf3f4f8);
  193. _tableView.showsVerticalScrollIndicator = NO;
  194. [_tableView registerNib:[UINib nibWithNibName:@"NotifyMessageCell" bundle:nil] forCellReuseIdentifier:@"NotifyMessageCell"];
  195. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  196. bottomView.backgroundColor = HexRGB(0xf3f4f8);
  197. _tableView.tableFooterView = bottomView;
  198. }
  199. return _tableView;
  200. }
  201. /*
  202. #pragma mark - Navigation
  203. // In a storyboard-based application, you will often want to do a little preparation before navigation
  204. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  205. // Get the new view controller using [segue destinationViewController].
  206. // Pass the selected object to the new view controller.
  207. }
  208. */
  209. @end