123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- //
- // 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 ()<WKNavigationDelegate,TT_BaseTableVDelegate>
- @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<titleAry.count; i++) {
- RadioButton *radBtn= [[RadioButton alloc]init];
- radBtn.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
- radBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:14];
- radBtn.layer.cornerRadius = 4;
- radBtn.clipsToBounds = YES;
- radBtn.tag = i;
- [radBtn setTitle:titleAry[i] forState:UIControlStateNormal];
- [radBtn setTitleColor:[UIColor colorWithHexString:@"#000000"] forState:UIControlStateNormal];
- [radBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateSelected];
- [radBtn addTarget:self action:@selector(xxx_onRadioButtonValueChanged:) forControlEvents:UIControlEventValueChanged];
- [self addSubview:radBtn];
- [self.radioBtnAry addObject:radBtn];
- CGFloat btnWidth = (KScreenWidth -30)/2;
- [radBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10+(10+btnWidth)*i);
- make.height.mas_equalTo(40);
- make.top.equalTo(self.datails_IntroduceV.mas_bottom).offset(20);
- make.width.mas_equalTo(btnWidth);
- }];
- }
- RadioButton *firstBtn = self.radioBtnAry[0];
- [firstBtn setGroupButtons:self.radioBtnAry];
- [self.radioBtnAry[0] setSelected:YES];
- [self xxx_onRadioButtonValueChanged:self.radioBtnAry[0]];
-
-
- [self addSubview:self.wkWebView];
- [self.wkWebView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.top.equalTo(self.datails_IntroduceV.mas_bottom).offset(80);
- make.width.mas_equalTo(KScreenWidth);
- }];
-
-
- }
- - (void)tt_configData:(id)data{
-
-
- GoodsInformationM *model = (GoodsInformationM *)data;
- self.infoModel = model;
- [self.goodsBanner tt_confignewdata:self.infoModel];
- self.titleLab.text =MM_str(model.name);
- self.soldLab.text = [NSString stringWithFormat:@"SOLD: %@",model.sold] ;
- NSMutableAttributedString *reviewsStr = [[NSMutableAttributedString alloc]
- initWithString:[NSString stringWithFormat:@"REVIEWS:%@",model.review_nums]];
- NSRange contentRange = {0,[reviewsStr length]};
- [reviewsStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
- self.reviewsLab.attributedText = reviewsStr;
- self.reviewsLab.textAlignment = NSTextAlignmentRight;
-
- NSMutableAttributedString *priceAtr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",model.currency_symbol,model.final_prices]];
- [priceAtr addAttribute: NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#0B0B0B"] range:NSMakeRange(0, priceAtr.length)];
- [priceAtr addAttribute:NSFontAttributeName value:[UIFont fontWithName:Rob_Bold size:20] range:NSMakeRange(0, priceAtr.length)];
- NSString *saveStr = @"";
- if(model.final_prices == model.price){
- self.saveLab.hidden = YES;
- }else{
- self.saveLab.hidden = NO;
- double savePrice = [model.price doubleValue]-[model.final_prices doubleValue];
- saveStr = [NSString stringWithFormat:@"Save %@%.2f",model.currency_symbol,savePrice];
- [priceAtr appendAttributedString:[[NSAttributedString alloc]initWithString:@" "]];
- NSMutableAttributedString *priceAtrSub1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",model.price]];
- [priceAtrSub1 addAttribute:NSForegroundColorAttributeName
- value:[UIColor colorWithHexString:@"#8c8c8c"]
- range:NSMakeRange(0, priceAtrSub1.length)];
- [priceAtrSub1 addAttribute:NSFontAttributeName
- value:[UIFont fontWithName:Rob_Regular size:14]
- range:NSMakeRange(0, priceAtrSub1.length)];
- [priceAtrSub1 addAttribute:NSStrikethroughStyleAttributeName
- value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
- range:NSMakeRange(0, priceAtrSub1.length)];
- [priceAtr appendAttributedString:priceAtrSub1];
- }
- self.priceLab.attributedText = priceAtr;
- self.infoModel.priceAtr = priceAtr;
- self.saveLab.text = saveStr;
- self.datails_payV.titleLab.text = [NSString stringWithFormat:@"Pay in 4 interest-free payments of %@%.2f with",model.currency_symbol,[model.final_prices floatValue]/4];
- NSString *product_details= @"";
- for (NSDictionary *dic in model.custom_attributes) {
- NSString *tmpStr= MM_str(dic[@"attribute_code"]);
- if ([tmpStr isEqualToString:@"feature"]) {
- product_details = MM_str(dic[@"value"]);
- }
- }
- NSString *htmlStr = [NSString stringWithFormat:@"<html> \n"
- "<head> \n"
- "<meta charset=\"utf-8\" /> \n"
- "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no\" /> \n"
- "<style> \n"
- "*{ \n"
- "padding: 5; \n"
- "margin: 0; \n"
- "} \n"
- "table{ \n"
- "width: 100%%; \n"
- "border: 1px solid #A8A8A8; \n"
- "border-collapse:collapse; \n"
- "} \n"
- "th{ \n"
- "width: 30.42%%; \n"
- "min-height: 36px; \n"
- "padding: 10px; \n"
- "border: 1px solid #A8A8A8; \n"
- "font-size: 12px; \n"
- "font-weight: bold; \n"
- "color: #000; \n"
- "} \n"
- "td{ \n"
- "width: 69.58%%; \n"
- "min-height: 36px; \n"
- "padding: 10px; \n"
- "border: 1px solid #A8A8A8; \n"
- "font-size: 12px; \n"
- "font-weight: 400; \n"
- "color: #000; \n"
- "line-height: 16px; \n"
- "word-break: break-word; \n"
- "} \n"
- "</style> \n"
- "</head> \n"
- "<body style=\"font-family: -apple-system,Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol',sans-serif;\">%@</body> \n"
- "</html>",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
|