// // GuWenDetailViewController.m // jitao // // Created by 罗云飞 on 2018/8/19. // Copyright © 2018年 罗云飞. All rights reserved. // #import "GuWenDetailViewController.h" #import "MainTouchTableTableView.h" #import "WMPageController.h" #import "ParentClassScrollViewController.h" #import "GWJJViewController.h" #import "GWPJViewController.h" #import "GuwenDetaiModel.h" #import "placeorderViewController.h" #define Main_Screen_Height [[UIScreen mainScreen] bounds].size.height #define Main_Screen_Width [[UIScreen mainScreen] bounds].size.width static CGFloat const headViewHeight = 256; @interface GuWenDetailViewController (){ NSMutableArray *dataArray; UIButton *scBT; NSString *guanzhutype; } @property(nonatomic ,strong)MainTouchTableTableView * mainTableView; @property(nonatomic,strong) UIScrollView * parentScrollView; @property(nonatomic,strong)UIImageView *headImageView;//头部图片 @property(nonatomic,strong)UIView *CommodityinformationView;//商品信息 @property(nonatomic,strong)UIImageView * avatarImage; @property(nonatomic,strong)UILabel *countentLabel; @end @implementation GuWenDetailViewController @synthesize mainTableView; - (void)viewDidLoad { [super viewDidLoad]; [self setNavTitle:@"顾问详情"]; dataArray = NewMutableArrayInit; [self.view addSubview:self.mainTableView]; [self networkRequest:nil]; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-45, SCREEN_WIDTH, 45)]; view.backgroundColor = [UIColor colorWithString:@"#E3E3E3"]; [self.view addSubview:view]; UIButton *bianjiBT = [UIButton new]; bianjiBT.frame = CGRectMake(SCREEN_WIDTH-fitScreenWidth(150), 0, fitScreenWidth(150), 45); [bianjiBT setTitle:@"立即咨询" forState:UIControlStateNormal]; bianjiBT.titleLabel.font = NewFont(fitScreenWidth(18)); [bianjiBT setTitleColor:NewWhiteColor forState:UIControlStateNormal]; [bianjiBT setBackgroundColor:NewButtonColor]; NewTouchUpInside(bianjiBT, bianjiBTlick:); [view addSubview:bianjiBT]; scBT = [UIButton new]; NewTouchUpInside(scBT, scBTclick:); [view addSubview:scBT]; scBT.sd_layout .centerYEqualToView(view) .widthIs(15) .heightIs(15) .leftSpaceToView(view, 15); UIButton *scBTff = [UIButton new]; [scBTff setTitle:@"关注" forState:UIControlStateNormal]; NewTouchUpInside(scBTff, scBTclick:); scBTff.titleLabel.font = NewFont(14); [scBTff setTitleColor:[UIColor colorWithString:@"#6C6C6C"] forState:UIControlStateNormal]; [view addSubview:scBTff]; scBTff.sd_layout .centerYEqualToView(view) .widthIs(30) .heightIs(15) .leftSpaceToView(scBT, 10); if (@available(iOS 11.0, *)) { self.mainTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; }else { self.automaticallyAdjustsScrollViewInsets = NO; } // Do any additional setup after loading the view. } - (void)networkRequest:(id)object { [MBProgressHUD showLoadToView:self.view title:@"请稍后..."]; NSMutableDictionary *parameters = NewMutableDictionaryInit; [parameters safeSetObject:self.ID forKey:@"id"]; [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewexpertsDetail parameters:parameters onSuccess:^(id requestData) { [MBProgressHUD hideHUDForView:self.view]; if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ GuwenDetaiModel *model = [[GuwenDetaiModel alloc] initWithDictionary:requestData[@"data"] error:nil]; [dataArray addObject:model]; if ([model.interested isEqualToString:@"0"]) { [scBT setImage:NewImageNamed(@"wsc") forState:UIControlStateNormal]; guanzhutype = @"0"; }else{ [scBT setImage:NewImageNamed(@"sc") forState:UIControlStateNormal]; guanzhutype = @"1"; } [self loadCommodityinformationView]; [mainTableView reloadData]; } } onFailure:^{ }]; } - (void)scBTclick:(UIButton *)sender { if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); NSMutableDictionary *parameters = NewMutableDictionaryInit; [parameters safeSetObject:@"2" forKey:@"type"];//类型(0-成果,1-需求,2-专家,3-项目,4-活动,5-政策,6-其他) [parameters safeSetObject:self.ID forKey:@"objectId"]; [parameters safeSetObject:guanzhutype forKey:@"interest"];//是否标记兴趣(0则标记,1则去处) [NetworkRequestManager requestPostWithInterfacePrefix:JT_NewinterestAdd parameters:parameters onSuccess:^(id requestData) { if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ if ([guanzhutype isEqualToString:@"0"]) { [MBProgressHUD showSuccess:@"关注成功" toView:self.view]; guanzhutype = @"1"; [scBT setImage:NewImageNamed(@"sc") forState:UIControlStateNormal]; }else{ [MBProgressHUD showSuccess:@"您已取消关注" toView:self.view]; guanzhutype = @"0"; [scBT setImage:NewImageNamed(@"wsc") forState:UIControlStateNormal]; } } } onFailure:^{ }]; }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { NewPopViewController; }]; NewPushViewController(vc); } } #pragma scrollDelegate -(void)scrollViewLeaveAtTheTop:(UIScrollView *)scrollView { self.parentScrollView = scrollView; //离开顶部 主View 可以滑动 self.parentScrollView.scrollEnabled = NO; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ //获取滚动视图y值的偏移量 CGFloat tabOffsetY = [mainTableView rectForSection:0].origin.y; CGFloat offsetY = scrollView.contentOffset.y; if (offsetY>=tabOffsetY) { scrollView.contentOffset = CGPointMake(0, tabOffsetY); self.parentScrollView.scrollEnabled = YES; }else{ } } #pragma mark --tableDelegate - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return Main_Screen_Height-64; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; cell.selectionStyle = UITableViewCellSelectionStyleNone; /* 添加pageView * 这里可以任意替换你喜欢的pageView *作者这里使用一款github较多人使用的 WMPageController 地址https://github.com/wangmchn/WMPageController */ [cell.contentView addSubview:self.setPageViewControllers]; return cell; } #pragma mark -- setter/getter -(UIView *)setPageViewControllers { WMPageController *pageController = [self p_defaultController]; pageController.title = @"Line"; pageController.menuViewStyle = WMMenuViewStyleLine; pageController.titleSizeSelected = 15; [self addChildViewController:pageController]; [pageController didMoveToParentViewController:self]; return pageController.view; } - (WMPageController *)p_defaultController { GWJJViewController * oneVc = [GWJJViewController new]; oneVc.delegate = self; GWPJViewController * twoVc = [GWPJViewController new]; twoVc.delegate = self; if (dataArray.count>0) { GuwenDetaiModel *model = dataArray[0]; oneVc.neirong = model.introduction; twoVc.ID = self.ID; } NSArray *viewControllers = @[oneVc,twoVc]; NSArray *titles = @[@"顾问简介",@"用户评价"]; WMPageController *pageVC = [[WMPageController alloc] initWithViewControllerClasses:viewControllers andTheirTitles:titles]; [pageVC setViewFrame:CGRectMake(0, 0, Main_Screen_Width, Main_Screen_Height)]; pageVC.delegate = self; pageVC.menuItemWidth = 100; pageVC.menuHeight = 44; pageVC.postNotification = YES; pageVC.bounces = YES; pageVC.menuBGColor = NewWhiteColor; return pageVC; } - (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info { NSLog(@"%@",viewController); } -(UIImageView *)headImageView { if (_headImageView == nil) { _headImageView= [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"项目默认.jpg"]]; _headImageView.frame=CGRectMake(0, -headViewHeight-126 ,Main_Screen_Width,headViewHeight); _headImageView.userInteractionEnabled = YES; } return _headImageView; } - (void)loadCommodityinformationView{ GuwenDetaiModel *model = dataArray[0]; _CommodityinformationView = [[UIView alloc] initWithFrame:CGRectMake(0, -175, SCREEN_WIDTH, 175)]; [_CommodityinformationView setBackgroundColor:NewWhiteColor]; [self.mainTableView addSubview:self.CommodityinformationView]; UILabel *title = [UILabel new]; [title setText:model.username]; title.font = NewFont(fitScreenWidth(17)); [title setTextAlignment:NSTextAlignmentLeft]; [_CommodityinformationView addSubview:title]; title.sd_layout .leftSpaceToView(_CommodityinformationView, 20) .heightIs(fitScreenWidth(16)) .rightSpaceToView(_CommodityinformationView, 15) .topSpaceToView(_CommodityinformationView, 40); UILabel *titledetail = [UILabel new]; //顾问类型 0 专利代理人 1 专利顾问 2 版权顾问 3 商标顾问 if ([model.consultantType isEqualToString:@"0"]) { titledetail.text = @"专利代理人"; }else if ([model.consultantType isEqualToString:@"1"]) { titledetail.text = @"专利顾问"; }else if ([model.consultantType isEqualToString:@"2"]) { titledetail.text = @"版权顾问"; }else if ([model.consultantType isEqualToString:@"3"]) { titledetail.text = @"商标顾问"; } titledetail.font = NewFont(fitScreenWidth(13)); [titledetail setTextColor:[UIColor colorWithString:@"#0779D5"]]; [titledetail setTextAlignment:NSTextAlignmentLeft]; [_CommodityinformationView addSubview:titledetail]; titledetail.sd_layout .leftSpaceToView(_CommodityinformationView, 20) .heightIs(fitScreenWidth(13)) .rightSpaceToView(_CommodityinformationView, 90) .topSpaceToView(title, 20); UIImageView *headimage = [UIImageView new]; [headimage sd_setImageWithURL:NewURL([model.personPortraitUrl mosaicUrlPrefix]) placeholderImage:NewImageNamed(@"顾问-6")]; ViewRadius(headimage, 73/2); [_CommodityinformationView addSubview:headimage]; headimage.sd_layout .rightSpaceToView(_CommodityinformationView, 15) .heightIs(73) .widthIs(73) .topSpaceToView(_CommodityinformationView, 25); UILabel *line1 = [UILabel new]; line1.backgroundColor = NewLineGrayColor; [_CommodityinformationView addSubview:line1]; line1.sd_layout .leftSpaceToView(_CommodityinformationView, 20) .heightIs(0.8) .rightSpaceToView(_CommodityinformationView, 15) .topSpaceToView(titledetail, 15); UILabel *jiage = [UILabel new]; jiage.text = [NSString stringWithFormat:@"好评率:%@",model.favorableRate]; jiage.font = NewFont(fitScreenWidth(12)); jiage.textColor = [UIColor colorWithString:@"#FF9350"]; [jiage setSingleLineAutoResizeWithMaxWidth:0]; [_CommodityinformationView addSubview:jiage]; jiage.sd_layout .leftSpaceToView(_CommodityinformationView, 20) .heightIs(fitScreenWidth(12)) .bottomSpaceToView(_CommodityinformationView, 40); UILabel *line = [UILabel new]; line.backgroundColor = NewLineGrayColor; [_CommodityinformationView addSubview:line]; line.sd_layout .leftEqualToView(_CommodityinformationView) .rightEqualToView(_CommodityinformationView) .heightIs(10) .bottomEqualToView(_CommodityinformationView); UIButton *followBT = [UIButton new]; [followBT setBackgroundColor:NewClearColor]; [followBT setImage:NewImageNamed(@"pj") forState:UIControlStateNormal]; [_CommodityinformationView addSubview:followBT]; followBT.sd_layout .centerYEqualToView(jiage) .heightIs(15) .widthIs(15) .rightSpaceToView(_CommodityinformationView, 15); UILabel *followNumber = [UILabel new]; [followNumber setText:model.countInterest]; [followNumber setFont:NewFont(fitScreenWidth(13))]; [followNumber setTextColor:[UIColor colorWithString:@"#AEAEAE"]]; [followNumber setSingleLineAutoResizeWithMaxWidth:0]; [_CommodityinformationView addSubview:followNumber]; followNumber.sd_layout .rightSpaceToView(followBT, 3) .heightIs(fitScreenWidth(11)) .centerYEqualToView(followBT); } -(MainTouchTableTableView *)mainTableView { if (mainTableView == nil) { mainTableView = [[MainTouchTableTableView alloc]initWithFrame:CGRectMake(0,NavHeader,Main_Screen_Width,Main_Screen_Height-NavHeader-45)]; mainTableView.delegate=self; mainTableView.dataSource=self; mainTableView.showsVerticalScrollIndicator = NO; mainTableView.contentInset = UIEdgeInsetsMake(175,0, 0, 0); mainTableView.backgroundColor = [UIColor clearColor]; } return mainTableView; } - (void)bianjiBTlick:(UIButton *)sender { if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); if (dataArray.count>0) { GuwenDetaiModel *model = dataArray[0]; placeorderViewController *vc = [[placeorderViewController alloc] init]; vc.jiage = @"0"; vc.goumaititle = model.username; vc.ID = model.uid; vc.type = @"顾问"; 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