ChangeSchoolListViewController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // ChangeSchoolListViewController.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2019/7/1.
  6. // Copyright © 2019 JCZ. All rights reserved.
  7. //
  8. #import "ChangeSchoolListViewController.h"
  9. #import "ChangeSchoolListCell.h"
  10. #import <MJRefresh.h>
  11. #import "ChangeSchoolListModel.h"
  12. #import "ChangeSchoolDetailViewController.h"
  13. #import "HolderView.h"
  14. @interface ChangeSchoolListViewController () <UITableViewDataSource, UITableViewDelegate>
  15. @property (nonatomic, readwrite, strong) NSMutableArray *dataArr;
  16. @property (nonatomic, readwrite, strong) HolderView *holderView;
  17. @end
  18. @implementation ChangeSchoolListViewController
  19. #pragma mark - Life Cycle
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. [self initUI];
  23. }
  24. #pragma mark - UITableViewDataSource And UITableViewDelegate
  25. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  26. return self.dataArr.count;
  27. }
  28. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  29. return 1;
  30. }
  31. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  32. return kScreenWidth *0.45;
  33. }
  34. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  35. return 0.01;
  36. }
  37. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  38. return 10;
  39. }
  40. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  41. ChangeSchoolListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChangeSchoolListCell"];
  42. ChangeSchoolListModel *changeSchoolListModel = self.dataArr[indexPath.section];
  43. cell.changeSchoolListModel = changeSchoolListModel;
  44. return cell;
  45. }
  46. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  47. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  48. ChangeSchoolDetailViewController *vc = [ChangeSchoolDetailViewController suspendChangeSchoolDetailPageVC];
  49. ChangeSchoolListModel *changeSchoolListModel = self.dataArr[indexPath.section];
  50. vc.changeSchoolListModel = changeSchoolListModel;
  51. [vc initWithUpResultBlock:^(BOOL isSuccess) {
  52. if (isSuccess) {
  53. [self.tableView.mj_header beginRefreshing];
  54. }
  55. }];
  56. [self navPushHideTabbarToVC:vc];
  57. }
  58. #pragma mark - Private Functions
  59. - (void)initUI {
  60. self.title = @"转校记录";
  61. [self configNavigationBar];
  62. [_tableView registerNib:[UINib nibWithNibName:@"ChangeSchoolListCell" bundle:nil] forCellReuseIdentifier:@"ChangeSchoolListCell"];
  63. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  64. [self getData];
  65. }];
  66. [_tableView.mj_header beginRefreshing];
  67. [self.holderView freshBlock:^{
  68. [self.tableView.mj_header beginRefreshing];
  69. }];
  70. [self.view addSubview:self.holderView];
  71. }
  72. /// 请求数据
  73. - (void)getData {
  74. NSMutableArray *arr = [NSMutableArray array];
  75. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  76. [arr addPro:@"outId" Value:defUser.userDict[@"outId"]];
  77. [arr addPro:@"idcard" Value:defUser.sfzmhm];
  78. NSString *method = @"getZxInfoByStudent";
  79. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  80. _holderView.hidden = NO;
  81. [_tableView.mj_header endRefreshing];
  82. if (!root) {
  83. ShowMsgFailed();
  84. return;
  85. }
  86. if ([root[@"code"] isEqualToString:@"0"]) {
  87. if (self.dataArr.count > 0) {
  88. [self.dataArr removeAllObjects];
  89. }
  90. [self.dataArr addObjectsFromArray:[ChangeSchoolListModel modelArrayWithJSON:root[@"body"]]];
  91. [_tableView reloadData];
  92. _holderView.hidden = self.dataArr.count != 0;
  93. }else {
  94. if ([root[@"body"] isKindOfClass:[NSString class]]) {
  95. ShowMsg(root[@"body"]);
  96. }
  97. return;
  98. }
  99. }];
  100. }
  101. #pragma mark - Lazy Load
  102. - (NSMutableArray *)dataArr {
  103. if (!_dataArr) {
  104. _dataArr = [NSMutableArray array];
  105. }
  106. return _dataArr;
  107. }
  108. - (HolderView *)holderView {
  109. if (!_holderView) {
  110. _holderView = [[HolderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNavOffSet - kSafeAreaBottomHeight)];
  111. }
  112. return _holderView;
  113. }
  114. @end