| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- //
- // NewFWXMViewController.m
- // jitao
- //
- // Created by 罗云飞 on 2018/8/30.
- // Copyright © 2018年 罗云飞. All rights reserved.
- //
- #import "NewFWXMViewController.h"
- #import "NewFWXMCell.h"
- #import "NewFWXMModel.h"
- //#import "NewprojectDetailViewController.h"
- @interface NewFWXMViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>{
- UITableView *newtableView;
- NSMutableArray *dataArray;
- int pageIndex;
- int pageSize;
- int pageNumber;
- UIView *showView;
- NSString *sousuoname;
- }
- @end
- @implementation NewFWXMViewController
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self.navgationBar setHidden:YES];
- }
- - (void)viewDidDisappear:(BOOL)animated
- {
- [super viewDidDisappear:animated];
- [self.navgationBar setHidden:NO];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavTitle:@"服务项目"];
- [self loaddaohang];
- [self dataInitialization];
- [self loadsView];
- [self addRefreshing];
- [self networkRequest:nil];
- // Do any additional setup after loading the view.
- }
- - (void)loaddaohang{
- UIView *navgationBar = [[UIView alloc] init];
- [navgationBar setFrame:CGRectMake(0.0, 0.0, SCREEN_WIDTH, NavHeader+60)];
- [navgationBar setBackgroundColor:[UIColor colorWithString:@"#0097F4"]];
-
- UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavHeader+60)];
- [imageview setImage:NewImageNamed(@"bit")];
- [navgationBar addSubview:imageview];
- [self.view addSubview:navgationBar];
- // UIImage *backButtonImage = [[UIImage imageNamed:@"fh"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
- UIButton *backButton= [UIButton buttonWithType:UIButtonTypeCustom];
- backButton.frame = CGRectMake(10, 27, 30, 30);
- [backButton setBackgroundColor:[UIColor clearColor]];
- // [backButton setBackgroundImage:NewImageNamed(@"fh") forState:UIControlStateNormal];
- [backButton setImage:NewImageNamed(@"fh") forState:UIControlStateNormal];
- [backButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
- [navgationBar addSubview:backButton];
-
-
- UILabel*navTitleLabel = [[UILabel alloc] init];
- [navTitleLabel setFrame:CGRectMake(SCREEN_WIDTH*0.2, 18.0, SCREEN_WIDTH*0.6, NavHeader)];
- [navTitleLabel setBackgroundColor:NewClearColor];
- [navTitleLabel setTextAlignment:NSTextAlignmentCenter];
- [navTitleLabel setFont:NewBFont(18)];
- [navTitleLabel setTextColor:[UIColor whiteColor]];
- [navTitleLabel setText:@"服务项目"];
- [navgationBar addSubview:navTitleLabel];
-
- backButton.sd_layout
- .centerYEqualToView(navTitleLabel)
- .heightIs(30)
- .widthIs(30)
- .leftSpaceToView(navgationBar, 10);
-
- UIView *textBGview = [UIView new];
- textBGview.backgroundColor = NewWhiteColor;
- ViewBorderRadius(textBGview, 3, 1, NewClearColor);
- [navgationBar addSubview:textBGview];
-
- textBGview.sd_layout
- .leftSpaceToView(navgationBar, 40)
- .heightIs(40)
- .rightSpaceToView(navgationBar, 40)
- .topSpaceToView(backButton, 10);
- //tj
- UIImageView *imageview1 = [UIImageView new];
- [imageview1 setImage:NewImageNamed(@"search")];
- [textBGview addSubview:imageview1];
-
- imageview1.sd_layout
- .widthIs(11)
- .heightIs(10)
- .centerYEqualToView(textBGview)
- .leftSpaceToView(textBGview, 10);
-
- 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];
- textfield.text = self.seachStr;
- textfield.delegate = self;//设置代理
- [textBGview addSubview:textfield];
-
- textfield.sd_layout
- .leftSpaceToView(textBGview, 30)
- .topEqualToView(textBGview)
- .bottomEqualToView(textBGview)
- .rightEqualToView(textBGview);
- }
- - (void)popViewController{
- NewPopViewController;
- }
- //搜索虚拟键盘响应
- - (BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- sousuoname = textField.text;
- NSLog(@"点击了搜索");
- [textField resignFirstResponder];
- // [self networkRequest:nil Shijian:timeOrhaoping Sousuo:textField.text GuWentype:guwentype];
- [self networkRequest:nil];
- return YES;
-
- }
- - (void)dataInitialization{
- dataArray = NewMutableArrayInit;
- pageIndex = 1;
- pageSize = 10;
- pageNumber = 1;
- sousuoname = self.seachStr;
- }
- - (void)networkRequest:(id)object
- {
- int pageNumberIndex=1;
-
- if (!object) {
- [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
- }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
- pageNumberIndex = 1;
- }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
- pageNumberIndex = pageNumber+1;
- }
-
- NSMutableDictionary *parameters = NewMutableDictionaryInit;
- [parameters safeSetObject:@(pageSize) forKey:@"pageSize"];
- [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];
- [parameters safeSetObject:sousuoname forKey:@"name"];
- if (!self.biaoqianID) {
- [parameters safeSetObject:self.mokuaitype forKey:@"module"];//(默认0) 所属模块 0科技服务 1知识产权服务 2高新技术企业服务 3军民融合 4科技咨询 5科技项目
- }
- // (默认0) 所属模块 0科技服务 1知识产权服务 2高新技术企业服务 3军民融合 4科技咨询 5科技项目
- [parameters safeSetObject:@"1" forKey:@"privateProject"];//1(固定传)
- [parameters safeSetObject:@"2" forKey:@"auditStatus"];//2 (固定传)
- [parameters safeSetObject:self.topId forKey:@"topId"];//一级分类ID
- [parameters safeSetObject:self.secondId forKey:@"secondId"];//二级分类ID
- [parameters safeSetObject:self.biaoqianID forKey:@"tag"];//标签ID
- [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewprojectLis parameters:parameters onSuccess:^(id requestData) {
- [self dismiss:object];
- if ([requestData[@"error"] count] !=0) {
- for (NSDictionary *dic in requestData[@"error"]) {
- [MBProgressHUD showError:dic[@"message"] toView:self.view];
- }
- }else{
- pageNumber = pageNumberIndex;
- if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
- [dataArray removeAllObjects];
- }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
- NSMutableArray *arr = requestData[@"data"][@"list"];
- if ([arr count]<=0) {
- [[[UIApplication sharedApplication].delegate window] makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
- return;
- }
- }
- for (NSDictionary *dic in requestData[@"data"][@"list"]) {
- NewFWXMModel *model = [[NewFWXMModel alloc] initWithDictionary:dic error:nil];
- [dataArray addObject:model];
- }
- //查询不到类型底图
- if (dataArray.count<=0) {
- [self addErrorLoadingFrame:CGRectMake(0, NavHeader+60, newtableView.width, newtableView.height) title:@"暂无数据" buttonTitle:nil imageString:NewNoDataErrorImage];
- }else {
- [self hideReloadingview];
- [newtableView reloadData];
- }
- }
- } onFailure:^{
- [self dismiss:object];
- }];
- }
- #pragma mark ----加载界面
- - (void)loadsView{
- [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]];
- newtableView.separatorStyle = NO;
- }
- #pragma mark-------------------------UITableView------------------------------------
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- //返回每段行数
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return dataArray.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *Cell = @"Cell";
- NewFWXMCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
- if (cell == nil) {
- cell = [[NewFWXMCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
- cell.accessoryType = UITableViewCellAccessoryNone;
- if (dataArray.count>0) {
- [cell assignment:dataArray[indexPath.row]];
- }
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 145;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- // NewprojectDetailViewController *vc = [[NewprojectDetailViewController alloc] init];
- // NewFWXMModel *model = dataArray[indexPath.row];
- // vc.ID = model.ID;
- //// vc.type = @"立即购买";
- // NewPushViewController(vc);
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- return [[UIView alloc] init];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return [[UIView alloc] init];
- }
- #pragma mark - 上拉下拉初始化
- - (void)addRefreshing
- {
-
- __weak typeof(self) weakSelf = self;
- __weak UITableView *tableView = newtableView;
- tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
-
- if ([NetworkRequestManager connectedToNetwork]) {
- [weakSelf networkRequest:tableView.mj_header];
-
- }else{
- [tableView.mj_header endRefreshing];
- }
- }];
-
- tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
-
- if ([NetworkRequestManager connectedToNetwork]) {
-
- [weakSelf networkRequest:tableView.mj_footer];
-
- }else{
- [tableView.mj_footer endRefreshing];
- }
- }];
- }
- - (void)dismiss:(id)object
- {
- if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
-
- __weak UITableView *newvc = newtableView;
- [newvc.mj_header endRefreshing];
-
- }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
-
- __weak UITableView *newvc = newtableView;
- [newvc.mj_footer endRefreshing];
-
- }else {
- [MBProgressHUD hideHUDForView:self.view];
- }
- }
- #pragma mark- 外部触发自动刷新
- - (void)autoDownRefresh
- {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self autoRefresh];
- });
- }
- #pragma mark- 网络请求
- - (void)autoRefresh
- {
- __weak UITableView *tableView = newtableView;
- [tableView.mj_header beginRefreshing];
- }
- #pragma mark 初始化展示框
- - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
- {
- if(!showView)
- {
- [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
- [showView setHidden:NO];
- [showView setBackgroundColor:NewBgGrayColor];
-
- UIImage *NOimg = [UIImage imageNamed:image];
- UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
- [showView addSubview:tempIcon];
- tempIcon.sd_layout
- .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
- .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
- .widthIs(NOimg.size.width/2.0f)
- .heightIs(NOimg.size.height/2.0f);
-
- UILabel *tipLab = [UILabel new];
- [showView addSubview:tipLab];
- [tipLab setText:text];
- [tipLab setTextAlignment:NSTextAlignmentCenter];
- [tipLab setTextColor:NewLightGrayColor];
- [tipLab setBackgroundColor:NewClearColor];
- [tipLab setFont:NewAutoFont(16.0)];
- tipLab.sd_layout
- .leftEqualToView(showView)
- .rightEqualToView(showView)
- .topSpaceToView(tempIcon,10)
- .heightIs(20.0);
-
- if (buttonText.length>0) {
- UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
- [showView addSubview:button];
- [button setTitle:buttonText forState:UIControlStateNormal];
- [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
- ViewBorderRadius(button, 16, 2, NewNavigationColor);
- [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
- CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
-
- button.sd_layout
- .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
- .topSpaceToView(tipLab, 30.0)
- .widthIs(width+35)
- .heightIs(34);
- }
- }
-
- [UIView beginAnimations:@"ShowArrow" context:nil];
-
- [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
-
- [UIView setAnimationDuration:0.25f];
-
- [UIView setAnimationDelegate:self];
- [showView setAlpha:1.0f];
- [UIView commitAnimations];
-
- }
- - (void)hideReloadingview
- {
- [UIView animateWithDuration:0.25 animations:^{
-
- showView.hidden = YES;
-
- } completion:^(BOOL finished) {
- for (id obj in showView.subviews) {
-
- [obj removeFromSuperview];
- }
- showView = nil;
- [showView removeFromSuperview];
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|