NewFXViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. //
  2. // NewFXViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2022/3/6.
  6. // Copyright © 2022 罗云飞. All rights reserved.
  7. //
  8. #import "NewFXViewController.h"
  9. #import "ZCJDModel.h"
  10. #import "ZCJDCell.h"
  11. #import "FaXianDetailViewController.h"
  12. #import "ZCJDViewController.h"
  13. #import "KJZXViewController.h"
  14. #import "ZCBKViewController.h"
  15. #import "JTKFViewController.h"
  16. @interface NewFXViewController ()<UITableViewDelegate,UITableViewDataSource>{
  17. UITableView *newtableView;
  18. NSMutableArray *dataArray;
  19. int pageIndex;
  20. int pageSize;
  21. int pageNumber;
  22. UIView *showView;
  23. }
  24. @end
  25. @implementation NewFXViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self dataInitialization];
  29. [self setNavTitle:@"发现"];
  30. [self loadsView];
  31. [self addRefreshing];
  32. [self networkRequest:nil];
  33. }
  34. - (void)dataInitialization{
  35. dataArray = NewMutableArrayInit;
  36. pageIndex = 1;
  37. pageSize = 10;
  38. pageNumber = 1;
  39. }
  40. - (void)loadsView{
  41. UIView *backView = [UIView new];
  42. backView.backgroundColor = NewWhiteColor;
  43. [self.view addSubview:backView];
  44. backView.sd_layout
  45. .heightIs(160)
  46. .leftEqualToView(self.view)
  47. .rightEqualToView(self.view)
  48. .topSpaceToView(self.view, NavHeader);
  49. UIButton *oneBT = [UIButton new];
  50. [oneBT setBackgroundImage:NewImageNamed(@"政策解读") forState:UIControlStateNormal];
  51. ViewRadius(oneBT, 5);
  52. NewTouchUpInside(oneBT, oneBTclick:);
  53. oneBT.tag = 100;
  54. [backView addSubview:oneBT];
  55. oneBT.sd_layout
  56. .topSpaceToView(backView, 10)
  57. .leftSpaceToView(backView, 10)
  58. .heightIs((SCREEN_WIDTH-50)/4)
  59. .widthIs((SCREEN_WIDTH-50)/4);
  60. UIButton *TwoBT = [UIButton new];
  61. [TwoBT setBackgroundImage:NewImageNamed(@"科技资讯") forState:UIControlStateNormal];
  62. ViewRadius(TwoBT, 5);
  63. NewTouchUpInside(TwoBT, oneBTclick:);
  64. TwoBT.tag = 101;
  65. [backView addSubview:TwoBT];
  66. TwoBT.sd_layout
  67. .topSpaceToView(backView, 10)
  68. .leftSpaceToView(oneBT, 10)
  69. .heightIs((SCREEN_WIDTH-50)/4)
  70. .widthIs((SCREEN_WIDTH-50)/4);
  71. UIButton *ThreeBT = [UIButton new];
  72. [ThreeBT setBackgroundImage:NewImageNamed(@"知产百科") forState:UIControlStateNormal];
  73. ViewRadius(ThreeBT, 5);
  74. NewTouchUpInside(ThreeBT, oneBTclick:);
  75. ThreeBT.tag = 102;
  76. [backView addSubview:ThreeBT];
  77. ThreeBT.sd_layout
  78. .topSpaceToView(backView, 10)
  79. .leftSpaceToView(TwoBT, 10)
  80. .heightIs((SCREEN_WIDTH-50)/4)
  81. .widthIs((SCREEN_WIDTH-50)/4);
  82. UIButton *FourBT = [UIButton new];
  83. [FourBT setBackgroundImage:NewImageNamed(@"技淘客服") forState:UIControlStateNormal];
  84. ViewRadius(FourBT, 5);
  85. NewTouchUpInside(FourBT, oneBTclick:);
  86. FourBT.tag = 103;
  87. [backView addSubview:FourBT];
  88. FourBT.sd_layout
  89. .topSpaceToView(backView, 10)
  90. .leftSpaceToView(ThreeBT, 10)
  91. .heightIs((SCREEN_WIDTH-50)/4)
  92. .widthIs((SCREEN_WIDTH-50)/4);
  93. UILabel *titleLB = [UILabel new];
  94. titleLB.text = @"技淘观点";
  95. titleLB.textColor = NewBlackColor;
  96. titleLB.font = NewFont(18);
  97. [titleLB setSingleLineAutoResizeWithMaxWidth:0];
  98. [backView addSubview:titleLB];
  99. titleLB.sd_layout
  100. .bottomSpaceToView(backView, 20)
  101. .heightIs(20)
  102. .centerXEqualToView(backView);
  103. UILabel *line = [UILabel new];
  104. line.backgroundColor = [UIColor colorWithString:@"#F2F2F7"];
  105. [backView addSubview:line];
  106. line.sd_layout
  107. .leftEqualToView(backView)
  108. .rightEqualToView(backView)
  109. .heightIs(10)
  110. .bottomEqualToView(backView);
  111. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader+160, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader-160) backgroundColor:[UIColor colorWithString:@"#F2F2F7"] style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  112. newtableView.separatorStyle = NO;
  113. if (@available(iOS 11.0, *)) {
  114. newtableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  115. }
  116. }
  117. #pragma mark-------------------------UITableView------------------------------------
  118. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  119. {
  120. return 1;
  121. }
  122. //返回每段行数
  123. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  124. {
  125. return dataArray.count;
  126. }
  127. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  128. {
  129. static NSString *Cell = @"Cell";
  130. ZCJDCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  131. if (cell == nil) {
  132. cell = [[ZCJDCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  133. }
  134. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  135. cell.accessoryType = UITableViewCellAccessoryNone;
  136. cell.backgroundColor = NewWhiteColor;
  137. if (dataArray.count>0) {
  138. [cell assignment:dataArray[indexPath.row]];
  139. }
  140. return cell;
  141. }
  142. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  143. {
  144. return 135;
  145. }
  146. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  147. if (dataArray.count>0) {
  148. ZCJDModel *model = dataArray[indexPath.row];
  149. // TongyongDetailViewController *vc = [[TongyongDetailViewController alloc] init];
  150. // vc.title = model.title;
  151. // vc.neirong = model.content;
  152. // vc.time = model.releaseDate;
  153. // vc.type = @"政策";
  154. // NewPushViewController(vc);
  155. // FaDetaiH5ViewController *vc = [[FaDetaiH5ViewController alloc] init];
  156. // vc.type = @"政策";
  157. // vc.ID = model.ID;
  158. // NewPushViewController(vc);
  159. FaXianDetailViewController *vc = [FaXianDetailViewController new];
  160. vc.title = model.title;
  161. vc.neirong = model.content;
  162. vc.time = model.releaseDate;
  163. vc.type = @"资讯";
  164. vc.titleimg = model.titleImg;
  165. NewPushViewController(vc);
  166. }
  167. }
  168. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  169. return CGFLOAT_MIN;
  170. }
  171. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  172. return CGFLOAT_MIN;
  173. }
  174. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  175. return [[UIView alloc] init];
  176. }
  177. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  178. return [[UIView alloc] init];
  179. }
  180. - (void)networkRequest:(id)object
  181. {
  182. int pageNumberIndex=1;
  183. if (!object) {
  184. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  185. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  186. pageNumberIndex = 1;
  187. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  188. pageNumberIndex = pageNumber+1;
  189. }
  190. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  191. [parameters safeSetObject:@(pageSize) forKey:@"pageSize"];
  192. [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];
  193. [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewlistJtViewpoint parameters:parameters onSuccess:^(id requestData) {
  194. [self dismiss:object];
  195. if ([requestData[@"error"] count] !=0) {
  196. for (NSDictionary *dic in requestData[@"error"]) {
  197. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  198. }
  199. }else{
  200. pageNumber = pageNumberIndex;
  201. if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
  202. [dataArray removeAllObjects];
  203. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  204. NSMutableArray *arr = requestData[@"data"][@"list"];
  205. if ([arr count]<=0) {
  206. [[[UIApplication sharedApplication].delegate window] makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  207. return;
  208. }
  209. }
  210. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  211. ZCJDModel *model = [[ZCJDModel alloc] initWithDictionary:dic error:nil];
  212. [dataArray addObject:model];
  213. }
  214. //查询不到类型底图
  215. if (dataArray.count<=0) {
  216. [self addErrorLoadingFrame:CGRectMake(0, NavHeader+150, newtableView.width, newtableView.height) title:@"暂无资讯" buttonTitle:nil imageString:NewNoDataErrorImage];
  217. }else {
  218. [self hideReloadingview];
  219. [newtableView reloadData];
  220. }
  221. }
  222. } onFailure:^{
  223. [self dismiss:object];
  224. }];
  225. }
  226. #pragma mark - 上拉下拉初始化
  227. - (void)addRefreshing
  228. {
  229. __weak typeof(self) weakSelf = self;
  230. __weak UITableView *tableView = newtableView;
  231. tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  232. if ([NetworkRequestManager connectedToNetwork]) {
  233. [weakSelf networkRequest:tableView.mj_header];
  234. }else{
  235. [tableView.mj_header endRefreshing];
  236. }
  237. }];
  238. tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  239. if ([NetworkRequestManager connectedToNetwork]) {
  240. [weakSelf networkRequest:tableView.mj_footer];
  241. }else{
  242. [tableView.mj_footer endRefreshing];
  243. }
  244. }];
  245. }
  246. - (void)dismiss:(id)object
  247. {
  248. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  249. __weak UITableView *newvc = newtableView;
  250. [newvc.mj_header endRefreshing];
  251. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
  252. __weak UITableView *newvc = newtableView;
  253. [newvc.mj_footer endRefreshing];
  254. }else {
  255. [MBProgressHUD hideHUDForView:self.view];
  256. }
  257. }
  258. #pragma mark- 外部触发自动刷新
  259. - (void)autoDownRefresh
  260. {
  261. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  262. [self autoRefresh];
  263. });
  264. }
  265. #pragma mark- 网络请求
  266. - (void)autoRefresh
  267. {
  268. __weak UITableView *tableView = newtableView;
  269. [tableView.mj_header beginRefreshing];
  270. }
  271. #pragma mark 初始化展示框
  272. - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
  273. {
  274. if(!showView)
  275. {
  276. [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
  277. [showView setHidden:NO];
  278. [showView setBackgroundColor:NewBgGrayColor];
  279. UIImage *NOimg = [UIImage imageNamed:image];
  280. UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
  281. [showView addSubview:tempIcon];
  282. tempIcon.sd_layout
  283. .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
  284. .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
  285. .widthIs(NOimg.size.width/2.0f)
  286. .heightIs(NOimg.size.height/2.0f);
  287. UILabel *tipLab = [UILabel new];
  288. [showView addSubview:tipLab];
  289. [tipLab setText:text];
  290. [tipLab setTextAlignment:NSTextAlignmentCenter];
  291. [tipLab setTextColor:NewLightGrayColor];
  292. [tipLab setBackgroundColor:NewClearColor];
  293. [tipLab setFont:NewAutoFont(16.0)];
  294. tipLab.sd_layout
  295. .leftEqualToView(showView)
  296. .rightEqualToView(showView)
  297. .topSpaceToView(tempIcon,10)
  298. .heightIs(20.0);
  299. if (buttonText.length>0) {
  300. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  301. [showView addSubview:button];
  302. [button setTitle:buttonText forState:UIControlStateNormal];
  303. [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
  304. ViewBorderRadius(button, 16, 2, NewNavigationColor);
  305. [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
  306. CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
  307. button.sd_layout
  308. .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
  309. .topSpaceToView(tipLab, 30.0)
  310. .widthIs(width+35)
  311. .heightIs(34);
  312. }
  313. }
  314. [UIView beginAnimations:@"ShowArrow" context:nil];
  315. [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  316. [UIView setAnimationDuration:0.25f];
  317. [UIView setAnimationDelegate:self];
  318. [showView setAlpha:1.0f];
  319. [UIView commitAnimations];
  320. }
  321. - (void)hideReloadingview
  322. {
  323. [UIView animateWithDuration:0.25 animations:^{
  324. showView.hidden = YES;
  325. } completion:^(BOOL finished) {
  326. for (id obj in showView.subviews) {
  327. [obj removeFromSuperview];
  328. }
  329. showView = nil;
  330. [showView removeFromSuperview];
  331. }];
  332. }
  333. - (void)oneBTclick:(UIButton *)sender{
  334. if (sender.tag == 100) {
  335. ZCJDViewController *vc = [ZCJDViewController new];
  336. NewPushViewController(vc);
  337. }else if (sender.tag == 101){
  338. KJZXViewController *vc = [KJZXViewController new];
  339. NewPushViewController(vc);
  340. }else if (sender.tag == 102){
  341. ZCBKViewController *vc = [ZCBKViewController new];
  342. NewPushViewController(vc);
  343. }else if (sender.tag == 103){
  344. JTKFViewController *vc = [JTKFViewController new];
  345. NewPushViewController(vc);
  346. }
  347. }
  348. @end