This commit is contained in:
lianxiang
2018-09-26 00:33:06 +08:00
parent 69522b22fc
commit d0230f55ed
68 changed files with 1599 additions and 209 deletions
@@ -248,7 +248,7 @@
-(void)loadRequestQuestions{
NSDictionary *params = @{};
GiGaBaseAPiRequest *request = [GiGaBaseAPiRequest initWithRequestPath:@"activity/maskquestion/v1/list" method:RequestPostMethod parms:params];
GiGaBaseAPiRequest *request = [GiGaBaseAPiRequest initWithRequestPath:kApiSkinTestQuestionList method:RequestPostMethod parms:params];
[self.view makeToastActivity:CSToastPositionCenter];
[request requstDataWithResult:^(GiGaAPIResult *result) {
@@ -359,42 +359,15 @@
-(void)submitAnswer{
NSDictionary *params = @{@"singleChoiceList":self.answerArray};
[self.view makeToastActivity:CSToastPositionCenter];
NSString *url = [NSString stringWithFormat:@"%@activity/maskquestion/v1/result",[GiGaServerConfig getMainUrl]];
[GiGaNetManager userbodyRequest:url params:params completionHandler:^(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error) {
[self.view hideToastActivity];
GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:resDic];
if (result.success) {
MaskTestResult* mode = [[MaskTestResult alloc] initWithDictionary:resDic error:nil];
[self userTestEnd:mode];
}else{
GIGA_ShowToast(result.message);
}
GILog(@"**测试结果***\n code:%ld\n message:%@\n *******\n dic:%@",result.code,result.message,result.dic);
}];
[self userTestEnd];
}
-(void)userTestEnd:(MaskTestResult*)model{
-(void)userTestEnd{
BOOL isUserLogin = [GiGaUserDefault isUserLogin];
if (isUserLogin) {
//展示结果
// NSDictionary *dic = @{
// @"dryness":@"0.41",
// @"drynessPercent":@"41%",
// @"mask":@"",
// @"minute":@"19",
// @"oiliness":@"0.59",
// @"oilinessPercent":@"59%"
// };
// MaskTestResult *model =[[MaskTestResult alloc] initWithDictionary:dic error:nil];
MaskTestResultVC *resultVC = [[MaskTestResultVC alloc] init];
resultVC.model = model;
[self.navigationController pushViewController:resultVC animated:YES];
[self getTestResult];
}else{
[self jxt_showAlertWithTitle:@"对不起您还没有登录" message:@"请登录后查看肤质测试结果" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) {
@@ -416,6 +389,46 @@
}
//获取结果
-(void)getTestResult{
NSDictionary *params = @{@"singleChoiceList":self.answerArray};
[self.view makeToastActivity:CSToastPositionCenter];
NSString *url = [NSString stringWithFormat:@"%@%@",[GiGaServerConfig getMainUrl],kAiSkinTestResult];
[GiGaNetManager userbodyRequest:url params:params completionHandler:^(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error) {
[self.view hideToastActivity];
GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:resDic];
if (result.success) {
MaskTestResult* mode = [[MaskTestResult alloc] initWithDictionary:resDic error:nil];
NSUInteger minute = [mode.minute integerValue];
NSTimeInterval time = minute * 60;
[GiGaUserDefault savaMaskeTime:time];
//展示结果
// NSDictionary *dic = @{
// @"dryness":@"0.41",
// @"drynessPercent":@"41%",
// @"mask":@"",
// @"minute":@"19",
// @"oiliness":@"0.59",
// @"oilinessPercent":@"59%"
// };
// MaskTestResult *model =[[MaskTestResult alloc] initWithDictionary:dic error:nil];
MaskTestResultVC *resultVC = [[MaskTestResultVC alloc] init];
resultVC.model = mode;
[self.navigationController pushViewController:resultVC animated:YES];
}else{
GIGA_ShowToast(result.message);
}
GILog(@"**测试结果***\n code:%ld\n message:%@\n *******\n dic:%@",result.code,result.message,result.dic);
}];
}
-(void)preBtnAction{
_page -- ;
@@ -12,4 +12,5 @@
@interface MaskTestResultVC : GiGaBaseViewController
@property (nonatomic,strong) MaskTestResult *model;
@end
@@ -10,9 +10,12 @@
#import "MaskResultMinViewCell.h"
#import "MaskResultPercentCell.h"
#import "MaskResultShareViewCell.h"
#import "GIGaUserFileHelper.h"
#import "UIImage+ShotImage.h"
#import "GiGaBaseAPiRequest.h"
#import "GiGaFileNanager.h"
#import <WXApi.h>
#import "MaskTestResult.h"
@interface MaskTestResultVC ()
@@ -22,9 +25,9 @@
- (void)viewDidLoad {
[super viewDidLoad];
[self addNavTitile:@"测试结果"];
// Do any additional setup after loading the view.
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
@@ -39,6 +42,32 @@
[self.tableView registerClass:[MaskResultMinViewCell class] forCellReuseIdentifier:@"MaskResultMinViewCell"];
[self.tableView registerClass:[MaskResultShareViewCell class] forCellReuseIdentifier:@"MaskResultShareViewCell"];
if (!self.model) {
[self addNavTitile:@"历史测试"];
[self requstLatestTestData];
}
}
-(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{
@@ -76,7 +105,7 @@
cell = [[MaskResultShareViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];;
}
[cell.shareBtn addTarget:self action:@selector(shareBtnAciton) forControlEvents:UIControlEventTouchUpInside];
[cell kidTitle:self.model.mask];
[cell kidTitle:self.model];
return cell;
}
@@ -101,41 +130,53 @@
}
-(void)shareBtnAciton{
UIImage *image = [self saveLongImage:self.tableView];
// SHareTestImageVC *imagevc = [[SHareTestImageVC alloc] init];
// imagevc.image = image;
//[self.navigationController pushViewController:imagevc animated:YES];
if (![WXApi isWXAppInstalled]) {
GIGA_ShowToast(@"未安装微信");
return;
}
UIImage *image = [UIImage saveLongImage: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) {
if (buttonIndex==0) {
//好友
[self shareImagToWX:image scene:WXSceneSession];
}else if (buttonIndex==1){
// 朋友圈
[self shareImagToWX:image scene:WXSceneTimeline];
}
}];
}
-(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];
}
- (UIImage *)saveLongImage:(UITableView *)table {
UIImage* image = nil;
// 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了,调整清晰度。
UIGraphicsBeginImageContextWithOptions(table.contentSize, YES, [UIScreen mainScreen].scale);
CGPoint savedContentOffset = table.contentOffset;
CGRect savedFrame = table.frame;
table.contentOffset = CGPointZero;
table.frame = CGRectMake(0, 0, table.contentSize.width, table.contentSize.height);
[table.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
table.contentOffset = savedContentOffset;
table.frame = savedFrame;
UIGraphicsEndImageContext();
[[GiGaFileNanager shareInstance] saveImaeToAlBum:image];
return image;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];