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.
320 lines
12 KiB
320 lines
12 KiB
// |
|
// MyViewController.m |
|
// LekangGuard |
|
// |
|
// Created by ecell on 2022/9/27. |
|
// |
|
|
|
#import "MyViewController.h" |
|
#import "MessageViewController.h" |
|
#import "ProblemViewController.h" |
|
#import "AboutViewController.h" |
|
#import "DPClearCacheTool.h" |
|
#import "ModifyDataViewController.h" |
|
#import "MyTableViewHeaderView.h" |
|
#import "MyTableViewCell.h" |
|
#import "SchAndJobMessageViewController.h" |
|
|
|
@interface MyViewController ()<UITableViewDelegate,UITableViewDataSource> |
|
|
|
@property (strong, nonatomic)NSMutableArray * iconImageArr; |
|
@property (strong, nonatomic)NSMutableArray * myDataSource; |
|
|
|
@property (nonatomic ,strong) UITableView *moreTableView; |
|
|
|
@property (nonatomic ,strong) MyTableViewHeaderView *headerView; |
|
|
|
|
|
@property (nonatomic ,assign) NSInteger messageCount; |
|
|
|
|
|
@property (nonatomic ,strong) MyUserMsgModel *userModel; |
|
|
|
@end |
|
|
|
@implementation MyViewController |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
self.view.backgroundColor = RGB(245, 248, 255); |
|
self.zx_navBarBackgroundColor = KKClearColor; |
|
|
|
self.zx_navLeftBtn.titleLabel.font = FontBoldADA_(18); |
|
[self.zx_navLeftBtn setZx_tintColor:KKTextBlackColor]; |
|
[self.zx_navLeftBtn setTitle:@"我的" forState:0]; |
|
[self.zx_navRightBtn setZx_imageColor:KKTextBlackColor]; |
|
|
|
[self zx_setRightBtnWithImg:ImageName_(@"icon_exit") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { |
|
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:nil subtitle:GJText(@"确定退出登录吗") AlertViewType:AlertViewTypeSystemActionSheet config:nil]; |
|
[alertV addAlertItem:^EasyAlertItem *{ |
|
return [EasyAlertItem itemWithTitle:GJText(@"取消") type:AlertItemTypeSystemCancel callback:nil]; |
|
}]; |
|
[alertV addAlertItemWithTitle:GJText(@"退出登录") type:AlertItemTypeSystemDestructive callback:^(EasyAlertView *showview, long index) { |
|
[self Logout]; |
|
}]; |
|
|
|
[alertV showAlertView]; |
|
}]; |
|
|
|
[self.view addSubview:self.moreTableView]; |
|
|
|
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"XIAOHONGHUA" object:nil] subscribeNext:^(NSNotification *x) { |
|
[self GetUnReadTotal]; |
|
}]; |
|
|
|
} |
|
|
|
|
|
|
|
- (UITableView *)moreTableView |
|
{ |
|
if (!_moreTableView) |
|
{ |
|
_moreTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, iPhoneX_NavHeight, SCREEN_WIDTH, SCREEN_HEIGHT-iPhoneX_NavHeight-TabBarHeight) style:UITableViewStylePlain]; |
|
_moreTableView.delegate = self; |
|
_moreTableView.dataSource = self; |
|
_moreTableView.backgroundColor = KKClearColor; |
|
_moreTableView.tableHeaderView = self.headerView; |
|
_moreTableView.tableHeaderView.height = 185; |
|
[_moreTableView registerClass:MyTableViewCell.class forCellReuseIdentifier:NSStringFromClass(MyTableViewCell.class)]; |
|
[UICommon setTavleViewlink:_moreTableView distance:10]; |
|
} |
|
return _moreTableView; |
|
} |
|
|
|
- (MyTableViewHeaderView *)headerView |
|
{ |
|
if (!_headerView) |
|
{ |
|
_headerView = [[MyTableViewHeaderView alloc] init]; |
|
_headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 185); |
|
[_headerView seCellModel]; |
|
} |
|
return _headerView; |
|
} |
|
|
|
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ |
|
return self.myDataSource.count; |
|
} |
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ |
|
|
|
return 55; |
|
} |
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
MyTableViewCell *cell = [MyTableViewCell cellWithTableView:tableView indexPath:indexPath]; |
|
cell.imageName = self.iconImageArr[indexPath.row]; |
|
cell.titleName = self.myDataSource[indexPath.row]; |
|
cell.messageCount = self.messageCount; |
|
[UICommon tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath cellCoutn:self.myDataSource.count sizeH:10]; |
|
return cell; |
|
} |
|
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
kWeakSelf(self) |
|
NSString *title = self.myDataSource[indexPath.row]; |
|
if ([title isEqualToString:@"消息中心"]) |
|
{ |
|
MessageViewController *vc = [MessageViewController new]; |
|
vc.selectedIndex = 0; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
} |
|
else if ([title isEqualToString:@"校园通知"]) |
|
{ |
|
SchAndJobMessageViewController *vc = [[SchAndJobMessageViewController alloc] init]; |
|
vc.navTitle = @"校园通知"; |
|
vc.viewType = 0; |
|
[[UICommon currentVC].navigationController pushViewController:vc animated:YES]; |
|
} |
|
else if ([title isEqualToString:@"意见反馈"]) |
|
{ |
|
NSString *string = [NSString stringWithFormat:@"mailto://support@ecellsz.com ?subject=%@意见反馈",APPName]; |
|
string = [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; |
|
NSURL *emailURL = [NSURL URLWithString:string]; |
|
[[UIApplication sharedApplication] openURL:emailURL options:[NSDictionary new] completionHandler:nil]; |
|
} |
|
else if ([title isEqualToString:@"清除缓存"]) |
|
{ |
|
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"提示") subtitle:GJText(@"确定要清除缓存吗?") 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) { |
|
[DPClearCacheTool clearCaches]; |
|
AfterDispatch(1, ^{ |
|
[weakself.moreTableView reloadData]; |
|
}); |
|
}]; |
|
}]; |
|
[alertV showAlertView]; |
|
} |
|
else if ([title isEqualToString:@"关于我们"]) |
|
{ |
|
AboutViewController *vc = [AboutViewController new]; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
} |
|
else if ([title isEqualToString:@"修改密码"]) |
|
{ |
|
} |
|
else if ([title isEqualToString:@"常见问题"]) |
|
{ |
|
ProblemViewController *vc = [ProblemViewController new]; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
} |
|
} |
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ |
|
if (section == 0) { |
|
return 130; |
|
} |
|
return 0.01; |
|
} |
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ |
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; |
|
if (section == 0) |
|
{ |
|
UIButton *btn2 = [UICommon ui_buttonSimple:CGRectMake(20, 50,SCREEN_WIDTH-40, 50) font:FontBold_(18) normalColor:KKWhiteColorColor normalText:@"注销用户(谨慎)" click:^(id x) { |
|
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"警告:注销用户信息将被清空无法恢复,请确认是否注销!") subtitle:nil AlertViewType:AlertViewTypeSystemAlert config:nil]; |
|
[alertV addAlertItem:^EasyAlertItem *{ |
|
return [EasyAlertItem itemWithTitle:GJText(@"取消") type:AlertItemTypeSystemCancel callback:^(EasyAlertView *showview, long index) {}]; |
|
}]; |
|
[alertV addAlertItem:^EasyAlertItem *{ |
|
return [EasyAlertItem itemWithTitle:GJText(@"确定") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) { |
|
[self UserCancel]; |
|
}]; |
|
}]; |
|
[alertV showAlertView]; |
|
}]; |
|
[btn2 setBackgroundColor:KKMainColor]; |
|
btn2.layer.cornerRadius = 25; |
|
btn2.layer.masksToBounds = YES; |
|
[view addSubview:btn2]; |
|
|
|
} |
|
return view; |
|
} |
|
|
|
- (void)viewWillAppear:(BOOL)animated |
|
{ |
|
[super viewWillAppear:animated]; |
|
self.myDataSource = [[NSMutableArray alloc] initWithObjects:@"消息中心",@"校园通知",@"关于我们",@"常见问题",@"清除缓存",@"意见反馈", nil]; |
|
self.iconImageArr = [[NSMutableArray alloc] initWithObjects:@"icon_message_center",@"icon_campus_news",@"icon_aboutus",@"icon_question",@"icon_cleanup",@"icon_feedback", nil]; |
|
|
|
if (APIManager.sharedManager.deviceList.count <= 0 || APIManager.sharedManager.deviceModel.virtualFlag) |
|
{ |
|
self.myDataSource = [[NSMutableArray alloc] initWithObjects:@"消息中心",@"关于我们",@"常见问题",@"清除缓存",@"意见反馈", nil]; |
|
self.iconImageArr = [[NSMutableArray alloc] initWithObjects:@"icon_message_center",@"icon_aboutus",@"icon_question",@"icon_cleanup",@"icon_feedback", nil]; |
|
} |
|
[self QueryMsg]; |
|
[self GetUnReadTotal]; |
|
} |
|
|
|
#pragma mark 查看个人资料 |
|
/// 查看个人资料 |
|
- (void)QueryMsg |
|
{ |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"]; |
|
[[[APIManager sharedManager] APGET:QueryMsg_URL parameters:parameters resultClass:MyUserMsgModel.class] subscribeNext:^(MyUserMsgModel *model) { |
|
[UICommon HidenLoading]; |
|
if (model != nil) |
|
{ |
|
self.userModel = model; |
|
[self.headerView seCellModel]; |
|
[self.moreTableView reloadData]; |
|
} |
|
|
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
|
|
#pragma mark 用户注销 |
|
/// 用户注销 |
|
- (void)UserCancel |
|
{ |
|
[UICommon MessageUpload:@"正在注销"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[[[APIManager sharedManager] APGET:UserCancel_URL parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
[UICommon MessageSuccessText:@"注销成功"]; |
|
[[NSNotificationCenter defaultCenter] postNotificationName:sRelogin object:nil]; |
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
#pragma mark 退出登录 |
|
/// 退出登录 |
|
- (void)Logout |
|
{ |
|
[UICommon MessageUpload:@"正在退出登录"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[[[APIManager sharedManager] APGET:Logout_URL parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
[[NSNotificationCenter defaultCenter] postNotificationName:sRelogin object:nil]; |
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
#pragma mark 查询未读消息数 |
|
/// 查询未读消息数 |
|
- (void)GetUnReadTotal |
|
{ |
|
kWeakSelf(self) |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[[[APIManager sharedManager] APGET:UnReadTotal_URL parameters:parameters resultClass:nil] subscribeNext:^(NSArray *arr) { |
|
[UICommon HidenLoading]; |
|
if (ARRAYHASVALUE(arr)) |
|
{ |
|
self.messageCount = 0; |
|
for (NSDictionary *obj in arr) { |
|
NSInteger total = [obj[@"total"] integerValue]; |
|
NSInteger type = [obj[@"type"] integerValue]; |
|
if (type != 3) |
|
{ |
|
self.messageCount += total; |
|
} |
|
} |
|
[self.moreTableView reloadData]; |
|
} |
|
|
|
|
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
#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
|
|
|