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.

385 lines
16 KiB

2 years ago
//
// 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"
@interface MyViewController ()
@property (nonatomic ,strong) UIScrollView *myScroll;
@property (nonatomic ,weak) UIView *headerView;
@property (nonatomic ,weak) UIView *bgView;
@property (nonatomic ,weak) UILabel *cacheLabel;
@property (nonatomic ,assign) UILabel *nameLabel;
@property (nonatomic ,assign) UILabel *phoneLabel;
@property (nonatomic ,assign) UIButton *iconImg;
@property (nonatomic ,weak) UILabel *newsMeg;
@property (nonatomic ,strong) MyUserMsgModel *userModel;
@end
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.zx_navTitle = GJText(@"我的");
self.view.backgroundColor = KKBackgroundGrey;
[self.view addSubview:self.myScroll];
[self.myScroll mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.view).offset(iPhoneX_NavHeight);
make.bottom.equalTo(self.view.mas_bottom);
}];
//[self QueryMsg];
NSArray *titleArr = @[@[@""],
@[GJText(@"消息中心"),GJText(@"清除缓存")],
@[GJText(@"关于我们"),GJText(@"常见问题")],
//@[GJText(@"地图切换")]
];
NSArray *imgeArr = @[@[@""],
@[@"icon_my_message_center",@"icon_my_clear_the_cache"],
@[@"icon_my_about_us",@"icon_my_common_problems"],
//@[@"icon_common_map"]
];
for (int i = 0; i < titleArr.count; i++)
{
CGFloat hh = Adapted(100);
//if (i == titleArr.count-1) hh = Adapted(50);
UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:8 borderWidth:0 borderColor:KKWhiteColorColor];
bgView.frame = CGRectMake(10, 10+i*10+Adapted(100)*i, SCREEN_WIDTH-20, hh);
if(i == 0) self.headerView = bgView;
else if(i == titleArr.count-1) self.bgView = bgView;
[self.myScroll addSubview:bgView];
if (i > 0)
{
NSArray *tArr = titleArr[i];
NSArray *iarr = imgeArr[i];
for (int j = 0; j < tArr.count; j++)
{
UIImageView *leftImg = [UICommon ui_imageView:CGRectZero fileName:iarr[j]];
[bgView addSubview:leftImg];
UIButton *btn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(14) normalColor:KKTextBlackColor normalText:tArr[j] click:^(UIButton *button) {
if ([button.currentTitle isEqualToString:GJText(@"消息中心")])
{
MessageViewController *vc = [MessageViewController new];
vc.selectedIndex = 0;
[self.navigationController pushViewController:vc animated:YES];
}
else if ([button.currentTitle isEqualToString:GJText(@"常见问题")])
{
ProblemViewController *vc = [ProblemViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
else if ([button.currentTitle isEqualToString:GJText(@"关于我们")])
{
AboutViewController *vc = [AboutViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
else if ([button.currentTitle isEqualToString:GJText(@"清除缓存")])
{
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) {
//[UICommon MessageUpload:@"清除缓存中"];
[DPClearCacheTool clearCaches];
AfterDispatch(1, ^{
//[UICommon HidenLoading];
self.cacheLabel.text = [DPClearCacheTool getCacheSize];
});
}];
}];
[alertV showAlertView];
}
}];
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[bgView addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(bgView).offset(Adapted(50)*j);
make.left.equalTo(bgView).offset(Adapted(leftImg.image.size.width)+20);
make.right.equalTo(bgView.mas_right);
make.height.mas_equalTo(Adapted(50));
}];
[leftImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(bgView).offset(10);
make.centerY.equalTo(btn);
make.size.mas_equalTo(CGSizeMake(Adapted(leftImg.image.size.width), Adapted(leftImg.image.size.height)));
}];
UIImageView *rightImg = [UICommon ui_imageView:CGRectZero fileName:@"icon_enter_gray"];
[bgView addSubview:rightImg];
[rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(bgView.mas_right).inset(10);
make.centerY.equalTo(btn);
make.size.mas_equalTo(rightImg.image.size);
}];
if (i == 1 && j == 0)
{
/// 未读消息展示红点
UILabel *newsMeg = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(12) textColor:KKGrey121 text:@"" Radius:5];
newsMeg.backgroundColor = UIColor.redColor;
newsMeg.hidden = YES;
self.newsMeg = newsMeg;
[bgView addSubview:newsMeg];
[newsMeg mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(rightImg.mas_left).inset(15);
make.centerY.equalTo(btn);
make.width.height.mas_equalTo(10);
}];
}
if (i == 1 && j == 1)
{
///缓存显示
UILabel *cacheLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(12) textColor:KKGrey121 text:[DPClearCacheTool getCacheSize] Radius:0];
self.cacheLabel = cacheLabel;
[bgView addSubview:cacheLabel];
[cacheLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(rightImg.mas_left).inset(15);
make.centerY.equalTo(btn);
}];
}
if (tArr.count > 1)
{
UILabel *line = [UILabel new];
line.backgroundColor = KKLineColor;
[bgView addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(bgView);
make.centerY.equalTo(bgView);
make.height.mas_equalTo(0.5);
}];
}
}
}
else
{
UIButton *btn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(0) normalColor:KKTextBlackColor normalText:@"" click:^(UIButton *button) {
ModifyDataViewController *vc = [ModifyDataViewController new];
vc.model = self.userModel;
[self.navigationController pushViewController:vc animated:YES];
}];
[bgView addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(bgView);
make.left.right.equalTo(bgView);
make.height.mas_equalTo(hh);
}];
}
}
UIButton *outLoginBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(15) normalColor:KKWhiteColorColor normalText:GJText(@"退出登录") click:^(id x) {
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];
}];
outLoginBtn.backgroundColor = KKMainColor;
outLoginBtn.layer.cornerRadius = 8;
outLoginBtn.layer.masksToBounds = YES;
[self.view addSubview:outLoginBtn];
[outLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view).inset(10);
make.top.equalTo(self.bgView.mas_bottom).offset(Adapted(50));
make.height.mas_equalTo(Adapted(45));
}];
UIButton *cancelBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(15) normalColor:UIColor.redColor normalText:GJText(@"注销用户(谨慎)") 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];
}];
cancelBtn.layer.borderWidth = 1;
cancelBtn.layer.borderColor = UIColor.redColor.CGColor;
cancelBtn.layer.cornerRadius = 8;
[self.view addSubview:cancelBtn];
[cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view).inset(10);
make.top.equalTo(outLoginBtn.mas_bottom).offset(Adapted(20));
make.height.mas_equalTo(Adapted(45));
}];
/// 头像
UIButton *iconImg = [UICommon ui_buttonSimple:CGRectZero font:0 normalColor:KKWhiteColorColor normalText:@"" click:^(id x) {
ModifyDataViewController *vc = [ModifyDataViewController new];
vc.model = self.userModel;
[self.navigationController pushViewController:vc animated:YES];
}];
iconImg.layer.cornerRadius = Adapted(33);
iconImg.layer.masksToBounds = YES;
iconImg.backgroundColor = KKWhiteColorColor;
self.iconImg = iconImg;
[self.headerView addSubview:iconImg];
[iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.headerView).offset(15);
make.centerY.equalTo(self.headerView);
make.width.height.mas_equalTo(Adapted(66));
}];
UILabel *nameLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBoldADA_(18) textColor:KKTextBlackColor text:@"" Radius:0];
self.nameLabel = nameLabel;
[self.headerView addSubview:nameLabel];
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(iconImg.mas_right).offset(10);
make.top.equalTo(iconImg).offset(5);
}];
UILabel *phoneLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(15) textColor:KKGrey219 text:@"" Radius:0];
self.phoneLabel = phoneLabel;
[self.headerView addSubview:phoneLabel];
[phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(nameLabel.mas_left);
make.bottom.equalTo(iconImg.mas_bottom).inset(5);
}];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[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.iconImg sd_setImageWithURL:[NSURL URLWithString:model.image] forState:0 placeholderImage:ImageName_(@"icon_adults_occupies_the_head")];
self.nameLabel.text = model.name;
self.phoneLabel.text = F(@"%@:%@",GJText(@"号码"), model.phone.length > 0 ? model.phone : @"--");
}
} 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))
{
[arr enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSInteger total = [obj[@"total"] integerValue];
weakself.newsMeg.hidden = total > 0 ? NO : YES;
}];
}
} error:^(NSError * _Nullable error) {
NSDictionary *dic = error.userInfo;
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
}];
}
- (UIScrollView *)myScroll
{
if (!_myScroll)
{
_myScroll = [UIScrollView new];
_myScroll.backgroundColor = KKClearColor;
}
return _myScroll;
}
/*
#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