// // activityDetailVController.m // ZhongJingLianMeng // // Created by youke on 2018/12/6. // Copyright © 2018 youke. All rights reserved. // #import "activityDetailVController.h" #import "UIAlertController+LY.h" #import #import #import #import "ZLCWebView.h" #import//设置简单分享菜单样式 #import "logInViewController.h" #import "UserInfoModel.h" #import "eventActivityVController.h" #import "OrderAirportPayCancelView.h" #import "joinAllianceVController.h" @interface activityDetailVController () @property (nonatomic, strong) ZLCWebView *webView; @property(nonatomic,strong) JSContext *jsContext; @property(nonatomic,strong)UIButton *collectionBtn; @property(nonatomic,strong)UIButton *sendBtn; @property (strong, nonatomic) HttpRequestManger *sessionManager; @property(nonatomic,strong)NSString *collectionStaus; @property(nonatomic,strong)UserInfoModel *userInfoModel; @property (strong, nonatomic) OrderAirportPayCancelView *cancelView; @end @implementation activityDetailVController - (HttpRequestManger*) sessionManager{ if (!_sessionManager) { _sessionManager = [[HttpRequestManger alloc]init]; } return _sessionManager; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:YES]; [self loadSelectActivityStatus]; [self loadIsCollection]; } -(void)loadSelectActivityStatus{ kWeakSelf(self); NSMutableDictionary *parma = [NSMutableDictionary dictionary]; parma[@"id"] = weakself.newsId; self.sessionManager = [[HttpRequestManger alloc]init]; [self.sessionManager sendPostHttpRequestWithUrl:selectActivityStatus params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) { NSLog(@"%@",response); weakself.activityStatus =[NSString stringWithFormat:@"%@", response[@"activityStatus"]]; if ([weakself.activityStatus isEqualToString:@"0"]) { [weakself.sendBtn setTitle:@"活动报名" forState:UIControlStateNormal]; weakself.sendBtn.userInteractionEnabled = YES; }else{ [weakself.sendBtn setTitle:@"活动已结束" forState:UIControlStateNormal]; weakself.sendBtn.userInteractionEnabled = NO; } } failure:^(NSError *error) { NSLog(@"%@",error); }]; } -(void)loadIsCollection{ kWeakSelf(self); NSMutableDictionary *parma = [NSMutableDictionary dictionary]; parma[@"id"] = weakself.newsId; parma[@"type"] = @"1"; self.sessionManager = [[HttpRequestManger alloc]init]; [self.sessionManager sendPostHttpRequestWithUrl:isCollection params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) { weakself.collectionStaus = response[@"isCollected"]; if ([weakself.collectionStaus isEqualToString:@"1"]) { [weakself.collectionBtn setImage:[UIImage imageNamed:@"collectionIng"] forState:UIControlStateNormal]; [_collectionBtn setTitle:@"取消收藏" forState:UIControlStateNormal]; }else{ [weakself.collectionBtn setImage:[UIImage imageNamed:@"collectionNo"] forState:UIControlStateNormal]; [_collectionBtn setTitle:@"收藏" forState:UIControlStateNormal]; } } failure:^(NSError *error) { NSLog(@"%@",error); }]; } - (void)viewDidLoad { [super viewDidLoad]; [self.navigationView removeAllLeftButton]; self.navigationView.titleLabel.text = self.titleStr; self.navigationView.titleLabel.textColor = [UIColor whiteColor]; self.view.backgroundColor = [UIColor whiteColor]; kWeakSelf(self); [self.navigationView setNavigationBackgroundColor:[UIColor colorWithHexValue:0x3C915C]]; [self.navigationView addLeftButtonWithImage:[UIImage imageNamed:@"back_white"] clickCallBack:^(UIView *view) { [weakself.navigationController popViewControllerAnimated:YES]; }]; [self.navigationView addRightButtonWithImage:[UIImage imageNamed:@"share"] clickCallBack:^(UIView *view) { [weakself showShareView]; }]; UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, kGScreenHeight -50, kGScreenWidth, 50)]; bottomView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:bottomView]; UIView *btnView = [[UIView alloc]init]; btnView.backgroundColor = [UIColor whiteColor]; [bottomView addSubview:btnView]; [btnView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(kGScreenWidth -264, 50)); make.left.equalTo(bottomView.mas_left).offset(0); make.top.equalTo(bottomView.mas_top).offset(0); }]; _collectionBtn =[UIButton buttonWithType:UIButtonTypeCustom]; [_collectionBtn setImage:[UIImage imageNamed:@"collectionNo"] forState:UIControlStateNormal]; [_collectionBtn setTitle:@"收藏" forState:UIControlStateNormal]; _collectionBtn.titleLabel.size = CGSizeMake(30, 15); _collectionBtn.titleLabel.font = TextFont(12); [_collectionBtn setTitleColor:[UIColor colorWithHexValue:0x333333] forState:UIControlStateNormal]; [_collectionBtn setImageEdgeInsets:UIEdgeInsetsMake(-10, 10, 0, 0)]; [_collectionBtn setTitleEdgeInsets:UIEdgeInsetsMake(_collectionBtn.currentImage.size.height + 10, -_collectionBtn.currentImage.size.width, 0, 0)]; [_collectionBtn addTarget:self action:@selector(collectionClick:) forControlEvents:UIControlEventTouchUpInside]; [btnView addSubview:_collectionBtn]; [_collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(50, 50)); make.centerX.mas_equalTo(btnView.mas_centerX).offset(0); make.centerY.mas_equalTo(btnView.mas_centerY).offset(0); }]; _sendBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // if ([self.activityStatus isEqualToString:@"0"]) { // // [_sendBtn setTitle:@"活动报名" forState:UIControlStateNormal]; // _sendBtn.userInteractionEnabled = YES; // }else{ // // [_sendBtn setTitle:@"活动已结束" forState:UIControlStateNormal]; // // _sendBtn.userInteractionEnabled = NO; // } _sendBtn.titleLabel.size = CGSizeMake(30, 15); _sendBtn.titleLabel.font = TextFont(15); [_sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _sendBtn.backgroundColor = [UIColor colorWithHexValue:0x3C915C]; [_sendBtn addTarget:self action:@selector(OrderToClick:) forControlEvents:UIControlEventTouchUpInside]; [bottomView addSubview:_sendBtn]; [_sendBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(264, 50)); make.left.equalTo(btnView.mas_right).offset(0); make.top.equalTo(bottomView.mas_top).offset(0); }]; self.webView = [[ZLCWebView alloc] initWithFrame:CGRectMake(0,isFullScreen?35:20, kGScreenWidth,isFullScreen?kGScreenHeight -35 -90: kGScreenHeight-20 -70)]; if (@available(iOS 11.0, *)) { self.webView.wkWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; }else { self.automaticallyAdjustsScrollViewInsets = NO; } self.webView.delegate = self; [self.view addSubview:self.webView]; [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlStr]]]; self.webView.wkWebView.scrollView.backgroundColor = [UIColor whiteColor]; self.webView.wkWebView.scrollView.showsVerticalScrollIndicator = NO; // self.webView.wkWebView.scrollView.showsHorizontalScrollIndicator = NO; _webView.wkWebView.scrollView.bounces = NO; // Do any additional setup after loading the view. } -(void)collectionClick:(UIButton *)sender{ if (!IsStrEmpty([DKGlobal sharedInstance].token)) { kWeakSelf(self); if (![weakself.collectionStaus isEqualToString:@"0"]) { NSMutableDictionary *parma = [NSMutableDictionary dictionary]; parma[@"id"] = weakself.newsId; parma[@"collectType"] = @"1"; self.sessionManager = [[HttpRequestManger alloc]init]; [self.sessionManager sendPostHttpRequestWithUrl:cancelCollection params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) { [MBProgressHUD showSuccess:@"取消收藏"]; weakself.collectionStaus = @"0"; [weakself.collectionBtn setImage:[UIImage imageNamed:@"collectionNo"] forState:UIControlStateNormal]; [_collectionBtn setTitle:@"收藏" forState:UIControlStateNormal]; } failure:^(NSError *error) { NSLog(@"%@",error); }]; }else{ kWeakSelf(self); NSMutableDictionary *parma = [NSMutableDictionary dictionary]; parma[@"id"] = weakself.newsId; parma[@"type"] = @"1"; self.sessionManager = [[HttpRequestManger alloc]init]; [self.sessionManager sendPostHttpRequestWithUrl:collectionNews params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) { [MBProgressHUD showSuccess:@"收藏成功"]; weakself.collectionStaus = @"1"; [weakself.collectionBtn setImage:[UIImage imageNamed:@"collectionIng"] forState:UIControlStateNormal]; [_collectionBtn setTitle:@"取消收藏" forState:UIControlStateNormal]; } failure:^(NSError *error) { NSLog(@"%@",error); }]; } }else{ [MBProgressHUD showError:@"请先登录"]; logInViewController *loginVC = [[logInViewController alloc]init]; [self.navigationController pushViewController:loginVC animated:YES]; } } - (void)zlcwebViewDidStartLoad:(ZLCWebView *)webview { [SVProgressHUD show]; NSLog(@"页面开始加载"); } - (void)zlcwebView:(ZLCWebView *)webview shouldStartLoadWithURL:(NSURL *)URL { NSLog(@"截取到URL:%@",URL); } - (void)zlcwebView:(ZLCWebView *)webview didFinishLoadingURL:(NSURL *)URL { [SVProgressHUD dismiss]; NSLog(@"页面加载完成%@",URL); } - (void)zlcwebView:(ZLCWebView *)webview didFailToLoadURL:(NSURL *)URL error:(NSError *)error { [SVProgressHUD dismiss]; NSLog(@"加载出现错误"); } //} -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:YES]; _webView = nil; [self cleanCacheAndCookie]; } /**清除缓存和cookie*/ - (void)cleanCacheAndCookie{ //清除cookies NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [storage cookies]){ [storage deleteCookie:cookie]; } //清除UIWebView的缓存 [[NSURLCache sharedURLCache] removeAllCachedResponses]; NSURLCache * cache = [NSURLCache sharedURLCache]; [cache removeAllCachedResponses]; [cache setDiskCapacity:0]; [cache setMemoryCapacity:0]; } -(void)showShareView{ NSArray *arr =@[[UIImage imageNamed:@"projectItem"]]; if (IsStrEmpty(_shareTitle)) { _shareTitle = @""; } if (arr) { NSMutableDictionary *shareParams = [NSMutableDictionary dictionary]; [shareParams SSDKSetupShareParamsByText:@"中经联盟" images:arr url:[NSURL URLWithString:[NSString stringWithFormat:@"%@",_shareUrl]] title:_shareTitle type:SSDKContentTypeAuto]; // [shareParams SSDKEnableUseClientShare]; [ShareSDK showShareActionSheet:nil //要显示菜单的视图, iPad版中此参数作为弹出菜单的参照视图,只有传这个才可以弹出我们的分享菜单,可以传分享的按钮对象或者自己创建小的view 对象,iPhone可以传nil不会影响 items:@[@(SSDKPlatformSubTypeWechatSession),@(SSDKPlatformSubTypeWechatTimeline)] shareParams:shareParams onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) { switch (platformType) { case SSDKPlatformSubTypeWechatSession: break; case SSDKPlatformSubTypeWechatTimeline: break; default: break; } switch (state) { case SSDKResponseStateSuccess: // { // UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功" // message:nil // delegate:nil // cancelButtonTitle:@"确定" // otherButtonTitles:nil]; // [alertView show]; break; // } case SSDKResponseStateFail: // { // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败" // message:nil // delegate:nil // cancelButtonTitle:@"OK" // otherButtonTitles:nil, nil]; // [alert show]; // // // NSLog(@"%@",error); break; // } default: break; } } ]; } } -(void)OrderToClick:(UIButton *)sender{ if (![DKGlobal sharedInstance].token ) { logInViewController *control = [[logInViewController alloc] init]; [self.navigationController pushViewController:control animated:YES]; }else{ [self isSpeicialStatus]; } } - (OrderAirportPayCancelView*)cancelView{ WS(weakSelf); if (!_cancelView) { _cancelView = [[NSBundle mainBundle]loadNibNamed:@"OrderAirportPayCancelView" owner:self options:nil].firstObject; _cancelView.frame = self.view.bounds; // _cancelView.isFromOrder = self.isFromOrder; _cancelView.tipLabel.hidden = YES; _cancelView.contentLabel.hidden = YES; _cancelView.titleLabel.text = @"您还未加入会员"; _cancelView.titleLabelTop.constant = 35; [_cancelView.rightBtn setBackgroundColor:[UIColor colorWithHexValue:0x3C915C]]; [_cancelView.leftBtn setTitle:@"继续报名" forState:UIControlStateNormal]; [_cancelView.rightBtn setTitle:@"加入会员" forState:UIControlStateNormal]; _cancelView.leftBtnCallback = ^{ eventActivityVController *control = [[eventActivityVController alloc] init]; control.activityId = weakSelf.newsId; [weakSelf.navigationController pushViewController:control animated:YES]; // [weakSelf.cancelView removeFromSuperview]; }; _cancelView.rightBtnCallback = ^{ joinAllianceVController *joinVC = [[joinAllianceVController alloc]init]; joinVC.phone = weakSelf.userInfoModel.phone; joinVC.model = weakSelf.userInfoModel; [weakSelf.navigationController pushViewController:joinVC animated:YES]; }; } return _cancelView; } -(void)isSpeicialStatus{ kWeakSelf(self); [ProgressHUD show]; _sessionManager =[[HttpRequestManger alloc]init]; [_sessionManager sendPostHttpRequestWithUrl:getMemberInfo params:nil bodyBlock:nil progress:nil success:^(NSDictionary *response) { [ProgressHUD hide]; NSLog(@"%@",response); NSDictionary *dic = [response objectForKeySafely:@"memberInfo"]; weakself.userInfoModel = [UserInfoModel mj_objectWithKeyValues:dic]; if ([weakself.userInfoModel.level isEqualToString:@"1"]||[weakself.userInfoModel.level isEqualToString:@"2"]||[weakself.userInfoModel.level isEqualToString:@"3"]){ //是会员的话 走 loadActivityStatus 方法 [self loadActivityStatus]; }else{ //弹窗 UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; [window addSubview: weakself.cancelView]; } } failure:^(NSError *error) { NSLog(@"%@",error); [ProgressHUD hide]; }]; } -(void)loadActivityStatus{ WS(weakSelf) [ProgressHUD show]; _sessionManager = [[HttpRequestManger alloc] init]; NSMutableDictionary *parma = [NSMutableDictionary dictionary]; parma[@"id"] = weakSelf.newsId; [self.sessionManager sendPostHttpRequestWithUrl:ActivityStatus params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) { [ProgressHUD hide]; NSLog(@"%@",response); NSString *flag = [NSString stringWithFormat:@"%@",response[@"flag"]]; if ([flag isEqualToString:@"0"]) { eventActivityVController *control = [[eventActivityVController alloc] init]; control.activityId = weakSelf.newsId; [self.navigationController pushViewController:control animated:YES]; }else if([flag isEqualToString:@"1"]){ [ToastView showToast:@"已报名该活动,不能重复报名"]; }else{ [ToastView showToast:@"相同时间段的活动只能报名一场"]; } } failure:^(NSError *error) { [ProgressHUD hide]; NSLog(@"%@",error); }]; } - (void)dealloc { if (_sessionManager) { [_sessionManager cancelAllTask]; } DebugLog(@"%@没有造成循环引用", [self class]); } - (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