ApplyQuit.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. //@RQ-MARK 1.0.2修改:“退学申请”模块审核人移除
  33. _titles = @[@[@"学员证件号",@"报名费用",@"已收金额",@"应退款金额"],@[@"退学原因"]];
  34. _dataArr = @[[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. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 100)];
  47. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 25, kSize.width - 20, 50)];
  48. btn.backgroundColor = RQMianColor;
  49. [btn borderCornorRadios:5];
  50. [btn setTitle:@"提交" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  51. [btn target:self Tag:1];
  52. [view addSubview:btn];
  53. _tableView.tableFooterView = view;
  54. }
  55. - (void)btnClick:(UIButton *)sender
  56. {
  57. [self.view endEditing:YES];
  58. [self quitSchool];
  59. }
  60. #pragma mark tableview代理方法
  61. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  62. {
  63. return _titles.count;
  64. }
  65. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  66. {
  67. return [_titles[section] count];
  68. }
  69. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  70. if (indexPath.section == 1) {
  71. return 106;
  72. }
  73. return 44;
  74. }
  75. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  76. {
  77. //textView
  78. if (indexPath.section == 1) {
  79. QuitTextViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
  80. if (!cell) {
  81. cell = [[[NSBundle mainBundle]loadNibNamed:@"QuitTextViewCell" owner:nil options:nil]lastObject];
  82. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  83. }
  84. cell.textView.delegate = self;
  85. return cell;
  86. }
  87. applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  88. if (cell == nil)
  89. {
  90. cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  91. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  92. }
  93. [cell.titLabel setText:[_titles[indexPath.section] objectAtIndex:indexPath.row]];
  94. NSArray *detailArray = _dataArr[indexPath.section];
  95. cell.detailField.delegate = self;
  96. cell.detailField.keyboardType = UIKeyboardTypeNumberPad;
  97. cell.detailField.tag = indexPath.section * 10 + indexPath.row;
  98. if (indexPath.section == 0) {
  99. cell.detailField.userInteractionEnabled = YES;
  100. if ([_placeholders containsObject:detailArray[indexPath.row]]) {
  101. cell.detailField.placeholder = detailArray[indexPath.row];
  102. }else {
  103. cell.detailField.textColor = KTitleColor;
  104. cell.detailField.text = detailArray[indexPath.row];
  105. }
  106. }
  107. return cell;
  108. }
  109. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  110. {
  111. [self.view endEditing:YES];
  112. }
  113. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  114. {
  115. return .1;
  116. }
  117. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  118. {
  119. return 25;
  120. }
  121. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  122. //NSLog(@"1");
  123. [self.view endEditing:YES];
  124. }
  125. #pragma mark textField
  126. -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  127. {
  128. NSIndexPath *indexpath = indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:textField.tag/10];;
  129. //获取当前cell在tableview中的位置
  130. CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
  131. [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
  132. return YES;
  133. }
  134. -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
  135. {
  136. NSString *textString = textField.text;
  137. if (textString.length < 1) {
  138. textString = _placeholders[textField.tag];
  139. }
  140. NSMutableArray *array = _dataArr[textField.tag/10];
  141. [array replaceObjectAtIndex:textField.tag%10 withObject:textString];
  142. [_tableView reloadData];
  143. return YES;
  144. }
  145. -(BOOL)textFieldShouldReturn:(UITextField *)textField
  146. {
  147. [textField endEditing:YES];
  148. return YES;
  149. }
  150. #pragma mark textview代理
  151. -(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
  152. NSIndexPath *indexpath= [NSIndexPath indexPathForRow:0 inSection:2];
  153. //获取当前cell在tableview中的位置
  154. CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
  155. [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25)];
  156. return YES;
  157. }
  158. - (BOOL)textViewShouldEndEditing:(UITextView *)textView{
  159. NSString * str = textView.text;
  160. [_dataArr[1] replaceObjectAtIndex:0 withObject:str];
  161. return YES;
  162. }
  163. - (void)textViewDidChange:(UITextView *)textView{
  164. NSString * str = textView.text;
  165. [_dataArr[1] replaceObjectAtIndex:0 withObject:str];
  166. return;
  167. }
  168. #pragma mark 网络请求
  169. -(void)getAuditUserInfo{
  170. //
  171. if (![NetManager connectedToNetWork]) {
  172. showMsgUnconnect();
  173. return;
  174. }
  175. NSMutableDictionary * dic = [NSMutableDictionary new];
  176. [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"];
  177. [NetManager requestAnythingWithURL:@"getAuditUserInfo" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  178. if (!root) {
  179. ShowErrorMsg(@"请求失败!");
  180. return;
  181. }
  182. if ([root[@"code"] isEqualToString:@"1"]) {
  183. ShowErrorMsg(root[@"msg"]);
  184. NSLog(@"%@",root[@"msg"]);
  185. return;
  186. }
  187. _auditUserInfo = root[@"body"];
  188. [_sheetsArray removeAllObjects];
  189. for (NSDictionary * dic in _auditUserInfo) {
  190. [_sheetsArray addObject:dic[@"text"]];
  191. }
  192. }];
  193. }
  194. -(void)quitSchool{
  195. for (NSString *str in _dataArr[0]) {
  196. if (str.length == 0 || [_placeholders containsObject:str]) {
  197. ShowMsg(@"请填写完整信息");
  198. return;
  199. }
  200. }
  201. for (NSString *str in _dataArr[1]) {
  202. if (str.length == 0) {
  203. ShowMsg(@"请填写完整信息");
  204. return;
  205. }
  206. }
  207. //
  208. if (![NetManager connectedToNetWork]) {
  209. showMsgUnconnect();
  210. return;
  211. }
  212. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  213. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  214. [dic setObject:_dataArr[0][0] forKey:@"idcard"];
  215. [dic setObject:_dataArr[0][1] forKey:@"price"];
  216. [dic setObject:_dataArr[0][2] forKey:@"priceIn"];
  217. [dic setObject:_dataArr[0][3] forKey:@"priceOut"];
  218. [dic setObject:_dataArr[1][0] forKey:@"reason"];
  219. // [dic setObject:@"" forKey:@"auditUser"];
  220. [NetManager requestAnythingWithURL:@"quitSchool" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  221. if (!root) {
  222. ShowErrorMsg(@"请求失败!");
  223. return;
  224. }
  225. if ([root[@"code"] isEqualToString:@"1"]) {
  226. ShowErrorMsg(root[@"msg"]);
  227. NSLog(@"%@",root[@"msg"]);
  228. return;
  229. }
  230. ShowMsg(@"登记成功");
  231. if (self.blcok) {
  232. self.blcok();
  233. }
  234. [self.navigationController popViewControllerAnimated:YES];
  235. }];
  236. }
  237. #pragma mark - 限制输入字符
  238. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  239. if (textField.tag == 0 && range.location >= 18) {
  240. return NO;
  241. }
  242. if (textField.tag != 0 && range.location >= 5) {
  243. return NO;
  244. }
  245. return YES;
  246. }
  247. @end