fix 首页
This commit is contained in:
@@ -15,12 +15,15 @@
|
||||
#import "ExercisesModel.h"
|
||||
#import "QustionAnswer.h"
|
||||
#import "GiGaServerConfig.h"
|
||||
#import "MaskTestResult.h"
|
||||
#import "GiGaUserDefault.h"
|
||||
#import "GiGaUserLoginVC.h"
|
||||
#import "MaskTestResultVC.h"
|
||||
|
||||
@interface GiGaQuestionVC ()<QeustionViewDelegate>
|
||||
|
||||
@property (nonatomic,weak) MaskQuestionView *questionView;
|
||||
@property (nonatomic,assign) NSInteger page;
|
||||
@property (nonatomic,assign) NSInteger curentAnswerIdex;
|
||||
|
||||
@property (nonatomic,strong) NSMutableArray *questonArray;
|
||||
@property (nonatomic,strong) NSMutableArray *answerArray;
|
||||
@@ -44,10 +47,6 @@
|
||||
|
||||
// self.title = @"测试肤质";
|
||||
_page = 1;
|
||||
//默认
|
||||
_curentAnswerIdex = 0;
|
||||
|
||||
//
|
||||
[self loadRequestQuestions];
|
||||
|
||||
}
|
||||
@@ -192,6 +191,7 @@
|
||||
//[tit insertObject:mode.answer atIndex:0];
|
||||
[tit addObject:mode.answer];
|
||||
}
|
||||
|
||||
titles = tit;
|
||||
if (self.questionView) {
|
||||
[self.questionView removeFromSuperview];
|
||||
@@ -199,27 +199,48 @@
|
||||
}
|
||||
[self.view layoutIfNeeded];
|
||||
|
||||
MaskQuestionView *questionView = [[MaskQuestionView alloc] initQuestionView:CGRectMake(0,248, self.view.frame.size.width,212) style:style titles:titles];
|
||||
questionView.answerList = _currentModel.answerList;
|
||||
MaskQuestionView *questionView = [[MaskQuestionView alloc] initQuestionView:CGRectMake(0,248, self.view.frame.size.width,212) style:style titles:titles current:_currentModel];
|
||||
NSLog(@"_currentModel--ID:%d",_currentModel.questionId);
|
||||
questionView.delegate = self;
|
||||
|
||||
[self.view addSubview:questionView];
|
||||
self.questionView = questionView;
|
||||
|
||||
}
|
||||
|
||||
- (void)sliderChangeValueShouldChoiceModelAt:(NSInteger)index
|
||||
- (void)sliderChangeValueShouldChoiceModelAt:(int)index slider:(float)value
|
||||
|
||||
{
|
||||
NSLog(@"答案下标:%ld",(long)index);
|
||||
_curentAnswerIdex = index;
|
||||
}
|
||||
|
||||
- (void)yesOrNoChoiceModelAt:(NSInteger)index{
|
||||
if (index > _currentModel.answerList.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
_curentAnswerIdex = index;
|
||||
NSLog(@"答案下标:%d",index);
|
||||
//修改答案默认下标
|
||||
_currentModel.slidervalue = value;
|
||||
[self changeAnswerDefaultflag:index];
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)yesOrNoChoiceModelAt:(int)index{
|
||||
|
||||
_currentModel.slidervalue = index;
|
||||
[self changeAnswerDefaultflag:index];
|
||||
}
|
||||
|
||||
-(void)changeAnswerDefaultflag:(int)index{
|
||||
|
||||
NSArray *temparr = [NSArray arrayWithArray:_currentModel.answerList];
|
||||
[temparr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
QustionAnswer *model = obj;
|
||||
if ((int)index == idx) {
|
||||
model.defaultFlag = 1;
|
||||
}else{
|
||||
model.defaultFlag = 0;
|
||||
}
|
||||
|
||||
}];
|
||||
}
|
||||
-(void)loadRequestQuestions{
|
||||
|
||||
NSDictionary *params = @{};
|
||||
@@ -227,16 +248,41 @@
|
||||
[self.view makeToastActivity:CSToastPositionCenter];
|
||||
|
||||
[request requstDataWithResult:^(GiGaAPIResult *result) {
|
||||
[self.view hideToastActivity];
|
||||
if (result.success) {
|
||||
|
||||
[self.view hideToastActivity];
|
||||
NSLog(@"result:%@",result.dic);
|
||||
NSArray *list = result.dic[@"list"];
|
||||
for (NSDictionary *answerDic in list) {
|
||||
ExercisesModel *model = [[ExercisesModel alloc] initWithDictionary:answerDic error:nil];
|
||||
model.slidervalue = 0;
|
||||
if (model.optionsStyle == 2) {
|
||||
//1是 0否
|
||||
NSArray *answerlsit = [NSArray arrayWithArray:model.answerList];
|
||||
[answerlsit enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
QustionAnswer *answer = obj;
|
||||
if (answer.defaultFlag == 1) {
|
||||
model.slidervalue = (float)idx;
|
||||
}
|
||||
}];
|
||||
|
||||
}else{
|
||||
NSArray *answerlsit = [NSArray arrayWithArray:model.answerList];
|
||||
[answerlsit enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
QustionAnswer *answer = obj;
|
||||
if (answer.defaultFlag == 1) {
|
||||
model.slidervalue = (answerlsit.count -1 -idx) / (answerlsit.count - 1);
|
||||
//GILog(@"model.slidervalue%.2f",model.slidervalue);
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
[self.questonArray addObject:model];
|
||||
|
||||
}
|
||||
self.currentModel = self.questonArray[0];
|
||||
|
||||
[self initUI];
|
||||
}
|
||||
}];
|
||||
@@ -289,16 +335,14 @@
|
||||
|
||||
}
|
||||
|
||||
|
||||
-(void)nextBtnAction{
|
||||
|
||||
[self saveProgress];
|
||||
|
||||
if (_page == self.questonArray.count ) {
|
||||
GIGA_ShowToast(@"没有了");
|
||||
[self submitAnswer];
|
||||
return;
|
||||
}
|
||||
|
||||
_page ++ ;
|
||||
|
||||
//获取题目信息
|
||||
@@ -317,11 +361,38 @@
|
||||
[GiGaNetManager userbodyRequest:url params:params completionHandler:^(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error) {
|
||||
[self.view hideToastActivity];
|
||||
GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:resDic];
|
||||
GILog(@"**答案提交***\n code:%ld\n message:%@\n *******\n dic:%@",result.code,result.message,result.dic);
|
||||
|
||||
GILog(@"**测试结果***\n code:%ld\n message:%@\n *******\n dic:%@",result.code,result.message,result.dic);
|
||||
[self userTestEnd];
|
||||
}];
|
||||
}
|
||||
|
||||
-(void)userTestEnd{
|
||||
|
||||
BOOL isUserLogin = [GiGaUserDefault isUserLogin];
|
||||
if (isUserLogin) {
|
||||
//展示结果
|
||||
MaskTestResultVC *reusltVC = [[MaskTestResultVC alloc] init];
|
||||
[self.navigationController pushViewController:reusltVC animated:YES];
|
||||
}else{
|
||||
[self jxt_showAlertWithTitle:@"对不起您还没有登录" message:@"请登录后查看肤质测试结果" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) {
|
||||
alertMaker.addActionCancelTitle(@"返回首页");
|
||||
alertMaker.addActionDestructiveTitle(@"登录");
|
||||
} actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) {
|
||||
|
||||
if (buttonIndex == 0) {
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}else{
|
||||
GiGaUserLoginVC *userlogInVC= [[GiGaUserLoginVC alloc] init];
|
||||
GiGaBaseNavViewController *baseNav = [[GiGaBaseNavViewController alloc] initWithRootViewController:userlogInVC];
|
||||
[self presentViewController:baseNav animated:YES completion:nil];
|
||||
}
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(void)preBtnAction{
|
||||
|
||||
_page -- ;
|
||||
@@ -334,18 +405,28 @@
|
||||
-(void)saveProgress{
|
||||
|
||||
int questionId = _currentModel.questionId;
|
||||
QustionAnswer *curentAnswer = _currentModel.answerList[_curentAnswerIdex];
|
||||
int answerid = curentAnswer.answer_id;
|
||||
|
||||
__block int answerid = 0;
|
||||
NSArray *answerArr = [NSArray arrayWithArray:_currentModel.answerList];
|
||||
[answerArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
QustionAnswer *model = obj;
|
||||
if (model.defaultFlag == 1) {
|
||||
answerid = model.answer_id;
|
||||
}
|
||||
}];
|
||||
|
||||
GILog(@"问题ID:%d\n 角标id(答案号):%d\n 题号:%ld",questionId,answerid,(long)_page);
|
||||
|
||||
NSDictionary *answerDic = @{@"questionId":[NSString stringWithFormat:@"%d",questionId],@"answerId":[NSString stringWithFormat:@"%d",answerid]};
|
||||
for (NSDictionary *dic in self.answerArray) {
|
||||
// 返回时覆盖
|
||||
if (questionId == [dic[@"questionId"] intValue]) {
|
||||
//先删除再添加 上传测试结果顺序任意
|
||||
NSArray *tempArr= [NSArray arrayWithArray:self.answerArray];
|
||||
//返回时处理
|
||||
[tempArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
|
||||
NSDictionary *dic = obj;
|
||||
if ([dic[@"questionId"] intValue] == questionId) {
|
||||
[self.answerArray removeObject:dic];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
[self.answerArray addObject:answerDic];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user