// // SciencedemandViewController.m // jitao // // Created by 罗云飞 on 2017/12/12. // Copyright © 2017年 罗云飞. All rights reserved. // #import "SciencedemandViewController.h" #import "SQFiltrateView.h" #import "SciencedemandCell.h" #import "DemanddetailViewController.h" #import "Demandmodel.h" #import "YBPopupMenu.h" #import "MyattentionViewController.h" #import "MyOrderViewController.h" #import "AchievementsReleaseViewController.h" #import "ReleaserequirementsViewController.h" #define TITLES @[@"我的关注", @"我的订单",@"发布成果",@"发布需求"] #define ICONS @[@"wdgz",@"wddd",@"fbcg",@"fbxq"] @interface SciencedemandViewController (){ UITableView *newtableView; NSMutableArray *dataArray; SQFiltrateView *filtrateView; NSMutableArray *industrytypeArray; int pageNo; NSString *dataCategory; NSString *fieldA; } @property (strong ,nonatomic) UIButton * registerAccount; @end @implementation SciencedemandViewController - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [filtrateView hideAllItemView]; } - (void)viewDidLoad { [super viewDidLoad]; [self setNavTitle:@"科技需求"]; [self dataInitialization]; [self IndustrytypeNetworkrequest]; [self demandNetworkrequest:nil]; [self loadsView]; // Do any additional setup after loading the view. } - (void)demandNetworkrequest:(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 = pageNo+1; } NSMutableDictionary *parameters = NewMutableDictionaryInit; [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];//页码 [parameters safeSetObject:@"10" forKey:@"pageSize"];//页面显示数 [parameters safeSetObject:fieldA forKey:@"industryCategoryA"];//行业类型 [parameters safeSetObject:dataCategory forKey:@"demandType"];//技术类型 [NetworkRequestManager requestGetWithInterfacePrefix:JT_demandList parameters:parameters onSuccess:^(id requestData) { [self dismiss:object]; NSLog(@"服务器返回数据:%@",requestData); if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ pageNo = pageNumberIndex; if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {//下拉要清空数组 [dataArray removeAllObjects]; }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {//上拉 if ([requestData[@"data"][@"list"] count]<=0) { [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom]; } }else{//选择类型要清空数组 [dataArray removeAllObjects]; } for (NSDictionary *dic in requestData[@"data"][@"list"]) { Demandmodel *model = [[Demandmodel 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)IndustrytypeNetworkrequest { NSMutableDictionary *parameters = NewMutableDictionaryInit; [NetworkRequestManager requestGetWithInterfacePrefix:JT_industryList parameters:parameters onSuccess:^(id requestData) { NSLog(@"服务器返回数据:%@",requestData); if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ for (NSDictionary *dic in requestData[@"data"]) { [industrytypeArray addObject:dic]; } NSDictionary *dic = @{@"id":@"",@"name":@"全部"}; [industrytypeArray addObject:dic]; [self classificationview]; [filtrateView setNeedsLayout];//强行刷新view; } } onFailure:^{ }]; } - (void)dataInitialization { dataArray = NewMutableArrayInit; industrytypeArray = NewMutableArrayInit; pageNo = 1; fieldA = @""; dataCategory = @""; } #pragma mark -------分类------------- - (void)classificationview{ UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, 1)]; line.backgroundColor = NewLineGrayColor; [self.view addSubview:line]; SQFiltrateItem *item1 = [[SQFiltrateItem alloc]init]; item1.listType = OptionListType_Tag; item1.numberType = OptionNumberType_Single; NSMutableArray *arr = NewMutableArrayInit; for (NSDictionary *dic in industrytypeArray) { [arr addObject:dic[@"name"]]; } item1.optionData = arr; item1.title = @"行业类型"; SQFiltrateItem *item2 = [[SQFiltrateItem alloc]init]; item2.listType = OptionListType_Tag; item2.numberType = OptionNumberType_Single; /* demandType=0 技术购买需求 demandType=1 技术设备类需求 demandType=2 技术方案型需求 demandType=3 技术攻关型需求 demandType=4 技术咨询型需求 demandType=5 技术人才型需求 */ 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:@"行业类型"]) { NSMutableArray *arr = NewMutableArrayInit; for (NSDictionary *dic in industrytypeArray) { [arr addObject:dic[@"id"]]; } NSSet *luo = [NSSet new]; if (!item.choseSet.count) {//如果什么都不选 fieldA = @""; }else{ for (luo in item.choseSet) { NSString *str = [NSString stringWithFormat:@"%@",luo]; NSString *Id = [arr objectAtIndex:[str integerValue]]; fieldA = Id; } } }else{ if (!item.choseSet.count) {//如果什么都不选 dataCategory = @""; }else{ for (NSSet *luo in item.choseSet) { NSString *str = [NSString stringWithFormat:@"%@",luo]; if ([str isEqualToString:@"6"]) { dataCategory = @""; }else{ dataCategory = str; } } } } [self demandNetworkrequest:nil]; }]; [self.view addSubview:filtrateView]; } #pragma mark -----加载界面------- - (void)loadsView{ [self.navgationBar addSubview:self.registerAccount]; _registerAccount.sd_layout .widthIs(30) .rightSpaceToView(self.navgationBar, 10) .heightIs(44) .topSpaceToView(self.navgationBar, 18); // hideAllItemView [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader+44, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader-44) backgroundColor:NewLineGrayColor style:UITableViewStyleGrouped delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]]; newtableView.separatorStyle = NO; [self addRefreshing]; } #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"; SciencedemandCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell]; if (cell == nil) { cell = [[SciencedemandCell 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 132; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ Demandmodel *model = dataArray[indexPath.row]; DemanddetailViewController *vc = [[DemanddetailViewController alloc] init]; vc.ID = model.ID; 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 - 上拉下拉初始化 - (void)addRefreshing { __weak typeof(self) weakSelf = self; __weak UITableView *newvc = newtableView; newvc.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ if ([NetworkRequestManager connectedToNetwork]) { [weakSelf demandNetworkrequest:newvc.mj_header]; }else{ [newvc.mj_header endRefreshing]; } }]; newvc.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ if ([NetworkRequestManager connectedToNetwork]) { [weakSelf demandNetworkrequest:newvc.mj_footer]; }else{ [newvc.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]; } } - (UIButton *)registerAccount { if (!_registerAccount) { _registerAccount = [UIButton buttonWithType:UIButtonTypeCustom]; // [_registerAccount setTitle:@"" forState:UIControlStateNormal]; [_registerAccount setTitleColor:[UIColor colorWithString:@"#9A9A9A"] forState:UIControlStateNormal]; [_registerAccount setBackgroundColor:[UIColor clearColor]]; [_registerAccount setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]; [_registerAccount.titleLabel setFont:[UIFont systemFontOfSize:fitScreenWidth(14)]]; [_registerAccount addTarget:self action:@selector(touchRegister:) forControlEvents:UIControlEventTouchUpInside]; // [_registerAccount setupAutoSizeWithHorizontalPadding:5 buttonHeight:44]; [_registerAccount setImage:NewImageNamed(@"gd") forState:UIControlStateNormal]; } return _registerAccount; } - (void)touchRegister:(UIButton *)sender{ [YBPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:140 delegate:self]; } #pragma mark - YBPopupMenuDelegate - (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu { NSLog(@"点击了 %@ 选项",TITLES[index]); if (index == 0) { if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); MyattentionViewController *vc = [[MyattentionViewController alloc] init]; NewPushViewController(vc); }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { NewPopViewController; }]; NewPushViewController(vc); } }else if (index == 1){ if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); MyOrderViewController*vc = [[MyOrderViewController alloc] init]; NewPushViewController(vc); }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { NewPopViewController; }]; NewPushViewController(vc); } }else if (index == 2) { if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); AchievementsReleaseViewController *vc = [[AchievementsReleaseViewController alloc] init]; NewPushViewController(vc); }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { NewPopViewController; }]; NewPushViewController(vc); } }else if (index == 3){ if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); ReleaserequirementsViewController *vc = [[ReleaserequirementsViewController alloc] init]; NewPushViewController(vc); }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { NewPopViewController; }]; NewPushViewController(vc); } } } - (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