You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
327 lines
12 KiB
327 lines
12 KiB
// |
|
// SystermMessageViewController.m |
|
// tongxin |
|
// |
|
// Created by WeiChaoZheng on 2018/6/27. |
|
// Copyright © 2018年 xTT. All rights reserved. |
|
// |
|
|
|
#import "SystermMessageViewController.h" |
|
#import "MessageTableViewCell.h" |
|
|
|
@interface SystermMessageViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate> |
|
|
|
|
|
@property (nonatomic ,strong) UITableView *myTableView; |
|
@property (nonatomic ,assign) NSInteger page; |
|
|
|
@end |
|
|
|
@implementation SystermMessageViewController |
|
|
|
|
|
- (UITableView *)myTableView |
|
{ |
|
if (!_myTableView) |
|
{ |
|
kWeakSelf(self) |
|
_myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; |
|
_myTableView.backgroundColor = KKClearColor; |
|
_myTableView.delegate = self; |
|
_myTableView.dataSource = self; |
|
_myTableView.emptyDataSetSource = self; |
|
_myTableView.emptyDataSetDelegate = self; |
|
_myTableView.showsHorizontalScrollIndicator = NO; |
|
_myTableView.showsVerticalScrollIndicator = NO; |
|
_myTableView.estimatedRowHeight = 0; |
|
_myTableView.estimatedSectionHeaderHeight = 0; |
|
_myTableView.estimatedSectionFooterHeight = 0; |
|
//去线 |
|
//_myTableView.separatorStyle = UITableViewCellSelectionStyleNone; |
|
[_myTableView registerNib:[UINib nibWithNibName:@"MessageTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MessageTableViewCellID"]; |
|
[_myTableView bindHeadRefreshHandler:^{ |
|
[UICommon feedbackGenerator]; |
|
[weakself GetNotifyList:TableisReload_h]; |
|
} themeColor:KKMainColor refreshStyle:KafkaRefreshStyleReplicatorWoody]; |
|
|
|
[_myTableView bindFootRefreshHandler:^{ |
|
[weakself GetNotifyList:TableisReload_f]; |
|
} themeColor:KKMainColor refreshStyle:KafkaRefreshStyleReplicatorWoody]; |
|
|
|
} |
|
return _myTableView; |
|
} |
|
|
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
self.emptyTitle = GJText(@"没有通知消息"); |
|
self.emptyText = GJText(@"点击刷新一下"); |
|
self.ImgType = Xiaoxi; |
|
[self.view addSubview:self.myTableView]; |
|
[self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.edges.equalTo(self.view); |
|
}]; |
|
[self GetNotifyList:TableisReload_h]; |
|
|
|
// Do any additional setup after loading the view. |
|
} |
|
|
|
#pragma mark 获取通知 |
|
/// 获取通知 |
|
- (void)GetNotifyList:(TableisReload)isReload |
|
{ |
|
kWeakSelf(self) |
|
[UICommon MessageUpload:@"加载中"]; |
|
if (isReload == TableisReload_h) |
|
{ |
|
self.page = 1; |
|
[self.modelListArr removeAllObjects]; |
|
} |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:@(self.page) forKey:@"current"]; |
|
[parameters setValue:@(KSizeNO) forKey:@"pageSize"]; |
|
[[[APIManager sharedManager] APGET:QueryNotify_URL parameters:parameters resultClass:BaseModel.class] subscribeNext:^(BaseModel *model) { |
|
[UICommon HidenLoading]; |
|
NSArray *arr = model.records; |
|
[weakself.myTableView.headRefreshControl endRefreshingWithAlertText:GJText(@"已为你加载最新数据~") completion:^{ |
|
|
|
}]; |
|
[weakself.myTableView.footRefreshControl endRefreshing]; |
|
for (NSDictionary *dic in arr) |
|
{ |
|
SystermModel *model = [SystermModel yy_modelWithJSON:dic]; |
|
[self.modelListArr addObject:model]; |
|
} |
|
weakself.page++; |
|
weakself.myTableView.footRefreshControl.hidden = arr.count < KSizeNO ? YES : NO; |
|
|
|
[weakself.myTableView reloadData]; |
|
|
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
#pragma mark 删除通知 |
|
/// 删除通知 |
|
- (void)DeleteNotify |
|
{ |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[[[APIManager sharedManager] APPOST:DeleteNotify_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
[UICommon MessageSuccessText:@"删除成功"]; |
|
[self GetNotifyList:TableisReload_h]; |
|
[[NSNotificationCenter defaultCenter] postNotificationName:KK_UPDATE_ALL_NEWS_MESSAGE object:nil]; |
|
|
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
//MARK :刪除方法 |
|
-(void)deletAction |
|
{ |
|
kWeakSelf(self) |
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:GJText(@"注意") message:GJText(@"确认要清空通知消息?") style:LGAlertViewStyleAlert buttonTitles:@[GJText(@"确定")] cancelButtonTitle:GJText(@"取消") destructiveButtonTitle:nil actionHandler:^(LGAlertView * _Nonnull alertView, NSUInteger index, NSString * _Nullable title) { |
|
[weakself DeleteNotify]; |
|
|
|
} cancelHandler:^(LGAlertView * _Nonnull alertView) { |
|
|
|
} destructiveHandler:^(LGAlertView * _Nonnull alertView) { |
|
|
|
}]; |
|
[alertView showAnimated:YES completionHandler:nil]; |
|
} |
|
|
|
|
|
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView |
|
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ |
|
return UITableViewCellEditingStyleNone; |
|
} |
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section |
|
{ |
|
return self.modelListArr.count; |
|
} |
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
SystermModel *dMessage = self.modelListArr[indexPath.row]; |
|
NSString *watchImei = dMessage.imei; |
|
NSString *content = dMessage.content; |
|
if([dMessage.type isEqualToString:@"systemUpdate"] && dMessage.content) |
|
{ |
|
CGFloat tempWidth = SCREEN_WIDTH*(280.0/320); |
|
CGFloat cellHeight = [self getLineHeight:content withWidth:tempWidth withFont:FontADA_(14)]; |
|
if(cellHeight < 66){ |
|
return 66; |
|
}else{ |
|
return cellHeight; |
|
} |
|
|
|
} |
|
else |
|
{ |
|
NSString *allTmp = @""; |
|
if ([dMessage.type isEqualToString:@"identityTransfered"]) |
|
{ |
|
//设备(225977895624552)的管理员(13242881234)将管理员转让给你 |
|
NSString *tmp = [NSString stringWithFormat:@"(%@)",dMessage.phone]; |
|
NSString *tmp2 = [NSString stringWithFormat:@"%@ (%@)",dMessage.name,watchImei]; |
|
allTmp = [NSString stringWithFormat:GJText(@"%@的管理员%@把管理员转让给您"),tmp2,tmp]; |
|
|
|
} |
|
else if ([dMessage.type isEqualToString:@"identityTransfer"]) |
|
{ |
|
//您将设备(225977895624552)的管理员转让给用户(13212345678) |
|
NSString *tmp = [NSString stringWithFormat:GJText(@"用户(%@)"),dMessage.phone]; |
|
NSString *tmp2 = [NSString stringWithFormat:@" %@ (%@)",dMessage.name,watchImei]; |
|
allTmp = [NSString stringWithFormat:GJText(@"您将%@的管理员转让给%@"),tmp2,tmp]; |
|
|
|
} |
|
CGFloat tempWidth = SCREEN_WIDTH*(280.0/320); |
|
return [self getLineHeight:allTmp withWidth:tempWidth withFont:FontADA_(14)]; |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
|
SystermModel *dMessage = self.modelListArr[indexPath.row]; |
|
MessageTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"MessageTableViewCellID" forIndexPath:indexPath]; |
|
cell.timeLabel.text = [UICommon getDateFormatWithStr:@"HH:mm" date:[UICommon getTimeStrWithString:dMessage.createTime]]; //时间 |
|
|
|
//标题 |
|
NSString * titleStr ; |
|
|
|
NSString *watchImei = dMessage.imei; |
|
//信息 |
|
|
|
if ([dMessage.type isEqualToString:@"identityTransfered"]) { |
|
titleStr = GJText(@"管理员转让记录"); |
|
//设备(225977895624552)的管理员(13242881234)将管理员转让给你 |
|
NSString *tmp = [NSString stringWithFormat:@"(%@)",dMessage.phone]; |
|
NSString *tmp2 = [NSString stringWithFormat:@"%@ (%@)",dMessage.name,watchImei]; |
|
NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:GJText(@"%@的管理员%@把管理员转让给您"),tmp2,tmp]]; |
|
[att addAttribute:NSForegroundColorAttributeName |
|
value:KKMainColor |
|
range:NSMakeRange(0,tmp2.length)]; |
|
[att addAttribute:NSForegroundColorAttributeName |
|
value:KKMainColor |
|
range:NSMakeRange(tmp2.length+4,tmp.length)]; |
|
|
|
cell.messageLabel.attributedText = att; |
|
|
|
}else if ([dMessage.type isEqualToString:@"identityTransfer"]) { |
|
titleStr = GJText(@"管理员转让记录"); |
|
//您将设备(225977895624552)的管理员转让给用户(13212345678) |
|
NSString *tmp = [NSString stringWithFormat:GJText(@"用户(%@)"),dMessage.phone]; |
|
NSInteger length = tmp.length; |
|
NSString *tmp2 = [NSString stringWithFormat:@" %@ (%@)",dMessage.name,watchImei]; |
|
tmp = [NSString stringWithFormat:GJText(@"您将%@的管理员转让给%@"),tmp2,tmp]; |
|
|
|
NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:tmp]; |
|
[att addAttribute:NSForegroundColorAttributeName |
|
value:KKMainColor |
|
range:NSMakeRange(att.length-length,length)]; |
|
[att addAttribute:NSForegroundColorAttributeName |
|
value:KKMainColor |
|
range:NSMakeRange(2,tmp2.length)]; |
|
cell.messageLabel.attributedText = att; |
|
|
|
} |
|
else if ([dMessage.type isEqualToString:@"systemUpdate"]) { |
|
titleStr = GJText(@"系统通知"); |
|
cell.messageLabel.text = dMessage.content; |
|
} |
|
cell.aTitleLabel.text = titleStr; |
|
|
|
if (dMessage.messageRead && [dMessage.messageRead intValue] == 0) { |
|
cell.readLabel.hidden = NO; |
|
}else { |
|
cell.readLabel.hidden = YES; |
|
} |
|
|
|
return cell; |
|
|
|
} |
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
|
SystermModel *dMessage = self.modelListArr[indexPath.row]; |
|
if (dMessage.messageRead && [dMessage.messageRead intValue] == 0) |
|
{ |
|
[UICommon MessageUpload:@"加载中"]; |
|
[self updateNotify:dMessage]; |
|
} |
|
} |
|
|
|
//- (void)viewWillAppear:(BOOL)animated |
|
//{ |
|
// [super viewWillAppear:animated]; |
|
// [self xiaoxiyidu]; |
|
//} |
|
|
|
|
|
- (void)xiaoxiyidu |
|
{ |
|
[self.modelListArr enumerateObjectsUsingBlock:^(SystermModel *model, NSUInteger idx, BOOL * _Nonnull stop) { |
|
if (model.messageRead && model.messageRead == 0) |
|
{ |
|
[self updateNotify:model]; |
|
} |
|
}]; |
|
} |
|
|
|
- (void)updateNotify:(SystermModel *)model |
|
{ |
|
kWeakSelf(self) |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:model.Id forKey:@"id"]; |
|
[parameters setValue:@"1" forKey:@"messageRead"]; |
|
[[[APIManager sharedManager] APPOST:UpdateNotify_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
model.messageRead = @"1"; |
|
[[NSNotificationCenter defaultCenter] postNotificationName:KK_UPDATE_ALL_NEWS_MESSAGE object:nil]; |
|
[weakself.myTableView reloadData]; |
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
|
|
|
|
- (CGFloat)getLineHeight:(NSString *)string withWidth:(CGFloat)width withFont:(UIFont *)font{ |
|
UILabel *label = [[UILabel alloc]init]; |
|
label.numberOfLines = 0; |
|
label.lineBreakMode = NSLineBreakByWordWrapping; |
|
label.textAlignment = NSTextAlignmentLeft; |
|
label.text = string; |
|
label.font = font; |
|
CGSize labelSize = [label sizeThatFits:CGSizeMake(width, MAXFLOAT)]; |
|
CGFloat height = ceil(labelSize.height) + 1 + 34 + 10 + 8 ; |
|
// xLog(@"文本框应该高 Height :%f ", height); |
|
if(height < 66){ |
|
height = 66; |
|
} |
|
return height; |
|
} |
|
|
|
|
|
#pragma mark - DZNEmptyDataSetSource,DZNEmptyDataSetDelegate |
|
- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view |
|
{ |
|
[self GetNotifyList:TableisReload_h]; |
|
} |
|
|
|
|
|
@end |
|
|
|
|