CoachDetail.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. @interface CoachDetail ()
  11. {
  12. BOOL _isLock;//锁定状态
  13. UIButton * _locakBtn;//锁定/解锁
  14. NSArray * _dataArr;
  15. HolderView * _holderV;
  16. }
  17. @end
  18. @implementation CoachDetail
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.navigationItem.title = @"教练详情";
  22. if (self.byWillDo) {
  23. [self createBottomBarWithtoolTitles:@[@"审核"]];
  24. [self setSegmentControllWithTitles:@[@"基本信息"]];
  25. }else{
  26. [self createBottomBarWithtoolTitles:@[@"锁定/解锁"]];
  27. [self setSegmentControllWithTitles:@[@"基本信息",@"锁定历史记录"]];
  28. UITableView *tableV = _tableViews[1];
  29. tableV.estimatedRowHeight=100;
  30. tableV.rowHeight=UITableViewAutomaticDimension;
  31. [self getLockRecords];
  32. [self getRequsetData];
  33. UITableView * tabV = [_tableViews lastObject];
  34. _holderV = [[HolderView alloc] initWithFrame:tabV.frame];
  35. [_holderV freshBlock:^{
  36. [self getLockRecords];
  37. }];
  38. [_mainScroolView addSubview:_holderV];
  39. }
  40. }
  41. -(void)setData{
  42. _keysArr = @[
  43. @[@"培训机构编号",@"CI_INSCODE"],
  44. @[@"教练全国编号",@"CI_COACHNUM"],
  45. @[@"姓名",@"CI_NAME"],
  46. @[@"性别",@"CI_SEX"],
  47. @[@"证件号",@"CI_IDCARD"],
  48. @[@"手机号码",@"CI_MOBILE"],
  49. @[@"联系地址",@"CI_ADDRESS"],
  50. @[@"驾驶证号",@"CI_DRILICENCE"],
  51. @[@"驾驶证初领日期",@"CI_FSTDRILICDATE"],
  52. @[@"职业资格证号",@"CI_OCCUPATIONNO"],
  53. @[@"职业资格等级",@"CI_OCCUPATIONLEVEL"],
  54. @[@"准驾车型",@"CI_DRIPERMITTED"],
  55. @[@"准教车型",@"CI_TEACHPERMITTED"],
  56. @[@"供职状态",@"CI_EMPLOYSTATUS"],
  57. @[@"入职日期",@"CI_HIREDATE"],
  58. @[@"离职日期",@"CI_LEAVEDATE"],
  59. @[@"备案状态",@"CI_RECORD_STATUS"],
  60. @[@"备案时间",@"CI_RECORD_TIME"],
  61. @[@"锁定状态",@"CI_LOCK_STATUS"],
  62. @[@"锁定/解锁时间",@"CI_LOCK_DATE"]];
  63. [super setData];
  64. }
  65. -(void)getRequsetData{
  66. [self getDataWithDic:self.requesetDic method:@"coachs" block:^(NSDictionary *successDic) {
  67. self.dataSource = [NSMutableDictionary dictionaryWithDictionary:successDic[@"body"][0]];
  68. [_tableViews[0] reloadData];
  69. _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"CI_LOCK_STATUS"]] isEqualToString:@"1"];
  70. [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  71. //
  72. if (self.lockBlock) {
  73. self.lockBlock(self.dataSource);
  74. }
  75. }];
  76. }
  77. -(void)getLockRecords{
  78. //判断网络是否连接
  79. if (![NetworkManager connectedToNetWork]) {
  80. [self showMsgByAlertVCWithString:@"网络连接异常"];
  81. return;
  82. }
  83. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  84. [mDic setObject:self.coachNum forKey:@"objnum"];
  85. [mDic setObject:@"2" forKey:@"type"];
  86. [MBProgressHUD hideHUDForView:self.view animated:NO];
  87. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  88. [NetworkManager requestWithMethod:@"lockLogs" parameters:mDic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  89. [MBProgressHUD hideHUDForView:self.view animated:YES];
  90. [_holderV setHidden:NO];
  91. if (failureStr) {
  92. [self showMsgByAlertVCWithString:failureStr];
  93. return;
  94. }
  95. if ([successDic[@"code"] isEqualToString:@"1"]) {
  96. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  97. return;
  98. }
  99. _dataArr = successDic[@"body"];
  100. if (_dataArr.count != 0) {
  101. _holderV.hidden = YES;
  102. }
  103. [_tableViews[1] reloadData];
  104. }];
  105. }
  106. #pragma mark 创建BottomBarButton
  107. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  108. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  109. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  110. for (int i=0; i<toolTitles.count; i++) {
  111. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  112. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-SafeAreaBottomHeight, widthBtn, HeightBth);
  113. if (i == 0 && self.byWillDo == NO) {
  114. [button setTitle:@"锁定" forState:UIControlStateNormal];
  115. _locakBtn = button;
  116. }else{
  117. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  118. }
  119. UIColor * color = COLOR_THEME;
  120. button.backgroundColor = color;
  121. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  122. [button addTarget:self action:@selector(lockReason) forControlEvents:UIControlEventTouchUpInside];
  123. button.tag = 100+i;
  124. [self.view addSubview:button];
  125. }
  126. }
  127. -(void)lockReason{
  128. if (self.byWillDo && self.shenheBLock) {
  129. self.shenheBLock();
  130. return;
  131. }
  132. NSString * title = _isLock ? @"解锁":@"锁定";
  133. NSString *message = [NSString stringWithFormat:@"请输入%@理由:",title];
  134. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  135. [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  136. textField.placeholder = [NSString stringWithFormat:@"(必须填写,否则将无法完成%@)",title];
  137. }];
  138. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  139. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  140. UITextField *tf = alertFind.textFields[0];
  141. if (tf.text.length > 0) {
  142. [self lockCoachWithReason:tf.text];
  143. }else{
  144. [self showMsgByMBWithString:@"操作失败,请输入锁定/解锁理由"];
  145. }
  146. }]];
  147. NSString *theId = _isLock ? @"550":@"549";
  148. [Tools permissionValidationWithID:theId result:^(BOOL isCan, NSString *failureStr) {
  149. if (!isCan) {
  150. if (failureStr) {
  151. [self showMsgByMBWithString:failureStr];
  152. }
  153. return;
  154. }
  155. [self presentViewController:alertFind animated:true completion:nil];
  156. }];
  157. }
  158. -(void)lockCoachWithReason:(NSString *)reason{
  159. NSMutableDictionary * mdic = [NSMutableDictionary new];
  160. [mdic setValue:MYAPPDELEGATE.userDic[@"id"] forKey:@"userId"];
  161. [mdic setValue:reason forKey:@"reason"];
  162. [mdic setValue:_isLock ? @"0" : @"1" forKey:@"status"];//类型 类型 1 锁定 0 解锁
  163. [mdic setValue:self.dataSource[@"CI_COACHNUM"] forKey:@"coachnum"];
  164. [self getDataWithDic:mdic method:@"lockCoach" block:^(NSDictionary *successdic) {
  165. //解锁成功,重新请求数据
  166. [self getRequsetData];
  167. [self getLockRecords];
  168. }];
  169. }
  170. #pragma mark 重写代理方法
  171. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  172. if ([_tableViews indexOfObject:tableView] == 1) {
  173. return _dataArr.count;
  174. }
  175. return [_keysArr count];
  176. }
  177. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  178. if ([_tableViews indexOfObject:tableView] == 1) {
  179. return [LockCell heightForDic:_dataArr[indexPath.row]];
  180. }
  181. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  182. }
  183. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  184. {
  185. if ([_tableViews indexOfObject:tableView] == 1) {
  186. LockCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  187. if (!cell) {
  188. cell = [[[NSBundle mainBundle] loadNibNamed:@"LockCell" owner:nil options:nil]lastObject];
  189. }
  190. [cell upDataWithDic:_dataArr[indexPath.row]];
  191. return cell;
  192. }
  193. return [super tableView:tableView cellForRowAtIndexPath:indexPath];
  194. }
  195. - (void)didReceiveMemoryWarning {
  196. [super didReceiveMemoryWarning];
  197. // Dispose of any resources that can be recreated.
  198. }
  199. /*
  200. #pragma mark - Navigation
  201. // In a storyboard-based application, you will often want to do a little preparation before navigation
  202. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  203. // Get the new view controller using [segue destinationViewController].
  204. // Pass the selected object to the new view controller.
  205. }
  206. */
  207. @end