add test
This commit is contained in:
@@ -13,18 +13,27 @@
|
||||
#import "GIGaQuestionSlider.h"
|
||||
#import "MaskQuestionView.h"
|
||||
#import "ExercisesModel.h"
|
||||
#import "QustionAnswer.h"
|
||||
#import "GiGaServerConfig.h"
|
||||
|
||||
@interface GiGaQuestionVC ()
|
||||
@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;
|
||||
|
||||
@property (nonatomic,strong) ExercisesModel *currentModel;
|
||||
|
||||
@property (nonatomic,strong) UILabel *questionlabel;
|
||||
@property (nonatomic,strong) UILabel *descLabel;
|
||||
@property (nonatomic,strong) UIButton *numberBtn;
|
||||
@property (nonatomic,strong) UIButton *nextBtn;
|
||||
@property (nonatomic,strong) UIButton *preBtn;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation GiGaQuestionVC
|
||||
@@ -32,13 +41,31 @@
|
||||
- (void)viewDidLoad {
|
||||
[self addNavTitile:@"测试肤质"];
|
||||
[super viewDidLoad];
|
||||
|
||||
// self.title = @"测试肤质";
|
||||
_page = 1;
|
||||
//默认
|
||||
_curentAnswerIdex = 0;
|
||||
|
||||
//
|
||||
[self loadRequestQuestions];
|
||||
|
||||
//[self initUI];
|
||||
|
||||
}
|
||||
|
||||
-(NSMutableArray *)questonArray{
|
||||
if (!_questonArray) {
|
||||
_questonArray = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return _questonArray;
|
||||
}
|
||||
|
||||
//questionId answerid
|
||||
|
||||
- (NSMutableArray *)answerArray{
|
||||
if (!_answerArray) {
|
||||
_answerArray = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return _answerArray;
|
||||
}
|
||||
|
||||
-(void)initUI{
|
||||
@@ -48,12 +75,14 @@
|
||||
NSAttributedString *numbertitle = [[NSAttributedString alloc] initWithString:@"1" attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
||||
|
||||
[numberBtn setAttributedTitle:numbertitle forState:UIControlStateNormal];
|
||||
self.numberBtn = numberBtn;
|
||||
[self.view addSubview:numberBtn];
|
||||
|
||||
UILabel *titleLabel = [[UILabel alloc] init];
|
||||
titleLabel.text = @"悄悄地告诉你小优的年龄区间是?";
|
||||
titleLabel.font = [UIFont fontWithName:GIGA_FONTBOLD size:16];
|
||||
titleLabel.textColor = GIGARGB(63, 63, 63, 1);
|
||||
self.questionlabel = titleLabel;
|
||||
[self.view addSubview:titleLabel];
|
||||
|
||||
UILabel *descLabel = [[UILabel alloc] init];
|
||||
@@ -62,7 +91,7 @@
|
||||
descLabel.textColor = GIGARGB(208, 208, 208, 1);
|
||||
descLabel.numberOfLines = 0;
|
||||
descLabel.textAlignment = NSTextAlignmentCenter;
|
||||
|
||||
self.descLabel = descLabel;
|
||||
[self.view addSubview:descLabel];
|
||||
|
||||
[numberBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
@@ -87,52 +116,127 @@
|
||||
|
||||
}];
|
||||
|
||||
//测试题
|
||||
[self creatQustionView];
|
||||
|
||||
//下一题
|
||||
UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
nextBtn.backgroundColor = GIGARGB(181, 14, 14, 1);
|
||||
[nextBtn addTarget:self action:@selector(nextBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
NSAttributedString *nextTitle = [[NSAttributedString alloc] initWithString:@"下一题" attributes:@{NSFontAttributeName:[UIFont fontWithName:GIGA_FONTBOLD size:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
||||
[nextBtn setAttributedTitle:nextTitle forState:UIControlStateNormal];
|
||||
nextBtn.layer.masksToBounds = YES;
|
||||
nextBtn.layer.cornerRadius = 2;
|
||||
self.nextBtn = nextBtn;
|
||||
[self.view addSubview:nextBtn];
|
||||
|
||||
[nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(529);
|
||||
make.size.mas_equalTo(CGSizeMake(126, 40));
|
||||
make.left.mas_equalTo(self.view.mas_left).offset(self.view.frame.size.width /2 - 126 /2);
|
||||
}];
|
||||
|
||||
|
||||
//上一题
|
||||
UIButton *preBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[preBtn addTarget:self action:@selector(preBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
NSAttributedString *preTitle = [[NSAttributedString alloc] initWithString:@"上一题" attributes:@{NSFontAttributeName:[UIFont fontWithName:GIGA_FONTBOLD size:18],NSForegroundColorAttributeName:GIGARGB(181, 14, 14, 1)}];
|
||||
[preBtn setAttributedTitle:preTitle forState:UIControlStateNormal];
|
||||
|
||||
preBtn.layer.borderWidth = 1;
|
||||
preBtn.layer.borderColor = GIGARGB(181, 14, 14, 1).CGColor;
|
||||
preBtn.layer.masksToBounds = YES;
|
||||
preBtn.layer.cornerRadius = 2;
|
||||
self.preBtn = preBtn;
|
||||
[self.view addSubview:self.preBtn];
|
||||
|
||||
[self.preBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.view.mas_left).offset(69);
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(529);
|
||||
make.size.mas_equalTo(CGSizeMake(97, 40));
|
||||
|
||||
}];
|
||||
|
||||
if (_page == 1) {
|
||||
self.preBtn.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)creatQustionView{
|
||||
|
||||
if (!_currentModel&&!_currentModel.optionsStyle) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentModel.optionsStyle == 1) {
|
||||
[self creatAnswerView:MaskQuetionViewStleSliderNormal];
|
||||
}else if (_currentModel.optionsStyle == 2){
|
||||
[self creatAnswerView:MaskQuetionViewStleYesOrNO];
|
||||
}else if (_currentModel.optionsStyle == 3 ){
|
||||
[self creatAnswerView:MaskQuetionViewStyleSliderShowIndicator];
|
||||
}else if (_currentModel.optionsStyle == 4){
|
||||
[self creatAnswerView:MaskQuetionViewStleSliderGradient];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-(void)creatAnswerView:(MaskQuetionViewStyle)style{
|
||||
|
||||
//选择题view
|
||||
NSArray *titles = @[@"hahah",@"呵呵呵呵",@"哦哦",@"有有u哟哦",@"呵呵呵呵"];
|
||||
NSArray *titles = @[@"title0",@"title1",@"title2",@"title3",@"title4"];
|
||||
NSMutableArray *tit = [NSMutableArray new];
|
||||
ExercisesModel *model = self.questonArray[0];
|
||||
NSArray *modeA = model.answerList;
|
||||
for (NSDictionary *mode in modeA){
|
||||
[tit addObject:mode[@"answer"]];
|
||||
|
||||
NSArray *answerList1 = _currentModel.answerList;
|
||||
for (QustionAnswer *mode in answerList1){
|
||||
//[tit insertObject:mode.answer atIndex:0];
|
||||
[tit addObject:mode.answer];
|
||||
}
|
||||
titles = tit;
|
||||
MaskQuestionView *questionView = [[MaskQuestionView alloc] initQuestionView:CGRectMake(0,248, self.view.frame.size.width,212) style:MaskQuetionViewStleSliderNormal titles:titles];
|
||||
if (self.questionView) {
|
||||
[self.questionView removeFromSuperview];
|
||||
self.questionView = nil;
|
||||
}
|
||||
[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;
|
||||
NSLog(@"_currentModel--ID:%d",_currentModel.questionId);
|
||||
questionView.delegate = self;
|
||||
|
||||
questionView.backgroundColor = [UIColor redColor];
|
||||
[self.view addSubview:questionView];
|
||||
self.questionView = questionView;
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(void)updateValue:(UISlider *)slider{
|
||||
NSLog(@"value%f",slider.value);
|
||||
GILog(@"formatvalue:%.2f",slider.value*60);
|
||||
|
||||
- (void)sliderChangeValueShouldChoiceModelAt:(NSInteger)index
|
||||
{
|
||||
NSLog(@"答案下标:%ld",(long)index);
|
||||
_curentAnswerIdex = index;
|
||||
}
|
||||
|
||||
-(NSMutableArray *)questonArray{
|
||||
if (!_questonArray) {
|
||||
_questonArray = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return _questonArray;
|
||||
- (void)yesOrNoChoiceModelAt:(NSInteger)index{
|
||||
|
||||
_curentAnswerIdex = index;
|
||||
}
|
||||
|
||||
-(void)loadRequestQuestions{
|
||||
|
||||
NSDictionary *params = @{};
|
||||
GiGaBaseAPiRequest *request = [GiGaBaseAPiRequest initWithRequestPath:@"activity/maskquestion/v1/list" method:RequestPostMethod parms:params];
|
||||
[self.view makeToastActivity:CSToastPositionCenter];
|
||||
|
||||
[request requstDataWithResult:^(GiGaAPIResult *result) {
|
||||
if (result.success) {
|
||||
|
||||
[self.view hideToastActivity];
|
||||
NSLog(@"result:%@",result.dic);
|
||||
NSArray *list = result.dic[@"list"];
|
||||
NSDictionary *answer = list[0];
|
||||
for (NSDictionary *answerDic in list) {
|
||||
ExercisesModel *model = [[ExercisesModel alloc] initWithDictionary:answerDic error:nil];
|
||||
[self.questonArray addObject:model];
|
||||
|
||||
}
|
||||
self.currentModel = self.questonArray[0];
|
||||
[self initUI];
|
||||
}
|
||||
}];
|
||||
@@ -147,44 +251,106 @@
|
||||
}
|
||||
|
||||
#pragma mark 刷新题目
|
||||
|
||||
-(void)reloadViews{
|
||||
//刷新问题相关数据
|
||||
// NSString *questionlabelText = [NSString stringWithFormat:@"%@.%@", _currentModel.questionid, _currentModel.question];
|
||||
// NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
// [paragraphStyle setLineSpacing:4.0f];
|
||||
// NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:questionlabelText];
|
||||
// NSDictionary *attrs =@{NSFontAttributeName:[UIFont systemFontOfSize:18]};
|
||||
// [attributedString setAttributes:attrs range:NSMakeRange(0, 2)];
|
||||
//
|
||||
// _questionlabel.attributedText = attributedString;
|
||||
|
||||
[self.view layoutIfNeeded];//必加
|
||||
// //刷新答案相关数据
|
||||
// [_questionView reloadViewWithFrame:CGRectMake(30, CGRectGetMaxY(_questionlabel.frame) + 15, KMainW - 30*2, 0) style:[_currentModel.questiontype intValue] - 1 answerArray:_currentModel.tkselect userAnswers:_currentModel.userAnswer];
|
||||
//刷新问题相关数据
|
||||
NSAttributedString *numbertitle = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld",(long)_page] attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
||||
|
||||
[_numberBtn setAttributedTitle:numbertitle forState:UIControlStateNormal];
|
||||
|
||||
self.questionlabel.text = [NSString stringWithFormat:@"%@",_currentModel.question];
|
||||
self.descLabel.text = _currentModel.remark;
|
||||
|
||||
//
|
||||
[self creatQustionView];
|
||||
|
||||
//next pre
|
||||
[self.view layoutIfNeeded];
|
||||
|
||||
if (_page > 1) {
|
||||
self.preBtn.hidden = NO;
|
||||
[self.nextBtn mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(529);
|
||||
make.size.mas_equalTo(CGSizeMake(126, 40));
|
||||
make.left.mas_equalTo(self.view.mas_left).offset(self.view.frame.size.width /2 + 10);
|
||||
|
||||
}];
|
||||
|
||||
}else{
|
||||
|
||||
[self.nextBtn mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(529);
|
||||
make.size.mas_equalTo(CGSizeMake(126, 40));
|
||||
make.left.mas_equalTo(self.view.mas_left).offset(self.view.frame.size.width /2 - 126 /2);
|
||||
}];
|
||||
self.preBtn.hidden = YES;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
-(void)nextBtnAction{
|
||||
// if (_page == [_currentModel.totalCount integerValue] ) {
|
||||
// GIGA_ShowToast(@"没有了");
|
||||
// return;
|
||||
// }
|
||||
// [self saveProgress];
|
||||
// _page ++ ;
|
||||
// //获取题目信息
|
||||
// [self getQuestionsInfo];
|
||||
[self saveProgress];
|
||||
|
||||
if (_page == self.questonArray.count ) {
|
||||
GIGA_ShowToast(@"没有了");
|
||||
[self submitAnswer];
|
||||
return;
|
||||
}
|
||||
|
||||
_page ++ ;
|
||||
|
||||
//获取题目信息
|
||||
[self getQuestionsInfo];
|
||||
|
||||
//self.nextBtn.enabled = _page == [_currentModel.totalCount integerValue] ? NO : YES;
|
||||
|
||||
}
|
||||
|
||||
-(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];
|
||||
GILog(@"**答案提交***\n code:%ld\n message:%@\n *******\n dic:%@",result.code,result.message,result.dic);
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
-(void)preBtnAction{
|
||||
|
||||
_page -- ;
|
||||
//获取题目信息
|
||||
[self getQuestionsInfo];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark -做题记录
|
||||
-(void)saveProgress{
|
||||
// NSString *answer = self.questionView.selectAnswer;
|
||||
// NSString *anserNum = self.questionView.qrnum;
|
||||
// NSString *anserid = _currentModel.questionid;
|
||||
// GILog(@"选择答案:%@\n 角标:%@\n 题号:%@",answer,anserNum,anserid);
|
||||
|
||||
int questionId = _currentModel.questionId;
|
||||
QustionAnswer *curentAnswer = _currentModel.answerList[_curentAnswerIdex];
|
||||
int answerid = curentAnswer.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]) {
|
||||
//先删除再添加 上传测试结果顺序任意
|
||||
[self.answerArray removeObject:dic];
|
||||
}
|
||||
}
|
||||
|
||||
[self.answerArray addObject:answerDic];
|
||||
|
||||
NSLog(@"选择题答案:%@",self.answerArray);
|
||||
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
@@ -192,6 +358,4 @@
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user