// // MaskTestResultVC.m // GIGA // // Created by lianxiang on 2018/9/13. // Copyright © 2018年 com.giga.ios. All rights reserved. // #import "MaskTestResultVC.h" #import "MaskResultMinViewCell.h" #import "MaskResultPercentCell.h" #import "MaskResultShareViewCell.h" #import "GIGaUserFileHelper.h" #import "UIImage+ShotImage.h" #import "GiGaBaseAPiRequest.h" #import "GiGaFileNanager.h" #import #import "MaskTestResult.h" #import "MaskTestNODataViewCell.h" #import "UIButton+WebCache.h" #import "UIImageView+WebCache.h" #import "GiGaUserInfoVC.h" #import "LXCustomActionSheet.h" @interface MaskTestResultVC () @property (nonatomic,strong) UIView *tabheader; //@property (nonatomic,strong) UIImageView *qrimageView; @end @implementation MaskTestResultVC - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.view addSubview:self.tableView]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.backgroundColor = [UIColor whiteColor]; self.tableView.separatorStyle = UITableViewCellSelectionStyleNone; self.tableView.sectionFooterHeight = 0; self.tableView.estimatedSectionFooterHeight= 0; self.tableView.estimatedSectionHeaderHeight = 0; //分享用默认隐藏 UIView *holdView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, SAFE_NAV_HEIGHT)]; holdView.backgroundColor = [UIColor whiteColor]; UIView *tabheader = [[UIView alloc] initWithFrame:holdView.bounds]; tabheader.backgroundColor = GIGA_MAIN_BGCOLOR; [holdView addSubview:tabheader]; UILabel *reslabel = [[UILabel alloc] init]; reslabel.text = @"我的皮肤测试结果:"; reslabel.textColor = [UIColor whiteColor]; reslabel.font = GIGA_TEXTFONTBOLD(20); [tabheader addSubview:reslabel]; [reslabel sizeToFit]; [reslabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(tabheader.mas_left).offset(18); make.centerY.mas_equalTo(tabheader.mas_centerY); }]; UIImageView *shareUserImageView = [[UIImageView alloc] init]; BOOL isUserLogin = [GiGaUserDefault isUserLogin]; if (isUserLogin) { GiGaUser *user = [[GiGaUserManager shareUser] getCurrentUser]; if (user) { if (user.headImgUrl && ![user.headImgUrl isKindOfClass:[NSNull class]]) { NSURL *url = [NSURL URLWithString:user.headImgUrl]; [shareUserImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"nav_circle_avatar"]]; } } } [tabheader addSubview:shareUserImageView]; [shareUserImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(tabheader.mas_right).offset(-18); make.size.mas_equalTo(CGSizeMake(34, 34)); make.centerY.mas_equalTo(tabheader.mas_centerY); }]; shareUserImageView.layer.masksToBounds = YES; shareUserImageView.layer.cornerRadius = 17; tabheader.hidden = YES; self.tabheader = tabheader; self.tableView.tableHeaderView = holdView; self.tableView.frame = CGRectMake(0,-SAFE_NAV_HEIGHT,KMainW,KMainH); [self.tableView registerClass:[MaskResultPercentCell class] forCellReuseIdentifier:@"MaskResultPercentCell"]; [self.tableView registerClass:[MaskResultMinViewCell class] forCellReuseIdentifier:@"MaskResultMinViewCell"]; [self.tableView registerClass:[MaskResultShareViewCell class] forCellReuseIdentifier:@"MaskResultShareViewCell"]; // if (@available(iOS 11.0, *)) { // self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; // // // } else { // // self.automaticallyAdjustsScrollViewInsets = NO; // } if (!self.model) { [self addNavTitile:@"历史测试"]; [self requstLatestTestData]; }else{ [self addNavTitile:@"测试结果"]; } NC_ADD_TARGET_NAME_OBJECT(self, @selector(usershareSuccessNoti), NC_UseShareSuccessNoti, nil); [self initUserAvator]; //重写返回按钮 UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; backBtn.frame = CGRectMake(0, 0, 40, 40); [backBtn setImage:[UIImage imageNamed:@"btn_moment_back"] forState:UIControlStateNormal]; [backBtn setImageEdgeInsets:UIEdgeInsetsMake(0,-14, 0, 14)]; //backBtn.backgroundColor = [UIColor redColor]; [backBtn addTarget:self action:@selector(backItemAction) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn]; self.navigationItem.leftBarButtonItem = backItem; } //重写返回事件 - (void)backItemAction{ if (_isfromshouYE) { [self.navigationController popToRootViewControllerAnimated:YES]; }else{ [self.navigationController popViewControllerAnimated:YES]; } } - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; if (_isfromshouYE) { if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; } } } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; if (_isfromshouYE) { if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; } } } -(void)dealloc{ NC_REMOVE_NAME(self, NC_UseShareSuccessNoti, nil); } -(void)initUserAvator{ //rightItem UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom]; rightBtn.frame = CGRectMake(0, 0, 40, 40); rightBtn.layer.masksToBounds = YES; rightBtn.layer.cornerRadius = 20; [rightBtn setImage:[UIImage imageNamed:@"nav_circle_avatar"] forState:UIControlStateNormal]; [rightBtn addTarget:self action:@selector(goUserInfoView) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn]; if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 11.0) { [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(40, 40)); }]; } BOOL isUserLogin = [GiGaUserDefault isUserLogin]; if (isUserLogin) { GiGaUser *user = [[GiGaUserManager shareUser] getCurrentUser]; if (user) { if (user.headImgUrl && ![user.headImgUrl isKindOfClass:[NSNull class]]) { NSURL *url = [NSURL URLWithString:user.headImgUrl]; [rightBtn sd_setImageWithURL:url forState:UIControlStateNormal]; } } } } -(void)goUserInfoView{ GiGaUserInfoVC *userVC= [[GiGaUserInfoVC alloc] init]; [self.navigationController pushViewController:userVC animated:YES]; } -(void)requstLatestTestData{ [self.view makeToastActivity:CSToastPositionCenter]; GiGaBaseAPiRequest *api = [GiGaBaseAPiRequest initWithRequestPath:kApiGetLatestTest method:RequestPostMethod parms:@{}]; [api requstDataWithResult:^(GiGaAPIResult *result) { [self.view hideToastActivity]; if (result.success) { NSDictionary *dic = result.dic; NSDictionary *reult = dic[@"result"]; MaskTestResult *resultMode = [[MaskTestResult alloc] initWithDictionary:reult error:nil]; self.model = resultMode; [self.tableView reloadData]; }else{ GIGA_ShowToast(result.message); } }]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (self.model == nil) { return 1; } return 3; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (self.model == nil) { MaskTestNODataViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MaskTestNODataViewCell"]; if(!cell){ cell = [[[NSBundle mainBundle] loadNibNamed:@"MaskTestNODataViewCell" owner:self options:nil] lastObject]; } [cell.testBtn addTarget:self action:@selector(testBtnAction) forControlEvents:UIControlEventTouchUpInside]; return cell; } if (indexPath.row == 0) { static NSString *cellID = @"MaskResultPercentCell"; MaskResultPercentCell *cell =[tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[MaskResultPercentCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];; } [cell loadCellData:self.model]; return cell; }else if (indexPath.row == 1){ static NSString *cellID = @"MaskResultMinViewCell"; MaskResultMinViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[MaskResultMinViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];; } [cell loadMineWith:self.model.minute]; return cell; }else if (indexPath.row == 2){ static NSString *cellID = @"MaskResultShareViewCell"; MaskResultShareViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[MaskResultShareViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];; } [cell.shareBtn addTarget:self action:@selector(shareBtnAciton) forControlEvents:UIControlEventTouchUpInside]; [cell kidTitle:self.model]; return cell; } return nil; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (self.model == nil) { return 255; } if (KMainW == 375) { return (KMainH - SAFE_NAV_HEIGHT) / 3.00 - 10; }else if (KMainW <= 375){ return 201; } CGFloat viewH = self.view.frame.size.height - SAFE_NAV_HEIGHT; CGFloat cellH = viewH / 3; return cellH; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.1; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.1; } -(void)shareBtnAciton{ if (![WXApi isWXAppInstalled]) { GIGA_ShowToast(@"未安装微信"); return; } [self showFinalShareView]; UIImage *image = [UIImage saveNavsuitImage:self.tableView]; //[[GiGaFileNanager shareInstance] saveImaeToAlBum:image]; // [self jxt_showActionSheetWithTitle:@"分享到微信" message:@"" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { // // alertMaker.addActionDefaultTitle(@"微信好友"); // alertMaker.addActionDefaultTitle(@"朋友圈"); // alertMaker.addActionCancelTitle(@"取消"); // } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) { // [self hidSomeViews]; // if (buttonIndex==0) { // //好友 // [self shareImagToWX:image scene:WXSceneSession]; // // // }else if (buttonIndex==1){ // // 朋友圈 // [self shareImagToWX:image scene:WXSceneTimeline]; // }else{ // GILog(@"取消"); // // } // }]; LXCustomActionSheet *sheet = [[LXCustomActionSheet alloc] initWithTitle:@"分享到微信" optionsArr:@[@"微信好友",@"朋友圈"] cancelTitle:@"取消" selectedBlock:^(NSInteger index) { if (index==0) { [self hidSomeViews]; //好友 [self shareImagToWX:image scene:WXSceneSession]; }else if (index==1){ [self hidSomeViews]; // 朋友圈 [self shareImagToWX:image scene:WXSceneTimeline]; } } cancelBlock:^{ [self hidSomeViews]; GILog(@"取消"); }]; [sheet show]; } -(void)hidSomeViews{ MaskResultShareViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]]; cell.qrcodeImage.hidden = YES; cell.shareBtn.hidden = NO; cell.lastLabe.text = @"让更多的朋友一起加入面膜时间吧!"; self.tabheader.hidden = YES; } -(void)showFinalShareView{ MaskResultShareViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]]; cell.qrcodeImage.hidden = NO; cell.shareBtn.hidden = YES; cell.lastLabe.text = @"长按扫描二维码,测试你的肤质"; self.tabheader.hidden = NO; } -(void)shareImagToWX:(UIImage *)image scene:(int)scene{ WXMediaMessage *msg = [WXMediaMessage message]; UIImage * masllThumb = [GIGaUserFileHelper scaleFromImage:image toSize:CGSizeMake(100, 100)]; msg.title = @"面膜时间"; msg.description= @"极迦面膜"; [msg setThumbImage:masllThumb]; WXImageObject *imageObject = [WXImageObject object]; NSData *imageData = UIImagePNGRepresentation(image); imageObject.imageData = imageData; msg.mediaObject = imageObject; SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; req.message = msg; req.scene = scene; req.bText = NO; [WXApi sendReq:req]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } //分享成功 -(void)usershareSuccessNoti{ //GIGA_ShowToast(@"分享成功"); if (_isfromshouYE) { [self.navigationController popToRootViewControllerAnimated:YES]; } } -(void)testBtnAction{ [self.navigationController popToRootViewControllerAnimated:YES]; } @end