RepairViewController.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //
  2. // RepairViewController.m
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/6/15.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "RepairViewController.h"
  9. #import "STSegView.h"
  10. #import "Rep_DetailCell.h"
  11. #import "RepDetailVC.h"
  12. #import "RepairApplyVC.h"
  13. @interface RepairViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
  14. {
  15. STSegView *seg;
  16. UITableView *mainTableView;
  17. HolderView *holder;
  18. NSInteger currentPage;
  19. NSString *orderState;
  20. NSMutableArray *dataArray;
  21. }
  22. @end
  23. @implementation RepairViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. [self myInit];
  27. [self getRepairs];
  28. }
  29. -(void)viewDidAppear:(BOOL)animated{
  30. [super viewDidAppear:animated];
  31. self.navigationController.navigationBar.translucent = YES;//这里主要针对pop回来的时候
  32. }
  33. -(void)myInit
  34. {
  35. self.view.backgroundColor = backGroundColor;
  36. currentPage = 1;
  37. orderState = @"0";
  38. dataArray = [NSMutableArray array];
  39. CGFloat x,y,w,h;
  40. x = 0;
  41. y = kNavOffSet;
  42. w = kSize.width;
  43. h = 50;
  44. seg = [[STSegView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  45. [seg setTitles:@[@"待处理",@"已派单",@"已完成"]];
  46. seg.font = 20;
  47. seg.selectedIndex = 0;
  48. [self.view addSubview:seg];
  49. [seg click:^(NSString* sInd) {
  50. currentPage = 1;
  51. orderState = sInd;
  52. [self getRepairs];
  53. }];
  54. y += h;
  55. h = kSize.height - y;
  56. mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(x, y, w, h) style:UITableViewStyleGrouped];
  57. mainTableView.delegate = self;
  58. mainTableView.dataSource = self;
  59. mainTableView.estimatedRowHeight = 85;
  60. [self.view addSubview:mainTableView];
  61. holder = [[HolderView alloc] initWithFrame:mainTableView.frame];
  62. [holder freshBlock:^{
  63. currentPage = 1;
  64. [self getRepairs];
  65. }];
  66. [self.view addSubview:holder];
  67. //报修
  68. UIButton *bxBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  69. bxBtn.frame = CGRectMake(kSize.width - 80, kSize.height - 80 -64, 60, 60);
  70. bxBtn.backgroundColor = defGreen;
  71. [bxBtn setTitle:@"申请" textColor:[UIColor whiteColor] font:25 fotState:UIControlStateNormal];
  72. bxBtn.clipsToBounds = YES;
  73. bxBtn.layer.cornerRadius = bxBtn.width/2;
  74. [bxBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
  75. [self.view addSubview:bxBtn];
  76. }
  77. -(void)btnClick{
  78. RepairApplyVC * vc = [[RepairApplyVC alloc]init];
  79. vc.type = @"1";
  80. vc.blcok = ^{
  81. seg.selectedIndex = 0;
  82. };
  83. [self.navigationController pushViewController:vc animated:YES];
  84. }
  85. #pragma mark tableView
  86. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  87. {
  88. return dataArray.count;
  89. }
  90. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  91. {
  92. return 1;
  93. }
  94. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  95. {
  96. Rep_DetailCell *cell = [Rep_DetailCell cellForTableView:tableView];
  97. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  98. [cell setDic:dataArray[indexPath.section]];
  99. return cell;
  100. }
  101. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  102. RepDetailVC * vc = [[RepDetailVC alloc]init];
  103. vc.dic = dataArray[indexPath.section];
  104. vc.block = ^{
  105. currentPage = 1;
  106. [self getRepairs];
  107. };
  108. [self.navigationController pushViewController:vc animated:YES];
  109. }
  110. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  111. return 15;
  112. }
  113. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  114. return .1f;
  115. }
  116. -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
  117. CGFloat offset_y = scrollView.contentOffset.y;
  118. CGFloat x = scrollView.contentSize.height < scrollView.frame.size.height ? scrollView.contentSize.height:scrollView.frame.size.height;
  119. if (offset_y<-70) {
  120. currentPage = 1;
  121. [self getRepairs];
  122. }else if(offset_y+x>scrollView.contentSize.height+70){
  123. [self getRepairs];
  124. }
  125. }
  126. #pragma mark 数据请求
  127. -(void)getRepairs
  128. {
  129. [LoadingView showHUD];
  130. if (![Util connectedToNetWork]) {
  131. showMsgUnconnect();
  132. return;
  133. }
  134. NSMutableArray *arr = [[NSMutableArray alloc]init];
  135. [arr addPro:@"coachOutId" Value:defUser.userDict[@"outId"]];
  136. [arr addPro:@"status" Value:orderState];
  137. [arr addPro:@"isPage" Value:@"1"];
  138. [arr addPro:@"pageSize" Value:@"10"];
  139. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]];
  140. NSString *method = @"getRepairs";
  141. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  142. RemoveHUD();
  143. if (currentPage == 1) {
  144. holder.hidden = NO;
  145. [dataArray removeAllObjects];
  146. }
  147. if (!root) {
  148. ShowMsg(@"请求失败");
  149. return;
  150. }
  151. if ([root[@"code"] isEqualToString:@"1"]) {
  152. ShowMsg(root[@"body"]);
  153. return;
  154. }
  155. NSArray *array = root[@"body"];
  156. if ([array count] < 1) {
  157. ShowMsg(@"已加载全部");
  158. [mainTableView reloadData];
  159. return;
  160. }
  161. static BOOL once = YES;
  162. if (once) {
  163. [dataArray addObjectsFromArray:array];
  164. [dataArray addObjectsFromArray:array];
  165. [dataArray addObjectsFromArray:array];
  166. once = NO;
  167. }
  168. [dataArray addObjectsFromArray:array];
  169. currentPage += 1;
  170. holder.hidden = YES;
  171. [mainTableView reloadData];
  172. }];
  173. }
  174. - (void)didReceiveMemoryWarning {
  175. [super didReceiveMemoryWarning];
  176. // Dispose of any resources that can be recreated.
  177. }
  178. /*
  179. #pragma mark - Navigation
  180. // In a storyboard-based application, you will often want to do a little preparation before navigation
  181. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  182. // Get the new view controller using [segue destinationViewController].
  183. // Pass the selected object to the new view controller.
  184. }
  185. */
  186. @end