GoodsDetailSrcView.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. //
  2. // GoodsDetailSrcView.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2023/5/8.
  6. //
  7. #import "GoodsDetailSrcView.h"
  8. #import "WKM_goodsBanner.h"
  9. #import "GoodsDetailsPayV.h"
  10. #import "GoodsDetailsIntroduceV.h"
  11. #import "RadioButton.h"
  12. @interface GoodsDetailSrcView ()<WKNavigationDelegate,TT_BaseTableVDelegate>
  13. @property (nonatomic, strong) GoodsInformationM *infoModel;
  14. @property (nonatomic, strong) WKM_goodsBanner *goodsBanner;
  15. @property (nonatomic, strong) QMUILabel *titleLab;
  16. @property (nonatomic, strong) QMUILabel *soldLab;
  17. @property (nonatomic, strong) QMUILabel *reviewsLab;
  18. @property (nonatomic, strong) QMUILabel *priceLab;
  19. @property (nonatomic, strong) QMUILabel *saveLab;
  20. @property (nonatomic, strong) QMUILabel *couponLab;
  21. @property (nonatomic, strong) QMUILabel *sizeLab;
  22. @property (nonatomic, strong) GoodsDetailsPayV *datails_payV;
  23. @property (nonatomic, strong) GoodsDetailsIntroduceV *datails_IntroduceV;
  24. @property (nonatomic, strong) NSMutableArray *radioBtnAry;
  25. @property (nonatomic, strong)WKWebView *wkWebView;
  26. @end
  27. @implementation GoodsDetailSrcView
  28. - (void)tt_addsubviewS{
  29. [self addSubview:self.goodsBanner];
  30. [self addSubview:self.titleLab];
  31. [self addSubview:self.soldLab];
  32. [self addSubview:self.reviewsLab];
  33. [self addSubview:self.priceLab];
  34. [self addSubview:self.saveLab];
  35. [self addSubview:self.couponLab];
  36. [self addSubview:self.sizeLab];
  37. [self addSubview:self.datails_payV];
  38. [self addSubview:self.datails_IntroduceV];
  39. [self.goodsBanner mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.top.mas_equalTo(0);
  41. make.width.mas_equalTo(KScreenWidth);
  42. make.height.mas_equalTo(KScreenWidth+112+10);
  43. }];
  44. [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.mas_equalTo(10);
  46. make.width.mas_equalTo(KScreenWidth-20);
  47. make.top.equalTo(self.goodsBanner.mas_bottom).offset(20);
  48. make.height.mas_equalTo(45);
  49. }];
  50. [self.soldLab mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.mas_equalTo(10);
  52. make.height.mas_equalTo(16);
  53. make.top.equalTo(self.titleLab.mas_bottom).offset(10);
  54. }];
  55. [self.reviewsLab mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.right.equalTo(self.titleLab.mas_right);
  57. make.height.mas_equalTo(16);
  58. make.top.equalTo(self.titleLab.mas_bottom).offset(10);
  59. }];
  60. [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.mas_equalTo(10);
  62. make.top.equalTo(self.reviewsLab.mas_bottom).offset(20);
  63. make.height.mas_equalTo(24);
  64. }];
  65. [self.saveLab mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.left.equalTo(self.priceLab.mas_right).offset(10);
  67. make.height.mas_equalTo(20);
  68. make.centerY.equalTo(self.priceLab);
  69. }];
  70. [self.couponLab mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.mas_equalTo(10);
  72. make.top.equalTo(self.priceLab.mas_bottom).offset(20);
  73. make.width.mas_equalTo(KScreenWidth-20);
  74. make.height.mas_equalTo(45);
  75. }];
  76. [self.sizeLab mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.left.mas_equalTo(10);
  78. make.top.equalTo(self.couponLab.mas_bottom).offset(10);
  79. make.width.mas_equalTo(KScreenWidth-20);
  80. make.height.mas_equalTo(45);
  81. }];
  82. [self.datails_payV mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.mas_equalTo(10);
  84. make.top.equalTo(self.sizeLab.mas_bottom).offset(10);
  85. make.width.mas_equalTo(KScreenWidth-20);
  86. make.height.mas_equalTo(78);
  87. }];
  88. [self.datails_IntroduceV mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.left.mas_equalTo(10);
  90. make.top.equalTo(self.datails_payV.mas_bottom).offset(10);
  91. make.width.mas_equalTo(KScreenWidth-20);
  92. make.height.mas_equalTo(120);
  93. }];
  94. NSArray *titleAry = @[@"PRODUCT DETAILS",@"REVIEWS"];
  95. for (int i= 0; i<titleAry.count; i++) {
  96. RadioButton *radBtn= [[RadioButton alloc]init];
  97. radBtn.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  98. radBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:14];
  99. radBtn.layer.cornerRadius = 4;
  100. radBtn.clipsToBounds = YES;
  101. radBtn.tag = i;
  102. [radBtn setTitle:titleAry[i] forState:UIControlStateNormal];
  103. [radBtn setTitleColor:[UIColor colorWithHexString:@"#000000"] forState:UIControlStateNormal];
  104. [radBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateSelected];
  105. [radBtn addTarget:self action:@selector(xxx_onRadioButtonValueChanged:) forControlEvents:UIControlEventValueChanged];
  106. [self addSubview:radBtn];
  107. [self.radioBtnAry addObject:radBtn];
  108. CGFloat btnWidth = (KScreenWidth -30)/2;
  109. [radBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.left.mas_equalTo(10+(10+btnWidth)*i);
  111. make.height.mas_equalTo(40);
  112. make.top.equalTo(self.datails_IntroduceV.mas_bottom).offset(20);
  113. make.width.mas_equalTo(btnWidth);
  114. }];
  115. }
  116. RadioButton *firstBtn = self.radioBtnAry[0];
  117. [firstBtn setGroupButtons:self.radioBtnAry];
  118. [firstBtn setSelected:YES];
  119. firstBtn.backgroundColor = [UIColor colorWithHexString:@"#113632"];
  120. [self addSubview:self.wkWebView];
  121. [self.wkWebView mas_makeConstraints:^(MASConstraintMaker *make) {
  122. make.left.mas_equalTo(0);
  123. make.top.equalTo(self.datails_IntroduceV.mas_bottom).offset(80);
  124. make.width.mas_equalTo(KScreenWidth);
  125. }];
  126. }
  127. - (void)tt_configData:(id)data{
  128. GoodsInformationM *model = (GoodsInformationM *)data;
  129. self.infoModel = model;
  130. [self.goodsBanner tt_confignewdata:model];
  131. self.titleLab.text =MM_str(model.name);
  132. //wm_todo soldLab\ reviewsLab\ coupon 和 size
  133. self.soldLab.text = [NSString stringWithFormat:@"SOLD: %@",model.sold] ;
  134. NSMutableAttributedString *reviewsStr = [[NSMutableAttributedString alloc]
  135. initWithString:[NSString stringWithFormat:@"REVIEWS:%@",model.review_nums]];
  136. NSRange contentRange = {0,[reviewsStr length]};
  137. [reviewsStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
  138. self.reviewsLab.attributedText = reviewsStr;
  139. self.reviewsLab.textAlignment = NSTextAlignmentRight;
  140. NSMutableAttributedString *priceAtr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",model.currency_symbol,model.final_prices]];
  141. [priceAtr addAttribute: NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#0B0B0B"] range:NSMakeRange(0, priceAtr.length)];
  142. [priceAtr addAttribute:NSFontAttributeName value:[UIFont fontWithName:Rob_Bold size:20] range:NSMakeRange(0, priceAtr.length)];
  143. NSString *saveStr = @"";
  144. if(model.final_prices == model.price){
  145. self.saveLab.hidden = YES;
  146. }else{
  147. self.saveLab.hidden = NO;
  148. double savePrice = [model.price doubleValue]-[model.final_prices doubleValue];
  149. saveStr = [NSString stringWithFormat:@"Save %@%.2f",model.currency_symbol,savePrice];
  150. [priceAtr appendAttributedString:[[NSAttributedString alloc]initWithString:@" "]];
  151. NSMutableAttributedString *priceAtrSub1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",model.price]];
  152. [priceAtrSub1 addAttribute:NSForegroundColorAttributeName
  153. value:[UIColor colorWithHexString:@"#8c8c8c"]
  154. range:NSMakeRange(0, priceAtrSub1.length)];
  155. [priceAtrSub1 addAttribute:NSFontAttributeName
  156. value:[UIFont fontWithName:Rob_Regular size:14]
  157. range:NSMakeRange(0, priceAtrSub1.length)];
  158. [priceAtrSub1 addAttribute:NSUnderlineStyleAttributeName
  159. value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
  160. range:NSMakeRange(0, priceAtrSub1.length)];
  161. [priceAtr appendAttributedString:priceAtrSub1];
  162. }
  163. self.priceLab.attributedText = priceAtr;
  164. self.saveLab.text = saveStr;
  165. self.datails_payV.titleLab.text = [NSString stringWithFormat:@"Pay in 4 interest-free payments of %@%.2f with",model.currency_symbol,[model.final_prices floatValue]/4];
  166. NSString *product_details= @"";
  167. for (NSDictionary *dic in model.custom_attributes) {
  168. NSString *tmpStr= MM_str(dic[@"attribute_code"]);
  169. if ([tmpStr isEqualToString:@"feature"]) {
  170. product_details = MM_str(dic[@"value"]);
  171. }
  172. }
  173. NSString *htmlStr = [NSString stringWithFormat:@"<html> \n"
  174. "<head> \n"
  175. "<meta charset=\"utf-8\" /> \n"
  176. "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no\" /> \n"
  177. "<style> \n"
  178. "*{ \n"
  179. "padding: 5; \n"
  180. "margin: 0; \n"
  181. "} \n"
  182. "table{ \n"
  183. "width: 100%%; \n"
  184. "border: 1px solid #A8A8A8; \n"
  185. "border-collapse:collapse; \n"
  186. "} \n"
  187. "th{ \n"
  188. "width: 30.42%%; \n"
  189. "min-height: 36px; \n"
  190. "padding: 10px; \n"
  191. "border: 1px solid #A8A8A8; \n"
  192. "font-size: 12px; \n"
  193. "font-weight: bold; \n"
  194. "color: #000; \n"
  195. "} \n"
  196. "td{ \n"
  197. "width: 69.58%%; \n"
  198. "min-height: 36px; \n"
  199. "padding: 10px; \n"
  200. "border: 1px solid #A8A8A8; \n"
  201. "font-size: 12px; \n"
  202. "font-weight: 400; \n"
  203. "color: #000; \n"
  204. "line-height: 16px; \n"
  205. "word-break: break-word; \n"
  206. "} \n"
  207. "</style> \n"
  208. "</head> \n"
  209. "<body style=\"font-family: -apple-system,Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol',sans-serif;\">%@</body> \n"
  210. "</html>",product_details];
  211. [self.wkWebView loadHTMLString:htmlStr baseURL:nil];
  212. }
  213. #pragma mark WKNavigationDelegate 计算webView
  214. -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
  215. @weakify(self)
  216. [webView evaluateJavaScript:@"document.body.offsetHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  217. @strongify(self)
  218. CGFloat height = [result doubleValue]+40;
  219. [self tool_webChangeFrame:height];
  220. }];
  221. }
  222. -(void)tool_webChangeFrame:(CGFloat)height{
  223. [self.wkWebView mas_updateConstraints:^(MASConstraintMaker *make) {
  224. make.height.mas_equalTo(height);
  225. }];
  226. }
  227. #pragma mark - **************** handle ****************
  228. -(void)xxx_onRadioButtonValueChanged:(RadioButton *)btn{
  229. if (btn.selected) {
  230. btn.backgroundColor = [UIColor colorWithHexString:@"#113632"];
  231. }else{
  232. btn.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  233. }
  234. }
  235. -(void)tap_sizeLab{ ///展开size 规格选择的页面
  236. }
  237. -(void)handle_couponEvent:(UIButton *)btn{
  238. //wm_todo
  239. btn.selected = !btn.selected;
  240. }
  241. - (WKM_goodsBanner *)goodsBanner {
  242. if (!_goodsBanner) {
  243. _goodsBanner = [[WKM_goodsBanner alloc] init];
  244. }
  245. return _goodsBanner;
  246. }
  247. - (QMUILabel *)titleLab {
  248. if (!_titleLab) {
  249. _titleLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  250. _titleLab.textAlignment = NSTextAlignmentLeft;
  251. _titleLab.numberOfLines = 2;
  252. _titleLab.textColor = [UIColor colorWithHexString:@"#000000"];
  253. _titleLab.font = [UIFont fontWithName:Rob_Bold size:16];
  254. }
  255. return _titleLab;
  256. }
  257. - (QMUILabel *)soldLab {
  258. if (!_soldLab) {
  259. _soldLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  260. _soldLab.textAlignment = NSTextAlignmentLeft;
  261. _soldLab.textColor = [UIColor colorWithHexString:@"#666666"];
  262. _soldLab.font = [UIFont systemFontOfSize:12];
  263. }
  264. return _soldLab;
  265. }
  266. - (QMUILabel *)reviewsLab {
  267. if (!_reviewsLab) {
  268. _reviewsLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  269. _reviewsLab.textAlignment = NSTextAlignmentRight;
  270. _reviewsLab.textColor = [UIColor colorWithHexString:@"#666666"];
  271. _reviewsLab.font = [UIFont fontWithName:Rob_Regular size:12];
  272. // reviewsStr.underlineStyle = NSUnderlineStyleSingle;
  273. }
  274. return _reviewsLab;
  275. }
  276. - (QMUILabel *)priceLab {
  277. if (!_priceLab) {
  278. _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  279. _priceLab.textAlignment = NSTextAlignmentLeft;
  280. _priceLab.textColor = [UIColor blackColor];
  281. _priceLab.font = [UIFont systemFontOfSize:18];
  282. }
  283. return _priceLab;
  284. }
  285. - (QMUILabel *)saveLab {
  286. if (!_saveLab) {
  287. _saveLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  288. _saveLab.contentEdgeInsets= UIEdgeInsetsMake(10, 10, 10, 10);
  289. _saveLab.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"];
  290. _saveLab.textAlignment = NSTextAlignmentCenter;
  291. _saveLab.textColor = [UIColor colorWithHexString:@"#113632"];
  292. _saveLab.font = [UIFont fontWithName:Rob_Bold size:12];
  293. }
  294. return _saveLab;
  295. }
  296. - (QMUILabel *)couponLab {
  297. if (!_couponLab) {
  298. _couponLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  299. _couponLab.mj_size = CGSizeMake(KScreenWidth-20, 45);
  300. _couponLab.backgroundColor = [UIColor colorWithHexString:@"#113632"];
  301. _couponLab.textAlignment = NSTextAlignmentLeft;
  302. _couponLab.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
  303. _couponLab.font = [UIFont fontWithName:Rob_Bold size:14];
  304. _couponLab.text = @"COUPON";
  305. _couponLab.layer.cornerRadius = 4;
  306. _couponLab.clipsToBounds = YES;
  307. _couponLab.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
  308. UIButton *btn = [[UIButton alloc]init];
  309. btn.selected = NO;
  310. [btn addTarget:self action:@selector(handle_couponEvent:) forControlEvents:UIControlEventTouchUpInside];
  311. btn.frame = CGRectMake(_couponLab.mj_w-45-10, 0, 45, 45);
  312. [btn setImage:[UIImage imageNamed:@"base_add_white"] forState:UIControlStateNormal];
  313. [btn setImage:[UIImage imageNamed:@"base_subtract_white"] forState:UIControlStateSelected];
  314. [_couponLab addSubview:btn];
  315. }
  316. return _couponLab;
  317. }
  318. - (QMUILabel *)sizeLab {
  319. if (!_sizeLab) {
  320. _sizeLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  321. _sizeLab.mj_size = CGSizeMake(KScreenWidth-20, 45);
  322. _sizeLab.backgroundColor = [UIColor colorWithHexString:@"#113632"];
  323. _sizeLab.textAlignment = NSTextAlignmentLeft;
  324. _sizeLab.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
  325. _sizeLab.font = [UIFont fontWithName:Rob_Bold size:14];
  326. _sizeLab.text = @"Size Selection";
  327. _sizeLab.layer.cornerRadius = 4;
  328. _sizeLab.clipsToBounds = YES;
  329. _sizeLab.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
  330. UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"base_add_white"]];
  331. imgV.frame = CGRectMake(_sizeLab.mj_w-45-10, 0, 45, 45);
  332. imgV.userInteractionEnabled = YES;
  333. imgV.contentMode = UIViewContentModeCenter;
  334. [_sizeLab addSubview:imgV];
  335. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap_sizeLab)];
  336. [_sizeLab addGestureRecognizer:tap];
  337. }
  338. return _sizeLab;
  339. }
  340. -(GoodsDetailsPayV *)datails_payV{
  341. if (!_datails_payV) {
  342. _datails_payV = [[GoodsDetailsPayV alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth-20, 78)];
  343. _datails_payV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  344. _datails_payV.layer.cornerRadius = 4;
  345. _datails_payV.clipsToBounds = YES;
  346. }
  347. return _datails_payV;
  348. }
  349. - (GoodsDetailsIntroduceV *)datails_IntroduceV {
  350. if (!_datails_IntroduceV) {
  351. _datails_IntroduceV = [[GoodsDetailsIntroduceV alloc] initWithFrame:CGRectMake(10, 0, KScreenWidth-20, 120)];
  352. _datails_IntroduceV.backgroundColor = _F5F5F5;
  353. _datails_IntroduceV.clipsToBounds = YES;
  354. }
  355. return _datails_IntroduceV;
  356. }
  357. - (NSMutableArray *)radioBtnAry {
  358. if (!_radioBtnAry) {
  359. _radioBtnAry = [[NSMutableArray alloc] init];
  360. }
  361. return _radioBtnAry;
  362. }
  363. - (WKWebView *)wkWebView {
  364. if(!_wkWebView){
  365. NSString *injectionJSString = @"var script = document.createElement('meta');"
  366. "script.name = 'viewport';"
  367. "script.content=\"width=device-width, user-scalable=no\";"
  368. "document.getElementsByTagName('head')[0].appendChild(script);";
  369. // CSS选中样式取消 ---禁用web 长按菜单里的查询、学习、共享等按钮,
  370. NSString *css = @"body{-webkit-user-select:none;-webkit-user-drag:none;}";
  371. NSMutableString *javascript = [NSMutableString string];
  372. [javascript appendString:injectionJSString];
  373. [javascript appendString:@"var style = document.createElement('style');"];
  374. [javascript appendString:@"style.type = 'text/css';"];
  375. [javascript appendFormat:@"var cssContent = document.createTextNode('%@');", css];
  376. [javascript appendString:@"style.appendChild(cssContent);"];
  377. [javascript appendString:@"document.body.appendChild(style);"];
  378. WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:javascript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
  379. WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc]init];
  380. config.selectionGranularity = WKSelectionGranularityDynamic;
  381. WKUserContentController * wkUController = [[WKUserContentController alloc] init];
  382. [wkUController addUserScript:wkUScript];
  383. config.userContentController= wkUController;
  384. WKPreferences *wkp = [WKPreferences new];
  385. wkp.minimumFontSize = 12;
  386. config.preferences = wkp;
  387. _wkWebView = [[WKWebView alloc] initWithFrame: CGRectMake(0, 0, KScreenWidth, KScreenWidth) configuration:config];
  388. _wkWebView.navigationDelegate=self;
  389. _wkWebView.backgroundColor=[UIColor colorWithHexString:@"#FFFFFF"];
  390. _wkWebView.scrollView.scrollEnabled=NO;
  391. _wkWebView.allowsLinkPreview = NO;
  392. if(@available(iOS 16.4 , *)){
  393. _wkWebView.inspectable = YES;
  394. }
  395. }
  396. return _wkWebView;
  397. }
  398. @end