// // AttentionMessageViewController.m // tongxin // // Created by WeiChaoZheng on 2018/6/27. // Copyright © 2018年 xTT. All rights reserved. // #import "AttentionMessageViewController.h" #import "MessageTableViewCell.h" @interface AttentionMessageViewController () @property (nonatomic ,strong) UITableView *myTableView; @property (nonatomic ,assign) NSInteger page; @end @implementation AttentionMessageViewController - (UITableView *)myTableView { if (!_myTableView) { kWeakSelf(self) if (@available(iOS 13.0, *)) { _myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleInsetGrouped]; } else { // Fallback on earlier versions } _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 GetQueryFollowInfo:TableisReload_h]; } themeColor:KKMainColor refreshStyle:KafkaRefreshStyleReplicatorWoody]; [_myTableView bindFootRefreshHandler:^{ [weakself GetQueryFollowInfo: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.top.equalTo(self.view); make.left.right.equalTo(self.view).inset(-10); make.bottom.equalTo(self.view.mas_bottom); }]; if (@available(iOS 15.0, *)) { self.myTableView.sectionHeaderTopPadding = 0.01; } [self GetQueryFollowInfo:TableisReload_h]; // Do any additional setup after loading the view. } #pragma mark 获取关注记录 /// 获取关注记录 - (void)GetQueryFollowInfo:(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:@"pageNumber"]; // [parameters setValue:@(KSizeNO) forKey:@"pageSize"]; // [parameters setValue:APIManager.sharedManager.loginModel.openid forKey:@"userId"]; NSString *url = F(@"%@/20/%ld", APIManager.sharedManager.loginModel.openid,self.page); [[[APIManager sharedManager] APPOST:F(@"%@%@", QueryFollowInfo_URL,url) parameters:parameters isJson:YES 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) { AttentionModel *model = [AttentionModel 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)DeleteAttention { [UICommon MessageUpload:@"加载中"]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [[[APIManager sharedManager] APGET:F(@"%@648454/2", UpdateInfoStatus_URL) parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) { [UICommon HidenLoading]; [UICommon MessageSuccessText:@"删除成功"]; [self GetQueryFollowInfo: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 DeleteAttention]; } cancelHandler:^(LGAlertView * _Nonnull alertView) { } destructiveHandler:^(LGAlertView * _Nonnull alertView) { }]; [alertView showAnimated:YES completionHandler:nil]; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewCellEditingStyleNone; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.modelListArr.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 12; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { AttentionModel *dMessage = self.modelListArr[indexPath.section]; NSString *str ; if([dMessage.type isEqualToString:@"applicationRrecord"]){ //申请记录的消息 str = [NSString stringWithFormat:GJText(@"用户(%@)申请关注【%@】的设备"),dMessage.phone,dMessage.name]; CGFloat cellHeight = [self getLineHeight:str withWidth:SCREEN_WIDTH*(280.0/320) withFont:FontADA_(14)]+25; return cellHeight; }else if ([dMessage.type isEqualToString:@"checkResults"]) { //审核结果消息 NSString *checkStr = [NSString stringWithFormat:GJText(@"您已同意用户(%@)关注设备"),dMessage.phone]; str = [NSString stringWithFormat:GJText(@"用户(%@)申请关注【%@】的设备 \n %@"),dMessage.phone,dMessage.name,checkStr]; }else if ([dMessage.type isEqualToString:@"checkedResults"]) { //被审核结果消息 str = [NSString stringWithFormat:GJText(@"设备(%@)的管理员同意您关注设备"),dMessage.imei]; }else if ([dMessage.type isEqualToString:@"applicationOvertime"]) { //记录失效消息 str = [NSString stringWithFormat:GJText(@"用户(%@)申请关注【%@】设备,记录未及时处理,已失效"),dMessage.phone,dMessage.name]; } CGFloat cellHeight = [self getLineHeight:str withWidth:SCREEN_WIDTH*(280.0/320) withFont:FontADA_(14)]; return cellHeight; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { AttentionModel *dMessage = self.modelListArr[indexPath.section]; MessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessageTableViewCellID" forIndexPath:indexPath]; cell.timeLabel.text = [UICommon getDateFormatWithStr:@"HH:mm" date:[UICommon getTimeStrWithString:dMessage.createTime]]; //时间 //信息 NSString * titleStr ; cell.isApplicationRrecord = NO; titleStr = GJText(@"申请关注设备记录"); if(dMessage.action == 0 && [dMessage.adminId isEqualToString:APIManager.sharedManager.loginModel.openid]) { //申请记录的消息 // 用户(17328339622)申请关注【宝贝】设备 cell.isApplicationRrecord = YES; NSString *tmp = [NSString stringWithFormat:GJText(@"用户(%@)"),dMessage.phone]; NSInteger lenght = tmp.length; tmp = [NSString stringWithFormat:GJText(@"%@申请关注【%@】的设备"),tmp,dMessage.name]; NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:tmp]; [att addAttribute:NSForegroundColorAttributeName value:KKMainColor range:NSMakeRange(0,lenght)]; cell.messageLabel.attributedText = att; kWeakSelf(self) cell.agreeOrNOBlock = ^(BOOL ifAgree) { NSString *msg = [NSString stringWithFormat:GJText(@"确认%@用户关注【%@】?"),ifAgree ? GJText(@"同意"):GJText(@"拒绝"),dMessage.name]; EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"提示") subtitle:msg AlertViewType:AlertViewTypeSystemAlert config:nil]; [alertV addAlertItem:^EasyAlertItem *{ return [EasyAlertItem itemWithTitle:GJText(@"取消") type:AlertItemTypeSystemCancel callback:nil]; }]; [alertV addAlertItem:^EasyAlertItem *{ return [EasyAlertItem itemWithTitle:GJText(@"确定") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) { [weakself ApprovalFollow:dMessage status:ifAgree ? 1 : 2]; }]; }]; [alertV showAlertView]; }; } else if (dMessage.action == 0 && ![dMessage.adminId isEqualToString:APIManager.sharedManager.loginModel.openid]) { //审核结果消息 cell.messageLabel.text = F(GJText(@"关注(%@)设备审核中"),dMessage.imei); } else { NSString *state = dMessage.action == 1 ? GJText(@"同意") : dMessage.action == 2 ? GJText(@"拒绝") : GJText(@"审核中"); NSString *str = F(GJText(@"设备(%@)的管理员%@关注设备"),dMessage.imei,state); if ([dMessage.adminId isEqualToString:APIManager.sharedManager.loginModel.openid]) str = F(GJText(@"您%@用户(%@)申请关注【%@】的设备"),state,dMessage.phone,dMessage.name); cell.messageLabel.text = str; } cell.aTitleLabel.text = titleStr; if (dMessage.read && [dMessage.read intValue] == 0) { cell.readLabel.hidden = NO; } else { cell.readLabel.hidden = YES; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ AttentionModel *dMessage = self.modelListArr[indexPath.section]; [UICommon MessageUpload:@"加载中"]; [self updateInfoStatus:dMessage]; } //- (void)viewWillAppear:(BOOL)animated //{ // [super viewWillAppear:animated]; // [self xiaoxiyidu]; //} - (void)xiaoxiyidu { [self.modelListArr enumerateObjectsUsingBlock:^(AttentionModel *model, NSUInteger idx, BOOL * _Nonnull stop) { if (model.read && model.read == 0) { [self updateInfoStatus:model]; } }]; } - (void)updateInfoStatus:(AttentionModel *)model { kWeakSelf(self) NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [[[APIManager sharedManager] APGET:F(@"%@%@/1", UpdateInfoStatus_URL,model.Id) parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) { [UICommon HidenLoading]; [weakself GetQueryFollowInfo:TableisReload_h]; [[NSNotificationCenter defaultCenter] postNotificationName:KK_UPDATE_ALL_NEWS_MESSAGE object:nil]; } error:^(NSError * _Nullable error) { NSDictionary *dic = error.userInfo; [UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; }]; } #pragma mark 管理员审批申请关注接口 /// 管理员审批申请关注接口 - (void)ApprovalFollow:(AttentionModel *)dMessage status:(NSInteger)status { [UICommon MessageUpload:@"加载中"]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setValue:dMessage.adminId forKey:@"adminId"]; [parameters setValue:@"" forKey:@"email"]; [parameters setValue:dMessage.Id forKey:@"id"]; [parameters setValue:dMessage.imei forKey:@"imei"]; [parameters setValue:dMessage.phone forKey:@"phone"]; [parameters setValue:dMessage.relationship forKey:@"relationship"]; [parameters setValue:dMessage.relationshipImageId forKey:@"relationshipImageId"]; [parameters setValue:dMessage.userId forKey:@"userId"]; [parameters setValue:@(status) forKey:@"status"];// 1通过,2拒绝 [[[APIManager sharedManager] APPOST:ApprovalFollow_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { [UICommon HidenLoading]; [[NSNotificationCenter defaultCenter] postNotificationName:KK_UPDATE_ALL_NEWS_MESSAGE object:nil]; [UICommon MessageSuccessText:@"操作成功"]; [self GetQueryFollowInfo:TableisReload_h]; } 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 GetQueryFollowInfo:TableisReload_h]; } @end