JXQuestionnnnVc.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. //
  2. // JXQuestionnnnVc.m
  3. // shiku_im
  4. //
  5. // Created by os on 2020/7/2.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXQuestionnnnVc.h"
  9. #import "JXQuestionCell.h"
  10. #import "JXApplyViewController.h"
  11. @interface JXQuestionnnnVc ()<UIAlertViewDelegate,UITableViewDelegate,UITableViewDataSource>
  12. @property(strong,nonatomic)UIView * navigationView;
  13. @property(strong,nonatomic)UIView * alertViews;
  14. @property(strong,nonatomic)UILabel * alertLabel;
  15. @property(strong,nonatomic)UILabel * countLabel;
  16. @property(strong,nonatomic)UIButton * backButton;
  17. @property(strong,nonatomic)UILabel * questionLabel;
  18. @property(strong,nonatomic)UILabel * questionTitle;
  19. @property(strong,nonatomic)UITableView * questionTable;
  20. @property(strong,nonatomic)UIScrollView * scrollView;
  21. @property(strong,nonatomic)NSArray * questionArray;
  22. @property(assign,nonatomic)NSUInteger currentSort;
  23. @property(strong,nonatomic)NSDictionary * currentQuestion;
  24. @property(strong,nonatomic)NSTimer * timer;
  25. @property(assign,nonatomic)int count;
  26. @property(strong,nonatomic)UIButton * nextButton;
  27. @property (nonatomic,copy) NSString *Id_str;
  28. @property (nonatomic,assign) NSInteger indexRightRow;
  29. @property (nonatomic,strong) NSMutableArray *dataArr;
  30. @property (nonatomic,strong) NSMutableArray *firstArr;
  31. @property (nonatomic,strong) NSMutableArray *questionArr;
  32. @property (nonatomic,strong) NSMutableArray *ruleArr;
  33. @property (nonatomic,assign) NSInteger indexRecordIndex;
  34. @property (nonatomic,assign) NSInteger indexRow;
  35. @property (nonatomic,strong) NSMutableArray *saveSelectIndexArr;
  36. @property (nonatomic,strong) NSMutableDictionary *saveSelectIndexDict;
  37. @property (nonatomic,weak) UIAlertView * aler;
  38. @property (nonatomic,strong) NSMutableArray *dataArr222;
  39. @property (nonatomic,strong) NSMutableArray *dataArr333;
  40. @end
  41. @implementation JXQuestionnnnVc
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. _currentQuestion=[NSDictionary dictionary];
  45. _indexRightRow=100;
  46. _indexRow=200;
  47. _isAnsware=YES;
  48. //保存选中的数据
  49. _saveSelectIndexArr=[NSMutableArray array];
  50. _saveSelectIndexDict=[NSMutableDictionary dictionary];
  51. _firstArr=[NSMutableArray array];
  52. _dataArr222=[NSMutableArray array];
  53. _dataArr333=[NSMutableArray array];
  54. //_errorArray=[NSMutableArray arrayWithCapacity:0];
  55. _dataArr=[NSMutableArray array];
  56. _questionArr=[NSMutableArray array];
  57. _ruleArr=[NSMutableArray array];
  58. self.view.backgroundColor = [UIColor colorWithRed:126/255.0f green:23/255.0f blue:21/255.0f alpha:1.0f];
  59. self.tableView.alpha = 0.0f;
  60. self.currentSort = 0;
  61. [self initNavigationView];
  62. [self initComponents];
  63. [SVProgressHUD show];
  64. self.count = 5;
  65. long time = (long)[[NSDate date] timeIntervalSince1970];
  66. time = (time *1000 + g_server.timeDifference);
  67. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  68. [g_server getAllQuestions:salt andToView:self];
  69. self.questionTitle.text = [NSString stringWithFormat:@"%d",1];
  70. }
  71. #pragma mark --- 提交
  72. -(void)postButtonClicked:(UIButton *)sender
  73. {
  74. if (_dataArr333.count==10) {
  75. [SVProgressHUD setMaximumDismissTimeInterval:2];
  76. [SVProgressHUD showErrorWithStatus:@"已经完成所有答题"];
  77. NSMutableArray * mutableArray = [[NSMutableArray alloc]initWithCapacity:0];
  78. [_dataArr333 enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  79. QustionJX *optionModel=obj[@"option"];
  80. NSString *Id_str=obj[@"Id_str"];
  81. NSDictionary * dictionary = @{@"questionId":[NSString stringWithFormat:@"%@",optionModel.id],@"optionId":Id_str};
  82. [mutableArray addObject:dictionary];
  83. }];
  84. long time = (long)[[NSDate date] timeIntervalSince1970];
  85. time = (time *1000 + g_server.timeDifference);
  86. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  87. NSArray * postArray = mutableArray.copy;
  88. NSError *parseError = nil;
  89. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postArray options:NSJSONWritingPrettyPrinted error:&parseError];
  90. NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  91. [SVProgressHUD show];
  92. [g_server postQuestionAnswers:salt andOptions:jsonstr andToView:self];
  93. }else{
  94. UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您有题目没有答完,请返回检查"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  95. [aler show];
  96. self.aler=aler;
  97. }
  98. if([self.ifAnswer isEqualToString:@"NO"])
  99. {
  100. [SVProgressHUD setMaximumDismissTimeInterval:2];
  101. [SVProgressHUD showErrorWithStatus:@"已经完成所有答题"];
  102. }
  103. else
  104. {
  105. NSMutableArray * mutableArray = [[NSMutableArray alloc]initWithCapacity:0];
  106. for(NSDictionary * dict in _questionArray)
  107. {
  108. NSString * lastAnswer = [NSString stringWithFormat:@"%@",[dict objectForKey:@"answerid"]];
  109. if(lastAnswer != nil && lastAnswer.length != 0 && ![lastAnswer isEqualToString:@"(null)"] && ![lastAnswer isEqualToString:@"<null>"])
  110. {
  111. NSDictionary * dictionary = [[NSDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%@",[dict objectForKey:@"id"]],@"questionId",lastAnswer,@"optionId", nil];
  112. [mutableArray addObject:dictionary];
  113. long time = (long)[[NSDate date] timeIntervalSince1970];
  114. time = (time *1000 + g_server.timeDifference);
  115. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  116. NSArray * postArray = mutableArray.copy;
  117. NSError *parseError = nil;
  118. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postArray options:NSJSONWritingPrettyPrinted error:&parseError];
  119. NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  120. [SVProgressHUD show];
  121. [g_server postQuestionAnswers:salt andOptions:jsonstr andToView:self];
  122. }
  123. else
  124. {
  125. UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您有题目没有答完,请返回检查"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  126. [aler show];
  127. self.aler=aler;
  128. break;
  129. }
  130. }
  131. }
  132. }
  133. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  134. return _dataArr.count;
  135. }
  136. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  137. {
  138. if (_firstArr.count==0) {
  139. return 0;
  140. }else{
  141. QustionJX *optionArr = _firstArr[section];
  142. return optionArr.options.count;
  143. }
  144. }
  145. #pragma mark --- 代理 tableView
  146. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  147. { //NSArray * options = [_currentQuestion objectForKey:@"options"];
  148. JXQuestionCell * cell = [JXQuestionCell cellWithTableView:tableView];
  149. QustionJX *optionArr = [_firstArr firstObject];
  150. OptionsJX *model=optionArr.options[indexPath.row];
  151. [cell createUI:model andDui:_indexRightRow andSelect:_indexRow andCell:indexPath.row];
  152. return cell;
  153. }
  154. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  155. {
  156. return 54.0f;
  157. }
  158. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  159. {
  160. _isAnsware=NO;
  161. QustionJX *optionArr = [_firstArr firstObject];
  162. __block OptionsJX *model=nil;
  163. _indexRow=indexPath.row;
  164. [optionArr.options enumerateObjectsUsingBlock:^(OptionsJX *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  165. if ( [obj.right isEqualToString:@"1"]) {
  166. _indexRightRow=idx;
  167. _Id_str=obj.sort;
  168. model=obj;
  169. }if ( [obj.right isEqualToString:@"1"] && indexPath.row==idx) {
  170. [_dataArr222 addObject:model];
  171. }
  172. }];
  173. __block QustionJX *modelS=nil;
  174. [_questionArr enumerateObjectsUsingBlock:^(QustionJX * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  175. // if ([obj.sort intValue]==_currentSort) {
  176. if ([obj.title isEqualToString:self.questionTitle.text]) {
  177. modelS=obj;
  178. }
  179. }];
  180. if (_isclick==YES) {
  181. return;
  182. }
  183. _currentSort ++;
  184. _isclick=YES;
  185. _isCheck=1;
  186. NSDictionary *dict=@{@"option":modelS,@"title":modelS.title,@"selectIndex":[NSString stringWithFormat:@"%zd",indexPath.row] ,@"rightRow":[NSString stringWithFormat:@"%zd",_indexRightRow],@"checkNo":[NSString stringWithFormat:@"%d",_isCheck],@"currentSort":[NSString stringWithFormat:@"%lu",(unsigned long)_currentSort],@"Id_str":[NSString stringWithFormat:@"%zd",indexPath.row+1]};
  187. [_saveSelectIndexArr addObject:dict];
  188. if (_saveSelectIndexArr.count==10) {
  189. //提交答卷
  190. [_nextButton setImage:[UIImage imageNamed:@"提交答卷"] forState:UIControlStateNormal];
  191. }
  192. [_dataArr333 addObject:dict];
  193. [_questionTable reloadData];
  194. }
  195. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  196. [SVProgressHUD dismiss];
  197. if([aDownload.action isEqualToString:act_GetQuestionAndRules])
  198. {
  199. NSDictionary * dict0 = [array1 objectAtIndex:0];
  200. NSLog(@"aaa %@",dict0);
  201. _questionArr=[QustionJX mj_objectArrayWithKeyValuesArray:dict0[@"questions"]];
  202. _ruleArr=[RulesJX mj_objectArrayWithKeyValuesArray:dict0[@"rules"]];
  203. [_firstArr addObject:[_questionArr firstObject]];
  204. /* [_questionArr enumerateObjectsUsingBlock:^(QustionJX * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  205. if (idx==0) {
  206. [_firstArr addObject:obj];
  207. }
  208. }];*/
  209. _dataArr=[packageRoolModel mj_objectArrayWithKeyValuesArray:array1];
  210. QustionJX *modell=[_firstArr firstObject];
  211. self.questionLabel.text = modell.title;
  212. [self.questionTable reloadData];
  213. [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshes" object:nil];
  214. }if([aDownload.action isEqualToString:act_PostQuestionAnswers])
  215. {
  216. UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"本次答题:正确:%zd道题,错误 %zd道题",_dataArr222.count,_dataArr333.count-_dataArr222.count] delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil];
  217. aler.tag=3000;
  218. [aler show];
  219. }
  220. }
  221. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  222. NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
  223. if([errorCode isEqualToString:@"权限验证失败"])
  224. {
  225. if([aDownload.action isEqualToString:act_GetQuestionAndRules])
  226. {
  227. long time = (long)[[NSDate date] timeIntervalSince1970];
  228. time = (time *1000 + g_server.timeDifference);
  229. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  230. [g_server getAllQuestions:salt andToView:self];
  231. }
  232. if([aDownload.action isEqualToString:act_PostQuestionAnswers])
  233. {
  234. if([self.ifAnswer isEqualToString:@"NO"])
  235. {
  236. [SVProgressHUD setMaximumDismissTimeInterval:2];
  237. [SVProgressHUD showErrorWithStatus:@"已经完成所有答题"];
  238. }
  239. else
  240. {
  241. NSMutableArray * mutableArray = [[NSMutableArray alloc]initWithCapacity:0];
  242. for(NSDictionary * dict in self.questionArray)
  243. {
  244. NSString * lastAnswer = [NSString stringWithFormat:@"%@",[dict objectForKey:@"answerid"]];
  245. if(lastAnswer != nil && lastAnswer.length != 0 && ![lastAnswer isEqualToString:@"(null)"] && ![lastAnswer isEqualToString:@"<null>"])
  246. {
  247. NSDictionary * dictionary = [[NSDictionary alloc]initWithObjectsAndKeys:[NSString stringWithFormat:@"%@",[dict objectForKey:@"id"]],@"questionId",lastAnswer,@"optionId", nil];
  248. [mutableArray addObject:dictionary];
  249. }
  250. else
  251. {
  252. UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"您有题目没有答完,请返回检查"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  253. [aler show];
  254. break;
  255. }
  256. }
  257. long time = (long)[[NSDate date] timeIntervalSince1970];
  258. time = (time *1000 + g_server.timeDifference);
  259. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  260. NSArray * postArray = mutableArray.copy;
  261. NSError *parseError = nil;
  262. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postArray options:NSJSONWritingPrettyPrinted error:&parseError];
  263. NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  264. [g_server postQuestionAnswers:salt andOptions:jsonstr andToView:self];
  265. }
  266. }
  267. }
  268. else
  269. {
  270. [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]]];
  271. }
  272. if( [aDownload.action isEqualToString:act_UserLogout] ){
  273. //[self performSelector:@selector(doSwitch) withObject:nil afterDelay:1];
  274. }
  275. return hide_error;
  276. }
  277. -(void)backButtonClicked:(UIButton *)sender
  278. {
  279. [g_navigation dismissViewController:self animated:YES];
  280. }
  281. -(void)initNavigationView
  282. {
  283. self.navigationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT>=812?88:64)];
  284. self.navigationView.backgroundColor = [UIColor whiteColor];
  285. [self.view addSubview:self.navigationView];
  286. UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 40, JX_SCREEN_WIDTH, 40)];
  287. titleLabel.text = @"每日答题";
  288. titleLabel.textColor = [UIColor blackColor];
  289. titleLabel.font = [UIFont systemFontOfSize:18.0f];
  290. titleLabel.textAlignment = NSTextAlignmentCenter;
  291. [self.navigationView addSubview:titleLabel];
  292. self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
  293. self.backButton.frame = CGRectMake(15, 30, 30, 30);
  294. if(JX_SCREEN_HEIGHT >= 812)
  295. {
  296. self.backButton.frame = CGRectMake(15, 45, 30, 30);
  297. }
  298. [self.backButton setImage:[UIImage imageNamed:@"title_back_black"] forState:UIControlStateNormal];
  299. [self.backButton addTarget:self action:@selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  300. [self.navigationView addSubview:self.backButton];
  301. }
  302. -(void)initComponents
  303. {
  304. UIImageView * backView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 0.68*JX_SCREEN_WIDTH)];
  305. backView.image = [UIImage imageNamed:@"每日答题"];
  306. [self.view addSubview:backView];
  307. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  308. make.top.mas_equalTo(JX_SCREEN_TOP+44);
  309. make.centerX.mas_equalTo(self.view.mas_centerX);
  310. }];
  311. UIImageView * backViewtitle = [[UIImageView alloc]init];
  312. backViewtitle.image = [UIImage imageNamed:@"每日完成任务豪礼送不断"];
  313. [self.view addSubview:backViewtitle];
  314. [backViewtitle mas_makeConstraints:^(MASConstraintMaker *make) {
  315. make.top.mas_equalTo(backView.mas_bottom).mas_offset(20);
  316. make.centerX.mas_equalTo(backView.mas_centerX);
  317. }];
  318. //黄框框
  319. UIImageView * questionView = [[UIImageView alloc]init];
  320. questionView.image = [UIImage imageNamed:@"questionImage"];
  321. [self.view addSubview:questionView];
  322. questionView.userInteractionEnabled = YES;
  323. [questionView mas_makeConstraints:^(MASConstraintMaker *make) {
  324. make.top.mas_equalTo(backViewtitle.mas_bottom).mas_offset(20);
  325. make.centerX.mas_equalTo(backViewtitle.mas_centerX);
  326. make.height.mas_equalTo(280);
  327. make.width.mas_equalTo(JX_SCREEN_WIDTH - 40);
  328. }];
  329. //数字标题 提交答卷
  330. UILabel *titleLL = [[UILabel alloc]init];
  331. titleLL.text = @"1";
  332. titleLL.textColor = [UIColor colorWithRed:115/255.0f green:20/255.0f blue:5/255.0f alpha:1.0f];
  333. titleLL.font = [UIFont boldSystemFontOfSize:15.0f];
  334. titleLL.textAlignment = NSTextAlignmentCenter;
  335. [questionView addSubview:titleLL];
  336. self.questionTitle=titleLL;
  337. [titleLL mas_makeConstraints:^(MASConstraintMaker *make) {
  338. make.top.mas_equalTo(10);
  339. make.centerX.mas_equalTo(questionView.mas_centerX);
  340. }];
  341. UIImageView * lefIMG = [[UIImageView alloc]init];
  342. lefIMG.image = [UIImage imageNamed:@"第dati"];
  343. [questionView addSubview:lefIMG];
  344. [lefIMG mas_makeConstraints:^(MASConstraintMaker *make) {
  345. make.right.mas_equalTo(titleLL.mas_left).mas_offset(-20);
  346. make.centerY.mas_equalTo(titleLL.mas_centerY);
  347. }];
  348. UIImageView * rightIMG = [[UIImageView alloc]init];
  349. rightIMG.image = [UIImage imageNamed:@"题"];
  350. [questionView addSubview:rightIMG];
  351. [rightIMG mas_makeConstraints:^(MASConstraintMaker *make) {
  352. make.left.mas_equalTo(titleLL.mas_right).mas_offset(20);
  353. make.centerY.mas_equalTo(titleLL.mas_centerY);
  354. }];
  355. self.questionLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 40, questionView.frame.size.width - 30, 40)];
  356. self.questionLabel.text = @"吉利公司保持着多少年的百分百出款?";
  357. self.questionLabel.numberOfLines = 0;
  358. self.questionLabel.textAlignment=NSTextAlignmentCenter;
  359. self.questionLabel.textColor = self.questionTitle.textColor;
  360. self.questionLabel.font = [UIFont systemFontOfSize:14.0f];
  361. [questionView addSubview:self.questionLabel];
  362. [self.questionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  363. make.top.mas_equalTo(titleLL.mas_bottom).mas_offset(20);
  364. //make.centerX.mas_equalTo(questionView.mas_centerX);
  365. make.left.mas_equalTo(5);
  366. make.right.mas_equalTo(-5);
  367. }];
  368. UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  369. tableView.dataSource = self;
  370. tableView.delegate = self;
  371. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  372. tableView.backgroundColor = [UIColor clearColor];
  373. [questionView addSubview:tableView];
  374. self.questionTable=tableView;
  375. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  376. make.top.mas_equalTo(self.questionLabel.mas_bottom).mas_offset(20);
  377. make.left.mas_equalTo(10);
  378. make.right.mas_equalTo(-10);
  379. make.bottom.mas_equalTo(-10);
  380. }];
  381. UIButton * nextButton = [UIButton buttonWithType:UIButtonTypeCustom]; //提交答卷
  382. [nextButton setImage:[UIImage imageNamed:@"下一题"] forState:UIControlStateNormal];
  383. [nextButton addTarget:self action:@selector(nextButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  384. nextButton.alpha = 1.0f;
  385. [self.view addSubview:nextButton];
  386. self.nextButton=nextButton;
  387. [nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
  388. make.top.mas_equalTo(self.questionTable.mas_bottom).mas_offset(40);
  389. make.centerX.mas_equalTo(self.questionTable.mas_centerX).mas_offset(0);
  390. }];
  391. }
  392. /**下一题*/
  393. -(void)nextButtonClicked:(UIButton *)sender
  394. {
  395. self.questionTitle.text = [NSString stringWithFormat:@"%zd",_saveSelectIndexArr.count+1];
  396. if (_saveSelectIndexArr.count>=_currentSort) {
  397. _isclick=NO;
  398. if (_currentSort>_questionArr.count-1) {
  399. // _currentSort=(int)_questionArr.count;
  400. // UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"当前已是最后一题了" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  401. // [alert show];
  402. if (_dataArr333.count==10) {
  403. [SVProgressHUD setMaximumDismissTimeInterval:2];
  404. [SVProgressHUD showErrorWithStatus:@"已经完成所有答题"];
  405. NSMutableArray * mutableArray = [[NSMutableArray alloc]initWithCapacity:0];
  406. [_dataArr333 enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  407. QustionJX *optionModel=obj[@"option"];
  408. NSString *Id_str=obj[@"Id_str"];
  409. NSDictionary * dictionary = @{@"questionId":[NSString stringWithFormat:@"%@",optionModel.id],@"optionId":Id_str};
  410. [mutableArray addObject:dictionary];
  411. }];
  412. long time = (long)[[NSDate date] timeIntervalSince1970];
  413. time = (time *1000 + g_server.timeDifference);
  414. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  415. NSArray * postArray = mutableArray.copy;
  416. NSError *parseError = nil;
  417. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postArray options:NSJSONWritingPrettyPrinted error:&parseError];
  418. NSString *jsonstr =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  419. [SVProgressHUD show];
  420. [g_server postQuestionAnswers:salt andOptions:jsonstr andToView:self];
  421. }
  422. return;
  423. }else{
  424. if (_isAnsware==NO) {
  425. _isAnsware=YES;
  426. }else{
  427. [SVProgressHUD showWithStatus:@"请先做答当前题目,再进入下一题。"];
  428. [SVProgressHUD dismissWithDelay:1.1];
  429. }
  430. }
  431. self.questionTable.userInteractionEnabled=YES;
  432. [_firstArr removeAllObjects];
  433. _indexRow=100;
  434. _indexRightRow=100;
  435. [_questionArr enumerateObjectsUsingBlock:^(QustionJX * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  436. //if ([obj.sort intValue]==_currentSort) {
  437. if ( _currentSort == idx) {
  438. [_firstArr addObject:obj];
  439. self.questionLabel.text = obj.title;
  440. }
  441. }];
  442. [self.questionTable reloadData];
  443. }
  444. return;
  445. [_saveSelectIndexArr enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  446. QustionJX *modelJx=obj[@"option"];
  447. //if (( [modelJx.title isEqualToString:self.questionTitle.text])&& obj[@"option"]!=nil) {
  448. if (( [modelJx.title isEqualToString:self.questionTitle.text])&& obj[@"option"]!=nil) {
  449. _indexRightRow=[obj[@"rightRow"] intValue];
  450. _indexRow=[obj[@"selectIndex"] intValue];
  451. }else{
  452. self.questionTable.userInteractionEnabled=YES;
  453. }
  454. // if ( _currentSort == idx) {
  455. // _indexRightRow=idx;
  456. // _indexRow=idx;
  457. // }
  458. }];
  459. }
  460. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  461. {
  462. if (alertView.tag==3000) {
  463. [g_navigation popToViewController:[JXApplyViewController class] animated:YES];
  464. return;
  465. }
  466. if(alertView.tag == 1000)
  467. {
  468. if(buttonIndex==0){
  469. return;
  470. }
  471. [g_navigation popToViewController:[JXApplyViewController class] animated:YES];
  472. }
  473. else if(alertView.tag == 10000)
  474. {
  475. self.currentSort ++;
  476. for(NSDictionary * dictionary in self.questionArray)
  477. {
  478. NSString * questionSort = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"sort"]];
  479. if(questionSort.intValue == self.currentSort)
  480. {
  481. NSString * questionTitle = [NSString stringWithFormat:@"第%@题:%@",questionSort,[dictionary objectForKey:@"title"]];
  482. NSString * questionDesc = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"desc"]];
  483. if(questionTitle != nil && questionTitle.length != 0 && ![questionTitle isEqualToString:@"(null)"] && ![questionTitle isEqualToString:@"<null>"])
  484. {
  485. self.questionTitle.text = questionTitle;
  486. }
  487. if(questionDesc != nil && questionDesc.length != 0 && ![questionDesc isEqualToString:@"(null)"] && ![questionDesc isEqualToString:@"<null>"])
  488. {
  489. self.questionLabel.text = questionDesc;
  490. }
  491. self.currentQuestion = dictionary;
  492. break;
  493. }
  494. }
  495. [self.questionTable reloadData];
  496. }
  497. }
  498. @end