// // MineViewController.m // 千模 // // Created by Drew on 2018/10/24. // Copyright © 2018 MUMEI. All rights reserved. // #import "MineNewViewController.h" #import "MyWalletController.h" #import "MySkillsController.h" #import "MyOrderController.h" #import "ModelDataController.h" #import "PlatformActivityController.h" #import "AboutUsViewController.h" #import "ModelCodeController.h" #import "PromoteController.h" #import "SettingsViewController.h" #import "ShareViewController.h" #import "IntroView.h" #import "ModelCardController.h" #import "RankController.h" #import "ApplyRecommendView.h" #import "WZLBadgeImport.h" #import "AppDelegate.h" #import "LoginViewController.h" #import "SwitchClientAlertController.h" #import "SwitchClientPresentationController.h" @interface MineNewViewController () { BOOL online; } @property(weak, nonatomic) IBOutlet UIView *headView; @property(weak, nonatomic) IBOutlet UIView *bgView; @property(weak, nonatomic) IBOutlet UILabel *nameLabel; @property(weak, nonatomic) IBOutlet UIView *avatarBg; @property(weak, nonatomic) IBOutlet UIImageView *avatarView; @property(weak, nonatomic) IBOutlet UIView *container1; @property(weak, nonatomic) IBOutlet UIView *container2; @property(weak, nonatomic) IBOutlet UIView *incomeView; @property(weak, nonatomic) IBOutlet UILabel *incomeLabel; @property(weak, nonatomic) IBOutlet UISwitch *onlineSwitch; @property(weak, nonatomic) IBOutlet UIView *modelCardView; @property(weak, nonatomic) IBOutlet UIView *skillView; @property(weak, nonatomic) IBOutlet UIView *switchView; @property(weak, nonatomic) IBOutlet UIView *switchIndicatorView; @property(weak, nonatomic) IBOutlet UIView *transformView; @property(weak, nonatomic) IBOutlet UIImageView *orderIcon; @end @implementation MineNewViewController - (void)viewDidLoad { [super viewDidLoad]; NSArray *constrains = self.headView.constraints; for (NSLayoutConstraint *constraint in constrains) { if (constraint.firstAttribute == NSLayoutAttributeHeight) { constraint.constant = 104 + [[UIApplication sharedApplication] statusBarFrame].size.height; } } [self.headView updateConstraints]; self.nameLabel.userInteractionEnabled = YES; self.avatarBg.layer.cornerRadius = 43; self.avatarView.layer.cornerRadius = 35; self.avatarView.layer.masksToBounds = YES; self.avatarView.userInteractionEnabled = YES; online = YES; } - (void)viewWillAppear:(BOOL)animated { [self.navigationController setNavigationBarHidden:YES animated:NO]; [self getDataFromNetworking]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; CAGradientLayer *gl = [CAGradientLayer layer]; gl.frame = CGRectMake(0, 0, self.headView.frame.size.width, 104 + [[UIApplication sharedApplication] statusBarFrame].size.height); gl.startPoint = CGPointMake(0, 0); gl.endPoint = CGPointMake(0, 1); gl.colors = @[(__bridge id) [UIColor colorWithRed:251 / 255.0 green:92 / 255.0 blue:163 / 255.0 alpha:1].CGColor, (__bridge id) [UIColor colorWithRed:253 / 255.0 green:127 / 255.0 blue:141 / 255.0 alpha:1].CGColor]; gl.locations = @[@(0), @(1.0f)]; [self.headView.layer addSublayer:gl]; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(30, 30)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = self.bgView.bounds; maskLayer.path = maskPath.CGPath; self.bgView.layer.mask = maskLayer; self.container1.layer.cornerRadius = 12; self.container1.layer.shadowColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.08].CGColor; self.container1.layer.shadowOffset = CGSizeMake(0, 6); self.container1.layer.shadowOpacity = 1; self.container1.layer.shadowRadius = 12; self.container2.layer.cornerRadius = 12; self.container2.layer.shadowColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.08].CGColor; self.container2.layer.shadowOffset = CGSizeMake(0, 6); self.container2.layer.shadowOpacity = 1; self.container2.layer.shadowRadius = 12; self.incomeView.layer.cornerRadius = 17; self.incomeView.layer.shadowColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:0.36].CGColor; self.incomeView.layer.shadowOffset = CGSizeMake(0, 8); self.incomeView.layer.shadowOpacity = 1; self.incomeView.layer.shadowRadius = 10; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; AppDelegate *app = [[UIApplication sharedApplication] delegate]; if (app.firstLogin) { __weak MineNewViewController *this = self; IntroView *introView = [[IntroView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) confirm:^{ ModelCardController *modelCardVC = [[ModelCardController alloc] init]; modelCardVC.type = @"init"; modelCardVC.hidesBottomBarWhenPushed = YES; [this.navigationController pushViewController:modelCardVC animated:YES]; } cancel:^{ }]; UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; CGRect rect1 = [self.modelCardView convertRect:self.modelCardView.bounds toView:window]; introView.icon1left.constant = rect1.origin.x + rect1.size.width / 2 - 43; introView.icon1top.constant = rect1.origin.y + rect1.size.height / 2 - 43 - [[UIApplication sharedApplication] statusBarFrame].size.height; CGRect rect2 = [self.skillView convertRect:self.skillView.bounds toView:window]; introView.icon2left.constant = rect2.origin.x + rect2.size.width / 2 - 43; [window addSubview:introView]; [introView updateConstraints]; [introView layoutIfNeeded]; app.firstLogin = false; } } - (void)viewWillDisappear:(BOOL)animated { [self.navigationController setNavigationBarHidden:NO animated:YES]; } - (void)getDataFromNetworking { // [MBProgressHUD showHUDAddedTo:self.view animated:YES]; NSDictionary *dic = @{@"modelpk": [ModelUser user].modelpk}; [YanCNetWorkManager requestPostWithURLStr:Url_refreshLogin(PublicUrl) parameters:dic finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { ModelUser *user = [ModelUser modelUser]; [user setValuesForKeysWithDictionary:dataDic[@"data"]]; user.modelpk = dataDic[@"data"][@"modelpk"]; user.coin_a = dataDic[@"data"][@"coin_a"]; user.coin_ir = dataDic[@"data"][@"coin_ir"]; user.pk = dataDic[@"data"][@"pk"]; user.qrcode = dataDic[@"data"][@"qrcode"]; [ModelUser save:user]; self.nameLabel.text = [NSString stringWithFormat:@"%@", dataDic[@"data"][@"pet"]]; [self.avatarView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", PublicUrl, dataDic[@"data"][@"hphoto"]]] placeholderImage:[UIImage imageNamed:@"morentouxiang"]]; online = user.is_a; [self setSwitchState:user.is_a]; if ([dataDic[@"data"][@"hasred"] isEqualToString:@"1"]) { [self.orderIcon showBadge]; } else { [self.orderIcon clearBadge]; } [self getIncomeFromNetworking]; } else { [MBProgressHUD showInfo:@"请重新登录"]; [self logout]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } - (void)logout { [[[NIMSDK sharedSDK] loginManager] logout:^(NSError *error) { }]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"token"]; [[NSUserDefaults standardUserDefaults] synchronize]; [self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil]; LoginViewController *loginController = [[LoginViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginController]; self.view.window.rootViewController = nav; } - (void)getIncomeFromNetworking { NSDictionary *dic = @{@"memberpk": [ModelUser modelUser].pk}; [YanCNetWorkManager requestPostWithURLStr:Url_getIncomeToday(PublicUrl) parameters:dic finish:^(id dataDic) { NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { self.incomeLabel.text = [NSString stringWithFormat:@"今日收入 %@元", dataDic[@"count"]]; } else { [MBProgressHUD showInfo:@"请求失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } - (IBAction)handelTap:(id)sender { switch (((UITapGestureRecognizer *) sender).view.tag) { case 1: { ModelCardController *modelCardVC = [[ModelCardController alloc] init]; modelCardVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:modelCardVC animated:YES]; break; } case 2: { MySkillsController *mySkillsVC = [[MySkillsController alloc] init]; mySkillsVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:mySkillsVC animated:YES]; break; } case 3: { [ApplyRecommendView showIntoView:[UIApplication sharedApplication].keyWindow confirm:^{ NSDictionary *dic = @{@"modelpk": [ModelUser modelUser].modelpk}; [YanCNetWorkManager requestPostWithURLStr:Url_applyRecommend(PublicUrl) parameters:dic finish:^(id res) { BOOL success = [res[@"success"] intValue] == 1; if (success) { [MBProgressHUD showInfo:@"申请已提交"]; } else { [MBProgressHUD showInfo:@"请求失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; }]; break; // UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确定申请首页推荐展示?" preferredStyle:UIAlertControllerStyleAlert]; // [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; // [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) { // NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser modelUser].modelpk, @"modelpk", nil]; // [YanCNetWorkManager requestPostWithURLStr:Url_applyRecommend(PublicUrl) // parameters:dic // finish:^(id res) { // BOOL success = [res[@"success"] intValue] == 1; // if (success) { // [MBProgressHUD showInfo:@"申请已提交"]; // } else { // [MBProgressHUD showInfo:@"请求失败!"]; // } // } // enError:^(NSError *error) { // [MBProgressHUD hideHUDForView:self.view animated:YES]; // }]; // }]]; // [self presentViewController:alert animated:YES completion:nil]; } case 4: { PromoteController *vc = [[PromoteController alloc] init]; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; break; } case 5: { MyOrderController *vc = [[MyOrderController alloc] init]; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; break; } case 6: { MyWalletController *myWalletVC = [[MyWalletController alloc] init]; myWalletVC.hidesBottomBarWhenPushed = YES; myWalletVC.amount = [ModelUser modelUser].coin_a; [self.navigationController pushViewController:myWalletVC animated:YES]; break; } case 7: { PlatformActivityController *activityVC = [[PlatformActivityController alloc] init]; activityVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:activityVC animated:YES]; break; } case 8: { AboutUsViewController *aboutUsVC = [[AboutUsViewController alloc] init]; aboutUsVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:aboutUsVC animated:YES]; break; } case 9: { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [MBProgressHUD hideHUDForView:self.view]; [MBProgressHUD showInfo:@"清理完成"]; }); break; } default: break; } } - (IBAction)tapSettings:(id)sender { SettingsViewController *settingsVC = [[SettingsViewController alloc] init]; settingsVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:settingsVC animated:YES]; } - (IBAction)tapSwitch:(id)sender { [self updateOnline:!online]; } - (IBAction)jumpToMemberClient:(id)sender { SwitchClientAlertController *vc = [[SwitchClientAlertController alloc] init]; vc.modalPresentationStyle = UIModalPresentationCustom; vc.transitioningDelegate = self; [self presentViewController:vc animated:YES completion:nil]; } - (void)updateOnline:(BOOL)state { __weak MineNewViewController *this = self; NSDictionary *dic = @{@"modelpk": [ModelUser modelUser].modelpk, @"state": @(state)}; [YanCNetWorkManager requestPostWithURLStr:Url_setOnline(PublicUrl) parameters:dic finish:^(id res) { BOOL success = [@"success" isEqualToString:res[@"msg"]]; if (success) { online = state; [this setSwitchState:state]; if (online) { MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES]; hud.mode = MBProgressHUDModeText; hud.detailsLabel.text = @"您已开启在线状态\n将优先排序获得更多商业订单"; hud.detailsLabel.font = [UIFont boldSystemFontOfSize:16]; hud.margin = 15.f; hud.removeFromSuperViewOnHide = YES; [hud.bezelView setBackgroundColor:[UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.8]]; hud.contentColor = [UIColor whiteColor]; [hud hideAnimated:YES afterDelay:2]; } else { MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES]; hud.mode = MBProgressHUDModeText; hud.detailsLabel.text = @"您已开启离线状态\n客户无法及时联系您将造成经济损失"; hud.detailsLabel.font = [UIFont boldSystemFontOfSize:16]; hud.margin = 15.f; hud.removeFromSuperViewOnHide = YES; [hud.bezelView setBackgroundColor:[UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.8]]; hud.contentColor = [UIColor whiteColor]; [hud hideAnimated:YES afterDelay:2]; } } else { [MBProgressHUD showInfo:@"请求失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } - (void)setSwitchState:(BOOL)state { if (state) { [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ self.switchView.backgroundColor = [UIColor whiteColor]; self.switchIndicatorView.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:1]; self.transformView.transform = CGAffineTransformMakeTranslation(0, 0); } completion:nil]; } else { [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ self.switchView.backgroundColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.3]; self.switchIndicatorView.backgroundColor = [UIColor whiteColor]; self.transformView.transform = CGAffineTransformMakeTranslation(-32, 0); } completion:nil]; } } - (IBAction)tapRank:(id)sender { RankController *rankVC = [[RankController alloc] init]; rankVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:rankVC animated:YES]; } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } #pragma mark - UIViewControllerTransitioningDelegate - (UIPresentationController* )presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source { if ([presented isKindOfClass:[SwitchClientAlertController class]]) { return [[SwitchClientPresentationController alloc] initWithPresentedViewController:presented presentingViewController:self]; } return [[UIPresentationController alloc] initWithPresentedViewController:presented presentingViewController:self]; } @end