SchoolDetail.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. if (self.lockBlock) {
  79. self.lockBlock(self.dataSource);
  80. }
  81. }];
  82. }
  83. -(void)getLockLogs{
  84. //判断网络是否连接
  85. if (![NetworkManager connectedToNetWork]) {
  86. [self showMsgByAlertVCWithString:@"网络连接异常"];
  87. return;
  88. }
  89. NSMutableDictionary * mdic = [[NSMutableDictionary alloc]init];
  90. [mdic setValue:@"1" forKey:@"type"];//类型 1 培训机构 2 教练 3 教练车 4 学员 5 终端
  91. [mdic setValue:self.requesetDic[@"inscode"] forKey:@"objnum"];
  92. [MBProgressHUD hideHUDForView:self.view animated:NO];
  93. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  94. [NetworkManager requestWithMethod:@"lockLogs" parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  95. [MBProgressHUD hideHUDForView:self.view animated:YES];
  96. [_holderV setHidden:NO];
  97. if (failureStr) {
  98. [self showMsgByAlertVCWithString:failureStr];
  99. return;
  100. }
  101. if ([successDic[@"code"] isEqualToString:@"1"]) {
  102. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  103. return;
  104. }
  105. _dataArr = successDic[@"body"];
  106. if (_dataArr.count != 0) {
  107. _holderV.hidden = YES;
  108. }
  109. [_tableViews[2] reloadData];
  110. }];
  111. }
  112. #pragma mark 创建BottomBarButton
  113. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  114. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  115. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  116. for (int i=0; i<toolTitles.count; i++) {
  117. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  118. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-SafeAreaBottomHeight, widthBtn, HeightBth);
  119. if (i == 1) {
  120. [button setTitle:@"锁定" forState:UIControlStateNormal];
  121. _locakBtn = button;
  122. }else{
  123. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  124. }
  125. UIColor * color = COLOR_THEME;
  126. button.backgroundColor = color;
  127. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  128. [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  129. button.tag = 100+i;
  130. [self.view addSubview:button];
  131. }
  132. }
  133. - (void)buttonClick:(UIButton *)sender{
  134. if (self.byWillDo && self.shenheBLock) {
  135. self.shenheBLock();
  136. return;
  137. }
  138. if (sender.tag == 100) {
  139. [Tools permissionValidationWithID:@"752" result:^(BOOL isCan, NSString *failureStr) {
  140. if (!isCan) {
  141. if (failureStr) {
  142. [self showMsgByMBWithString:failureStr];
  143. }
  144. return;
  145. }
  146. [self setTrainability];
  147. }];
  148. }else if (sender.tag == 101){
  149. NSString * title = _isLock ? @"解锁":@"锁定";
  150. NSString *message = [NSString stringWithFormat:@"请输入%@理由:",title];
  151. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  152. [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  153. textField.placeholder = [NSString stringWithFormat:@"(必须填写,否则将无法完成%@)",title];
  154. }];
  155. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  156. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  157. UITextField *tf = alertFind.textFields[0];
  158. if (tf.text.length > 0) {
  159. [self lockSchoolWith:tf.text];
  160. }else{
  161. [self showMsgByMBWithString:@"操作失败,请输入锁定/解锁理由"];
  162. }
  163. }]];
  164. NSString *theId = _isLock ? @"544":@"542";
  165. [Tools permissionValidationWithID:theId result:^(BOOL isCan, NSString *failureStr) {
  166. if (!isCan) {
  167. if (failureStr) {
  168. [self showMsgByMBWithString:failureStr];
  169. }
  170. return;
  171. }
  172. [self presentViewController:alertFind animated:true completion:nil];
  173. }];
  174. }
  175. }
  176. -(void)setTrainability{
  177. UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"设置培训能力" message:@"请选择设置方式" preferredStyle:UIAlertControllerStyleActionSheet];
  178. //添加操作
  179. [ac addAction:[UIAlertAction actionWithTitle:@"按车设置(每辆车最大带教人数)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  180. [self setCountWithType:@"1"];
  181. }]];
  182. [ac addAction:[UIAlertAction actionWithTitle:@"按月设置(每月最大允许招生量)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  183. [self setCountWithType:@"2"];
  184. }]];
  185. [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  186. [self presentViewController:ac animated:YES completion:nil];
  187. }
  188. - (void)setCountWithType:(NSString *)type
  189. {
  190. BOOL isCar = [type isEqualToString:@"1"];
  191. NSString * title = isCar ? @"按车设置" : @"按月设置";
  192. NSString * message = isCar ? @"请写入每辆车最大带教人数" : @"请写入每月最大允许招生量";
  193. UIAlertController *ac = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  194. [ac addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  195. textField.placeholder = message;
  196. textField.keyboardType = UIKeyboardTypeNumberPad;
  197. }];
  198. [ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  199. NSString *tfStr = [ac.textFields firstObject].text;
  200. NSMutableDictionary * mdic = [NSMutableDictionary new];
  201. [mdic setValue:self.dataSource[@"TSI_INSCODE"] forKey:@"inscode"];
  202. [mdic setValue:type forKey:@"type"];//类型 1 按车设置 2 按月设置
  203. [mdic setValue:isCar ? tfStr : @"" forKey:@"limitCar"];//如果type=1 则不能为空
  204. [mdic setValue:isCar ? @"" : tfStr forKey:@"limitMonth"];//如果type=2 则不能为空
  205. [self getDataWithDic:mdic method:@"setSchoolTrain" block:^(NSDictionary *successdic) {
  206. if (isCar) {
  207. [self showMsgByAlertVCWithString:[NSString stringWithFormat:@"已成功设置该驾校每辆车最大带教人数为:%@个",tfStr]];
  208. }else{
  209. [self showMsgByAlertVCWithString:[NSString stringWithFormat:@"已成功设置该驾校每月最大允许招生量为:%@个",tfStr]];
  210. }
  211. }];
  212. }]];
  213. [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  214. [self presentViewController:ac animated:YES completion:nil];
  215. }
  216. -(void)lockSchoolWith:(NSString *)reason{
  217. NSMutableDictionary * mdic = [NSMutableDictionary new];
  218. [mdic setValue:MYAPPDELEGATE.userDic[@"id"] forKey:@"userId"];
  219. [mdic setValue:reason forKey:@"reason"];
  220. [mdic setValue:_isLock ? @"0" : @"1" forKey:@"status"];
  221. [mdic setValue:self.dataSource[@"TSI_INSCODE"] forKey:@"inscode"];
  222. [self getDataWithDic:mdic method:@"lockSchool" block:^(NSDictionary *successdic) {
  223. //解锁成功,重新请求数据
  224. [self getRequsetData];
  225. [self getLockLogs];
  226. }];
  227. }
  228. #pragma mark 重写代理方法
  229. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  230. NSInteger index = [_tableViews indexOfObject:tableView];
  231. if (index == 2) {
  232. return _dataArr.count;
  233. }
  234. if (index == 1) {
  235. return _titles2.count;
  236. }
  237. if (self.dataSource == nil) {
  238. return 0;
  239. }
  240. return [_keysArr count];
  241. }
  242. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  243. if ([_tableViews indexOfObject:tableView] == 2) {
  244. return [LockCell heightForDic:_dataArr[indexPath.row]];
  245. }else if([_tableViews indexOfObject:tableView] == 1){
  246. return 44;
  247. }
  248. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  249. }
  250. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  251. {
  252. NSInteger index = [_tableViews indexOfObject:tableView];
  253. if (index == 2) {
  254. LockCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  255. if (!cell) {
  256. cell = [[[NSBundle mainBundle] loadNibNamed:@"LockCell" owner:nil options:nil]lastObject];
  257. }
  258. [cell upDataWithDic:_dataArr[indexPath.row]];
  259. return cell;
  260. }
  261. if (index == 1) {
  262. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId2"];
  263. if (!cell) {
  264. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId2"];
  265. }
  266. NSString * key = _titles2[indexPath.row][1];
  267. cell.textLabel.text = _titles2[indexPath.row][0];
  268. cell.detailTextLabel.numberOfLines = 0;
  269. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  270. return cell;
  271. }
  272. //index == 0
  273. return [super tableView:tableView cellForRowAtIndexPath:indexPath];
  274. }
  275. - (void)didReceiveMemoryWarning {
  276. [super didReceiveMemoryWarning];
  277. // Dispose of any resources that can be recreated.
  278. }
  279. /*
  280. #pragma mark - Navigation
  281. // In a storyboard-based application, you will often want to do a little preparation before navigation
  282. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  283. // Get the new view controller using [segue destinationViewController].
  284. // Pass the selected object to the new view controller.
  285. }
  286. */
  287. @end