HJMyIntegralExchangeGiftDetailVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. //
  2. // HJMyIntegralExchangeGiftDetailViewController.m
  3. // HappyJob
  4. //
  5. // Created by 张晓光 on 2019/9/7.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "HJMyIntegralExchangeGiftDetailVC.h"
  9. #import <WebKit/WebKit.h>
  10. #import "HJMyIntegralExchangeGiftDetailHeaderView.h"
  11. #import "HJMyIntegralExchangeDetailView.h"
  12. #import "HJMyIntegralExchangePayViewController.h"//支付
  13. #import "HJMyIntegralExchangeGiftDetailAPI.h"
  14. #import "HJMyIntegralExchangeGiftAPI.h"
  15. #import "HJMyIntergralExchangeGiftDetailModel.h"
  16. @interface HJMyIntegralExchangeGiftDetailVC ()
  17. <
  18. FBScrollLayoutViewDelegate,
  19. UIGestureRecognizerDelegate,
  20. WKNavigationDelegate,
  21. FBAPIManagerDelegate,
  22. FBAPIManagerInterceptor
  23. >
  24. @property (nonatomic, strong) FBScrollLayoutView *scrollLayoutView;
  25. @property (nonatomic, strong) HJMyIntegralExchangeGiftDetailHeaderView *headerView;
  26. @property (nonatomic, strong) HJMyIntegralExchangeDetailView *detailView;
  27. @property (nonatomic, strong) UIButton *exchangeBtn;
  28. @property (nonatomic, strong) HJConfirmPanelInputView *inputPhoneView;
  29. @property (nonatomic, strong) HJMyIntegralExchangeGiftDetailAPI *detailAPI;//详情
  30. @property (nonatomic, strong) HJMyIntegralExchangeGiftAPI *exchangeGiftAPI;//兑换积分
  31. @property (nonatomic, strong) NSDictionary *detailDict;
  32. @end
  33. @implementation HJMyIntegralExchangeGiftDetailVC
  34. - (void)dealloc {
  35. [self.detailView.webView removeObserver:self forKeyPath:@"estimatedProgress"];
  36. }
  37. - (void)viewWillAppear:(BOOL)animated {
  38. [super viewWillAppear:animated];
  39. [self.navigationController setNavigationBarHidden:NO animated:animated];
  40. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  41. }
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. self.navigationItem.title = @"兑好礼";
  45. self.view.backgroundColor = [UIColor whiteColor];
  46. [self.view addSubview:self.scrollLayoutView];
  47. [self.scrollLayoutView.contentView addSubview:self.headerView];
  48. [self.scrollLayoutView.contentView addSubview:self.detailView];
  49. [self.scrollLayoutView.footerView addSubview:self.exchangeBtn];
  50. [self.scrollLayoutView makeConstraints];
  51. self.detailAPI.mpCompaignsRewardSettingId = self.ID;
  52. [self.detailAPI start];
  53. self.detailView.webView.navigationDelegate = self;
  54. [self.detailView.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
  55. [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"]]]];
  56. // DDLogDebug(@"--------------------");
  57. }
  58. #pragma mark - FBScrollLayoutViewDelegate
  59. - (void)scrollLayoutViewMakeConstraints:(FBScrollLayoutView *)scrollLayoutView {
  60. [scrollLayoutView mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.edges.equalTo(self.view);
  62. }];
  63. }
  64. - (void)subviewsMakeConstraintsInScrollLayoutView:(FBScrollLayoutView *)scrollLayoutView contentView:(UIView *)contentView {
  65. [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.equalTo(contentView.mas_top).offset(0);
  67. make.left.right.equalTo(contentView);
  68. }];
  69. [self.detailView mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.top.equalTo(self.headerView.mas_bottom).offset(0);
  71. make.left.right.equalTo(contentView);
  72. }];
  73. [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.bottom.equalTo(self.detailView.mas_bottom).with.offset(0);
  75. }];
  76. }
  77. - (void)subviewsMakeConstraintsInScrollLayoutView:(FBScrollLayoutView *)scrollLayoutView footerView:(UIView *)footerView {
  78. [footerView mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.height.mas_equalTo(64);
  80. }];
  81. [self.exchangeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.edges.equalTo(footerView).with.insets(UIEdgeInsetsMake(10, 15, 10, 15));
  83. }];
  84. }
  85. #pragma mark - FBAPIManagerInterceptor
  86. - (BOOL)manager:(FBBaseAPIManager *)manager shouldStartCallAPIWithParams:(NSDictionary *)params {
  87. [self.view fb_showLoading];
  88. return YES;
  89. }
  90. - (void)managerShouldFinishCallAPI:(FBBaseAPIManager *)manager {
  91. [self.view fb_dismiss];
  92. }
  93. #pragma mark - FBAPIManagerDelegate
  94. - (void)managerCallAPIDidSuccess:(FBBaseAPIManager *)manager {
  95. if (manager == self.detailAPI)
  96. {
  97. self.detailDict = [manager fetchDataWithBox:nil];
  98. [self.headerView configureHJMyIntegralExchangeGiftDetailHeaderViewDict:self.detailDict];
  99. HJMyIntergralExchangeGiftDetailModel *model = [HJMyIntergralExchangeGiftDetailModel yy_modelWithDictionary:self.detailDict[@"data"]];
  100. if ([model.mpCompaignsRewardSettingAPI.rewardNumber isEqualToString:model.mpCompaignsRewardSettingAPI.exchangeRewardNum])
  101. {
  102. self.exchangeBtn.enabled = NO;
  103. }
  104. }
  105. if (manager == self.exchangeGiftAPI)
  106. {
  107. [self.view fb_showSuccessWithStatus:@"兑换成功"];
  108. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1*NSEC_PER_SEC)),dispatch_get_main_queue(), ^{
  109. [self.navigationController popViewControllerAnimated:YES];
  110. [[NSNotificationCenter defaultCenter] postNotificationName:HJIntegralChangeNotification object:nil];
  111. });
  112. }
  113. }
  114. - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager {
  115. FBAPIManagerErrorType type = manager.errorType;
  116. if (type == FBAPIManagerErrorTypeNoContent)
  117. {
  118. id fetchData = [manager fetchDataWithBox:nil];
  119. if ([fetchData isKindOfClass:[NSDictionary class]])
  120. {
  121. [self.view fb_showFailureWithStatus:fetchData[@"errmsg"]];
  122. }
  123. }
  124. else
  125. {
  126. [self.view fb_showFailureWithStatus:manager.errorMessage];
  127. }
  128. }
  129. #pragma mark - WKwebVIew代理
  130. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
  131. if (self.detailView.webView.estimatedProgress < 1.0)
  132. {
  133. return;
  134. }
  135. //完全加载后获取webview的高度
  136. NSString *js = @"document.body.scrollHeight";
  137. [self.detailView.webView evaluateJavaScript:js completionHandler:^(id _Nullable height, NSError * _Nullable error) {
  138. CGFloat documentHeight = [height floatValue];
  139. [self.detailView.webView mas_updateConstraints:^(MASConstraintMaker *make) {
  140. make.height.mas_equalTo(documentHeight);
  141. }];
  142. }];
  143. }
  144. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
  145. //修改字体大小 300%
  146. [ webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'" completionHandler:nil];
  147. }
  148. #pragma mark - event response
  149. - (void)exchangeButtonClick:(UIButton *)btn {
  150. HJMyIntergralExchangeGiftListModel *model = [HJMyIntergralExchangeGiftListModel yy_modelWithDictionary:self.detailDict[@"data"][@"mpCompaignsRewardSettingAPI"]];
  151. if ([model.money floatValue] == 0)
  152. {//不需要支付的
  153. self.inputPhoneView = [[HJConfirmPanelInputView alloc]init];
  154. self.inputPhoneView.titleLabel.text = @"请留下您的联系方式";
  155. self.inputPhoneView.inputTF.keyboardType = UIKeyboardTypeNumberPad;
  156. [self.inputPhoneView.confirmButton setTitle:@"好的" forState:UIControlStateNormal];
  157. [self.inputPhoneView.confirmButton addTarget:self action:@selector(confirmButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  158. [self.inputPhoneView ShowConfirmPanelInputView];
  159. self.exchangeGiftAPI.mpCompaignsRewardSettingId = model.ID;
  160. }
  161. else
  162. {
  163. HJMyIntegralExchangePayViewController *vc = [[HJMyIntegralExchangePayViewController alloc]init];
  164. [self.navigationController pushViewController:vc animated:YES];
  165. }
  166. }
  167. - (void)confirmButtonClick:(UIButton *)btn {
  168. if (self.inputPhoneView.inputTF.text.length > 0)
  169. {
  170. self.exchangeGiftAPI.phone = self.inputPhoneView.inputTF.text;
  171. [self.exchangeGiftAPI start];
  172. }
  173. }
  174. #pragma mark - setter and getter
  175. - (FBScrollLayoutView *)scrollLayoutView {
  176. if (_scrollLayoutView == nil)
  177. {
  178. _scrollLayoutView = [[FBScrollLayoutView alloc] init];
  179. _scrollLayoutView.backgroundColor = COLOR_GRAYFA5;
  180. _scrollLayoutView.delegate = self;
  181. // 去除顶部空白
  182. if (@available(iOS 11.0, *))
  183. {
  184. _scrollLayoutView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  185. }
  186. else
  187. {
  188. self.automaticallyAdjustsScrollViewInsets = NO;
  189. }
  190. }
  191. return _scrollLayoutView;
  192. }
  193. - (HJMyIntegralExchangeGiftDetailHeaderView *)headerView {
  194. if (_headerView == nil)
  195. {
  196. _headerView = [[HJMyIntegralExchangeGiftDetailHeaderView alloc]init];
  197. }
  198. return _headerView;
  199. }
  200. - (HJMyIntegralExchangeDetailView *)detailView {
  201. if (_detailView == nil)
  202. {
  203. _detailView = [[HJMyIntegralExchangeDetailView alloc]init];
  204. }
  205. return _detailView;
  206. }
  207. - (UIButton *)exchangeBtn {
  208. if (_exchangeBtn == nil)
  209. {
  210. _exchangeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  211. _exchangeBtn.titleLabel.font = [UIFont boldSystemFontOfSize:17];
  212. [_exchangeBtn setBackgroundImage:[UIImage imageNamed:@"button_bg"] forState:UIControlStateNormal];
  213. [_exchangeBtn setBackgroundImage:[UIImage imageNamed:@"button_bg_gray"] forState:UIControlStateDisabled];
  214. [_exchangeBtn setTitle:@"立即兑换" forState:UIControlStateNormal];
  215. [_exchangeBtn setTitle:@"已兑完" forState:UIControlStateDisabled];
  216. [_exchangeBtn addTarget:self action:@selector(exchangeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  217. }
  218. return _exchangeBtn;
  219. }
  220. - (HJMyIntegralExchangeGiftDetailAPI *)detailAPI {
  221. if (_detailAPI == nil)
  222. {
  223. _detailAPI = [[HJMyIntegralExchangeGiftDetailAPI alloc]init];
  224. _detailAPI.APIManagerDelegate = self;
  225. _detailAPI.APIManagerInterceptor = self;
  226. }
  227. return _detailAPI;
  228. }
  229. - (HJMyIntegralExchangeGiftAPI *)exchangeGiftAPI {
  230. if (_exchangeGiftAPI == nil)
  231. {
  232. _exchangeGiftAPI = [[HJMyIntegralExchangeGiftAPI alloc]init];
  233. _exchangeGiftAPI.APIManagerDelegate = self;
  234. _exchangeGiftAPI.APIManagerInterceptor = self;
  235. }
  236. return _exchangeGiftAPI;
  237. }
  238. /*
  239. #pragma mark - Navigation
  240. // In a storyboard-based application, you will often want to do a little preparation before navigation
  241. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  242. // Get the new view controller using [segue destinationViewController].
  243. // Pass the selected object to the new view controller.
  244. }
  245. */
  246. @end