SchoolDetail.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. //
  2. // SchoolDetail.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/9.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "SchoolDetail.h"
  9. #import "LockCell.h"
  10. @interface SchoolDetail ()
  11. {
  12. NSArray *_titles2;//_tableviews[1] 的相关key值
  13. BOOL _isLock;//锁定状态
  14. UIButton * _locakBtn;//锁定/解锁
  15. NSArray * _dataArr;//锁定记录
  16. HolderView * _holderV;
  17. }
  18. @end
  19. @implementation SchoolDetail
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.navigationItem.title = @"驾校详情";
  23. if (self.byWillDo) {
  24. [self createBottomBarWithtoolTitles:@[@"审核"]];
  25. [self setSegmentControllWithTitles:@[@"基本信息",@"场地信息"]];
  26. }else{
  27. [self createBottomBarWithtoolTitles:@[@"设置培训能力",@"锁定/解锁"]];
  28. [self setSegmentControllWithTitles:@[@"基本信息",@"场地信息",@"锁定历史记录"]];
  29. [self getLockLogs];
  30. [self getRequsetData];
  31. UITableView * tabV = [_tableViews lastObject];
  32. _holderV = [[HolderView alloc] initWithFrame:tabV.frame];
  33. [_holderV freshBlock:^{
  34. [self getLockLogs];
  35. }];
  36. [_mainScroolView addSubview:_holderV];
  37. }
  38. }
  39. -(void)setData{
  40. _keysArr = @[@[@"地市名称",@"TSI_DQMC"],
  41. @[@"区县名称",@"TSI_QXMC"],
  42. @[@"机构名称",@"TSI_NAME"],
  43. @[@"机构简称",@"TSI_SHORTNAME"],
  44. @[@"培训机构地址",@"TSI_ADDRESS"],
  45. @[@"经营范围",@"TSI_BUSISCOPE"],
  46. @[@"经营状态",@"TSI_BUSISTATUS"],
  47. @[@"经营许可证编号",@"TSI_LICNUM"],
  48. @[@"经营许可日期",@"TSI_LICETIME"],
  49. @[@"营业执照注册号",@"TSI_BUSINESS"],
  50. @[@"统一社会信用代码",@"TSI_CREDITCODE"],
  51. @[@"法人代表",@"TSI_LEGAL"],
  52. @[@"联系人",@"TSI_CONTACT"],
  53. @[@"联系电话",@"TSI_PHONE"],
  54. @[@"分类等级",@"TSI_LEVEL"],
  55. @[@"全国编号",@"TSI_INSCODE"],
  56. @[@"邮政编码",@"TSI_POSTCODE"],
  57. @[@"备案时间",@"TSI_RECORD_DATE"],
  58. @[@"锁定状态",@"TSI_LOCK_STATUS"],
  59. @[@"锁定/解锁时间",@"TSI_LOCK_DATE"]];
  60. _titles2 = @[@[@"教练员总数",@"TSI_COACHNUMBER"],
  61. @[@"考核员总数",@"TSI_GRASUPVNUM"],
  62. @[@"安全员总数",@"TSI_SAFMNGNUM"],
  63. @[@"教练车总数",@"TSI_TRACARNUM"],
  64. @[@"教室总面积(m2)",@"TSI_CLASSROOM"],
  65. @[@"理论教室面积(单位:m2)",@"TSI_THCLASSROOM"],
  66. @[@"教练场总面积(单位:m2)",@"TSI_PRATICEFIELD"]];
  67. [super setData];
  68. }
  69. -(void)getRequsetData{
  70. [self getDataWithDic:self.requesetDic method:@"schools" block:^(NSDictionary *successDic) {
  71. self.dataSource = [NSMutableDictionary dictionaryWithDictionary:successDic[@"body"][0]];
  72. for (UITableView * tableView in _tableViews) {
  73. [tableView reloadData];
  74. }
  75. _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TSI_LOCK_STATUS"]] isEqualToString:@"1"];
  76. [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  77. }];
  78. }
  79. -(void)getLockLogs{
  80. //判断网络是否连接
  81. if (![NetworkManager connectedToNetWork]) {
  82. [self showMsgByAlertVCWithString:@"网络连接异常"];
  83. return;
  84. }
  85. NSMutableDictionary * mdic = [[NSMutableDictionary alloc]init];
  86. [mdic setValue:@"1" forKey:@"type"];//类型 1 培训机构 2 教练 3 教练车 4 学员 5 终端
  87. [mdic setValue:self.requesetDic[@"inscode"] forKey:@"objnum"];
  88. [MBProgressHUD hideHUDForView:self.view animated:NO];//强行先掉一次@lee
  89. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  90. [NetworkManager requestWithMethod:@"lockLogs" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  91. [MBProgressHUD hideHUDForView:self.view animated:YES];
  92. [_holderV setHidden:NO];
  93. if (failureStr) {
  94. [self showMsgByAlertVCWithString:failureStr];
  95. return;
  96. }
  97. if ([successDic[@"code"] isEqualToString:@"1"]) {
  98. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  99. return;
  100. }
  101. _dataArr = successDic[@"body"];
  102. if (_dataArr.count != 0) {
  103. _holderV.hidden = YES;
  104. }
  105. [_tableViews[2] reloadData];
  106. }];
  107. }
  108. #pragma mark 创建BottomBarButton
  109. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  110. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  111. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  112. for (int i=0; i<toolTitles.count; i++) {
  113. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  114. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-SafeAreaBottomHeight, widthBtn, HeightBth);
  115. if (i == 1) {
  116. [button setTitle:@"锁定" forState:UIControlStateNormal];
  117. _locakBtn = button;
  118. }else{
  119. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  120. }
  121. UIColor * color = COLOR_THEME;
  122. button.backgroundColor = color;
  123. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  124. [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  125. button.tag = 100+i;
  126. [self.view addSubview:button];
  127. }
  128. }
  129. - (void)buttonClick:(UIButton *)sender{
  130. if (self.byWillDo && self.shenheBLock) {
  131. self.shenheBLock();
  132. return;
  133. }
  134. if (sender.tag == 100) {
  135. [self setTrainability];
  136. }else if (sender.tag == 101){
  137. NSString * title = _isLock ? @"解锁":@"锁定";
  138. NSString *message = [NSString stringWithFormat:@"请输入%@理由:",title];
  139. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  140. [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  141. textField.placeholder = [NSString stringWithFormat:@"(必须填写,否则将无法完成%@)",title];
  142. }];
  143. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  144. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  145. UITextField *tf = alertFind.textFields[0];
  146. if (tf.text.length > 0) {
  147. [self lockSchoolWith:tf.text];
  148. }else{
  149. [self showMsgByMBWithString:@"操作失败,请输入锁定/解锁理由"];
  150. }
  151. }]];
  152. [self presentViewController:alertFind animated:true completion:nil];
  153. }
  154. }
  155. -(void)setTrainability{
  156. UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"设置培训能力" message:@"请选择设置方式" preferredStyle:UIAlertControllerStyleActionSheet];
  157. //添加操作
  158. [ac addAction:[UIAlertAction actionWithTitle:@"按车设置(每辆车最大带教人数)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  159. [self setCountWithType:@"1"];
  160. }]];
  161. [ac addAction:[UIAlertAction actionWithTitle:@"按月设置(每月最大允许招生量)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  162. [self setCountWithType:@"2"];
  163. }]];
  164. [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  165. [self presentViewController:ac animated:YES completion:nil];
  166. }
  167. - (void)setCountWithType:(NSString *)type
  168. {
  169. BOOL isCar = [type isEqualToString:@"1"];
  170. NSString * title = isCar ? @"按车设置" : @"按月设置";
  171. NSString * message = isCar ? @"请写入每辆车最大带教人数" : @"请写入每月最大允许招生量";
  172. UIAlertController *ac = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  173. [ac addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  174. textField.placeholder = message;
  175. textField.keyboardType = UIKeyboardTypeNumberPad;
  176. }];
  177. [ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  178. NSString *tfStr = [ac.textFields firstObject].text;
  179. NSMutableDictionary * mdic = [NSMutableDictionary new];
  180. [mdic setValue:self.dataSource[@"TSI_INSCODE"] forKey:@"inscode"];
  181. [mdic setValue:type forKey:@"type"];//类型 1 按车设置 2 按月设置
  182. [mdic setValue:isCar ? tfStr : @"" forKey:@"limitCar"];//如果type=1 则不能为空
  183. [mdic setValue:isCar ? @"" : tfStr forKey:@"limitMonth"];//如果type=2 则不能为空
  184. [self getDataWithDic:mdic method:@"setSchoolTrain" block:^(NSDictionary *successdic) {
  185. if (isCar) {
  186. [self showMsgByAlertVCWithString:[NSString stringWithFormat:@"已成功设置该驾校每辆车最大带教人数为:%@个",tfStr]];
  187. }else{
  188. [self showMsgByAlertVCWithString:[NSString stringWithFormat:@"已成功设置该驾校每月最大允许招生量为:%@个",tfStr]];
  189. }
  190. }];
  191. }]];
  192. [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  193. [self presentViewController:ac animated:YES completion:nil];
  194. }
  195. -(void)lockSchoolWith:(NSString *)reason{
  196. NSMutableDictionary * mdic = [NSMutableDictionary new];
  197. [mdic setValue:MYAPPDELEGATE.userDic[@"id"] forKey:@"userId"];
  198. [mdic setValue:reason forKey:@"reason"];
  199. [mdic setValue:_isLock ? @"0" : @"1" forKey:@"status"];
  200. [mdic setValue:self.dataSource[@"TSI_INSCODE"] forKey:@"inscode"];
  201. [self getDataWithDic:mdic method:@"lockSchool" block:^(NSDictionary *successdic) {
  202. //解锁成功,重新请求数据
  203. [self getRequsetData];
  204. [self getLockLogs];
  205. }];
  206. }
  207. #pragma mark 重写代理方法
  208. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  209. NSInteger index = [_tableViews indexOfObject:tableView];
  210. if (index == 2) {
  211. return _dataArr.count;
  212. }
  213. if (index == 1) {
  214. return _titles2.count;
  215. }
  216. if (self.dataSource == nil) {
  217. return 0;
  218. }
  219. return [_keysArr count];
  220. }
  221. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  222. if ([_tableViews indexOfObject:tableView] == 2) {
  223. return 85;
  224. }else if([_tableViews indexOfObject:tableView] == 1){
  225. return 44;
  226. }
  227. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  228. }
  229. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  230. {
  231. NSInteger index = [_tableViews indexOfObject:tableView];
  232. if (index == 2) {
  233. LockCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  234. if (!cell) {
  235. cell = [[[NSBundle mainBundle] loadNibNamed:@"LockCell" owner:nil options:nil]lastObject];
  236. }
  237. [cell upDataWithDic:_dataArr[indexPath.row]];
  238. return cell;
  239. }
  240. if (index == 1) {
  241. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId2"];
  242. if (!cell) {
  243. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId2"];
  244. }
  245. NSString * key = _titles2[indexPath.row][1];
  246. cell.textLabel.text = _titles2[indexPath.row][0];
  247. cell.detailTextLabel.numberOfLines = 0;
  248. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  249. return cell;
  250. }
  251. //index == 0
  252. return [super tableView:tableView cellForRowAtIndexPath:indexPath];
  253. }
  254. - (void)didReceiveMemoryWarning {
  255. [super didReceiveMemoryWarning];
  256. // Dispose of any resources that can be recreated.
  257. }
  258. /*
  259. #pragma mark - Navigation
  260. // In a storyboard-based application, you will often want to do a little preparation before navigation
  261. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  262. // Get the new view controller using [segue destinationViewController].
  263. // Pass the selected object to the new view controller.
  264. }
  265. */
  266. @end