ProfileController.m 4.8 KB
//
//  ProfileController.m
//  DreamSleep
//
//  Created by peter on 2022/4/1.
//

#import "ProfileController.h"
#import "FeedbackController.h"
#import "AccountController.h"
#import "SystemSetController.h"
#import "InviteController.h"
#import "ProfileAlertView.h"
#import "ProfileTableView.h"
#import "DailyTaskController.h"
#import "MyPointController.h"

@interface ProfileController () <ProfileTableViewDelegate>
@property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) ProfileTableView *profileTableView;
@end

@implementation ProfileController

- (void)viewDidLoad {
    self.naviTitle = @"我的";
    self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
    [self.view addSubview:self.bgIV];
    [self.view addSubview:self.profileTableView];
    
    [super viewDidLoad];
}

#pragma mark - ProfileTableViewDelegate
- (void)didSelectedIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0: // 意见反馈入口
            {
                [self jumpViewController:@"FeedbackController"];
            }
                break;
            case 1: // 系统设置入口
            {
                SystemSetController *sysVC = [SystemSetController new];
                [self.navigationController pushViewController:sysVC animated:YES];
            }
                break;
            case 2: // 邀请好友
            {
                InviteController *inviteVC = [InviteController new];
                [self.navigationController pushViewController:inviteVC animated:YES];
            }
                break;
            case 3: // 关于我们
            {
                [self.navigationController pushViewController:[[DsWebController alloc] initWithTitle:@"关于我们" link:AboutUS] animated:YES];
            }
                break;
            default:
                break;
        }
    } else if (indexPath.section == 1) {
        switch (indexPath.row) {
            case 0: // 前往小程序
            {
                [[[ProfileAlertView alloc] initWithIndexPath:indexPath] showAlertView];
            }
                break;
            case 1: // 关注公众号
            {
                [UIPasteboard generalPasteboard].string = @"xiaomeng-sleep";
                [[[ProfileAlertView alloc] initWithIndexPath:indexPath] showAlertView];
            }
                break;
            case 2: // 添加客服微信
            {
                [UIPasteboard generalPasteboard].string = @"xiaomengsleep";
                [[[ProfileAlertView alloc] initWithIndexPath:indexPath] showAlertView];
            }
                break;
            default:
                break;
        }
    }
}

- (void)showNaviBar:(CGFloat)alpha {
    self.naviBarAlpha = alpha;
}

- (void)isUpdateStatusStyle:(BOOL)isUpdate {
    self.isNeedUpdateStatusBarStyle = isUpdate;
}

- (void)dealScoreTaskAction:(NSInteger)index {
    switch (index) {
        case 1: // 每日任务
        {
            [self jumpViewController:@"DailyTaskController"];
        }
            break;
        case 2: // 我的积分
        {
            [self jumpViewController:@"MyPointController"];
        }
            break;
        case 3: // 开通AI
        {
            self.tabBarController.selectedIndex = 1;
        }
            break;
        case 4: // 我的睡眠报告
        {
            [self.navigationController pushViewController:[[DsWebController alloc] initWithLink:MySleepReportURL isShowNavi:NO] animated:YES];
        }
            break;
        case 5: // 我的睡眠评测
        {
            [self.navigationController pushViewController:[[DsWebController alloc] initWithLink:MySleepReviewURL isShowNavi:NO] animated:YES];
        }
            break;
        default:
            break;
    }
}

#pragma mark - Actions
- (void)modifyUserInfoAction {
    // 账户与资料页面
    [self jumpViewController:@"AccountController"];
}

- (void)jumpViewController:(NSString *)className {
    // 判断是否登录成功
    if ([LoginUtils getUserLoginData]) {
        // 进入相关页面
        Class cls = NSClassFromString(className);
        [self.navigationController pushViewController:[cls new] animated:YES];
    } else {
        // 跳转到登录页面
        [LoginUtils jumpToLoginControllerWithTarget:self];
    }
}

#pragma mark - lazy
- (UIImageView *)bgIV {
    if (!_bgIV) {
        _bgIV = [[UIImageView alloc] dk_initWithImagePicker:DKImagePickerWithNames(@"bg_person_normal", @"dk_bg_person_normal", @"bg_person_normal")];
        _bgIV.frame = CGRectMake(0, 0, kScreenWidth, 220);
    }
    return _bgIV;
}

- (ProfileTableView *)profileTableView {
    if (!_profileTableView) {
        _profileTableView = [[ProfileTableView alloc] initWithDelegate:self];
    }
    return _profileTableView;
}

@end