ApplyQuit.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. //
  2. // ApplyQuit.m
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/4/20.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "ApplyQuit.h"
  9. #import "applyCell.h"
  10. #import "QuitTextViewCell.h"
  11. @interface ApplyQuit ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UITextViewDelegate,UINavigationControllerDelegate>
  12. {
  13. UITableView * _tableView;
  14. NSArray *_titles;
  15. NSArray *_dataArr;
  16. NSMutableArray *_sheetsArray;
  17. NSArray *_auditUserInfo;
  18. NSArray *_placeholders;
  19. }
  20. @end
  21. @implementation ApplyQuit
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.navigationItem.title = @"退学申请";
  25. self.navigationController.navigationBar.translucent = NO;
  26. self.view.backgroundColor = KBackGroundColor;
  27. [self goBackByNavigation];
  28. [self myInit];
  29. [self getAuditUserInfo];
  30. }
  31. -(void)myInit{
  32. _titles = @[@[@"学员证件号",@"报名费用",@"已收金额",@"应退款金额"],@[@"审核人"],@[@"退学原因"]];
  33. _dataArr = @[[NSMutableArray arrayWithArray:@[@"请输入学员证件号",@"请填写报名费用",@"请填写已收金额",@"请填写应退款金额"]],
  34. [NSMutableArray arrayWithArray:@[@" >"]],//请选择审核人
  35. [NSMutableArray arrayWithArray:@[@""]]//请输入退学原因
  36. ];
  37. _placeholders = [NSArray arrayWithArray:_dataArr[0]];
  38. _sheetsArray = [NSMutableArray arrayWithArray:@[@"无"]];
  39. _auditUserInfo = [NSArray array];
  40. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height-kNavOffSet) style:UITableViewStyleGrouped];
  41. _tableView.dataSource = self;
  42. _tableView.delegate = self;
  43. _tableView.estimatedSectionHeaderHeight = 0;
  44. _tableView.estimatedSectionFooterHeight = 0;
  45. [self.view addSubview:_tableView];
  46. //
  47. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 100)];
  48. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 25, kSize.width - 20, 50)];
  49. btn.backgroundColor = defGreen;
  50. [btn borderCornorRadios:5];
  51. [btn setTitle:@"提交" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  52. [btn target:self Tag:1];
  53. [view addSubview:btn];
  54. _tableView.tableFooterView = view;
  55. }
  56. - (void)btnClick:(UIButton *)sender
  57. {
  58. [self.view endEditing:YES];
  59. [self quitSchool];
  60. }
  61. #pragma mark tableview代理方法
  62. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  63. {
  64. return _titles.count;
  65. }
  66. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  67. {
  68. return [_titles[section] count];
  69. }
  70. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  71. if (indexPath.section == 2) {
  72. return 106;
  73. }
  74. return 44;
  75. }
  76. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  77. {
  78. //textView
  79. if (indexPath.section == 2) {
  80. QuitTextViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
  81. if (!cell) {
  82. cell = [[[NSBundle mainBundle]loadNibNamed:@"QuitTextViewCell" owner:nil options:nil]lastObject];
  83. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  84. }
  85. cell.textView.delegate = self;
  86. return cell;
  87. }
  88. applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  89. if (cell == nil)
  90. {
  91. cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  92. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  93. }
  94. [cell.titLabel setText:[_titles[indexPath.section] objectAtIndex:indexPath.row]];
  95. NSArray *detailArray = _dataArr[indexPath.section];
  96. cell.detailField.delegate = self;
  97. cell.detailField.keyboardType = UIKeyboardTypeNumberPad;
  98. if (indexPath.row == 0) {
  99. cell.detailField.keyboardType = UIKeyboardTypeDefault;
  100. }
  101. cell.detailField.tag = indexPath.section * 10 + indexPath.row;
  102. if (indexPath.section == 1)
  103. {
  104. cell.detailField.userInteractionEnabled = NO;
  105. cell.detailField.textColor = defGreen;
  106. cell.detailField.text = detailArray[indexPath.row];
  107. }else if (indexPath.section == 0) {
  108. cell.detailField.userInteractionEnabled = YES;
  109. if ([_placeholders containsObject:detailArray[indexPath.row]]) {
  110. cell.detailField.placeholder = detailArray[indexPath.row];
  111. }else {
  112. cell.detailField.textColor = KTitleColor;
  113. cell.detailField.text = detailArray[indexPath.row];
  114. }
  115. }
  116. return cell;
  117. }
  118. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  119. {
  120. [self.view endEditing:YES];
  121. if (indexPath.section == 1)
  122. {
  123. if (_sheetsArray.count == 0) {
  124. [self getAuditUserInfo];
  125. return;
  126. }
  127. UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:@"审核人列表" preferredStyle:UIAlertControllerStyleActionSheet];
  128. for (NSString * str in _sheetsArray) {
  129. [alert addAction:[UIAlertAction actionWithTitle:str style:0 handler:^(UIAlertAction * _Nonnull action) {
  130. [_dataArr[1] replaceObjectAtIndex:0 withObject:str];
  131. [_tableView reloadData];
  132. }]];
  133. }
  134. [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  135. [self presentViewController:alert animated:YES completion:nil];
  136. }
  137. }
  138. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  139. {
  140. return .1;
  141. }
  142. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  143. {
  144. return 25;
  145. }
  146. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  147. //NSLog(@"1");
  148. [self.view endEditing:YES];
  149. }
  150. #pragma mark textField
  151. -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  152. {
  153. NSIndexPath *indexpath = indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:textField.tag/10];;
  154. //获取当前cell在tableview中的位置
  155. CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
  156. [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
  157. return YES;
  158. }
  159. -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
  160. {
  161. NSString *textString = textField.text;
  162. NSMutableArray *array = _dataArr[textField.tag/10];
  163. [array replaceObjectAtIndex:textField.tag%10 withObject:textString];
  164. [_tableView reloadData];
  165. return YES;
  166. }
  167. -(BOOL)textFieldShouldReturn:(UITextField *)textField
  168. {
  169. [textField endEditing:YES];
  170. return YES;
  171. }
  172. #pragma mark textview代理
  173. -(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
  174. NSIndexPath *indexpath= [NSIndexPath indexPathForRow:0 inSection:2];
  175. //获取当前cell在tableview中的位置
  176. CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
  177. [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25)];
  178. return YES;
  179. }
  180. - (BOOL)textViewShouldEndEditing:(UITextView *)textView{
  181. NSString * str = textView.text;
  182. [_dataArr[2] replaceObjectAtIndex:0 withObject:str];
  183. return YES;
  184. }
  185. - (void)textViewDidChange:(UITextView *)textView{
  186. NSString * str = textView.text;
  187. [_dataArr[2] replaceObjectAtIndex:0 withObject:str];
  188. return;
  189. }
  190. #pragma mark 网络请求
  191. -(void)getAuditUserInfo{
  192. //
  193. if (![NetManager connectedToNetWork]) {
  194. showMsgUnconnect();
  195. return;
  196. }
  197. NSMutableDictionary * dic = [NSMutableDictionary new];
  198. [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"];
  199. [MBProgressHUD showLoadToView:self.view];
  200. [NetManager requestAnythingWithURL:@"getAuditUserInfo" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  201. [MBProgressHUD hideHUDForView:self.view];
  202. if (!root) {
  203. ShowErrorMsg(@"请求失败!");
  204. return;
  205. }
  206. if ([root[@"code"] isEqualToString:@"1"]) {
  207. ShowErrorMsg(root[@"msg"]);
  208. NSLog(@"%@",root[@"msg"]);
  209. return;
  210. }
  211. _auditUserInfo = root[@"body"];
  212. [_sheetsArray removeAllObjects];
  213. for (NSDictionary * dic in _auditUserInfo) {
  214. [_sheetsArray addObject:dic[@"text"]];
  215. }
  216. if (_auditUserInfo.count == 0) {
  217. ShowMsg(@"未获取到审核人列表");
  218. }
  219. }];
  220. }
  221. -(void)quitSchool{
  222. for (NSString *str in _dataArr[0]) {
  223. if (str.length == 0 || [_placeholders containsObject:str]) {
  224. ShowMsg(@"请填写完整信息");
  225. return;
  226. }
  227. }
  228. for (NSString * str in _dataArr[1]) {
  229. if([str isEqualToString:@" >"])
  230. {
  231. ShowMsg(@"请选择审核人");
  232. return;
  233. }
  234. }
  235. for (NSString *str in _dataArr[2]) {
  236. if (str.length == 0) {
  237. ShowMsg(@"请填写完整信息");
  238. return;
  239. }
  240. }
  241. //
  242. if (![NetManager connectedToNetWork]) {
  243. showMsgUnconnect();
  244. return;
  245. }
  246. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  247. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  248. [dic setObject:_dataArr[0][0] forKey:@"idcard"];
  249. [dic setObject:_dataArr[0][1] forKey:@"price"];
  250. [dic setObject:_dataArr[0][2] forKey:@"priceIn"];
  251. [dic setObject:_dataArr[0][3] forKey:@"priceOut"];
  252. [dic setObject:_dataArr[2][0] forKey:@"reason"];
  253. NSString * auditUserId = @"";
  254. for (NSDictionary * dic in _auditUserInfo) {
  255. if ([dic[@"text"] isEqualToString:_dataArr[1][0]]) {
  256. auditUserId = [NSString stringWithFormat:@"%@",dic[@"id"]];
  257. }
  258. }
  259. [dic setObject:auditUserId forKey:@"auditUser"];
  260. [MBProgressHUD showLoadToView:self.view];
  261. [NetManager requestAnythingWithURL:@"quitSchool" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  262. [MBProgressHUD hideHUDForView:self.view];
  263. if (!root) {
  264. ShowErrorMsg(@"请求失败!");
  265. return;
  266. }
  267. if ([root[@"code"] isEqualToString:@"1"]) {
  268. ShowErrorMsg(root[@"msg"]);
  269. NSLog(@"%@",root[@"msg"]);
  270. return;
  271. }
  272. ShowMsg(@"登记成功");
  273. if (self.blcok) {
  274. self.blcok();
  275. }
  276. [self.navigationController popViewControllerAnimated:YES];
  277. }];
  278. }
  279. #pragma mark - 限制输入字符
  280. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  281. if (textField.tag == 0 && range.location >= 18) {
  282. return NO;
  283. }
  284. if (textField.tag != 0 && range.location >= 5) {
  285. return NO;
  286. }
  287. return YES;
  288. }
  289. - (void)didReceiveMemoryWarning {
  290. [super didReceiveMemoryWarning];
  291. // Dispose of any resources that can be recreated.
  292. }
  293. /*
  294. #pragma mark - Navigation
  295. // In a storyboard-based application, you will often want to do a little preparation before navigation
  296. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  297. // Get the new view controller using [segue destinationViewController].
  298. // Pass the selected object to the new view controller.
  299. }
  300. */
  301. @end