JXQuestionnnnVc.m 25 KB

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