// // AchievementsdetailViewController.m // jitao // // Created by 罗云飞 on 2017/12/16. // Copyright © 2017年 罗云飞. All rights reserved. // #import "AchievementsdetailViewController.h" #import "AchievementsdetailCell.h" #import "ZZCarousel.h" #import "RequirementdescriptionCell.h" #import "ResultsDetailsModel.h" #import "CGPurchaseintentionViewController.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 AchievementsdetailViewController (){ UITableView *newtableView; NSMutableArray *dataArray; ZZCarousel *_headwheel;//广告图 NSMutableArray *_headwheelArray; NSMutableArray *ResultsDetailArray; UIButton *followBT; } @property (strong ,nonatomic) UIButton * registerAccount; @end @implementation AchievementsdetailViewController - (void)viewDidLoad { [super viewDidLoad]; [self setNavTitle:@"成果详情"]; [self dataInitialization]; [self resultsDetailsNetworkrequest]; [self loadsView]; // Do any additional setup after loading the view. } #pragma mark ---------成果详情关注网络请求------- - (void)followBTclick:(UIButton *)sender { if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); NSMutableDictionary *parameters = NewMutableDictionaryInit; // [parameters safeSetObject:[UserEntity sharedInstance].token forKey:@"uid"]; /* 0-成果 1-需求 2-专家 3-政策 4-活动 5-其他 */ [parameters safeSetObject:@"0" forKey:@"type"]; ResultsDetailsModel *model = ResultsDetailArray[0]; [parameters safeSetObject:model.ID forKey:@"objectId"]; //model.interest 0未关注 1已关注 [parameters safeSetObject:model.interest forKey:@"interest"]; [NetworkRequestManager requestGetWithInterfacePrefix:JT_interestAdd parameters:parameters onSuccess:^(id requestData) { [MBProgressHUD hideHUDForView:self.view]; NSLog(@"服务器返回数据:%@",requestData); if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ if ([requestData[@"data"] isEqualToString:@"取消关注成功"]) { ResultsDetailsModel *model = ResultsDetailArray[0]; NSInteger follownumber = [model.countInterest integerValue]-1; model.countInterest = [NSString stringWithFormat:@"%ld",follownumber]; model.interest = @"0"; [ResultsDetailArray removeAllObjects]; [ResultsDetailArray addObject:model]; [followBT setImage:[UIImage imageNamed:@"未关注"] forState:UIControlStateNormal]; [MBProgressHUD showSuccess:@"哎呀,您取消关注啦!" toView:self.view]; [newtableView reloadData]; }else{ ResultsDetailsModel *model = ResultsDetailArray[0]; NSInteger follownumber = [model.countInterest integerValue]+1; model.countInterest = [NSString stringWithFormat:@"%ld",follownumber]; model.interest = @"1"; [ResultsDetailArray removeAllObjects]; [ResultsDetailArray addObject:model]; [followBT setImage:[UIImage imageNamed:@"已关注"] forState:UIControlStateNormal]; [MBProgressHUD showSuccess:@"哎呀,您关注成功啦!" toView:self.view]; [newtableView reloadData]; } } } onFailure:^{ [MBProgressHUD hideHUDForView:self.view]; }]; }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { [self resultsDetailsNetworkrequest]; NewPopViewController; }]; NewPushViewController(vc); } } #pragma mark -------成果详情网络请求-------- - (void)resultsDetailsNetworkrequest { [MBProgressHUD showLoadToView:self.view title:@"请稍后..."]; NSMutableDictionary *parameters = NewMutableDictionaryInit; [parameters safeSetObject:_ID forKey:@"id"]; [NetworkRequestManager requestGetWithInterfacePrefix:JT_achievementDetail parameters:parameters onSuccess:^(id requestData) { [MBProgressHUD hideHUDForView:self.view]; NSLog(@"服务器返回数据:%@",requestData); if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ ResultsDetailsModel *model = [[ResultsDetailsModel alloc] initWithDictionary:requestData[@"data"] error:nil]; [ResultsDetailArray addObject:model]; if (model.technicalPictureUrls.count>0) { _headwheelArray = model.technicalPictureUrls; }else{ [_headwheelArray addObject:@"ty"]; } if ([model.interest isEqualToString:@"1"]) { [followBT setImage:[UIImage imageNamed:@"已关注"] forState:UIControlStateNormal]; }else if([model.interest isEqualToString:@"0"]){ [followBT setImage:[UIImage imageNamed:@"未关注"] forState:UIControlStateNormal]; } [newtableView reloadData]; [_headwheel reloadData]; } } onFailure:^{ [MBProgressHUD hideHUDForView:self.view]; }]; } - (void)dataInitialization { dataArray = NewMutableArrayInit; ResultsDetailArray = NewMutableArrayInit; [dataArray addObject:@"1"]; [dataArray addObject:@"1"]; _headwheelArray = [NSMutableArray array]; } #pragma mark -----------提交购买意向-------- - (void)submissionpurchaseclick:(UIButton *)sender { if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); ResultsDetailsModel *model = ResultsDetailArray[0]; CGPurchaseintentionViewController *vc = [[CGPurchaseintentionViewController alloc] init]; vc.ID = model.ID; vc.commodityType = @"1"; NewPushViewController(vc); }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { [self resultsDetailsNetworkrequest]; NewPopViewController; }]; NewPushViewController(vc); } } #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, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader-44) backgroundColor:NewGroupTableViewBackgroundColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]]; newtableView.separatorStyle = NO; UIView *view = [UIView new]; view.backgroundColor = NewWhiteColor; [self.view addSubview:view]; view.sd_layout .bottomEqualToView(self.view) .heightIs(44) .widthIs(SCREEN_WIDTH); followBT = [UIButton new]; followBT.backgroundColor = NewClearColor; NewTouchUpInside(followBT, followBTclick:); [view addSubview:followBT]; followBT.sd_layout .leftEqualToView(view) .heightIs(44) .topEqualToView(view) .widthIs(44); UIButton *submissionpurchase = [UIButton new]; [submissionpurchase setTitle:@"提交购买意向" forState:UIControlStateNormal]; [submissionpurchase setTitleColor:NewWhiteColor forState:UIControlStateNormal]; submissionpurchase.titleLabel.font = NewFont(15); submissionpurchase.titleLabel.textAlignment = NSTextAlignmentCenter; submissionpurchase.backgroundColor = NewRGBColor(252, 133, 52, 1); NewTouchUpInside(submissionpurchase, submissionpurchaseclick:); [view addSubview:submissionpurchase]; submissionpurchase.sd_layout .rightEqualToView(view) .heightIs(44) .widthIs(fitScreenWidth(121)); UIButton *negotiate = [UIButton new]; [negotiate setTitle:@"洽 谈" forState:UIControlStateNormal]; [negotiate setTitleColor:NewWhiteColor forState:UIControlStateNormal]; negotiate.titleLabel.font = NewFont(15); negotiate.titleLabel.textAlignment = NSTextAlignmentCenter; negotiate.backgroundColor = NewButtonColor; NewTouchUpInside(negotiate, negotiateclick:); [view addSubview:negotiate]; negotiate.sd_layout .rightSpaceToView(submissionpurchase, 1) .heightIs(44) .widthIs(fitScreenWidth(121)); } #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"; static NSString *Cell1 = @"Cell1"; if (indexPath.row == 0) { AchievementsdetailCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell]; if (cell == nil) { cell = [[AchievementsdetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果) cell.accessoryType = UITableViewCellAccessoryNone; if (ResultsDetailArray.count>0) { [cell assignment:ResultsDetailArray[indexPath.row]]; } return cell; }else if (indexPath.row == 1){ RequirementdescriptionCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell1]; if (cell == nil) { cell = [[RequirementdescriptionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell1]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果) cell.accessoryType = UITableViewCellAccessoryNone; if (ResultsDetailArray.count>0) { cell.title.text = @"成果描述"; [cell assignment:ResultsDetailArray[0]]; } return cell; } return [[UITableViewCell alloc] init]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { return 240; }else{ if (ResultsDetailArray.count>0) { ResultsDetailsModel *model = ResultsDetailArray[0]; if (model.introduction == NULL) { model.introduction = @"暂无成果描述"; } CGFloat height = [NewUtils heightforString:model.introduction andWidth:SCREEN_WIDTH-30 fontSize:fitScreenWidth(13)]; return height+70; } return 0; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return CGFLOAT_MIN; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return homeHeadImageHEIGHT; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (!_headwheel) { _headwheel = nil; //创建轮播图 _headwheel = [self headViewwheel:500]; [_headwheel reloadData]; } return _headwheel; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [[UIView alloc] init]; } #pragma mark-------------------------ZZCarousel轮播图片---------------------------------- -(ZZCarousel*)headViewwheel:(NSInteger)tag { //self.navigationController.navigationBar.frame.size.height (SCREEN_WIDTH * 500 ) / 1080 ZZCarousel* wheel = [[ZZCarousel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,homeHeadImageHEIGHT)]; wheel.tag = tag; /* * carouseScrollTimeInterval --- 此属性为设置轮播多长时间滚动到下一张 */ wheel.carouseScrollTimeInterval = CarouselTime; // 代理 wheel.delegate = self; /* * isAutoScroll --- 默认为NO,当为YES时 才能使轮播进行滚动 */ wheel.isAutoScroll = YES; /* * pageType --- 设置轮播样式 默认为系统样式。ZZCarousel 中封装了 两种样式,另外一种为数字样式 */ wheel.pageType = ZZCarouselPageTypeOfNone; /* * 设置UIPageControl 在轮播中的位置、系统默认的UIPageControl 的顶层颜色 和底层颜色已经背景颜色 */ if(wheel.tag == 500) { wheel.pageControlFrame = CGRectMake((SCREEN_WIDTH - 60 ) / 2, wheel.frame.size.height - 10, 60, 5); wheel.pageIndicatorTintColor = [UIColor whiteColor]; wheel.currentPageIndicatorTintColor = NewRGBColor(191, 191, 191, 1); wheel.pageControlBackGroundColor = [UIColor whiteColor]; /* * 设置数字样式的 UIPageControl 中的字体和字体颜色。 背景颜色仍然按照上面pageControlBackGroundColor属性来设置 */ wheel.pageControlOfNumberFont = [UIFont fontWithName:@"Helvetica-Bold" size:18]; wheel.pageContolOfNumberFontColor = [UIColor whiteColor]; } return wheel; } //ZZCarouselDelegate 轮播图片代理方法 -(NSInteger)numberOfZZCarousel:(ZZCarousel *)wheel { return _headwheelArray.count; } //图片赋值 -(ZZCarouselView *)zzcarousel:(UICollectionView *)zzcarousel viewForItemAtIndex:(NSIndexPath *)index itemsIndex:(NSInteger)itemsIndex identifire:(NSString *)identifire ZZCarousel:(ZZCarousel *)zZCarousel { /* * index参数 ※ 注意 */ ZZCarouselView *cell = [zzcarousel dequeueReusableCellWithReuseIdentifier:identifire forIndexPath:index]; if (!cell) { cell = [[ZZCarouselView alloc]init]; } // cell.title.text = [_imagesGroup objectAtIndex:indexPath.row]; // [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"图片地址"]]; /* * itemsIndex 参数 ※ 注意 */ if(zZCarousel.tag == 500){ if(_headwheelArray.count > itemsIndex){ //cell.imageView.contentMode = UIViewContentModeScaleAspectFill; // bannerListModel *model = _headwheelArray[itemsIndex]; if ([_headwheelArray[0] isEqualToString:@"ty"]) { [cell.imageView sd_setImageWithURL:NewURL(@"") placeholderImage:NewImageNamed(@"ty")]; }else{ [cell.imageView sd_setImageWithURL:NewURL([_headwheelArray[itemsIndex] mosaicUrlPrefix]) placeholderImage:NewImageNamed(@"cgxqbj")]; [cell.imageView setBackgroundColor:NewClearColor]; } }else { [cell.imageView setImage:NewImageError_T]; } } return cell; } //图片点击方法 -(void)zzcarouselScrollView:(ZZCarousel *)zzcarouselScrollView didSelectItemAtIndex:(NSInteger)index { // if (![UserHelper isActived]) { // NewNoActivedHUD; // return; // } NSLog(@"%@",[NSString stringWithFormat:@"点击了 第%ld张 轮播图片",(long)index]); } - (void)negotiateclick:(UIButton *)sender { if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); if (ResultsDetailArray.count>0) { ResultsDetailsModel *model = ResultsDetailArray[0]; if (model.easemobName == NULL) { model.easemobName = HXKF; } EaseMessageViewController *viewController = [[EaseMessageViewController alloc] initWithConversationChatter:model.easemobName conversationType:0]; if ([model.easemobName isEqualToString:HXKF]) { viewController.title = @"客服在线"; }else{ viewController.title = model.easemobName; } viewController.hidesBottomBarWhenPushed = YES; [[NSNotificationCenter defaultCenter]postNotificationName:@"环信登录成功" object:nil]; [self.navigationController pushViewController:viewController animated:YES]; } }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { [self resultsDetailsNetworkrequest]; NewPopViewController; }]; NewPushViewController(vc); } } - (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) { [self resultsDetailsNetworkrequest]; 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) { [self resultsDetailsNetworkrequest]; 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) { [self resultsDetailsNetworkrequest]; 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) { [self resultsDetailsNetworkrequest]; 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