CoachDetail.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. //
  2. // CoachDetail.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/10.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "CoachDetail.h"
  9. #import "LockCell.h"
  10. #import "UploadCoachContractVC.h"
  11. #import "TileViewController.h"
  12. @interface CoachDetail ()
  13. {
  14. BOOL _isLock;//锁定状态
  15. UIButton * _locakBtn;//锁定/解锁
  16. NSArray * _dataArr;
  17. HolderView *_holderV;
  18. NSMutableArray *_dataImgs;
  19. HolderView *_holderV2;
  20. BOOL _isPermission;//上传合同权限
  21. }
  22. @end
  23. @implementation CoachDetail
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.navigationItem.title = @"教练详情";
  27. _dataArr = [[NSArray alloc]init];
  28. _dataImgs = [[NSMutableArray alloc]init];
  29. [Tools permissionValidationWithID:@"1187" view:self.view result:^(BOOL isCan, NSString *failureStr) {
  30. _isPermission = isCan;
  31. if (isCan) {
  32. [self setSegmentControllWithTitles:@[@"基本信息",@"锁定历史记录",@"合同"] isBttomBar:YES];
  33. [self createBottomBarWithtoolTitle:@"上传教练合同"];
  34. }else{
  35. [self setSegmentControllWithTitles:@[@"基本信息",@"锁定历史记录",@"合同"] isBttomBar:NO];
  36. }
  37. [self getRequsetData];
  38. [self getLockRecords];
  39. UITableView * tabV = _tableViews[1];
  40. _holderV = [[HolderView alloc] initWithFrame:tabV.frame];
  41. [_holderV freshBlock:^{
  42. [self getLockRecords];
  43. }];
  44. [_mainScroolView addSubview:_holderV];
  45. UITableView *tableV = _tableViews[2];
  46. _holderV2 = [[HolderView alloc]initWithFrame:tableV.frame];
  47. _holderV2.y -= JOb_DETAIL_BOTTOMBAR_HEIGHT;
  48. [_holderV2 freshBlock:^{
  49. [self getRequsetData];
  50. }];
  51. [_mainScroolView addSubview:_holderV2];
  52. }];
  53. }
  54. -(void)setData{
  55. _keysArr = @[
  56. // @[@"培训机构编号",@"TCI_INSCODE"],培训机构编号
  57. @[@"姓名",@"TCI_NAME"],
  58. @[@"性别",@"TCI_SEX"],
  59. @[@"证件号",@"TCI_IDCARD"],
  60. @[@"手机号码",@"TCI_MOBILE"],
  61. @[@"联系地址",@"TCI_ADDRESS"],
  62. @[@"供职状态",@"TCI_EMPLOYSTATUS"],
  63. @[@"驾驶证号",@"TCI_DRILICENCE"],
  64. @[@"驾驶证初领日期",@"TCI_FSTDRILICDATE"],
  65. @[@"职业资格证号",@"TCI_OCCUPATIONNO"],
  66. @[@"职业资格等级",@"TCI_OCCUPATIONLEVEL"],
  67. @[@"准驾车型",@"TCI_DRIPERMITTED"],
  68. @[@"准教车型",@"TCI_TEACHPERMITTED"],
  69. @[@"入职日期",@"TCI_HIREDATE"],
  70. @[@"离职日期",@"TCI_LEAVEDATE"],
  71. @[@"全国统一编号",@"TCI_COACHNUM"],
  72. @[@"备案时间",@"TCI_RECORD_DATE"]];
  73. [super setData];
  74. }
  75. -(void)getRequsetData{
  76. [self getDataWithDic:self.requesetDic method:@"coachs" block:^(NSDictionary *successDic) {
  77. self.dataSource = [NSMutableDictionary dictionaryWithDictionary:successDic[@"body"][0]];
  78. self.headImgStr = self.dataSource[@"TCI_PHOTO_PATH"];
  79. [_tableViews[0] reloadData];
  80. [_dataImgs removeAllObjects];
  81. _dataImgs = [NSMutableArray arrayWithArray:[self.dataSource[@"TCI_PROTOCOL_PATH"] componentsSeparatedByString:@","]];
  82. if (_dataImgs.count > 0) {
  83. _holderV2.hidden = YES;
  84. }
  85. [_tableViews[2] reloadData];
  86. _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCI_LOCK_STATUS"]] isEqualToString:@"1"];
  87. [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  88. }];
  89. }
  90. -(void)getLockRecords{
  91. //判断网络是否连接
  92. if (![NetManager connectedToNetWork]) {
  93. showMsgUnconnect();
  94. return;
  95. }
  96. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  97. [mDic setObject:self.coachNum forKey:@"qgcode"];
  98. [mDic setObject:@"2" forKey:@"type"];
  99. [MBProgressHUD showLoadToView:self.view];
  100. [NetManager requestAnythingWithURL:@"getLockRecords" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
  101. [MBProgressHUD hideHUDForView:self.view];
  102. _holderV.hidden = NO;
  103. if (!root) {
  104. ShowMsg(@"数据请求失败,请重试");
  105. return;
  106. }
  107. if ([root[@"code"] integerValue] == 1) {
  108. ShowMsg(root[@"msg"]);
  109. return;
  110. }
  111. _dataArr = root[@"body"];
  112. if (_dataArr.count > 0) {
  113. _holderV.hidden = YES;
  114. }
  115. [_tableViews[1] reloadData];
  116. _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCI_LOCK_STATUS"]] isEqualToString:@"1"];
  117. [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  118. }];
  119. }
  120. #pragma mark 创建BottomBarButton
  121. -(void)createBottomBarWithtoolTitle:(NSString *)title{
  122. UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
  123. button.frame = CGRectMake(0, kSize.height-kNavOffSet-JOb_DETAIL_BOTTOMBAR_HEIGHT-SafeAreaBottomHeight, kSize.width, JOb_DETAIL_BOTTOMBAR_HEIGHT);
  124. button.backgroundColor = defGreen;
  125. [button setTitle:title textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  126. [button addTarget:self action:@selector(goToUploadCoachContractVC) forControlEvents:UIControlEventTouchUpInside];
  127. [self.view addSubview:button];
  128. }
  129. -(void)goToUploadCoachContractVC {
  130. // NSLog(@"coachNum--->%@-----dataSource------>%@",self.coachNum,self.dataSource);
  131. UploadCoachContractVC *uploadVC = [[UploadCoachContractVC alloc] init];
  132. uploadVC.coachID = [NSString stringWithFormat:@"%@",self.dataSource[@"TCI_ID"]];
  133. uploadVC.imgPaths = self.dataSource[@"TCI_PROTOCOL_PATH"];
  134. uploadVC.block = ^{
  135. [self getRequsetData];
  136. self.currentIndex = 2;
  137. };
  138. [self navPushHideTabbarToVC:uploadVC];
  139. }
  140. -(void)lockCoachWithReason:(NSString *)reason{
  141. NSMutableDictionary * mdic = [NSMutableDictionary new];
  142. [mdic setValue:defUser.userDict[@"id"] forKey:@"userId"];
  143. [mdic setValue:reason forKey:@"reason"];
  144. [mdic setValue:_isLock ? @"0" : @"1" forKey:@"status"];//类型 类型 1 锁定 0 解锁
  145. [mdic setValue:self.dataSource[@"TCI_COACHNUM"] forKey:@"coachnum"];
  146. [self getDataWithDic:mdic method:@"lockCoach" block:^(NSDictionary *successdic) {
  147. //解锁成功,重新请求数据
  148. [self getRequsetData];
  149. [self getLockRecords];
  150. }];
  151. }
  152. #pragma mark 重写代理方法
  153. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  154. if ([_tableViews indexOfObject:tableView] == 1) {
  155. return _dataArr.count;
  156. }
  157. if ([_tableViews indexOfObject:tableView] == 2) {
  158. return 1;
  159. }
  160. return [super tableView:tableView numberOfRowsInSection:section];
  161. }
  162. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  163. if ([_tableViews indexOfObject:tableView] == 1) {
  164. return 44;
  165. }
  166. if ([_tableViews indexOfObject:tableView] == 2) {
  167. CGFloat height = _isPermission ? JOb_DETAIL_BOTTOMBAR_HEIGHT : 0;
  168. return kSize.height-kNavOffSet-height-JOb_DETAIL_SEGBAR_HEIGHT-SafeAreaBottomHeight;
  169. }
  170. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  171. }
  172. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  173. {
  174. if ([_tableViews indexOfObject:tableView] == 1) {
  175. LockCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LockCellId"];
  176. if (!cell) {
  177. cell = [[[NSBundle mainBundle] loadNibNamed:@"LockCell" owner:nil options:nil]lastObject];
  178. }
  179. [cell upDataWithDic:_dataArr[indexPath.row]];
  180. return cell;
  181. }
  182. if ([_tableViews indexOfObject:tableView] == 2) {
  183. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  184. if (!cell) {
  185. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
  186. }
  187. if (cell.contentView.subviews.count != 0) {
  188. [[cell.contentView.subviews lastObject] removeFromSuperview];
  189. }
  190. TileViewController *vc = [[TileViewController alloc]initWithImageNames:_dataImgs];
  191. CGFloat height = _isPermission ? JOb_DETAIL_BOTTOMBAR_HEIGHT : 0;
  192. vc.view.height -= 64+JOb_DETAIL_SEGBAR_HEIGHT+height;
  193. [self addChildViewController:vc];
  194. [cell.contentView addSubview:vc.view];
  195. return cell;
  196. }
  197. return [super tableView:tableView cellForRowAtIndexPath:indexPath];
  198. }
  199. #pragma mark - 上传头像
  200. -(void)uploadHeadImg:(UIImage*)image
  201. {
  202. NSData *data = UIImagePNGRepresentation([image scaledToWid:100]);
  203. NSString *imgString = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
  204. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  205. [dic setObject:imgString forKey:@"content"];
  206. [dic setObject:self.dataSource[@"TCI_ID"] forKey:@"coachId"];//这个值新增不要,此处修改要
  207. NSString *method = @"uploadCoachPhoto";
  208. [MBProgressHUD showLoadToView:self.view];
  209. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  210. [MBProgressHUD hideHUDForView:self.view];
  211. if (!root) {
  212. ShowMsg(@"上传头像失败!");
  213. return;
  214. }
  215. if ([root[@"code"] isEqualToString:@"1"]) {
  216. ShowErrorMsg(root[@"msg"]);
  217. return;
  218. }
  219. //上传照片成功
  220. self.headImgStr = root[@"body"];
  221. ShowMsg(root[@"msg"]);
  222. [_tableViews[0] reloadData];
  223. }];
  224. }
  225. - (void)didReceiveMemoryWarning {
  226. [super didReceiveMemoryWarning];
  227. // Dispose of any resources that can be recreated.
  228. }
  229. /*
  230. #pragma mark - Navigation
  231. // In a storyboard-based application, you will often want to do a little preparation before navigation
  232. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  233. // Get the new view controller using [segue destinationViewController].
  234. // Pass the selected object to the new view controller.
  235. }
  236. */
  237. @end