// // GoodsDetailSrcView.m // Asteria // // Created by 王猛 on 2023/5/8. // #import "GoodsDetailSrcView.h" #import "WKM_goodsBanner.h" #import "GoodsDetailsPayV.h" #import "GoodsDetailsIntroduceV.h" #import "RadioButton.h" @interface GoodsDetailSrcView () @property (nonatomic, strong) GoodsInformationM *infoModel; @property (nonatomic, strong) WKM_goodsBanner *goodsBanner; @property (nonatomic, strong) QMUILabel *titleLab; @property (nonatomic, strong) QMUILabel *soldLab; @property (nonatomic, strong) QMUILabel *reviewsLab; @property (nonatomic, strong) QMUILabel *priceLab; @property (nonatomic, strong) QMUILabel *saveLab; @property (nonatomic, strong) QMUILabel *couponLab; @property (nonatomic, strong) QMUILabel *sizeLab; @property (nonatomic, strong) GoodsDetailsPayV *datails_payV; @property (nonatomic, strong) GoodsDetailsIntroduceV *datails_IntroduceV; @property (nonatomic, strong) NSMutableArray *radioBtnAry; @property (nonatomic, strong)WKWebView *wkWebView; @end @implementation GoodsDetailSrcView - (void)tt_addsubviewS{ [self addSubview:self.goodsBanner]; [self addSubview:self.titleLab]; [self addSubview:self.soldLab]; [self addSubview:self.reviewsLab]; [self addSubview:self.priceLab]; [self addSubview:self.saveLab]; [self addSubview:self.couponLab]; [self addSubview:self.sizeLab]; [self addSubview:self.datails_payV]; [self addSubview:self.datails_IntroduceV]; [self.goodsBanner mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.mas_equalTo(0); make.width.mas_equalTo(KScreenWidth); make.height.mas_equalTo(KScreenWidth+112+10); }]; [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.width.mas_equalTo(KScreenWidth-20); make.top.equalTo(self.goodsBanner.mas_bottom).offset(20); make.height.mas_equalTo(45); }]; [self.soldLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.height.mas_equalTo(16); make.top.equalTo(self.titleLab.mas_bottom).offset(10); }]; [self.reviewsLab mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.titleLab.mas_right); make.height.mas_equalTo(16); make.top.equalTo(self.titleLab.mas_bottom).offset(10); }]; [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.top.equalTo(self.reviewsLab.mas_bottom).offset(20); make.height.mas_equalTo(24); }]; [self.saveLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.priceLab.mas_right).offset(10); make.height.mas_equalTo(20); make.centerY.equalTo(self.priceLab); }]; [self.couponLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.top.equalTo(self.priceLab.mas_bottom).offset(20); make.width.mas_equalTo(KScreenWidth-20); make.height.mas_equalTo(45); }]; [self.sizeLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.top.equalTo(self.couponLab.mas_bottom).offset(10); make.width.mas_equalTo(KScreenWidth-20); make.height.mas_equalTo(45); }]; [self.datails_payV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.top.equalTo(self.sizeLab.mas_bottom).offset(10); make.width.mas_equalTo(KScreenWidth-20); make.height.mas_equalTo(78); }]; [self.datails_IntroduceV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.top.equalTo(self.datails_payV.mas_bottom).offset(10); make.width.mas_equalTo(KScreenWidth-20); make.height.mas_equalTo(120); }]; NSArray *titleAry = @[@"PRODUCT DETAILS",@"REVIEWS"]; for (int i= 0; i \n" " \n" " \n" " \n" " \n" " \n" "%@ \n" "",product_details]; [self.wkWebView loadHTMLString:htmlStr baseURL:nil]; } #pragma mark WKNavigationDelegate 计算webView -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { @weakify(self) [webView evaluateJavaScript:@"document.body.offsetHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error) { @strongify(self) CGFloat height = [result doubleValue]+40; [self tool_webChangeFrame:height]; }]; } -(void)tool_webChangeFrame:(CGFloat)height{ [self.wkWebView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(height); }]; } #pragma mark - **************** handle **************** -(void)xxx_onRadioButtonValueChanged:(RadioButton *)btn{ if (btn.selected) { btn.backgroundColor = [UIColor colorWithHexString:@"#113632"]; }else{ btn.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"]; } } -(void)handle_couponEvent:(UIButton *)btn{ //wm_todo 优惠券的展开和合并 btn.selected = !btn.selected; } -(void)tap_reviewsClick{ [self delegate_configClosetype:GoodsReviewsTag data:@""]; } -(void)tap_sizeLab{ ///展开size 规格选择的页面 } - (void)delegate_configClosetype:(NSInteger)type data:(id)data { if (self.TTscrolldelegate && [self.TTscrolldelegate respondsToSelector:@selector(tengteng_configtapchilds:data:)]) { [self.TTscrolldelegate tengteng_configtapchilds:type data:data]; } } #pragma mark - **************** lazy **************** - (WKM_goodsBanner *)goodsBanner { if (!_goodsBanner) { _goodsBanner = [[WKM_goodsBanner alloc] init]; } return _goodsBanner; } - (QMUILabel *)titleLab { if (!_titleLab) { _titleLab = [[QMUILabel alloc] initWithFrame:CGRectZero]; _titleLab.textAlignment = NSTextAlignmentLeft; _titleLab.numberOfLines = 2; _titleLab.textColor = [UIColor colorWithHexString:@"#000000"]; _titleLab.font = [UIFont fontWithName:Rob_Bold size:16]; } return _titleLab; } - (QMUILabel *)soldLab { if (!_soldLab) { _soldLab = [[QMUILabel alloc] initWithFrame:CGRectZero]; _soldLab.textAlignment = NSTextAlignmentLeft; _soldLab.textColor = [UIColor colorWithHexString:@"#666666"]; _soldLab.font = [UIFont systemFontOfSize:12]; } return _soldLab; } - (QMUILabel *)reviewsLab { if (!_reviewsLab) { _reviewsLab = [[QMUILabel alloc] initWithFrame:CGRectZero]; _reviewsLab.textAlignment = NSTextAlignmentRight; _reviewsLab.textColor = [UIColor colorWithHexString:@"#666666"]; _reviewsLab.font = [UIFont fontWithName:Rob_Regular size:12]; _reviewsLab.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap_reviewsClick)]; [_reviewsLab addGestureRecognizer:tap]; // reviewsStr.underlineStyle = NSUnderlineStyleSingle; } return _reviewsLab; } - (QMUILabel *)priceLab { if (!_priceLab) { _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero]; _priceLab.textAlignment = NSTextAlignmentLeft; _priceLab.textColor = [UIColor blackColor]; _priceLab.font = [UIFont systemFontOfSize:18]; } return _priceLab; } - (QMUILabel *)saveLab { if (!_saveLab) { _saveLab = [[QMUILabel alloc] initWithFrame:CGRectZero]; _saveLab.contentEdgeInsets= UIEdgeInsetsMake(10, 10, 10, 10); _saveLab.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"]; _saveLab.textAlignment = NSTextAlignmentCenter; _saveLab.textColor = [UIColor colorWithHexString:@"#113632"]; _saveLab.font = [UIFont fontWithName:Rob_Bold size:12]; } return _saveLab; } - (QMUILabel *)couponLab { if (!_couponLab) { _couponLab = [[QMUILabel alloc] initWithFrame:CGRectZero]; _couponLab.mj_size = CGSizeMake(KScreenWidth-20, 45); _couponLab.backgroundColor = [UIColor colorWithHexString:@"#113632"]; _couponLab.textAlignment = NSTextAlignmentLeft; _couponLab.textColor = [UIColor colorWithHexString:@"#FFFFFF"]; _couponLab.font = [UIFont fontWithName:Rob_Bold size:14]; _couponLab.text = @"COUPON"; _couponLab.layer.cornerRadius = 4; _couponLab.clipsToBounds = YES; _couponLab.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0); UIButton *btn = [[UIButton alloc]init]; btn.selected = NO; [btn addTarget:self action:@selector(handle_couponEvent:) forControlEvents:UIControlEventTouchUpInside]; btn.frame = CGRectMake(_couponLab.mj_w-45-10, 0, 45, 45); [btn setImage:[UIImage imageNamed:@"base_add_white"] forState:UIControlStateNormal]; [btn setImage:[UIImage imageNamed:@"base_subtract_white"] forState:UIControlStateSelected]; [_couponLab addSubview:btn]; } return _couponLab; } - (QMUILabel *)sizeLab { if (!_sizeLab) { _sizeLab = [[QMUILabel alloc] initWithFrame:CGRectZero]; _sizeLab.mj_size = CGSizeMake(KScreenWidth-20, 45); _sizeLab.backgroundColor = [UIColor colorWithHexString:@"#113632"]; _sizeLab.textAlignment = NSTextAlignmentLeft; _sizeLab.textColor = [UIColor colorWithHexString:@"#FFFFFF"]; _sizeLab.font = [UIFont fontWithName:Rob_Bold size:14]; _sizeLab.text = @"Size Selection"; _sizeLab.layer.cornerRadius = 4; _sizeLab.clipsToBounds = YES; _sizeLab.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0); _sizeLab.userInteractionEnabled = YES; UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"base_add_white"]]; imgV.frame = CGRectMake(_sizeLab.mj_w-45-10, 0, 45, 45); imgV.userInteractionEnabled = YES; imgV.contentMode = UIViewContentModeCenter; [_sizeLab addSubview:imgV]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap_sizeLab)]; [_sizeLab addGestureRecognizer:tap]; } return _sizeLab; } -(GoodsDetailsPayV *)datails_payV{ if (!_datails_payV) { _datails_payV = [[GoodsDetailsPayV alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth-20, 78)]; _datails_payV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"]; _datails_payV.layer.cornerRadius = 4; _datails_payV.clipsToBounds = YES; } return _datails_payV; } - (GoodsDetailsIntroduceV *)datails_IntroduceV { if (!_datails_IntroduceV) { _datails_IntroduceV = [[GoodsDetailsIntroduceV alloc] initWithFrame:CGRectMake(10, 0, KScreenWidth-20, 120)]; _datails_IntroduceV.backgroundColor = _F5F5F5; _datails_IntroduceV.clipsToBounds = YES; } return _datails_IntroduceV; } - (NSMutableArray *)radioBtnAry { if (!_radioBtnAry) { _radioBtnAry = [[NSMutableArray alloc] init]; } return _radioBtnAry; } - (WKWebView *)wkWebView { if(!_wkWebView){ NSString *injectionJSString = @"var script = document.createElement('meta');" "script.name = 'viewport';" "script.content=\"width=device-width, user-scalable=no\";" "document.getElementsByTagName('head')[0].appendChild(script);"; // CSS选中样式取消 ---禁用web 长按菜单里的查询、学习、共享等按钮, NSString *css = @"body{-webkit-user-select:none;-webkit-user-drag:none;}"; NSMutableString *javascript = [NSMutableString string]; [javascript appendString:injectionJSString]; [javascript appendString:@"var style = document.createElement('style');"]; [javascript appendString:@"style.type = 'text/css';"]; [javascript appendFormat:@"var cssContent = document.createTextNode('%@');", css]; [javascript appendString:@"style.appendChild(cssContent);"]; [javascript appendString:@"document.body.appendChild(style);"]; WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:javascript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]; WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc]init]; config.selectionGranularity = WKSelectionGranularityDynamic; WKUserContentController * wkUController = [[WKUserContentController alloc] init]; [wkUController addUserScript:wkUScript]; config.userContentController= wkUController; WKPreferences *wkp = [WKPreferences new]; wkp.minimumFontSize = 12; config.preferences = wkp; _wkWebView = [[WKWebView alloc] initWithFrame: CGRectMake(0, 0, KScreenWidth, KScreenWidth) configuration:config]; _wkWebView.navigationDelegate=self; _wkWebView.backgroundColor=[UIColor colorWithHexString:@"#FFFFFF"]; _wkWebView.scrollView.scrollEnabled=NO; _wkWebView.allowsLinkPreview = NO; if(@available(iOS 16.4 , *)){ _wkWebView.inspectable = YES; } } return _wkWebView; } @end