QuitSch.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. //
  2. // QuitSch.m
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/4/22.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "QuitSch.h"
  9. #import "ApplyQuit.h"//申请退学
  10. #import "QuitShcoolList.h"//是列表的cell
  11. #import "MJRefresh.h"
  12. #import "MengBanView.h"
  13. typedef NS_ENUM(NSInteger, MyGetDataType) {
  14. //正常请求数据
  15. MyGetDataTypeNomal=0,
  16. //下拉刷新请求数据
  17. MyGetDataTypeHeaderRefresh,
  18. //上拉加载更多请求数据
  19. MyGetDataTypeFooterRefresh
  20. };
  21. #define JOb_DETAIL_BOTTOMBAR_HEIGHT 50
  22. @interface QuitSch ()<UITableViewDelegate,UITableViewDataSource>
  23. {
  24. UITableView * _tableView;
  25. NSMutableArray *_dataSurce;
  26. NSMutableDictionary * _requestDic;
  27. //记录页书
  28. NSInteger _currentPageNum;
  29. //正在加载的状态
  30. BOOL _IS_LOADING;
  31. //加载数据的类型
  32. MyGetDataType _getDataType;
  33. //
  34. HolderView * _holderV;
  35. //搜索
  36. MengBanView * _mengBanView;
  37. NSString *_name;
  38. NSString *_cardNum;
  39. NSString *_startDate;
  40. NSString *_endDate;
  41. BOOL haveRequestPermission;
  42. }
  43. @end
  44. @implementation QuitSch
  45. - (void)viewDidLoad {
  46. [super viewDidLoad];
  47. self.navigationItem.title = @"退学学员列表";
  48. self.navigationController.navigationBar.translucent = NO;
  49. self.view.backgroundColor = KBackGroundColor;
  50. [self goBackByNavigation];
  51. _dataSurce = [NSMutableArray new];
  52. _currentPageNum = 0;
  53. _IS_LOADING = NO;
  54. _getDataType = MyGetDataTypeNomal;
  55. _name = @"";
  56. _cardNum = @"";
  57. _startDate = @"";
  58. _endDate = @"";
  59. [self setRefreshAction];
  60. [Tools permissionValidationWithID:@"1103" view:self.view result:^(BOOL isCan, NSString *failureStr) {
  61. [self myInitWithPermission:isCan];
  62. [self getData];
  63. }];
  64. }
  65. -(void)myInitWithPermission:(BOOL)permission{
  66. [self customRight];
  67. //处理底部”上拉加载更多“显示异常(5c,ios10)
  68. UIView *view = [[UIView alloc]init];
  69. [self.view addSubview:view];
  70. CGFloat tableHeight = kSize.height-kNavOffSet-SafeAreaBottomHeight;
  71. if (myDelegate.isSchool) {
  72. [self createBottomBarWithtoolTitles:@[@"登记"]];
  73. tableHeight = kSize.height-kNavOffSet-SafeAreaBottomHeight-(permission?JOb_DETAIL_BOTTOMBAR_HEIGHT:0);
  74. }
  75. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, tableHeight)];
  76. _tableView.dataSource = self;
  77. _tableView.delegate = self;
  78. [self.view addSubview:_tableView];
  79. _tableView.tableFooterView = [UIView new];
  80. _holderV = [[HolderView alloc]initWithFrame:_tableView.frame];
  81. [_holderV freshBlock:^{
  82. [self headerRefresh];
  83. }];
  84. [self.view addSubview:_holderV];
  85. }
  86. #pragma mark - 右上角btn
  87. -(void)customRight{
  88. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  89. btn.frame = CGRectMake(0, 0, 43, 44);
  90. btn.titleLabel.font = [UIFont systemFontOfSize:17];
  91. [btn setTitle:@"搜索" forState:UIControlStateNormal];
  92. [btn setTitleColor:defGreen forState:UIControlStateNormal];
  93. [btn addTarget:self action:@selector(setMengbanView) forControlEvents:UIControlEventTouchUpInside];
  94. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  95. }
  96. -(void)setMengbanView{
  97. if (_mengBanView) {
  98. [_mengBanView showView];
  99. return;
  100. }
  101. UITextField * tf = [[UITextField alloc] initWithFrame:CGRectZero];
  102. tf.placeholder = @"请输入学员姓名";
  103. tf.clearButtonMode = UITextFieldViewModeWhileEditing;
  104. UITextField * tf2 = [[UITextField alloc] initWithFrame:CGRectZero];
  105. tf2.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  106. tf2.placeholder = @"请输入学员证件号码";
  107. tf2.clearButtonMode = UITextFieldViewModeWhileEditing;
  108. NSString *start = @"开始时间";
  109. NSString *end = @"结束时间";
  110. NSArray * buttonsArray = @[@[@"3",tf],@[@"3",tf2],@[@"2",start],@[@"2",end]];
  111. _mengBanView = [[MengBanView alloc]initWithTitileStr:nil buttonsArray:buttonsArray isAllbtn:NO block:^(NSArray *array) {
  112. _name = array[0];
  113. _cardNum = array[1];
  114. _startDate = array[2];
  115. if ([_startDate isEqualToString:start]) {
  116. _startDate = @"";
  117. }
  118. _endDate = array[3];
  119. if ([_endDate isEqualToString:end]) {
  120. _endDate = @"";
  121. }
  122. [self getData];
  123. }];
  124. [_mengBanView showView];
  125. }
  126. #pragma mark 创建BottomBarButton
  127. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  128. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  129. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  130. for (int i=0; i<toolTitles.count; i++) {
  131. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  132. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-kNavOffSet-SafeAreaBottomHeight, widthBtn, HeightBth);
  133. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  134. button.backgroundColor = defGreen;
  135. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  136. [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  137. button.tag = 10+i;
  138. [self.view addSubview:button];
  139. }
  140. }
  141. -(void)buttonClick:(UIButton *)sender{
  142. switch (sender.tag) {
  143. case 10:
  144. {
  145. //登记申请
  146. ApplyQuit * vc = [[ApplyQuit alloc]init];
  147. __weak QuitSch * weakself = self;
  148. vc.blcok = ^{
  149. _currentPageNum = 0;
  150. [weakself getData];
  151. };
  152. [self navPushHideTabbarToVC:vc];
  153. }
  154. break;
  155. default:
  156. break;
  157. }
  158. }
  159. #pragma mark - 下拉刷新,上拉加载 -
  160. -(void)setRefreshAction{
  161. // 下拉刷新
  162. __weak typeof(self) weakSelf = self;
  163. MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  164. [weakSelf headerRefresh];
  165. }];
  166. _tableView.mj_header = mj_header;
  167. MJRefreshBackNormalFooter *mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  168. [weakSelf footerRefresh];
  169. }];
  170. _tableView.mj_footer = mj_footer;
  171. }
  172. #pragma mark - 数据加载更多和刷新 -
  173. -(void)headerRefresh{
  174. //设置获取数据的方式
  175. _getDataType=MyGetDataTypeHeaderRefresh;
  176. //加载数据
  177. [self getData];
  178. [_tableView.mj_header endRefreshing];
  179. }
  180. -(void)footerRefresh{
  181. //设置获取数据的方式
  182. _getDataType=MyGetDataTypeFooterRefresh;
  183. //加载数据
  184. [self getData];
  185. [_tableView.mj_footer endRefreshing];
  186. }
  187. -(void)getData{
  188. //判断当前是否正在加载数据。如果正在加载数据,直接return。
  189. if (_IS_LOADING) {
  190. return;
  191. }
  192. if (![NetManager connectedToNetWork]) {
  193. showMsgUnconnect();
  194. return;
  195. }
  196. _IS_LOADING=YES;
  197. //获取第一页数据
  198. NSInteger needLoadPage;
  199. needLoadPage=_currentPageNum+1;
  200. if (_getDataType==MyGetDataTypeHeaderRefresh) {
  201. needLoadPage=1;
  202. }
  203. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  204. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  205. [dic setObject:_name forKey:@"name"];
  206. [dic setObject:_cardNum forKey:@"idcard"];
  207. [dic setObject:_startDate forKey:@"startTime"];
  208. [dic setObject:_endDate forKey:@"endTime"];
  209. [dic setObject:@"1" forKey:@"isPage"];
  210. [dic setObject:@"10" forKey:@"pageSize"];
  211. [dic setObject:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"];
  212. _requestDic = dic;
  213. [MBProgressHUD showLoadToView:self.view];
  214. [NetManager requestAnythingWithURL:@"quitStudents" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  215. [MBProgressHUD hideHUDForView:self.view];
  216. _holderV.hidden = NO;
  217. //设置加载状态
  218. _IS_LOADING=NO;
  219. if (!root) {
  220. ShowErrorMsg(@"请求失败!");
  221. return;
  222. }
  223. if ([root[@"code"] isEqualToString:@"1"]) {
  224. ShowErrorMsg(root[@"msg"]);
  225. return;
  226. }
  227. //处理数据
  228. //如果获取到了数据,而且是下拉刷新,清空数组。
  229. if (_getDataType==MyGetDataTypeHeaderRefresh){
  230. [_dataSurce removeAllObjects];
  231. }
  232. //追加数据
  233. [_dataSurce addObjectsFromArray:root[@"body"]];
  234. if (_dataSurce.count != 0) {
  235. _holderV.hidden = YES;
  236. }
  237. //计数器+1
  238. _currentPageNum=needLoadPage;
  239. [_tableView reloadData];
  240. //恢复初始状态。
  241. _getDataType=MyGetDataTypeNomal;
  242. }];
  243. }
  244. #pragma mark tableview代理方法
  245. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  246. return _dataSurce.count;
  247. }
  248. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  249. return 115;
  250. }
  251. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  252. QuitShcoolList * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  253. if (!cell) {
  254. cell = [[[NSBundle mainBundle] loadNibNamed:@"QuitShcoolList" owner:nil options:nil] lastObject];
  255. }
  256. cell.dataDic = _dataSurce[indexPath.row];
  257. return cell;
  258. }
  259. - (void)didReceiveMemoryWarning {
  260. [super didReceiveMemoryWarning];
  261. // Dispose of any resources that can be recreated.
  262. }
  263. /*
  264. #pragma mark - Navigation
  265. // In a storyboard-based application, you will often want to do a little preparation before navigation
  266. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  267. // Get the new view controller using [segue destinationViewController].
  268. // Pass the selected object to the new view controller.
  269. }
  270. */
  271. @end