123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- //
- // NotiferMessageViewController.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/4/18.
- //
- #import "NotiferMessageViewController.h"
- #import "NotiferMessageCell.h"
- #import "NotiferHeadView.h"
- #import "NotiferMessageModel.h"
- #import "KSBaseWKWebViewController.h"
- #import "CustomNavViewController.h"
- //#import "ReceiveEvaluateListController.h"
- #import "HomeworkDetailViewController.h"
- #import "UIButton+EnlargeEdge.h"
- @interface NotiferMessageViewController ()<UITableViewDelegate, UITableViewDataSource>
- @property (nonatomic, strong) NotiferHeadView *headView;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSString *groupType;
- @end
- @implementation NotiferMessageViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"消息盒子"];
- [self configRightButton];
- [self configUI];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self queryUnReadCount];
- [self resetSourceAndRequest];
- }
- - (void)configRightButton {
- UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [rightButton setTitle:@"全部已读" forState:UIControlStateNormal];
- [rightButton setTitleColor:HexRGB(0x999999) forState:UIControlStateNormal];
- [rightButton setImage:[UIImage imageNamed:@"clear_notifer"] forState:UIControlStateNormal];
- rightButton.frame =CGRectMake(0, 0, 80, 40);
- //使图片在右边,文字在左边(正常情况下是文字在右边,图片在左边)
- [rightButton setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
- //设置图片和文字之间的间隙
- rightButton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
- [rightButton.titleLabel setFont:[UIFont systemFontOfSize:11.0f]];
- [rightButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
- [rightButton addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
- self.navigationItem.rightBarButtonItem = rightItem;
- }
- - (void)rightBtnClick {
- [KSNetworkingManager batchSetReadRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- [self MBPShow:@"清除成功"];
- [self resetSourceAndRequest];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)configUI {
- [self.scrollView removeFromSuperview];
- [self.view addSubview:self.headView];
- [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(100);
- }];
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.headView.mas_bottom);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
- }];
-
- MJWeakSelf;
- self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf resetSourceAndRequest];
- }];
- self.tableView.mj_footer = [KSGifRefreshFooter footerWithRefreshingBlock:^{
- if (weakSelf.isLoadMore) {
- weakSelf.pages += 1;
- [weakSelf requestData];
- }
- else {
- [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- }];
- }
- - (void)resetSourceAndRequest {
- [self resetParamenter];
- [self requestData];
- [self queryUnReadCount];
- }
- - (void)queryUnReadCount {
- [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *countArray = [dic arrayValueForKey:@"data"];
- NSInteger courseCount = 0;
- NSInteger sysCount = 0;
- NSInteger noticeCount = 0;
- for (NSDictionary *parm in countArray) {
- if ([[parm stringValueForKey:@"key"] isEqualToString:@"COURSE"]) {
- courseCount = [parm integerValueForKey:@"value"];
- }
- if ([[parm stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) {
- sysCount = [parm integerValueForKey:@"value"];
- }
- if ([[parm stringValueForKey:@"key"] isEqualToString:@"NOTICE"]) {
- noticeCount = [parm integerValueForKey:@"value"];
- }
- }
-
- [self.headView configUnreadCountCourse:courseCount sysMessage:sysCount noticeCount:noticeCount];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)resetParamenter {
- self.pages = 1;
- self.isLoadMore = YES;
- self.dataArray = [NSMutableArray array];
- [self.tableView.mj_footer resetNoMoreData];
- [self setPromptString:@"暂无消息~" imageName:@"empty_message" inView:self.tableView];
- [self.tableView reloadData];
- }
- - (void)endRefresh {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- });
- }
- - (void)requestData {
- [self showhud];
- [KSNetworkingManager sysMessageListRequest:KS_POST group:self.groupType page:self.pages rows:self.rows success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- [self endRefresh];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- // rows
- NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
- for (NSDictionary *parm in sourceArray) {
- NotiferMessageModel *model = [[NotiferMessageModel alloc] initWithDictionary:parm];
- [self.dataArray addObject:model];
- }
- if (sourceArray.count < self.rows) {
- self.isLoadMore = NO;
- }
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- [self.tableView reloadData];
- [self changePromptLabelState];
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- [self endRefresh];
- if (self.networkAvaiable == NO) {
- [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
- }
- [self.dataArray removeAllObjects];
- [self.tableView reloadData];
- [self changePromptLabelState];
- }];
- }
- #pragma mark ----- table data source
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- NotiferMessageModel *model = self.dataArray[indexPath.row];
- NotiferMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NotiferMessageCell"];
- [cell configCellWithSource:model];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- // 选择跳转
- NotiferMessageModel *model = self.dataArray[indexPath.row];
- if (model.readStatus == 0) {
- NotiferMessageCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- [self readMessage:model baseCell:cell];
- }
- else {
- // 跳转页面
- [self toDetailViewWithTypeString:model.memo];
- }
- }
- - (void)readMessage:(NotiferMessageModel *)model baseCell:(NotiferMessageCell *)cell {
- [KSNetworkingManager setReadMessage:KS_POST messageId:model.internalBaseClassIdentifier success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- model.readStatus = 1;
- cell.isRead = YES;
- // 跳转页面
- [self toDetailViewWithTypeString:model.memo];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)toDetailViewWithTypeString:(NSString *)memo {
- if (![NSString isEmptyString:memo]) {
- NSString *headStr = [[memo componentsSeparatedByString:@"?"] firstObject];
- if ([headStr isEqualToString:@"buyPractice"] || [headStr isEqualToString:@"courseRemind"]) { // 课表
- [self toCourseTable];
- }
- else if ([headStr isEqualToString:@"evaluate"]) { // 评价页面
- // ReceiveEvaluateListController *ctrl = [[ReceiveEvaluateListController alloc] init];
- // [self.navigationController pushViewController:ctrl animated:YES];
- }
- else if ([headStr isEqualToString:@"H5"]) { // web
- NSString *valueStr = [[memo componentsSeparatedByString:@"?"] lastObject];
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = valueStr;
- CustomNavViewController *navCtrl = self.tabBarController.selectedViewController;
- [navCtrl pushViewController:webCtrl animated:YES];
- }
- else if ([headStr isEqualToString:@"homework"]) { // 作业详情
- NSString *valueStr = [[memo componentsSeparatedByString:@"?"] lastObject];
- NSArray *parmArray = [valueStr componentsSeparatedByString:@"&"];
- NSString *courseId = nil;
- for (NSString *subStr in parmArray) {
- if ([subStr containsString:@"courseId"]) {
- courseId = [[subStr componentsSeparatedByString:@"="] lastObject];
- }
- }
- HomeworkDetailViewController *detailVC = [[HomeworkDetailViewController alloc] init];
- detailVC.courseId = courseId;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- }
- }
- - (void)toCourseTable {
- [self selectBarHomeWithIndex:1];
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- #pragma mark ---- lazying
- - (NotiferHeadView *)headView {
- if (!_headView) {
- _headView = [NotiferHeadView shareIntance];
- MJWeakSelf;
- [_headView chooseTypeCallback:^(NOTIFER_TYPE type) {
- [weakSelf chooseTypeSort:type];
- }];
- }
- return _headView;
- }
- - (void)chooseTypeSort:(NOTIFER_TYPE)type {
- switch (type) {
- case NOTIFER_TYPE_ALL:
- {
- self.groupType = nil;
- }
- break;
- case NOTIFER_TYPE_COURSE:
- {
- self.groupType = @"COURSE";
- }
- break;
- case NOTIFER_TYPE_SYSMSG:
- {
- self.groupType = @"SYSTEM";
- }
- break;
- case NOTIFER_TYPE_NOTICE:
- {
- self.groupType = @"NOTICE";
- }
- break;
- default:
- break;
- }
- [self resetSourceAndRequest];
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [_tableView registerNib:[UINib nibWithNibName:@"NotiferMessageCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"NotiferMessageCell"];
- _tableView.estimatedRowHeight = 125.0f;
- _tableView.rowHeight = UITableViewAutomaticDimension;
- UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 15)];
- bottomView.backgroundColor = HexRGB(0xf6f8f9);
- _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
|