ZCJDViewController.m 11 KB

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