// // GUWENViewController.m // jitao // // Created by 罗云飞 on 2018/8/19. // Copyright © 2018年 罗云飞. All rights reserved. // #import "GUWENViewController.h" #import "SQFiltrateView.h" #import "GuWenCell.h" #import "GuWenDetailViewController.h" #import "CityListViewController.h" #import "GUWenlistModel.h" @interface GUWENViewController (){ SQFiltrateItem *item1; SQFiltrateView *filtrateView; UITableView *newtableView; NSMutableArray *dataArray; int pageIndex; int pageSize; int pageNumber; UIView *showView; NSString *timeOrhaoping; NSString *guwentype; NSString *Sheng; NSString *Shi; NSString *Qu; UIView *textBGview; UIView *dhView; UIButton *backButton; } @end @implementation GUWENViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navgationBar setHidden:YES]; if (self.navigationController.viewControllers.count <= 1) { NSLog(@"111"); if (NavHeader == 88) { textBGview.sd_layout .leftSpaceToView(dhView, 15) .heightIs(30) .topSpaceToView(dhView, 45) .rightSpaceToView(dhView, 60); }else{ textBGview.sd_layout .leftSpaceToView(dhView, 15) .heightIs(30) .topSpaceToView(dhView, 25) .rightSpaceToView(dhView, 60); } backButton.hidden = YES; }else{ NSLog(@"222"); if (NavHeader == 88) { textBGview.sd_layout .leftSpaceToView(dhView, 55) .heightIs(30) .topSpaceToView(dhView, 45) .rightSpaceToView(dhView, 60); }else{ textBGview.sd_layout .leftSpaceToView(dhView, 55) .heightIs(30) .topSpaceToView(dhView, 25) .rightSpaceToView(dhView, 60); } backButton.hidden = NO; } } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; [self.navgationBar setHidden:NO]; } - (void)viewDidLoad { [super viewDidLoad]; [self setNavTitle:@"顾问"]; [self loadsUI]; [self loaddata]; [self classificationview]; [self loadsView]; [self addRefreshing]; [self networkRequest:nil Shijian:timeOrhaoping Sousuo:self.seachStr GuWentype:guwentype]; // Do any additional setup after loading the view. } - (void)loaddata{ dataArray = NewMutableArrayInit; pageIndex = 1; pageSize = 10; pageNumber = 1; timeOrhaoping = @"0"; guwentype = @""; Sheng = @""; Shi = @""; Qu = @""; } - (void)networkRequest:(id)object Shijian:(NSString *)sortType Sousuo:(NSString *)name GuWentype:(NSString *)consultantType { 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:timeOrhaoping forKey:@"sortType"];//排序 0时间 1好评率 [parameters safeSetObject:name forKey:@"name"];//搜索输入名称 [parameters safeSetObject:consultantType forKey:@"consultantType"]; // 顾问类型 0 专利代理人 1 专利顾问 2 版权顾问 3 商标顾问 [parameters safeSetObject:Sheng forKey:@"province"];//省 [parameters safeSetObject:Shi forKey:@"city"];//市 [parameters safeSetObject:Qu forKey:@"area"];//区 [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewconsultantList 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"]) { GUWenlistModel *model = [[GUWenlistModel alloc] initWithDictionary:dic error:nil]; [dataArray addObject:model]; } //查询不到类型底图 if (dataArray.count<=0) { [self addErrorLoadingFrame:CGRectMake(0, NavHeader+44, newtableView.width, newtableView.height) title:@"暂无数据" buttonTitle:nil imageString:NewNoDataErrorImage]; }else { [self hideReloadingview]; [newtableView reloadData]; } } } onFailure:^{ [self dismiss:object]; }]; } #pragma mark -------分类------------- - (void)classificationview{ UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, 1)]; line.backgroundColor = NewLineGrayColor; [self.view addSubview:line]; item1 = [[SQFiltrateItem alloc]init]; item1.listType = OptionListType_Cell; item1.numberType = OptionNumberType_Single; // NSMutableArray *arr = NewMutableArrayInit; // for (NSDictionary *dic in industrytypeArray) { // [arr addObject:dic[@"name"]]; // } item1.optionData = @[@"时间",@"好评率"]; item1.title = @"时间"; SQFiltrateItem *item2 = [[SQFiltrateItem alloc]init]; item2.listType = OptionListType_Cell; item2.numberType = OptionNumberType_Single; /* 0--专利, 1--软著, 2--项目, 3--版权, 4--工业设计, 5--配方, 6--非标 */ item2.optionData = @[@"不限",@"专利代理人",@"专利顾问",@"版权顾问",@"商标顾问"]; item2.title = @"知识产权顾问"; filtrateView = [[SQFiltrateView alloc]initWithFrame:CGRectMake(0, NavHeader+1, SCREEN_WIDTH, 44) filtrateItems:@[item1,item2]]; [filtrateView touchBlock:^(SQFiltrateView * _Nonnull view, SQFiltrateItem * _Nonnull item) { NSLog(@"%@:%@",item.title,item.choseSet); if ([item.title isEqualToString:@"时间"]) { for (NSSet *luo in item.choseSet) { NSString *str = [NSString stringWithFormat:@"%@",luo]; if ([str isEqual:@"0"]) { NSLog(@"时间"); timeOrhaoping = @"0"; }else{ NSLog(@"好评率"); timeOrhaoping = @"1"; } } }else if ([item.title isEqualToString:@"知识产权顾问"]){ for (NSSet *luo in item.choseSet) { NSString *str = [NSString stringWithFormat:@"%@",luo]; if ([str isEqual:@"0"]) { NSLog(@"不限"); guwentype = @""; }else if([str isEqual:@"1"]){ NSLog(@"专利代理人"); guwentype = @"0"; }else if([str isEqual:@"2"]){ NSLog(@"专利顾问"); guwentype = @"1"; }else if([str isEqual:@"3"]){ NSLog(@"版权顾问"); guwentype = @"2"; }else if([str isEqual:@"4"]){ NSLog(@"商标顾问"); guwentype = @"3"; } } } [self networkRequest:nil Shijian:timeOrhaoping Sousuo:@"" GuWentype:guwentype]; }]; [self.view addSubview:filtrateView]; } #pragma mark ----自定义导航 - (void)loadsUI{ dhView = [UIView new]; dhView.backgroundColor = NewButtonColor; [self.view addSubview:dhView]; dhView.sd_layout .leftEqualToView(self.view) .rightEqualToView(self.view) .heightIs(NavHeader) .topEqualToView(self.view); UIImageView *imgaeview1111= [UIImageView new]; [imgaeview1111 setImage:NewImageNamed(@"pp")]; imgaeview1111.userInteractionEnabled = YES; [dhView addSubview:imgaeview1111]; imgaeview1111.sd_layout .leftEqualToView(dhView) .heightIs(NavHeader) .rightEqualToView(dhView) .topEqualToView(dhView); textBGview = [UIView new]; textBGview.backgroundColor = NewWhiteColor; ViewBorderRadius(textBGview, 3, 1, NewClearColor); [dhView addSubview:textBGview]; 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]; [dhView addSubview:backButton]; //tj UIImageView *imageview = [UIImageView new]; [imageview setImage:NewImageNamed(@"search")]; [textBGview addSubview:imageview]; imageview.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;//设置代理 [textfield addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged]; [textBGview addSubview:textfield]; textfield.sd_layout .leftSpaceToView(textBGview, 30) .topEqualToView(textBGview) .bottomEqualToView(textBGview) .rightEqualToView(textBGview); UIButton *button = [UIButton new]; [button setImage:NewImageNamed(@"dq") forState:UIControlStateNormal]; NewTouchUpInside(button, buttonclick:); [dhView addSubview:button]; button.sd_layout .centerYEqualToView(textBGview) .heightIs(19) .widthIs(19) .rightSpaceToView(dhView, 15); } #pragma mark -----加载界面------- - (void)loadsView{ [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader+44, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader-44-TABBAR_HEIGHT) backgroundColor:NewLineGrayColor style:UITableViewStyleGrouped 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"; GuWenCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell]; if (cell == nil) { cell = [[GuWenCell 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 150; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ GuWenDetailViewController *vc = [[GuWenDetailViewController alloc] init]; GUWenlistModel *model = dataArray[indexPath.row]; vc.ID = model.uid; NewPushViewController(vc); } // tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return CGFLOAT_MIN; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(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 - TextField作字符输入限制 - (void)textFieldEditingChanged:(UITextField *)textField { if ([textField.text length]>10) { UITextRange *markedRange = [textField markedTextRange]; if (markedRange) { return; } NSRange range = [textField.text rangeOfComposedCharacterSequenceAtIndex:10]; textField.text = [textField.text substringToIndex:range.location]; [self.view makeToast:@"搜索最多输入10个字哦~" duration:1.5 position:CSToastPositionCenter]; } // resultsTitleStr = textField.text; NSLog(@"%@",textField.text); } - (void)buttonclick:(UIButton *)sender { CityListViewController *cityListView = [[CityListViewController alloc]init]; cityListView.delegate = self; //热门城市列表 cityListView.arrayHotCity = [NSMutableArray arrayWithObjects:@"全国",@"北京",@"上海",@"天津",@"重庆",@"成都",@"广州",@"深圳",@"深圳",@"西安",@"南京",@"杭州", nil]; //历史选择城市列表 cityListView.arrayHistoricalCity = [NSMutableArray arrayWithObjects:@"福州",@"厦门",@"泉州", nil]; //定位城市列表 cityListView.arrayLocatingCity = [NSMutableArray arrayWithObjects:@"长沙", nil]; // [self presentViewController:cityListView animated:YES completion:nil]; NewPushViewController(cityListView); } - (void)didClickedWithCityName:(NSString*)cityName { NSString *sheng; NSString *shi; NSString *qu; NSString *path = [[NSBundle mainBundle] pathForResource:@"locationAll" ofType:@"txt"]; NSString *content = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; NSDictionary *dic = [self jsonStringToKeyValues:content]; NSMutableArray *array1= dic[@"list"]; NSLog(@"%@",cityName); for (int i = 0; i0) { 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]; }]; } //搜索虚拟键盘响应 - (BOOL)textFieldShouldReturn:(UITextField *)textField { NSLog(@"点击了搜索"); [textField resignFirstResponder]; [self networkRequest:nil Shijian:timeOrhaoping Sousuo:textField.text GuWentype:guwentype]; return YES; } - (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