NewFWXMViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. //
  2. // NewFWXMViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2018/8/30.
  6. // Copyright © 2018年 罗云飞. All rights reserved.
  7. //
  8. #import "NewFWXMViewController.h"
  9. #import "NewFWXMCell.h"
  10. #import "NewFWXMModel.h"
  11. //#import "NewprojectDetailViewController.h"
  12. @interface NewFWXMViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>{
  13. UITableView *newtableView;
  14. NSMutableArray *dataArray;
  15. int pageIndex;
  16. int pageSize;
  17. int pageNumber;
  18. UIView *showView;
  19. NSString *sousuoname;
  20. }
  21. @end
  22. @implementation NewFWXMViewController
  23. - (void)viewWillAppear:(BOOL)animated
  24. {
  25. [super viewWillAppear:animated];
  26. [self.navgationBar setHidden:YES];
  27. }
  28. - (void)viewDidDisappear:(BOOL)animated
  29. {
  30. [super viewDidDisappear:animated];
  31. [self.navgationBar setHidden:NO];
  32. }
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. [self setNavTitle:@"服务项目"];
  36. [self loaddaohang];
  37. [self dataInitialization];
  38. [self loadsView];
  39. [self addRefreshing];
  40. [self networkRequest:nil];
  41. // Do any additional setup after loading the view.
  42. }
  43. - (void)loaddaohang{
  44. UIView *navgationBar = [[UIView alloc] init];
  45. [navgationBar setFrame:CGRectMake(0.0, 0.0, SCREEN_WIDTH, NavHeader+60)];
  46. [navgationBar setBackgroundColor:[UIColor colorWithString:@"#0097F4"]];
  47. UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavHeader+60)];
  48. [imageview setImage:NewImageNamed(@"bit")];
  49. [navgationBar addSubview:imageview];
  50. [self.view addSubview:navgationBar];
  51. // UIImage *backButtonImage = [[UIImage imageNamed:@"fh"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
  52. UIButton *backButton= [UIButton buttonWithType:UIButtonTypeCustom];
  53. backButton.frame = CGRectMake(10, 27, 30, 30);
  54. [backButton setBackgroundColor:[UIColor clearColor]];
  55. // [backButton setBackgroundImage:NewImageNamed(@"fh") forState:UIControlStateNormal];
  56. [backButton setImage:NewImageNamed(@"fh") forState:UIControlStateNormal];
  57. [backButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
  58. [navgationBar addSubview:backButton];
  59. UILabel*navTitleLabel = [[UILabel alloc] init];
  60. [navTitleLabel setFrame:CGRectMake(SCREEN_WIDTH*0.2, 18.0, SCREEN_WIDTH*0.6, NavHeader)];
  61. [navTitleLabel setBackgroundColor:NewClearColor];
  62. [navTitleLabel setTextAlignment:NSTextAlignmentCenter];
  63. [navTitleLabel setFont:NewBFont(18)];
  64. [navTitleLabel setTextColor:[UIColor whiteColor]];
  65. [navTitleLabel setText:@"服务项目"];
  66. [navgationBar addSubview:navTitleLabel];
  67. backButton.sd_layout
  68. .centerYEqualToView(navTitleLabel)
  69. .heightIs(30)
  70. .widthIs(30)
  71. .leftSpaceToView(navgationBar, 10);
  72. UIView *textBGview = [UIView new];
  73. textBGview.backgroundColor = NewWhiteColor;
  74. ViewBorderRadius(textBGview, 3, 1, NewClearColor);
  75. [navgationBar addSubview:textBGview];
  76. textBGview.sd_layout
  77. .leftSpaceToView(navgationBar, 40)
  78. .heightIs(40)
  79. .rightSpaceToView(navgationBar, 40)
  80. .topSpaceToView(backButton, 10);
  81. //tj
  82. UIImageView *imageview1 = [UIImageView new];
  83. [imageview1 setImage:NewImageNamed(@"search")];
  84. [textBGview addSubview:imageview1];
  85. imageview1.sd_layout
  86. .widthIs(11)
  87. .heightIs(10)
  88. .centerYEqualToView(textBGview)
  89. .leftSpaceToView(textBGview, 10);
  90. UITextField *textfield = [NewControlPackage textFieldInitWithFrame:CGRectMake(0, 0, 0, 0) backgroundImage:nil backgroundColor:NewWhiteColor textColor:NewGrayColor placeholder:@"请输入关键字" hidden:NO tag:100 font:NewFont(fitScreenWidth(12)) textAlignment:NSTextAlignmentLeft clearButtonMode:UITextFieldViewModeAlways clearsOnBeginEditing:NO adjustsFontSizeToFitWidth:NO secureTextEntry:NO keyboardType:UIKeyboardTypeDefault returnKeyType:UIReturnKeySearch userInteractionEnabled:YES];
  91. textfield.text = self.seachStr;
  92. textfield.delegate = self;//设置代理
  93. [textBGview addSubview:textfield];
  94. textfield.sd_layout
  95. .leftSpaceToView(textBGview, 30)
  96. .topEqualToView(textBGview)
  97. .bottomEqualToView(textBGview)
  98. .rightEqualToView(textBGview);
  99. }
  100. - (void)popViewController{
  101. NewPopViewController;
  102. }
  103. //搜索虚拟键盘响应
  104. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  105. {
  106. sousuoname = textField.text;
  107. NSLog(@"点击了搜索");
  108. [textField resignFirstResponder];
  109. // [self networkRequest:nil Shijian:timeOrhaoping Sousuo:textField.text GuWentype:guwentype];
  110. [self networkRequest:nil];
  111. return YES;
  112. }
  113. - (void)dataInitialization{
  114. dataArray = NewMutableArrayInit;
  115. pageIndex = 1;
  116. pageSize = 10;
  117. pageNumber = 1;
  118. sousuoname = self.seachStr;
  119. }
  120. - (void)networkRequest:(id)object
  121. {
  122. int pageNumberIndex=1;
  123. if (!object) {
  124. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  125. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  126. pageNumberIndex = 1;
  127. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  128. pageNumberIndex = pageNumber+1;
  129. }
  130. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  131. [parameters safeSetObject:@(pageSize) forKey:@"pageSize"];
  132. [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];
  133. [parameters safeSetObject:sousuoname forKey:@"name"];
  134. if (!self.biaoqianID) {
  135. [parameters safeSetObject:self.mokuaitype forKey:@"module"];//(默认0) 所属模块 0科技服务 1知识产权服务 2高新技术企业服务 3军民融合 4科技咨询 5科技项目
  136. }
  137. // (默认0) 所属模块 0科技服务 1知识产权服务 2高新技术企业服务 3军民融合 4科技咨询 5科技项目
  138. [parameters safeSetObject:@"1" forKey:@"privateProject"];//1(固定传)
  139. [parameters safeSetObject:@"2" forKey:@"auditStatus"];//2 (固定传)
  140. [parameters safeSetObject:self.topId forKey:@"topId"];//一级分类ID
  141. [parameters safeSetObject:self.secondId forKey:@"secondId"];//二级分类ID
  142. [parameters safeSetObject:self.biaoqianID forKey:@"tag"];//标签ID
  143. [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewprojectLis parameters:parameters onSuccess:^(id requestData) {
  144. [self dismiss:object];
  145. if ([requestData[@"error"] count] !=0) {
  146. for (NSDictionary *dic in requestData[@"error"]) {
  147. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  148. }
  149. }else{
  150. pageNumber = pageNumberIndex;
  151. if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
  152. [dataArray removeAllObjects];
  153. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  154. NSMutableArray *arr = requestData[@"data"][@"list"];
  155. if ([arr count]<=0) {
  156. [[[UIApplication sharedApplication].delegate window] makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  157. return;
  158. }
  159. }
  160. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  161. NewFWXMModel *model = [[NewFWXMModel alloc] initWithDictionary:dic error:nil];
  162. [dataArray addObject:model];
  163. }
  164. //查询不到类型底图
  165. if (dataArray.count<=0) {
  166. [self addErrorLoadingFrame:CGRectMake(0, NavHeader+60, newtableView.width, newtableView.height) title:@"暂无数据" buttonTitle:nil imageString:NewNoDataErrorImage];
  167. }else {
  168. [self hideReloadingview];
  169. [newtableView reloadData];
  170. }
  171. }
  172. } onFailure:^{
  173. [self dismiss:object];
  174. }];
  175. }
  176. #pragma mark ----加载界面
  177. - (void)loadsView{
  178. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader+60, SCREEN_WIDTH, SCREEN_HEIGHT-(NavHeader+60)) backgroundColor:NewGroupTableViewBackgroundColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  179. newtableView.separatorStyle = NO;
  180. }
  181. #pragma mark-------------------------UITableView------------------------------------
  182. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  183. {
  184. return 1;
  185. }
  186. //返回每段行数
  187. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  188. {
  189. return dataArray.count;
  190. }
  191. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  192. {
  193. static NSString *Cell = @"Cell";
  194. NewFWXMCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  195. if (cell == nil) {
  196. cell = [[NewFWXMCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  197. }
  198. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  199. cell.accessoryType = UITableViewCellAccessoryNone;
  200. if (dataArray.count>0) {
  201. [cell assignment:dataArray[indexPath.row]];
  202. }
  203. return cell;
  204. }
  205. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  206. {
  207. return 145;
  208. }
  209. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  210. // NewprojectDetailViewController *vc = [[NewprojectDetailViewController alloc] init];
  211. // NewFWXMModel *model = dataArray[indexPath.row];
  212. // vc.ID = model.ID;
  213. //// vc.type = @"立即购买";
  214. // NewPushViewController(vc);
  215. }
  216. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  217. return CGFLOAT_MIN;
  218. }
  219. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  220. return CGFLOAT_MIN;
  221. }
  222. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  223. return [[UIView alloc] init];
  224. }
  225. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  226. return [[UIView alloc] init];
  227. }
  228. #pragma mark - 上拉下拉初始化
  229. - (void)addRefreshing
  230. {
  231. __weak typeof(self) weakSelf = self;
  232. __weak UITableView *tableView = newtableView;
  233. tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  234. if ([NetworkRequestManager connectedToNetwork]) {
  235. [weakSelf networkRequest:tableView.mj_header];
  236. }else{
  237. [tableView.mj_header endRefreshing];
  238. }
  239. }];
  240. tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  241. if ([NetworkRequestManager connectedToNetwork]) {
  242. [weakSelf networkRequest:tableView.mj_footer];
  243. }else{
  244. [tableView.mj_footer endRefreshing];
  245. }
  246. }];
  247. }
  248. - (void)dismiss:(id)object
  249. {
  250. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  251. __weak UITableView *newvc = newtableView;
  252. [newvc.mj_header endRefreshing];
  253. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
  254. __weak UITableView *newvc = newtableView;
  255. [newvc.mj_footer endRefreshing];
  256. }else {
  257. [MBProgressHUD hideHUDForView:self.view];
  258. }
  259. }
  260. #pragma mark- 外部触发自动刷新
  261. - (void)autoDownRefresh
  262. {
  263. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  264. [self autoRefresh];
  265. });
  266. }
  267. #pragma mark- 网络请求
  268. - (void)autoRefresh
  269. {
  270. __weak UITableView *tableView = newtableView;
  271. [tableView.mj_header beginRefreshing];
  272. }
  273. #pragma mark 初始化展示框
  274. - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
  275. {
  276. if(!showView)
  277. {
  278. [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
  279. [showView setHidden:NO];
  280. [showView setBackgroundColor:NewBgGrayColor];
  281. UIImage *NOimg = [UIImage imageNamed:image];
  282. UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
  283. [showView addSubview:tempIcon];
  284. tempIcon.sd_layout
  285. .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
  286. .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
  287. .widthIs(NOimg.size.width/2.0f)
  288. .heightIs(NOimg.size.height/2.0f);
  289. UILabel *tipLab = [UILabel new];
  290. [showView addSubview:tipLab];
  291. [tipLab setText:text];
  292. [tipLab setTextAlignment:NSTextAlignmentCenter];
  293. [tipLab setTextColor:NewLightGrayColor];
  294. [tipLab setBackgroundColor:NewClearColor];
  295. [tipLab setFont:NewAutoFont(16.0)];
  296. tipLab.sd_layout
  297. .leftEqualToView(showView)
  298. .rightEqualToView(showView)
  299. .topSpaceToView(tempIcon,10)
  300. .heightIs(20.0);
  301. if (buttonText.length>0) {
  302. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  303. [showView addSubview:button];
  304. [button setTitle:buttonText forState:UIControlStateNormal];
  305. [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
  306. ViewBorderRadius(button, 16, 2, NewNavigationColor);
  307. [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
  308. CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
  309. button.sd_layout
  310. .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
  311. .topSpaceToView(tipLab, 30.0)
  312. .widthIs(width+35)
  313. .heightIs(34);
  314. }
  315. }
  316. [UIView beginAnimations:@"ShowArrow" context:nil];
  317. [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  318. [UIView setAnimationDuration:0.25f];
  319. [UIView setAnimationDelegate:self];
  320. [showView setAlpha:1.0f];
  321. [UIView commitAnimations];
  322. }
  323. - (void)hideReloadingview
  324. {
  325. [UIView animateWithDuration:0.25 animations:^{
  326. showView.hidden = YES;
  327. } completion:^(BOOL finished) {
  328. for (id obj in showView.subviews) {
  329. [obj removeFromSuperview];
  330. }
  331. showView = nil;
  332. [showView removeFromSuperview];
  333. }];
  334. }
  335. - (void)didReceiveMemoryWarning {
  336. [super didReceiveMemoryWarning];
  337. // Dispose of any resources that can be recreated.
  338. }
  339. /*
  340. #pragma mark - Navigation
  341. // In a storyboard-based application, you will often want to do a little preparation before navigation
  342. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  343. // Get the new view controller using [segue destinationViewController].
  344. // Pass the selected object to the new view controller.
  345. }
  346. */
  347. @end