// // ScienceAchievementsViewController.m // jitao // // Created by 罗云飞 on 2017/12/12. // Copyright © 2017年 罗云飞. All rights reserved. // #import "ScienceAchievementsViewController.h" #import "SQFiltrateView.h" #import "ScienceachievementsCell.h" #import "AchievementsdetailViewController.h" #import "AchievementslistModel.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 ScienceAchievementsViewController (){ UITableView *newtableView; NSMutableArray *dataArray; SQFiltrateView *filtrateView; NSMutableArray *industrytypeArray;//行业类型 NSString *fieldA;//行业类型ID NSString *category; int pageNo; UIView *showView;//无数据UI SQFiltrateItem *item1; } @property (strong ,nonatomic) UIButton * registerAccount; @end @implementation ScienceAchievementsViewController - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [filtrateView hideAllItemView]; } - (void)viewDidLoad { [super viewDidLoad]; [self setNavTitle:@"科技成果"]; [self dataInitialization]; [self IndustrytypeNetworkrequest]; [self AchievementListNetworkrequest:nil]; [self loadsView]; // Do any additional setup after loading the view. } #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:^{ }]; } #pragma mark -----科技成果列表网络请求------ - (void)AchievementListNetworkrequest:(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:@"" forKey:@"ownerId"];//所有人ID [parameters safeSetObject:fieldA forKey:@"fieldA"]; //技术类型需要搞俩个参数 [parameters safeSetObject:category forKey:@"category"]; [NetworkRequestManager requestGetWithInterfacePrefix:JT_achievementList 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]; return; } }else{//选择类型要清空数组 [dataArray removeAllObjects]; } for (NSDictionary *dic in requestData[@"data"][@"list"]) { AchievementslistModel *model = [[AchievementslistModel 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]; }]; } - (void)dataInitialization { fieldA = @""; category = @""; pageNo = 1; dataArray = NewMutableArrayInit; industrytypeArray = NewMutableArrayInit; } #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_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; /* 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:@"行业类型"]) { 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) {//如果什么都不选 category = @""; }else{ for (NSSet *luo in item.choseSet) { NSString *str = [NSString stringWithFormat:@"%@",luo]; if ([str isEqualToString:@"7"]) { category = @""; }else{ category = str; } } } } [self AchievementListNetworkrequest: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); [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"; ScienceachievementsCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell]; if (cell == nil) { cell = [[ScienceachievementsCell 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{ AchievementsdetailViewController *vc = [[AchievementsdetailViewController alloc] init]; AchievementslistModel *model = dataArray[indexPath.row]; 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 AchievementListNetworkrequest:newvc.mj_header]; }else{ [newvc.mj_header endRefreshing]; } }]; newvc.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ if ([NetworkRequestManager connectedToNetwork]) { [weakSelf AchievementListNetworkrequest: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]; } } //#pragma mark - 无数据UI展示 //- (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image //{ // if(!showView) // { // [newtableView addSubview:showView = [[UIView alloc] initWithFrame:frame]]; // [showView setHidden:NO]; // [showView setBackgroundColor:NewGroupTableViewBackgroundColor]; // // UIImage *noimg = [UIImage imageNamed:image]; // UIImageView *tempIcon = [[UIImageView alloc]initWithImage:noimg]; // [showView addSubview:tempIcon]; // tempIcon.sd_layout // .leftSpaceToView(showView, (showView.width/2)-(noimg.size.height/2)) // .topSpaceToView(showView, (showView.height/2)-(noimg.size.height/2+20)) // .widthIs(noimg.size.width) // .heightIs(noimg.size.height); // // UILabel *tipLab = [UILabel new]; // [showView addSubview:tipLab]; // [tipLab setText:text]; // [tipLab setTextAlignment:NSTextAlignmentCenter]; // [tipLab setTextColor:NewNoDataColor]; // [tipLab setBackgroundColor:NewClearColor]; // [tipLab setFont:NewAutoFont(12.0)]; // tipLab.sd_layout // .leftEqualToView(showView) // .rightEqualToView(showView) // .topSpaceToView(tempIcon,0) // .heightIs(20.0); // // } // // [UIView beginAnimations:@"ShowArrow" context:nil]; // // [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; // // [UIView setAnimationDuration:0.25f]; // // [UIView setAnimationDelegate:self]; // [showView setAlpha:1.0f]; // [UIView commitAnimations]; // //} - (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