TrainDetailVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 = defGreen;
  31. if (defUser.isycbd != 1) {
  32. self.navigationItem.rightBarButtonItem = item;
  33. }
  34. }
  35. mainTable = [[UITableView alloc] initWithFrame:kFrame];
  36. mainTable.height -= kNavOffSet;
  37. mainTable.delegate = self;
  38. mainTable.dataSource = self;
  39. [self.view addSubview:mainTable];
  40. if (_datasourceArray.count < 1) {
  41. HolderView *placeHolder = [[HolderView alloc] initWithFrame:mainTable.frame];
  42. [self.view addSubview:placeHolder];
  43. }
  44. }
  45. -(void)clickToUpdate
  46. {
  47. [self upLoadTrainRecord];
  48. }
  49. -(void)upLoadTrainRecord{
  50. if (_datasourceArray.count < 1) {
  51. ShowMsg(@"本地无学时明细!");
  52. return;
  53. }
  54. //这里是对分段上传学时做的处理 如果学时上传有问题 查看这里
  55. [self uploadMoreTrainRecordWithArray:_datasourceArray];
  56. }
  57. - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray {
  58. if (![Util connectedToNetWork]) {
  59. showMsgUnconnect();
  60. return;
  61. }
  62. NSString* str = @"";
  63. for (TrainRecord *record in trainArray) {
  64. str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]];
  65. }
  66. TrainRecord *record = [trainArray firstObject];
  67. NSMutableArray *arr=[NSMutableArray array];
  68. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  69. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  70. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  71. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:defUser.userDict[@"outId"],@"stuOutid", nil]];
  72. NSString* method = @"uploadMoreTrainRecord";
  73. [MBProgressHUD showLoadToView:self.view];
  74. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  75. [MBProgressHUD hideHUDForView:self.view];
  76. if (!dict) {
  77. ShowMsg(@"操作失败");
  78. return;
  79. }
  80. if ([dict[@"code"] isEqualToString:@"90"]) {
  81. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:dict[@"msg"] preferredStyle:UIAlertControllerStyleAlert];
  82. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  83. [LoginViewController loginFromVC:self];
  84. }]];
  85. [self presentViewController:alertFind animated:true completion:nil];
  86. return;
  87. }
  88. if ( [dict[@"code"] isEqualToString:@"1"]) {
  89. ShowMsg(dict[@"body"]);
  90. return;
  91. }
  92. if ( [dict[@"code"] isEqualToString:@"0"]) {
  93. for (TrainRecord *record in trainArray) {
  94. [DB_Helper updateTrainState:record];
  95. }
  96. UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"上传学时成功!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
  97. [alert show];
  98. self.datasourceArray = [NSMutableArray array];
  99. [mainTable reloadData];
  100. }
  101. }];
  102. }
  103. #pragma mark tableView delegate
  104. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  105. return self.datasourceArray.count;
  106. }
  107. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  108. if ([self.type isEqualToString:@"1"])//
  109. {
  110. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  111. if (cell == nil)
  112. {
  113. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  114. cell.accessoryType = UITableViewCellAccessoryNone;
  115. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  116. }
  117. TrainRecord *train = (TrainRecord *)self.datasourceArray[indexPath.row];
  118. if (train.endTime.length > 10) {
  119. cell.textLabel.text = [NSString stringWithFormat:@"%@----%@",train.beginTime,[train.endTime substringFromIndex:10]];
  120. }else{
  121. cell.textLabel.text = [NSString stringWithFormat:@"%@----%@",train.beginTime,train.endTime];
  122. }
  123. int time = [train.trainTime intValue];
  124. int min = time%60;
  125. int hour = time/60;
  126. NSString *timeString = [NSString stringWithFormat:@"%d小时%d分钟",hour,min];
  127. if (hour == 0)
  128. {
  129. timeString = [NSString stringWithFormat:@"%d分钟",min];
  130. }
  131. cell.detailTextLabel.text = [NSString stringWithFormat:@"持续时间:%@",timeString];
  132. return cell;
  133. }else{
  134. /*
  135. CRI_VAILD_TIME:有效学时
  136. CRI_TRAIN_SUBJECT:学时阶段 1-4
  137. CRI_DURATION:培训学时
  138. PXKMTYPE:1实操 2课堂教练 3模拟器教学 4远程教练(理论)
  139. TCI_PHOTO_PATH:教练员照片
  140. TCI_NAME:教练名称
  141. CRI_STARTTIME:开始时间
  142. CRI_ENDTIME:结束时间
  143. CRI_SECOND_AUDIT_RESULT --二次审核结果 0审核通过 1审核不通过 2待审核
  144. CRI_SECOND_AUDIT_REASON --二次审核结果原因
  145. CRI_AUDIT_USERNAME --二次审核人
  146. CRI_AUDIT_TIME --二次审核时间
  147. */
  148. NSDictionary *dic = self.datasourceArray[indexPath.row];
  149. //显示按钮
  150. TrainDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"trainDetailCell"];
  151. if (cell == nil) {
  152. cell= [[[NSBundle mainBundle]loadNibNamed:@"TrainDetailCell" owner:nil options:nil] firstObject];
  153. cell.accessoryType = UITableViewCellAccessoryNone;
  154. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  155. }
  156. [cell updateWith:dic];
  157. if ([dic[@"PXKMTYPE"] isEqualToString:@"1"]) {
  158. [cell.orbitBtn addTarget:self action:@selector(lookOrbit:) forControlEvents:UIControlEventTouchUpInside];
  159. cell.orbitBtn.tag = indexPath.row *2 + 1;
  160. [cell.commentBtn target:self tag:indexPath.row *2];
  161. cell.commentBtn.width = 0;
  162. return cell;
  163. }else{
  164. [cell.orbitBtn removeFromSuperview];
  165. [cell.commentBtn removeFromSuperview];
  166. return cell;
  167. }
  168. }
  169. }
  170. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  171. if (![self.type isEqualToString:@"1"]) {
  172. NSDictionary *dic = self.datasourceArray[indexPath.row];
  173. //PXKMTYPE:1实操 (2课堂教练==》服务器改为返回到4里面去了) 3模拟器教学 4远程教学(理论)+ (终端)理论
  174. //实操的带有评价
  175. if ([dic[@"PXKMTYPE"] isEqualToString:@"1"]) {
  176. return [TrainDetailCell heightForDic:self.datasourceArray[indexPath.row]];
  177. }else{
  178. return [TrainDetailCell heightForDic:self.datasourceArray[indexPath.row]] - 30;
  179. }
  180. }
  181. return 44;
  182. }
  183. - (void)lookOrbit:(UIButton *)sender {
  184. NSDictionary *dic = self.datasourceArray[(sender.tag - 1)/2];
  185. OrbitVC * orc = [[OrbitVC alloc]init];
  186. orc.orderId = dic[@"ID"];
  187. orc.type = @"2";
  188. [self navPushHideTabbarToVC:orc];
  189. }
  190. - (void)btnClick:(UIButton *)sender {
  191. NSDictionary *dic = self.datasourceArray[sender.tag/2];
  192. if (sender.selected == YES) {
  193. //查看学时评价
  194. NSMutableDictionary * xsDic = [NSMutableDictionary new];
  195. [xsDic setValue:dic[@"TCI_ID"] forKey:@"coachId"];
  196. [xsDic setValue:dic[@"CRI_CLASSID"] forKey:@"classId"];
  197. [xsDic setValue:dic[@"TCI_NAME"] forKey:@"coachName"];
  198. orderCommentVC *cmVC = [[orderCommentVC alloc]init];
  199. cmVC.type = 2;
  200. cmVC.dic = xsDic;
  201. [self navPushHideTabbarToVC:cmVC];
  202. }else{
  203. //进行学时评价
  204. NSMutableDictionary * xsDic = [NSMutableDictionary new];
  205. [xsDic setValue:dic[@"CRI_TRAIN_SUBJECT"] forKey:@"kmStr"];
  206. [xsDic setValue:dic[@"TCI_ID"] forKey:@"coachId"];
  207. [xsDic setValue:dic[@"CRI_CLASSID"] forKey:@"classId"];
  208. [xsDic setValue:dic[@"TCI_NAME"] forKey:@"coachName"];
  209. Evaluation * evc = [[Evaluation alloc]init];
  210. evc.xsDic = xsDic;
  211. evc.tvc = self;
  212. __block NSMutableDictionary *mDic = [NSMutableDictionary dictionaryWithDictionary:dic];
  213. __weak typeof(self) weakSelf = self;
  214. self.blcok = ^(){
  215. sender.selected = YES;
  216. [mDic setObject:@"1" forKey:@"CRI_STU_EVALUATE"];
  217. [weakSelf.datasourceArray replaceObjectAtIndex:sender.tag/2 withObject:mDic];
  218. };
  219. [self navPushHideTabbarToVC:evc];
  220. }
  221. }
  222. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  223. return [UIView new];
  224. }
  225. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  226. return .1;
  227. }
  228. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath*)indexPath {
  229. @weakify(self)
  230. //删除
  231. TrainRecord *train = (TrainRecord *)self.datasourceArray[indexPath.row];
  232. UIContextualAction *deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  233. @strongify(self)
  234. [self.datasourceArray removeObject:train];
  235. [DB_Helper deleteTrain:train];
  236. [mainTable reloadData];
  237. }];
  238. UISwipeActionsConfiguration *configuration = [UISwipeActionsConfiguration configurationWithActions:([self.type isEqualToString:@"1"] && defUser.isycbd == 1)? @[deleteRowAction] : @[]];
  239. return configuration;
  240. }
  241. - (void)didReceiveMemoryWarning {
  242. [super didReceiveMemoryWarning];
  243. }
  244. @end