| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- //
- // HJMyIntegralExchangeGiftDetailViewController.m
- // HappyJob
- //
- // Created by 张晓光 on 2019/9/7.
- // Copyright © 2019 Bob. All rights reserved.
- //
- #import "HJMyIntegralExchangeGiftDetailVC.h"
- #import <WebKit/WebKit.h>
- #import "HJMyIntegralExchangeGiftDetailHeaderView.h"
- #import "HJMyIntegralExchangeDetailView.h"
- #import "HJMyIntegralExchangePayViewController.h"//支付
- #import "HJMyIntegralExchangeGiftDetailAPI.h"
- #import "HJMyIntegralExchangeGiftAPI.h"
- #import "HJMyIntergralExchangeGiftDetailModel.h"
- @interface HJMyIntegralExchangeGiftDetailVC ()
- <
- FBScrollLayoutViewDelegate,
- UIGestureRecognizerDelegate,
- WKNavigationDelegate,
- FBAPIManagerDelegate,
- FBAPIManagerInterceptor
- >
- @property (nonatomic, strong) FBScrollLayoutView *scrollLayoutView;
- @property (nonatomic, strong) HJMyIntegralExchangeGiftDetailHeaderView *headerView;
- @property (nonatomic, strong) HJMyIntegralExchangeDetailView *detailView;
- @property (nonatomic, strong) UIButton *exchangeBtn;
- @property (nonatomic, strong) HJConfirmPanelInputView *inputPhoneView;
- @property (nonatomic, strong) HJMyIntegralExchangeGiftDetailAPI *detailAPI;//详情
- @property (nonatomic, strong) HJMyIntegralExchangeGiftAPI *exchangeGiftAPI;//兑换积分
- @property (nonatomic, strong) NSDictionary *detailDict;
- @end
- @implementation HJMyIntegralExchangeGiftDetailVC
- - (void)dealloc {
-
- [self.detailView.webView removeObserver:self forKeyPath:@"estimatedProgress"];
- }
- - (void)viewWillAppear:(BOOL)animated {
-
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:NO animated:animated];
- self.navigationController.interactivePopGestureRecognizer.delegate = self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title = @"兑好礼";
- self.view.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:self.scrollLayoutView];
- [self.scrollLayoutView.contentView addSubview:self.headerView];
- [self.scrollLayoutView.contentView addSubview:self.detailView];
- [self.scrollLayoutView.footerView addSubview:self.exchangeBtn];
- [self.scrollLayoutView makeConstraints];
-
- self.detailAPI.mpCompaignsRewardSettingId = self.ID;
- [self.detailAPI start];
-
- self.detailView.webView.navigationDelegate = self;
- [self.detailView.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
- [self.detailView.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",@"https://hpjobtest.oss-cn-shanghai.aliyuncs.com/uploadfiles/banner/test/2019/6/8819934777436913/66c3e0eb86081e65ee416e0d6042584c.jpg"]]]];
-
- // DDLogDebug(@"--------------------");
-
- }
- #pragma mark - FBScrollLayoutViewDelegate
- - (void)scrollLayoutViewMakeConstraints:(FBScrollLayoutView *)scrollLayoutView {
-
- [scrollLayoutView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.view);
- }];
- }
- - (void)subviewsMakeConstraintsInScrollLayoutView:(FBScrollLayoutView *)scrollLayoutView contentView:(UIView *)contentView {
-
- [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.top.equalTo(contentView.mas_top).offset(0);
- make.left.right.equalTo(contentView);
- }];
- [self.detailView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.top.equalTo(self.headerView.mas_bottom).offset(0);
- make.left.right.equalTo(contentView);
- }];
-
- [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.bottom.equalTo(self.detailView.mas_bottom).with.offset(0);
- }];
- }
- - (void)subviewsMakeConstraintsInScrollLayoutView:(FBScrollLayoutView *)scrollLayoutView footerView:(UIView *)footerView {
-
- [footerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(64);
- }];
- [self.exchangeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.edges.equalTo(footerView).with.insets(UIEdgeInsetsMake(10, 15, 10, 15));
- }];
- }
- #pragma mark - FBAPIManagerInterceptor
- - (BOOL)manager:(FBBaseAPIManager *)manager shouldStartCallAPIWithParams:(NSDictionary *)params {
-
- [self.view fb_showLoading];
- return YES;
- }
- - (void)managerShouldFinishCallAPI:(FBBaseAPIManager *)manager {
-
- [self.view fb_dismiss];
- }
- #pragma mark - FBAPIManagerDelegate
- - (void)managerCallAPIDidSuccess:(FBBaseAPIManager *)manager {
-
- if (manager == self.detailAPI)
- {
- self.detailDict = [manager fetchDataWithBox:nil];
- [self.headerView configureHJMyIntegralExchangeGiftDetailHeaderViewDict:self.detailDict];
- HJMyIntergralExchangeGiftDetailModel *model = [HJMyIntergralExchangeGiftDetailModel yy_modelWithDictionary:self.detailDict[@"data"]];
- if ([model.mpCompaignsRewardSettingAPI.rewardNumber isEqualToString:model.mpCompaignsRewardSettingAPI.exchangeRewardNum])
- {
- self.exchangeBtn.enabled = NO;
- }
- }
- if (manager == self.exchangeGiftAPI)
- {
- [self.view fb_showSuccessWithStatus:@"兑换成功"];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1*NSEC_PER_SEC)),dispatch_get_main_queue(), ^{
-
- [self.navigationController popViewControllerAnimated:YES];
- [[NSNotificationCenter defaultCenter] postNotificationName:HJIntegralChangeNotification object:nil];
- });
- }
- }
- - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager {
-
- FBAPIManagerErrorType type = manager.errorType;
-
- if (type == FBAPIManagerErrorTypeNoContent)
- {
- id fetchData = [manager fetchDataWithBox:nil];
- if ([fetchData isKindOfClass:[NSDictionary class]])
- {
- [self.view fb_showFailureWithStatus:fetchData[@"errmsg"]];
- }
- }
- else
- {
- [self.view fb_showFailureWithStatus:manager.errorMessage];
- }
- }
- #pragma mark - WKwebVIew代理
- -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
-
- if (self.detailView.webView.estimatedProgress < 1.0)
- {
- return;
- }
- //完全加载后获取webview的高度
- NSString *js = @"document.body.scrollHeight";
- [self.detailView.webView evaluateJavaScript:js completionHandler:^(id _Nullable height, NSError * _Nullable error) {
-
- CGFloat documentHeight = [height floatValue];
- [self.detailView.webView mas_updateConstraints:^(MASConstraintMaker *make) {
-
- make.height.mas_equalTo(documentHeight);
- }];
- }];
-
- }
- - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
- //修改字体大小 300%
- [ webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'" completionHandler:nil];
-
- }
- #pragma mark - event response
- - (void)exchangeButtonClick:(UIButton *)btn {
-
- HJMyIntergralExchangeGiftListModel *model = [HJMyIntergralExchangeGiftListModel yy_modelWithDictionary:self.detailDict[@"data"][@"mpCompaignsRewardSettingAPI"]];
-
- if ([model.money floatValue] == 0)
- {//不需要支付的
- self.inputPhoneView = [[HJConfirmPanelInputView alloc]init];
- self.inputPhoneView.titleLabel.text = @"请留下您的联系方式";
- self.inputPhoneView.inputTF.keyboardType = UIKeyboardTypeNumberPad;
- [self.inputPhoneView.confirmButton setTitle:@"好的" forState:UIControlStateNormal];
- [self.inputPhoneView.confirmButton addTarget:self action:@selector(confirmButtonClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.inputPhoneView ShowConfirmPanelInputView];
- self.exchangeGiftAPI.mpCompaignsRewardSettingId = model.ID;
- }
- else
- {
- HJMyIntegralExchangePayViewController *vc = [[HJMyIntegralExchangePayViewController alloc]init];
- [self.navigationController pushViewController:vc animated:YES];
- }
- }
- - (void)confirmButtonClick:(UIButton *)btn {
-
- if (self.inputPhoneView.inputTF.text.length > 0)
- {
- self.exchangeGiftAPI.phone = self.inputPhoneView.inputTF.text;
- [self.exchangeGiftAPI start];
- }
- }
- #pragma mark - setter and getter
- - (FBScrollLayoutView *)scrollLayoutView {
-
- if (_scrollLayoutView == nil)
- {
- _scrollLayoutView = [[FBScrollLayoutView alloc] init];
- _scrollLayoutView.backgroundColor = COLOR_GRAYFA5;
- _scrollLayoutView.delegate = self;
- // 去除顶部空白
- if (@available(iOS 11.0, *))
- {
- _scrollLayoutView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- else
- {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- }
- return _scrollLayoutView;
- }
- - (HJMyIntegralExchangeGiftDetailHeaderView *)headerView {
-
- if (_headerView == nil)
- {
- _headerView = [[HJMyIntegralExchangeGiftDetailHeaderView alloc]init];
- }
- return _headerView;
- }
- - (HJMyIntegralExchangeDetailView *)detailView {
-
- if (_detailView == nil)
- {
- _detailView = [[HJMyIntegralExchangeDetailView alloc]init];
- }
- return _detailView;
- }
- - (UIButton *)exchangeBtn {
-
- if (_exchangeBtn == nil)
- {
- _exchangeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _exchangeBtn.titleLabel.font = [UIFont boldSystemFontOfSize:17];
- [_exchangeBtn setBackgroundImage:[UIImage imageNamed:@"button_bg"] forState:UIControlStateNormal];
- [_exchangeBtn setBackgroundImage:[UIImage imageNamed:@"button_bg_gray"] forState:UIControlStateDisabled];
- [_exchangeBtn setTitle:@"立即兑换" forState:UIControlStateNormal];
- [_exchangeBtn setTitle:@"已兑完" forState:UIControlStateDisabled];
- [_exchangeBtn addTarget:self action:@selector(exchangeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _exchangeBtn;
- }
- - (HJMyIntegralExchangeGiftDetailAPI *)detailAPI {
-
- if (_detailAPI == nil)
- {
- _detailAPI = [[HJMyIntegralExchangeGiftDetailAPI alloc]init];
- _detailAPI.APIManagerDelegate = self;
- _detailAPI.APIManagerInterceptor = self;
- }
- return _detailAPI;
- }
- - (HJMyIntegralExchangeGiftAPI *)exchangeGiftAPI {
-
- if (_exchangeGiftAPI == nil)
- {
- _exchangeGiftAPI = [[HJMyIntegralExchangeGiftAPI alloc]init];
- _exchangeGiftAPI.APIManagerDelegate = self;
- _exchangeGiftAPI.APIManagerInterceptor = self;
- }
- return _exchangeGiftAPI;
- }
- /*
- #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
|