activityDetailVController.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. //
  2. // activityDetailVController.m
  3. // ZhongJingLianMeng
  4. //
  5. // Created by youke on 2018/12/6.
  6. // Copyright © 2018 youke. All rights reserved.
  7. //
  8. #import "activityDetailVController.h"
  9. #import "UIAlertController+LY.h"
  10. #import <JavaScriptCore/JavaScriptCore.h>
  11. #import <ShareSDK/ShareSDK.h>
  12. #import <ShareSDKUI/ShareSDK+SSUI.h>
  13. #import "ZLCWebView.h"
  14. #import<ShareSDKUI/SSUIShareActionSheetStyle.h>//设置简单分享菜单样式
  15. #import "logInViewController.h"
  16. #import "UserInfoModel.h"
  17. #import "eventActivityVController.h"
  18. #import "OrderAirportPayCancelView.h"
  19. #import "joinAllianceVController.h"
  20. @interface activityDetailVController ()<ZLCWebViewDelegate>
  21. @property (nonatomic, strong) ZLCWebView *webView;
  22. @property(nonatomic,strong) JSContext *jsContext;
  23. @property(nonatomic,strong)UIButton *collectionBtn;
  24. @property(nonatomic,strong)UIButton *sendBtn;
  25. @property (strong, nonatomic) HttpRequestManger *sessionManager;
  26. @property(nonatomic,strong)NSString *collectionStaus;
  27. @property(nonatomic,strong)UserInfoModel *userInfoModel;
  28. @property (strong, nonatomic) OrderAirportPayCancelView *cancelView;
  29. @end
  30. @implementation activityDetailVController
  31. - (HttpRequestManger*) sessionManager{
  32. if (!_sessionManager) {
  33. _sessionManager = [[HttpRequestManger alloc]init];
  34. }
  35. return _sessionManager;
  36. }
  37. -(void)viewWillAppear:(BOOL)animated{
  38. [super viewWillAppear:YES];
  39. [self loadSelectActivityStatus];
  40. [self loadIsCollection];
  41. }
  42. -(void)loadSelectActivityStatus{
  43. kWeakSelf(self);
  44. NSMutableDictionary *parma = [NSMutableDictionary dictionary];
  45. parma[@"id"] = weakself.newsId;
  46. self.sessionManager = [[HttpRequestManger alloc]init];
  47. [self.sessionManager sendPostHttpRequestWithUrl:selectActivityStatus params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) {
  48. NSLog(@"%@",response);
  49. weakself.activityStatus =[NSString stringWithFormat:@"%@", response[@"activityStatus"]];
  50. if ([weakself.activityStatus isEqualToString:@"0"]) {
  51. [weakself.sendBtn setTitle:@"活动报名" forState:UIControlStateNormal];
  52. weakself.sendBtn.userInteractionEnabled = YES;
  53. }else{
  54. [weakself.sendBtn setTitle:@"活动已结束" forState:UIControlStateNormal];
  55. weakself.sendBtn.userInteractionEnabled = NO;
  56. }
  57. } failure:^(NSError *error) {
  58. NSLog(@"%@",error);
  59. }];
  60. }
  61. -(void)loadIsCollection{
  62. kWeakSelf(self);
  63. NSMutableDictionary *parma = [NSMutableDictionary dictionary];
  64. parma[@"id"] = weakself.newsId;
  65. parma[@"type"] = @"1";
  66. self.sessionManager = [[HttpRequestManger alloc]init];
  67. [self.sessionManager sendPostHttpRequestWithUrl:isCollection params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) {
  68. weakself.collectionStaus = response[@"isCollected"];
  69. if ([weakself.collectionStaus isEqualToString:@"1"]) {
  70. [weakself.collectionBtn setImage:[UIImage imageNamed:@"collectionIng"] forState:UIControlStateNormal];
  71. [_collectionBtn setTitle:@"取消收藏" forState:UIControlStateNormal];
  72. }else{
  73. [weakself.collectionBtn setImage:[UIImage imageNamed:@"collectionNo"] forState:UIControlStateNormal];
  74. [_collectionBtn setTitle:@"收藏" forState:UIControlStateNormal];
  75. }
  76. } failure:^(NSError *error) {
  77. NSLog(@"%@",error);
  78. }];
  79. }
  80. - (void)viewDidLoad {
  81. [super viewDidLoad];
  82. [self.navigationView removeAllLeftButton];
  83. self.navigationView.titleLabel.text = self.titleStr;
  84. self.navigationView.titleLabel.textColor = [UIColor whiteColor];
  85. self.view.backgroundColor = [UIColor whiteColor];
  86. kWeakSelf(self);
  87. [self.navigationView setNavigationBackgroundColor:[UIColor colorWithHexValue:0x3C915C]];
  88. [self.navigationView addLeftButtonWithImage:[UIImage imageNamed:@"back_white"] clickCallBack:^(UIView *view) {
  89. [weakself.navigationController popViewControllerAnimated:YES];
  90. }];
  91. [self.navigationView addRightButtonWithImage:[UIImage imageNamed:@"share"] clickCallBack:^(UIView *view) {
  92. [weakself showShareView];
  93. }];
  94. UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, kGScreenHeight -50, kGScreenWidth, 50)];
  95. bottomView.backgroundColor = [UIColor whiteColor];
  96. [self.view addSubview:bottomView];
  97. UIView *btnView = [[UIView alloc]init];
  98. btnView.backgroundColor = [UIColor whiteColor];
  99. [bottomView addSubview:btnView];
  100. [btnView mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.size.mas_equalTo(CGSizeMake(kGScreenWidth -264, 50));
  102. make.left.equalTo(bottomView.mas_left).offset(0);
  103. make.top.equalTo(bottomView.mas_top).offset(0);
  104. }];
  105. _collectionBtn =[UIButton buttonWithType:UIButtonTypeCustom];
  106. [_collectionBtn setImage:[UIImage imageNamed:@"collectionNo"] forState:UIControlStateNormal];
  107. [_collectionBtn setTitle:@"收藏" forState:UIControlStateNormal];
  108. _collectionBtn.titleLabel.size = CGSizeMake(30, 15);
  109. _collectionBtn.titleLabel.font = TextFont(12);
  110. [_collectionBtn setTitleColor:[UIColor colorWithHexValue:0x333333] forState:UIControlStateNormal];
  111. [_collectionBtn setImageEdgeInsets:UIEdgeInsetsMake(-10, 10, 0, 0)];
  112. [_collectionBtn setTitleEdgeInsets:UIEdgeInsetsMake(_collectionBtn.currentImage.size.height + 10, -_collectionBtn.currentImage.size.width, 0, 0)];
  113. [_collectionBtn addTarget:self action:@selector(collectionClick:) forControlEvents:UIControlEventTouchUpInside];
  114. [btnView addSubview:_collectionBtn];
  115. [_collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.size.mas_equalTo(CGSizeMake(50, 50));
  117. make.centerX.mas_equalTo(btnView.mas_centerX).offset(0);
  118. make.centerY.mas_equalTo(btnView.mas_centerY).offset(0);
  119. }];
  120. _sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  121. // if ([self.activityStatus isEqualToString:@"0"]) {
  122. //
  123. // [_sendBtn setTitle:@"活动报名" forState:UIControlStateNormal];
  124. // _sendBtn.userInteractionEnabled = YES;
  125. // }else{
  126. //
  127. // [_sendBtn setTitle:@"活动已结束" forState:UIControlStateNormal];
  128. //
  129. // _sendBtn.userInteractionEnabled = NO;
  130. // }
  131. _sendBtn.titleLabel.size = CGSizeMake(30, 15);
  132. _sendBtn.titleLabel.font = TextFont(15);
  133. [_sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  134. _sendBtn.backgroundColor = [UIColor colorWithHexValue:0x3C915C];
  135. [_sendBtn addTarget:self action:@selector(OrderToClick:) forControlEvents:UIControlEventTouchUpInside];
  136. [bottomView addSubview:_sendBtn];
  137. [_sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.size.mas_equalTo(CGSizeMake(264, 50));
  139. make.left.equalTo(btnView.mas_right).offset(0);
  140. make.top.equalTo(bottomView.mas_top).offset(0);
  141. }];
  142. self.webView = [[ZLCWebView alloc] initWithFrame:CGRectMake(0,isFullScreen?35:20, kGScreenWidth,isFullScreen?kGScreenHeight -35 -90: kGScreenHeight-20 -70)];
  143. if (@available(iOS 11.0, *)) {
  144. self.webView.wkWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  145. }else {
  146. self.automaticallyAdjustsScrollViewInsets = NO;
  147. }
  148. self.webView.delegate = self;
  149. [self.view addSubview:self.webView];
  150. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlStr]]];
  151. self.webView.wkWebView.scrollView.backgroundColor = [UIColor whiteColor];
  152. self.webView.wkWebView.scrollView.showsVerticalScrollIndicator = NO;
  153. // self.webView.wkWebView.scrollView.showsHorizontalScrollIndicator = NO;
  154. _webView.wkWebView.scrollView.bounces = NO;
  155. // Do any additional setup after loading the view.
  156. }
  157. -(void)collectionClick:(UIButton *)sender{
  158. if (!IsStrEmpty([DKGlobal sharedInstance].token)) {
  159. kWeakSelf(self);
  160. if (![weakself.collectionStaus isEqualToString:@"0"]) {
  161. NSMutableDictionary *parma = [NSMutableDictionary dictionary];
  162. parma[@"id"] = weakself.newsId;
  163. parma[@"collectType"] = @"1";
  164. self.sessionManager = [[HttpRequestManger alloc]init];
  165. [self.sessionManager sendPostHttpRequestWithUrl:cancelCollection params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) {
  166. [MBProgressHUD showSuccess:@"取消收藏"];
  167. weakself.collectionStaus = @"0";
  168. [weakself.collectionBtn setImage:[UIImage imageNamed:@"collectionNo"] forState:UIControlStateNormal];
  169. [_collectionBtn setTitle:@"收藏" forState:UIControlStateNormal];
  170. } failure:^(NSError *error) {
  171. NSLog(@"%@",error);
  172. }];
  173. }else{
  174. kWeakSelf(self);
  175. NSMutableDictionary *parma = [NSMutableDictionary dictionary];
  176. parma[@"id"] = weakself.newsId;
  177. parma[@"type"] = @"1";
  178. self.sessionManager = [[HttpRequestManger alloc]init];
  179. [self.sessionManager sendPostHttpRequestWithUrl:collectionNews params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) {
  180. [MBProgressHUD showSuccess:@"收藏成功"];
  181. weakself.collectionStaus = @"1";
  182. [weakself.collectionBtn setImage:[UIImage imageNamed:@"collectionIng"] forState:UIControlStateNormal];
  183. [_collectionBtn setTitle:@"取消收藏" forState:UIControlStateNormal];
  184. } failure:^(NSError *error) {
  185. NSLog(@"%@",error);
  186. }];
  187. }
  188. }else{
  189. [MBProgressHUD showError:@"请先登录"];
  190. logInViewController *loginVC = [[logInViewController alloc]init];
  191. [self.navigationController pushViewController:loginVC animated:YES];
  192. }
  193. }
  194. - (void)zlcwebViewDidStartLoad:(ZLCWebView *)webview
  195. {
  196. [SVProgressHUD show];
  197. NSLog(@"页面开始加载");
  198. }
  199. - (void)zlcwebView:(ZLCWebView *)webview shouldStartLoadWithURL:(NSURL *)URL
  200. {
  201. NSLog(@"截取到URL:%@",URL);
  202. }
  203. - (void)zlcwebView:(ZLCWebView *)webview didFinishLoadingURL:(NSURL *)URL
  204. {
  205. [SVProgressHUD dismiss];
  206. NSLog(@"页面加载完成%@",URL);
  207. }
  208. - (void)zlcwebView:(ZLCWebView *)webview didFailToLoadURL:(NSURL *)URL error:(NSError *)error
  209. {
  210. [SVProgressHUD dismiss];
  211. NSLog(@"加载出现错误");
  212. }
  213. //}
  214. -(void)viewWillDisappear:(BOOL)animated{
  215. [super viewWillDisappear:YES];
  216. _webView = nil;
  217. [self cleanCacheAndCookie];
  218. }
  219. /**清除缓存和cookie*/
  220. - (void)cleanCacheAndCookie{
  221. //清除cookies
  222. NSHTTPCookie *cookie;
  223. NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  224. for (cookie in [storage cookies]){
  225. [storage deleteCookie:cookie];
  226. }
  227. //清除UIWebView的缓存
  228. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  229. NSURLCache * cache = [NSURLCache sharedURLCache];
  230. [cache removeAllCachedResponses];
  231. [cache setDiskCapacity:0];
  232. [cache setMemoryCapacity:0];
  233. }
  234. -(void)showShareView{
  235. NSArray *arr =@[[UIImage imageNamed:@"projectItem"]];
  236. if (IsStrEmpty(_shareTitle)) {
  237. _shareTitle = @"";
  238. }
  239. if (arr) {
  240. NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
  241. [shareParams SSDKSetupShareParamsByText:@"中经联盟"
  242. images:arr
  243. url:[NSURL URLWithString:[NSString stringWithFormat:@"%@",_shareUrl]]
  244. title:_shareTitle
  245. type:SSDKContentTypeAuto];
  246. // [shareParams SSDKEnableUseClientShare];
  247. [ShareSDK showShareActionSheet:nil //要显示菜单的视图, iPad版中此参数作为弹出菜单的参照视图,只有传这个才可以弹出我们的分享菜单,可以传分享的按钮对象或者自己创建小的view 对象,iPhone可以传nil不会影响
  248. items:@[@(SSDKPlatformSubTypeWechatSession),@(SSDKPlatformSubTypeWechatTimeline)]
  249. shareParams:shareParams
  250. onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
  251. switch (platformType) {
  252. case SSDKPlatformSubTypeWechatSession:
  253. break;
  254. case SSDKPlatformSubTypeWechatTimeline:
  255. break;
  256. default:
  257. break;
  258. }
  259. switch (state) {
  260. case SSDKResponseStateSuccess:
  261. // {
  262. // UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
  263. // message:nil
  264. // delegate:nil
  265. // cancelButtonTitle:@"确定"
  266. // otherButtonTitles:nil];
  267. // [alertView show];
  268. break;
  269. // }
  270. case SSDKResponseStateFail:
  271. // {
  272. // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
  273. // message:nil
  274. // delegate:nil
  275. // cancelButtonTitle:@"OK"
  276. // otherButtonTitles:nil, nil];
  277. // [alert show];
  278. //
  279. //
  280. // NSLog(@"%@",error);
  281. break;
  282. // }
  283. default:
  284. break;
  285. }
  286. }
  287. ];
  288. }
  289. }
  290. -(void)OrderToClick:(UIButton *)sender{
  291. if (![DKGlobal sharedInstance].token ) {
  292. logInViewController *control = [[logInViewController alloc] init];
  293. [self.navigationController pushViewController:control animated:YES];
  294. }else{
  295. [self isSpeicialStatus];
  296. }
  297. }
  298. - (OrderAirportPayCancelView*)cancelView{
  299. WS(weakSelf);
  300. if (!_cancelView) {
  301. _cancelView = [[NSBundle mainBundle]loadNibNamed:@"OrderAirportPayCancelView" owner:self options:nil].firstObject;
  302. _cancelView.frame = self.view.bounds;
  303. // _cancelView.isFromOrder = self.isFromOrder;
  304. _cancelView.tipLabel.hidden = YES;
  305. _cancelView.contentLabel.hidden = YES;
  306. _cancelView.titleLabel.text = @"您还未加入会员";
  307. _cancelView.titleLabelTop.constant = 35;
  308. [_cancelView.rightBtn setBackgroundColor:[UIColor colorWithHexValue:0x3C915C]];
  309. [_cancelView.leftBtn setTitle:@"继续报名" forState:UIControlStateNormal];
  310. [_cancelView.rightBtn setTitle:@"加入会员" forState:UIControlStateNormal];
  311. _cancelView.leftBtnCallback = ^{
  312. eventActivityVController *control = [[eventActivityVController alloc] init];
  313. control.activityId = weakSelf.newsId;
  314. [weakSelf.navigationController pushViewController:control animated:YES];
  315. // [weakSelf.cancelView removeFromSuperview];
  316. };
  317. _cancelView.rightBtnCallback = ^{
  318. joinAllianceVController *joinVC = [[joinAllianceVController alloc]init];
  319. joinVC.phone = weakSelf.userInfoModel.phone;
  320. joinVC.model = weakSelf.userInfoModel;
  321. [weakSelf.navigationController pushViewController:joinVC animated:YES];
  322. };
  323. }
  324. return _cancelView;
  325. }
  326. -(void)isSpeicialStatus{
  327. kWeakSelf(self);
  328. [ProgressHUD show];
  329. _sessionManager =[[HttpRequestManger alloc]init];
  330. [_sessionManager sendPostHttpRequestWithUrl:getMemberInfo params:nil bodyBlock:nil progress:nil success:^(NSDictionary *response) {
  331. [ProgressHUD hide];
  332. NSLog(@"%@",response);
  333. NSDictionary *dic = [response objectForKeySafely:@"memberInfo"];
  334. weakself.userInfoModel = [UserInfoModel mj_objectWithKeyValues:dic];
  335. if ([weakself.userInfoModel.level isEqualToString:@"1"]||[weakself.userInfoModel.level isEqualToString:@"2"]||[weakself.userInfoModel.level isEqualToString:@"3"]){
  336. //是会员的话 走 loadActivityStatus 方法
  337. [self loadActivityStatus];
  338. }else{
  339. //弹窗
  340. UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
  341. [window addSubview: weakself.cancelView];
  342. }
  343. } failure:^(NSError *error) {
  344. NSLog(@"%@",error);
  345. [ProgressHUD hide];
  346. }];
  347. }
  348. -(void)loadActivityStatus{
  349. WS(weakSelf)
  350. [ProgressHUD show];
  351. _sessionManager = [[HttpRequestManger alloc] init];
  352. NSMutableDictionary *parma = [NSMutableDictionary dictionary];
  353. parma[@"id"] = weakSelf.newsId;
  354. [self.sessionManager sendPostHttpRequestWithUrl:ActivityStatus params:parma bodyBlock:nil progress:nil success:^(NSDictionary *response) {
  355. [ProgressHUD hide];
  356. NSLog(@"%@",response);
  357. NSString *flag = [NSString stringWithFormat:@"%@",response[@"flag"]];
  358. if ([flag isEqualToString:@"0"]) {
  359. eventActivityVController *control = [[eventActivityVController alloc] init];
  360. control.activityId = weakSelf.newsId;
  361. [self.navigationController pushViewController:control animated:YES];
  362. }else if([flag isEqualToString:@"1"]){
  363. [ToastView showToast:@"已报名该活动,不能重复报名"];
  364. }else{
  365. [ToastView showToast:@"相同时间段的活动只能报名一场"];
  366. }
  367. } failure:^(NSError *error) {
  368. [ProgressHUD hide];
  369. NSLog(@"%@",error);
  370. }];
  371. }
  372. - (void)dealloc {
  373. if (_sessionManager) {
  374. [_sessionManager cancelAllTask];
  375. }
  376. DebugLog(@"%@没有造成循环引用", [self class]);
  377. }
  378. - (void)didReceiveMemoryWarning {
  379. [super didReceiveMemoryWarning];
  380. // Dispose of any resources that can be recreated.
  381. }
  382. /*
  383. #pragma mark - Navigation
  384. // In a storyboard-based application, you will often want to do a little preparation before navigation
  385. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  386. // Get the new view controller using [segue destinationViewController].
  387. // Pass the selected object to the new view controller.
  388. }
  389. */
  390. @end