TrainDetailVC.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. //
  2. // TrainDetailVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/1/29.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "TrainDetailVC.h"
  9. #import "TrainRecord.h"
  10. #import "DES3Util.h"
  11. #import "HolderView.h"
  12. #import "Evaluation.h"
  13. #import "orderCommentVC.h"
  14. #import "OrbitVC.h"
  15. #import "TrainDetailCell.h"
  16. @interface TrainDetailVC ()<UITableViewDataSource,UITableViewDelegate>
  17. {
  18. UITableView *mainTable;
  19. }
  20. @end
  21. @implementation TrainDetailVC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self configNavigationBar];
  25. self.view.backgroundColor = backGroundColor;
  26. self.title = @"学时详细";
  27. if ([self.type isEqualToString:@"1"])
  28. {
  29. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"上传" style:UIBarButtonItemStyleDone target:self action:@selector(clickToUpdate)];
  30. item.tintColor = RQ_MAIN_COLOR;
  31. self.navigationItem.rightBarButtonItem = item;
  32. }
  33. mainTable = [[UITableView alloc] initWithFrame:kFrame];
  34. mainTable.height -= kNavOffSet;
  35. mainTable.delegate = self;
  36. mainTable.dataSource = self;
  37. [self.view addSubview:mainTable];
  38. if (_datasourceArray.count < 1) {
  39. HolderView *placeHolder = [[HolderView alloc] initWithFrame:mainTable.frame];
  40. [self.view addSubview:placeHolder];
  41. }
  42. }
  43. -(void)clickToUpdate
  44. {
  45. [self upLoadTrainRecord];
  46. }
  47. -(void)upLoadTrainRecord{
  48. if (_datasourceArray.count < 1) {
  49. ShowMsg(@"本地无学时明细!");
  50. return;
  51. }
  52. if (RQ_USER_MANAGER.isycbd == 1) {
  53. TrainRecord *record = [_datasourceArray lastObject];
  54. /// 1.本地活体检测
  55. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  56. if (success) {
  57. /// 2.线上活体检测
  58. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess) {
  59. if (isSuccess) {
  60. /// 2.5 温州(3303)上传照片的时间是实时取服务器时间 其他地市采取从开始计时时间+累计计时时长的时间
  61. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]) {
  62. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  63. if (isSuccess) {
  64. /// 3.签退
  65. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:_datasourceArray resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  66. if (isSuccess) {
  67. NSMutableArray *mutableArr = [NSMutableArray arrayWithArray:_datasourceArray];
  68. [mutableArr removeObject:record];
  69. [DB_Helper updateTrainState:record];
  70. self.datasourceArray = mutableArr.copy;
  71. [mainTable reloadData];
  72. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  73. NSString *timeStr = timeDict[@"body"];
  74. /// 4.1.上传签退照片
  75. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:record.classid timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  76. if (isSuccess) {
  77. NSLog(@"上传签退照片成功!");
  78. } else {
  79. ShowMsg(@"上传签退照片失败!");
  80. }
  81. }];
  82. }
  83. }];
  84. } else {
  85. }
  86. }];
  87. } else {
  88. /// 4.签退
  89. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:_datasourceArray resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  90. if (isSuccess) {
  91. NSMutableArray *mutableArr = [NSMutableArray arrayWithArray:_datasourceArray];
  92. [mutableArr removeObject:record];
  93. [DB_Helper updateTrainState:record];
  94. self.datasourceArray = mutableArr.copy;
  95. [mainTable reloadData];
  96. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  97. /// 4.2上传签退照片
  98. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:record.classid timeStr:record.endTime actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  99. if (isSuccess) {
  100. NSLog(@"上传签退照片成功!");
  101. } else {
  102. ShowMsg(@"上传签退照片失败!");
  103. }
  104. }];
  105. }
  106. }];
  107. }
  108. } else {
  109. ShowMsg(@"线上活体检测失败");
  110. }
  111. }];
  112. }
  113. }];
  114. } else {
  115. //这里是对分段上传学时做的处理 如果学时上传有问题 查看这里
  116. [self uploadMoreTrainRecordWithArray:_datasourceArray];
  117. }
  118. }
  119. - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray
  120. {
  121. ShowHUD();
  122. if (![Util connectedToNetWork]) {
  123. showMsgUnconnect();
  124. return;
  125. }
  126. NSString* str = @"";
  127. for (TrainRecord *record in trainArray) {
  128. str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]];
  129. }
  130. TrainRecord *record = [trainArray firstObject];
  131. NSMutableArray *arr=[NSMutableArray array];
  132. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  133. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  134. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  135. NSString* method = @"uploadMoreTrainRecord";
  136. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  137. RemoveHUD();
  138. //NSLog(@"---------><>%@----><>%@",arr,dict);
  139. if (!dict) {
  140. ShowMsg(@"操作失败");
  141. return;
  142. }
  143. if ( [dict[@"code"] isEqualToString:@"1"]) {
  144. ShowMsg(dict[@"body"]);
  145. return;
  146. }
  147. if ( [dict[@"code"] isEqualToString:@"0"]) {
  148. for (TrainRecord *record in trainArray) {
  149. [DB_Helper updateTrainState:record];
  150. }
  151. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传学时成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  152. self.datasourceArray = [NSArray array];
  153. [mainTable reloadData];
  154. }
  155. }];
  156. }
  157. #pragma mark tableView delegate
  158. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  159. {
  160. return self.datasourceArray.count;
  161. }
  162. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  163. {
  164. if ([self.type isEqualToString:@"1"])
  165. {
  166. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  167. if (cell == nil)
  168. {
  169. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  170. cell.accessoryType = UITableViewCellAccessoryNone;
  171. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  172. cell.backgroundColor = backGroundColor;
  173. }
  174. TrainRecord *train = (TrainRecord *)self.datasourceArray[indexPath.row];
  175. if (train.endTime.length > 10) {
  176. cell.textLabel.text = [NSString stringWithFormat:@"%@----%@",train.beginTime,[train.endTime substringFromIndex:10]];
  177. }else{
  178. cell.textLabel.text = [NSString stringWithFormat:@"%@----%@",train.beginTime,train.endTime];
  179. }
  180. int time = [train.trainTime intValue];
  181. int min = time%(_RATIONKS? : 60);
  182. int hour = time/(_RATIONKS? : 60);
  183. NSString *timeString = [NSString stringWithFormat:@"%d%@%d分钟",hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时"),min];
  184. if (hour == 0)
  185. {
  186. timeString = [NSString stringWithFormat:@"%d分钟",min];
  187. } else if (hour != 0 && min == 0) {
  188. timeString = [NSString stringWithFormat:@"%d%@",(int)hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时")];
  189. }
  190. cell.detailTextLabel.text = [NSString stringWithFormat:@"持续时间:%@",timeString];
  191. return cell;
  192. }else{
  193. /*
  194. CRI_VAILD_TIME:有效学时
  195. CRI_TRAIN_SUBJECT:学时阶段 1-4
  196. CRI_DURATION:培训学时
  197. PXKMTYPE:1实操 2课堂教练 3模拟器教学 4远程教练(理论)
  198. TCI_PHOTO_PATH:教练员照片
  199. TCI_NAME:教练名称
  200. CRI_STARTTIME:开始时间
  201. CRI_ENDTIME:结束时间
  202. */
  203. NSDictionary *dic = self.datasourceArray[indexPath.row];
  204. if ([dic[@"PXKMTYPE"] isEqualToString:@"1"]) {
  205. //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  206. //显示按钮
  207. TrainDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"trainDetailCell"];
  208. if (cell == nil) {
  209. cell= [[[NSBundle mainBundle]loadNibNamed:@"TrainDetailCell" owner:nil options:nil] firstObject];
  210. cell.accessoryType = UITableViewCellAccessoryNone;
  211. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  212. }
  213. [cell.orbitBtn setTitle:@"查看轨迹" textColor:RQ_MAIN_COLOR Font:15 fotState:UIControlStateNormal];
  214. [cell.orbitBtn addTarget:self action:@selector(lookOrbit:) forControlEvents:UIControlEventTouchUpInside];
  215. cell.orbitBtn.tag = indexPath.row *2 + 1;
  216. [cell.commentBtn setTitle:@"评价" textColor:RQ_MAIN_COLOR Font:15 fotState:UIControlStateNormal];
  217. [cell.commentBtn setTitle:@"查看评价" textColor:RQ_MAIN_COLOR Font:15 fotState:UIControlStateSelected];
  218. [cell.commentBtn target:self tag:indexPath.row *2];
  219. if ([dic[@"CRI_STU_EVALUATE"] isEqualToString:@"1"]) {
  220. cell.commentBtn.selected = YES;
  221. }else{
  222. cell.commentBtn.selected = NO;
  223. }
  224. if ([dic[@"CRI_ENDTIME"] length] > 10) {
  225. cell.titleLabel.text = [NSString stringWithFormat:@"%@----%@",dic[@"CRI_STARTTIME"],[dic[@"CRI_ENDTIME"] substringFromIndex:10]];
  226. }else{
  227. cell.titleLabel.text = [NSString stringWithFormat:@"%@----%@",dic[@"CRI_STARTTIME"],dic[@"CRI_ENDTIME"]];
  228. }
  229. int time = [dic[@"CRI_DURATION"] intValue];
  230. int min = time%(_RATIONKS? : 60);
  231. int hour = time/(_RATIONKS? : 60);
  232. NSString *timeString = [NSString stringWithFormat:@"%d%@%d分钟",hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时"),min];
  233. if (hour == 0){
  234. timeString = [NSString stringWithFormat:@"%d分钟",min];
  235. } else if (hour != 0 && min == 0) {
  236. timeString = [NSString stringWithFormat:@"%d%@",(int)hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时")];
  237. }
  238. int mileage = [dic[@"CRI_MILEAGE"] intValue];
  239. cell.mileage_label.text = [NSString stringWithFormat:@"%.2f公里",mileage/1000.0];
  240. cell.contentLabel.text = [NSString stringWithFormat:@"持续时间:%@",timeString];
  241. return cell;
  242. }else{
  243. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  244. if (cell == nil)
  245. {
  246. //trainDetailCell
  247. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  248. cell.accessoryType = UITableViewCellAccessoryNone;
  249. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  250. cell.backgroundColor = backGroundColor;
  251. }
  252. if ([dic[@"CRI_ENDTIME"] length] > 10) {
  253. cell.textLabel.text = [NSString stringWithFormat:@"%@----%@",dic[@"CRI_STARTTIME"],[dic[@"CRI_ENDTIME"] substringFromIndex:10]];
  254. }else{
  255. cell.textLabel.text = [NSString stringWithFormat:@"%@----%@",dic[@"CRI_STARTTIME"],dic[@"CRI_ENDTIME"]];
  256. }
  257. int time = [dic[@"CRI_DURATION"] intValue];
  258. int min = time%(_RATIONKS? : 60);
  259. int hour = time/(_RATIONKS? : 60);
  260. NSString *timeString = [NSString stringWithFormat:@"%d%@%d分钟",hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时"),min];
  261. if (hour == 0)
  262. {
  263. timeString = [NSString stringWithFormat:@"%d分钟",min];
  264. } else if (hour != 0 && min == 0) {
  265. timeString = [NSString stringWithFormat:@"%d%@",(int)hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时")];
  266. }
  267. cell.detailTextLabel.text = [NSString stringWithFormat:@"持续时间:%@",timeString];
  268. return cell;
  269. }
  270. }
  271. }
  272. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  273. {
  274. if (![self.type isEqualToString:@"1"]) {
  275. NSDictionary *dic = self.datasourceArray[indexPath.row];
  276. if ([dic[@"PXKMTYPE"] isEqualToString:@"1"]) {
  277. return 90;
  278. }
  279. }
  280. return 44;
  281. }
  282. - (void)lookOrbit:(UIButton *)sender
  283. {
  284. NSDictionary *dic = self.datasourceArray[(sender.tag - 1)/2];
  285. OrbitVC * orc = [[OrbitVC alloc]init];
  286. orc.orderId = dic[@"ID"];
  287. orc.type = @"2";
  288. [self navPushHideTabbarToVC:orc];
  289. }
  290. - (void)btnClick:(UIButton *)sender
  291. {
  292. NSDictionary *dic = self.datasourceArray[sender.tag/2];
  293. if (sender.selected == YES) {
  294. //查看学时评价
  295. NSMutableDictionary * xsDic = [NSMutableDictionary new];
  296. [xsDic setValue:dic[@"TCI_ID"] forKey:@"coachId"];
  297. [xsDic setValue:dic[@"CRI_CLASSID"] forKey:@"classId"];
  298. [xsDic setValue:dic[@"TCI_NAME"] forKey:@"coachName"];
  299. orderCommentVC *cmVC = [[orderCommentVC alloc]init];
  300. cmVC.type = 2;
  301. cmVC.dic = xsDic;
  302. [self navPushHideTabbarToVC:cmVC];
  303. }else{
  304. //进行学时评价
  305. NSMutableDictionary * xsDic = [NSMutableDictionary new];
  306. [xsDic setValue:dic[@"CRI_TRAIN_SUBJECT"] forKey:@"kmStr"];
  307. [xsDic setValue:dic[@"TCI_ID"] forKey:@"coachId"];
  308. [xsDic setValue:dic[@"CRI_CLASSID"] forKey:@"classId"];
  309. [xsDic setValue:dic[@"TCI_NAME"] forKey:@"coachName"];
  310. Evaluation * evc = [[Evaluation alloc]init];
  311. evc.xsDic = xsDic;
  312. evc.tvc = self;
  313. self.blcok = ^(){
  314. sender.selected = YES;
  315. };
  316. [self navPushHideTabbarToVC:evc];
  317. }
  318. }
  319. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  320. return [UIView new];
  321. }
  322. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  323. {
  324. return .1;
  325. }
  326. @end