BusinessViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. //
  2. // BusinessViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/24.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "BusinessViewController.h"
  9. #import "BusinessCell.h"
  10. #import "OrderdetailViewController.h"
  11. #import "fundingHistoryModel.h"
  12. #import "BusinesswaterDetailCell.h"
  13. @interface BusinessViewController ()<UITableViewDelegate,UITableViewDataSource>{
  14. UITableView *newtableView;
  15. NSMutableArray *dataArray;
  16. int pageIndex;
  17. int pageSize;
  18. int pageNumber;
  19. UIView *showView;
  20. }
  21. @end
  22. @implementation BusinessViewController
  23. - (void)viewWillAppear:(BOOL)animated
  24. {
  25. [super viewWillAppear:animated];
  26. if (newtableView) {
  27. [self autoRefresh];
  28. }
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. [self dataInitialization];
  33. [self loadsView];
  34. [self addRefreshing];
  35. // Do any additional setup after loading the view.
  36. }
  37. #pragma mark- 网络请求
  38. - (void)autoRefresh
  39. {
  40. __weak UITableView *tableView = newtableView;
  41. [tableView.mj_header beginRefreshing];
  42. }
  43. - (void)networkRequest:(id)object{
  44. int pageNumberIndex=1;
  45. if (!object) {
  46. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  47. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  48. pageNumberIndex = 1;
  49. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  50. pageNumberIndex = pageNumber+1;
  51. }
  52. NSMutableDictionary *dic = NewMutableDictionaryInit;
  53. [dic safeSetObject:@"" forKey:@"orderNo"];
  54. [dic safeSetObject:@(pageSize) forKey:@"pageSize"];
  55. [dic safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];
  56. [NetworkRequestManager requestPostWithInterfacePrefix:JT_fundingHistory parameters:dic onSuccess:^(id requestData) {
  57. [self dismiss:object];
  58. NSLog(@"服务器返回数据 :%@",requestData);
  59. if ([requestData[@"error"] count] !=0) {
  60. for (NSDictionary *dic in requestData[@"error"]) {
  61. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  62. }
  63. }else{
  64. pageNumber = pageNumberIndex;
  65. if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
  66. [dataArray removeAllObjects];
  67. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  68. NSMutableArray *arr = requestData[@"data"][@"list"];
  69. if ([arr count]<=0) {
  70. [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  71. return ;
  72. }
  73. }
  74. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  75. BusinesswaterModel *model = [[BusinesswaterModel alloc] initWithDictionary:dic error:nil];
  76. [dataArray addObject:model];
  77. }
  78. //查询不到类型底图
  79. if (dataArray.count<=0) {
  80. [self addErrorLoadingFrame:CGRectMake(0, NavHeader, newtableView.width, newtableView.height) title:@"咦,您还没有业务流水噢" buttonTitle:nil imageString:NewNoDataErrorImage];
  81. }else {
  82. [self hideReloadingview];
  83. [newtableView reloadData];
  84. }
  85. }
  86. } onFailure:^{
  87. [self dismiss:object];
  88. }];
  89. }
  90. #pragma mark - 数据初始化
  91. - (void)dataInitialization{
  92. dataArray = NewMutableArrayInit;
  93. pageIndex = 1;
  94. pageSize = 10;
  95. pageNumber = 1;
  96. }
  97. #pragma mark ----加载界面
  98. - (void)loadsView{
  99. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, 44, SCREEN_WIDTH, SCREEN_HEIGHT-(NavHeader+44)) backgroundColor:NewGroupTableViewBackgroundColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  100. newtableView.separatorStyle = NO;
  101. }
  102. #pragma mark-------------------------UITableView------------------------------------
  103. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  104. {
  105. return 1;
  106. }
  107. //返回每段行数
  108. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  109. {
  110. return dataArray.count;
  111. }
  112. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. static NSString *Cell = @"Cell";
  115. BusinesswaterDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  116. if (cell == nil) {
  117. cell = [[BusinesswaterDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  118. }
  119. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  120. cell.accessoryType = UITableViewCellAccessoryNone;
  121. if (dataArray.count>0) {
  122. [cell assignment:dataArray[indexPath.row]];
  123. }
  124. return cell;
  125. }
  126. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  127. {
  128. return fitScreenWidth(98);
  129. }
  130. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  131. }
  132. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  133. return CGFLOAT_MIN;
  134. }
  135. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  136. return CGFLOAT_MIN;
  137. }
  138. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  139. return [[UIView alloc] init];
  140. }
  141. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  142. return [[UIView alloc] init];
  143. }
  144. #pragma mark - 上拉下拉初始化
  145. - (void)addRefreshing
  146. {
  147. __weak typeof(self) weakSelf = self;
  148. __weak UITableView *tableView = newtableView;
  149. tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  150. if ([NetworkRequestManager connectedToNetwork]) {
  151. [weakSelf networkRequest:tableView.mj_header];
  152. }else{
  153. [tableView.mj_header endRefreshing];
  154. }
  155. }];
  156. tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  157. if ([NetworkRequestManager connectedToNetwork]) {
  158. [weakSelf networkRequest:tableView.mj_footer];
  159. }else{
  160. [tableView.mj_footer endRefreshing];
  161. }
  162. }];
  163. }
  164. - (void)dismiss:(id)object
  165. {
  166. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  167. __weak UITableView *newvc = newtableView;
  168. [newvc.mj_header endRefreshing];
  169. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
  170. __weak UITableView *newvc = newtableView;
  171. [newvc.mj_footer endRefreshing];
  172. }else {
  173. [MBProgressHUD hideHUDForView:self.view];
  174. }
  175. }
  176. #pragma mark- 外部触发自动刷新
  177. - (void)autoDownRefresh
  178. {
  179. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  180. [self autoRefresh];
  181. });
  182. }
  183. #pragma mark 初始化展示框
  184. - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
  185. {
  186. if(!showView)
  187. {
  188. [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
  189. [showView setHidden:NO];
  190. [showView setBackgroundColor:NewBgGrayColor];
  191. UIImage *NOimg = [UIImage imageNamed:image];
  192. UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
  193. [showView addSubview:tempIcon];
  194. tempIcon.sd_layout
  195. .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
  196. .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
  197. .widthIs(NOimg.size.width/2.0f)
  198. .heightIs(NOimg.size.height/2.0f);
  199. UILabel *tipLab = [UILabel new];
  200. [showView addSubview:tipLab];
  201. [tipLab setText:text];
  202. [tipLab setTextAlignment:NSTextAlignmentCenter];
  203. [tipLab setTextColor:NewLightGrayColor];
  204. [tipLab setBackgroundColor:NewClearColor];
  205. [tipLab setFont:NewAutoFont(16.0)];
  206. tipLab.sd_layout
  207. .leftEqualToView(showView)
  208. .rightEqualToView(showView)
  209. .topSpaceToView(tempIcon,10)
  210. .heightIs(20.0);
  211. if (buttonText.length>0) {
  212. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  213. [showView addSubview:button];
  214. [button setTitle:buttonText forState:UIControlStateNormal];
  215. [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
  216. ViewBorderRadius(button, 16, 2, NewNavigationColor);
  217. [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
  218. CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
  219. button.sd_layout
  220. .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
  221. .topSpaceToView(tipLab, 30.0)
  222. .widthIs(width+35)
  223. .heightIs(34);
  224. }
  225. }
  226. [UIView beginAnimations:@"ShowArrow" context:nil];
  227. [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  228. [UIView setAnimationDuration:0.25f];
  229. [UIView setAnimationDelegate:self];
  230. [showView setAlpha:1.0f];
  231. [UIView commitAnimations];
  232. }
  233. - (void)hideReloadingview
  234. {
  235. [UIView animateWithDuration:0.25 animations:^{
  236. showView.hidden = YES;
  237. } completion:^(BOOL finished) {
  238. for (id obj in showView.subviews) {
  239. [obj removeFromSuperview];
  240. }
  241. showView = nil;
  242. [showView removeFromSuperview];
  243. }];
  244. }
  245. - (void)didReceiveMemoryWarning {
  246. [super didReceiveMemoryWarning];
  247. // Dispose of any resources that can be recreated.
  248. }
  249. /*
  250. #pragma mark - Navigation
  251. // In a storyboard-based application, you will often want to do a little preparation before navigation
  252. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  253. // Get the new view controller using [segue destinationViewController].
  254. // Pass the selected object to the new view controller.
  255. }
  256. */
  257. @end