AS_GoodsSizeC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. //
  2. // AS_GoodsSizeC.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2024/1/23.
  6. //
  7. #import "AS_GoodsSizeC.h"
  8. #import "GoodsSizeSelectTableV.h"
  9. #import "GoodsDetailsBottomV.h"
  10. #import "ASGoodsDetailsVM.h"
  11. #import "Cart_CheckoutC.h"
  12. @interface AS_GoodsSizeC ()<RY_baseVMprotocol>
  13. @property (nonatomic, strong) UIImageView *sel_headImg;
  14. @property (nonatomic, strong) QMUILabel *sel_titleLab;
  15. @property (nonatomic, strong) QMUILabel *priceLab;
  16. @property (nonatomic, strong) QMUILabel *saveLab;
  17. @property (nonatomic, strong) GoodsSizeSelectTableV *TableV;
  18. @property (nonatomic, strong) GoodsDetailsBottomV *bottomV;
  19. //商品的数量
  20. @property (nonatomic, assign) NSInteger xxx_quantityNum;
  21. //所有的规格数据
  22. @property (nonatomic, strong) NSMutableArray <OptionsModel *>*xxx_optionAry;
  23. @property (nonatomic, strong) ASGoodsDetailsVM *VM;
  24. @property (nonatomic, assign) BOOL xxx_isCart;
  25. @end
  26. @implementation AS_GoodsSizeC
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. [self ucm_subVeiwsTapBlock];
  31. [self ucm_configNavbar];
  32. self.xxx_quantityNum = 1;
  33. if(self.model){
  34. [self configFreshData:self.model];
  35. }
  36. }
  37. - (void)ucm_configNavbar{
  38. self.navigationController.navigationBar.hidden = YES;
  39. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  40. [closeBtn setImage:[UIImage imageNamed:@"base_close_black"] forState:UIControlStateNormal];
  41. [closeBtn addTarget:self action:@selector(handle_closeVC) forControlEvents:UIControlEventTouchUpInside];
  42. [self.view addSubview:closeBtn];
  43. NSInteger top = IPHONEX ? 44 : 20;
  44. closeBtn.frame = CGRectMake(KScreenWidth -44-20, top, 44, 44);
  45. }
  46. - (void)ucm_subVeiwsTapBlock{
  47. @weakify(self)
  48. self.TableV.tapClose = ^(NSInteger num, id data) {
  49. //选择规格xxx_optionAry 和 修改商品数量xxx_quantityNum
  50. @strongify(self)
  51. if([data isKindOfClass:[GoodsSizeCountCellData class]]){
  52. GoodsSizeCountCellData *model = (GoodsSizeCountCellData *)data;
  53. self.xxx_quantityNum = model.quantityNum;
  54. }
  55. [self refresh_optionChangePrice];
  56. };
  57. self.bottomV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {
  58. @strongify(self)
  59. [self hanale_isShopOrCart:num];
  60. };
  61. }
  62. - (void)initSubviews {
  63. [super initSubviews];
  64. [self.view addSubview:self.sel_headImg];
  65. [self.view addSubview:self.sel_titleLab];
  66. [self.view addSubview:self.priceLab];
  67. [self.view addSubview:self.saveLab];
  68. [self.view addSubview:self.bottomV];
  69. IPhoneXHeigh
  70. self.sel_headImg.frame = CGRectMake(10, securitytop_Y +10, 93, 93);
  71. self.sel_titleLab.frame = CGRectMake(CGRectGetMaxX(self.sel_headImg.frame)+10, securitytop_Y +10,KScreenWidth - 93-10-20,40);
  72. [self.sel_headImg mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_equalTo(10);
  74. make.top.mas_equalTo(securitytop_Y +10);
  75. make.width.height.mas_equalTo(93);
  76. }];
  77. [self.sel_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.top.mas_equalTo(securitytop_Y +10);
  79. make.left.equalTo(self.sel_headImg.mas_right).offset(10);
  80. make.right.mas_equalTo(-10);
  81. make.height.mas_equalTo(40);
  82. }];
  83. [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.equalTo(self.sel_headImg.mas_right).offset(10);
  85. make.bottom.equalTo(self.sel_headImg);
  86. make.height.mas_equalTo(24);
  87. }];
  88. [self.saveLab mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.left.equalTo(self.priceLab.mas_right).offset(10);
  90. make.height.mas_equalTo(20);
  91. make.centerY.equalTo(self.priceLab);
  92. }];
  93. CGFloat tableVorgY = CGRectGetMaxY(self.sel_headImg.frame)+20;
  94. [self setupTableV:[GoodsSizeSelectTableV class] Frame:CGRectMake(0, tableVorgY, KScreenWidth, KScreenHeight-tableVorgY-self.bottomV.mj_h)];
  95. }
  96. -(void)configFreshData:(GoodsInformationM *)model{
  97. NSArray *media_gallery_entries = model.media_gallery_entries;
  98. NSString *imageUrl = @"";
  99. if (AS_Array_valid(media_gallery_entries)) {
  100. MediaGalleryEntriesModel *model = media_gallery_entries.firstObject;
  101. imageUrl = [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,model.file];
  102. }
  103. [self.sel_headImg sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:UIImageDefaultImg_SD];
  104. self.sel_titleLab.text = model.name;
  105. self.priceLab.attributedText = [ASGoodsDetailsVM tool_changePriceAtr:model];
  106. if(model.final_prices == model.price){
  107. self.saveLab.hidden = YES;
  108. }else{
  109. self.saveLab.hidden = NO;
  110. double savePrice = [model.price doubleValue]-[model.final_prices doubleValue];
  111. self.saveLab.text = [NSString stringWithFormat:@"Save %@%.2f",model.currency_symbol,savePrice];
  112. }
  113. for (OptionsModel *optM in model.options) {
  114. optM.optionSelectTag = 0;
  115. }
  116. [self.TableV.infodata removeAllObjects];
  117. self.xxx_optionAry = [NSMutableArray arrayWithArray:model.options];
  118. [self.TableV.infodata addObjectsFromArray:self.xxx_optionAry];
  119. GoodsSizeCountCellData *countM = [[GoodsSizeCountCellData alloc]init];
  120. countM.maxNum = 10;
  121. countM.quantityNum = self.xxx_quantityNum;
  122. [self.TableV.infodata addObject:countM];
  123. GoodsSizePayMentCellData *paytypeM = [[GoodsSizePayMentCellData alloc]init];
  124. paytypeM.paytypeAry = [NSMutableArray arrayWithArray:@[@"paypal",@"afterpay"]];
  125. paytypeM.final_prices_f = [self.model.final_prices floatValue];
  126. paytypeM.currency_symbol = self.model.currency_symbol;
  127. [self.TableV.infodata addObject:paytypeM];
  128. [self.TableV reloadData];
  129. }
  130. #pragma mark - **************** fresh 选择不同规格后的金额变化 ****************
  131. -(void)refresh_optionChangePrice{
  132. CGFloat add_price = 0.00;
  133. for (OptionsModel *optionM in self.xxx_optionAry) {
  134. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  135. add_price = add_price + valuesM.price;
  136. }
  137. float discount = [self.model.percent floatValue];
  138. if (discount == 0) {
  139. //优惠价
  140. CGFloat add_final_price_f = (add_price + [self.model.final_prices floatValue]) * self.xxx_quantityNum;
  141. self.model.show_final_prices = [NSString stringWithFormat:@"%.2lf", add_final_price_f];
  142. //原价
  143. CGFloat show_prices = (add_price + [self.model.price floatValue]) * self.xxx_quantityNum;
  144. self.model.show_prices = [NSString stringWithFormat:@"%.2lf", show_prices];
  145. } else {
  146. //优惠价
  147. discount = (100.00 - discount) / 100.00;
  148. CGFloat add_final_price_f = (add_price * discount + [self.model.final_prices floatValue]) * self.xxx_quantityNum;
  149. self.model.show_final_prices = [NSString stringWithFormat:@"%.2lf", add_final_price_f];
  150. //原价
  151. CGFloat show_prices = (add_price + [self.model.price floatValue]) * self.xxx_quantityNum;
  152. self.model.show_prices = [NSString stringWithFormat:@"%.2lf", show_prices];
  153. }
  154. self.priceLab.attributedText = [ASGoodsDetailsVM tool_addOptionPrice:add_price quantity:self.xxx_quantityNum infoMoel:self.model];
  155. CGFloat savePrice = ([self.model.show_prices doubleValue]-[self.model.show_final_prices doubleValue]);
  156. self.saveLab.text = [NSString stringWithFormat:@"Save %@%.2f",self.model.currency_symbol,savePrice];
  157. CGFloat add_final_price_f = [self.model.show_final_prices doubleValue];
  158. [self refresh_PayViewchangeValueCell:add_final_price_f];
  159. }
  160. -(void)refresh_PayViewchangeValueCell:(CGFloat )change_final_prices_f{
  161. // GoodsSizePayMentCellData *payModel = (GoodsSizePayMentCellData *)[self.TableV.infodata lastObject];
  162. // payModel.final_prices_f = change_final_prices_f;
  163. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.TableV.infodata.count-1 inSection:0];
  164. [self.TableV reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  165. }
  166. #pragma mark - **************** handle ****************
  167. -(void)handle_closeVC{
  168. [self dismissViewControllerAnimated:YES completion:nil];
  169. }
  170. -(void)hanale_isShopOrCart:(NSInteger)type{
  171. //1 shop 2cart
  172. if(type == 1){
  173. self.xxx_isCart = NO;
  174. }else{
  175. self.xxx_isCart = YES;
  176. }
  177. [self reqNet_Size_rewriteCartAddProducts:type];
  178. }
  179. - (void)ucm_bindvmmodel{
  180. self.VM = [[ASGoodsDetailsVM alloc]initDelegate:self];
  181. }
  182. -(void)reqNet_Size_rewriteCartAddProducts:(NSInteger)type{
  183. NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
  184. for (OptionsModel *optionM in self.xxx_optionAry) {
  185. OptionsValuesM *valuesM = optionM.values[optionM.optionSelectTag];
  186. NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
  187. optionDic[tempStr] =valuesM.option_type_id;
  188. }
  189. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:optionDic];
  190. params[@"product"] = self.model.Id;
  191. params[@"qty"] =[NSString stringWithFormat:@"%ld",(long)self.xxx_quantityNum];
  192. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  193. [self.VM ry_formDataRequestPostApi:Size_rewriteCartAddProducts param:params];
  194. }
  195. - (void)ry_respnsData:(id)data
  196. parseAry:(NSMutableArray *)arry
  197. sucess:(BOOL)sucessOrFail
  198. mark:(NSString *)mark
  199. reqNetType:(ReqNetType)reqNetType{
  200. [MBProgressHUD hideHUDForView:self.view animated:YES];
  201. if(sucessOrFail){
  202. [self.view makeToast:@"Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  203. if(self.xxx_isCart){
  204. [self dismissViewControllerAnimated:YES completion:^{
  205. }];
  206. }else{
  207. // [self handle_closeVC];
  208. // K_WEAK_SELF;
  209. [self dismissViewControllerAnimated:YES completion:^{
  210. // K_STRONG_SELF;
  211. Cart_CheckoutC *vc = [[Cart_CheckoutC alloc] init];
  212. [[Current_normalTool topViewController].navigationController pushViewController:vc animated:YES];
  213. }];
  214. }
  215. }];
  216. }else{
  217. [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
  218. }
  219. }
  220. - (UIImageView *)sel_headImg {
  221. if (!_sel_headImg) {
  222. _sel_headImg = [[UIImageView alloc] initWithImage:nil];
  223. _sel_headImg.contentMode = UIViewContentModeScaleAspectFill;
  224. _sel_headImg.clipsToBounds = YES;
  225. }
  226. return _sel_headImg;
  227. }
  228. - (QMUILabel *)sel_titleLab {
  229. if (!_sel_titleLab) {
  230. _sel_titleLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  231. _sel_titleLab.textAlignment = NSTextAlignmentLeft;
  232. _sel_titleLab.textColor = [UIColor colorWithHexString:@"#000000"];
  233. _sel_titleLab.font = [UIFont fontWithName:Rob_Regular size:12];
  234. _sel_titleLab.text = @"test";
  235. _sel_titleLab.numberOfLines = 2;
  236. }
  237. return _sel_titleLab;
  238. }
  239. - (QMUILabel *)priceLab {
  240. if (!_priceLab) {
  241. _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  242. _priceLab.textAlignment = NSTextAlignmentLeft;
  243. _priceLab.textColor = [UIColor blackColor];
  244. _priceLab.font = [UIFont fontWithName:Rob_Bold size:18];
  245. }
  246. return _priceLab;
  247. }
  248. - (QMUILabel *)saveLab {
  249. if (!_saveLab) {
  250. _saveLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  251. _saveLab.contentEdgeInsets= UIEdgeInsetsMake(10, 10, 10, 10);
  252. _saveLab.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"];
  253. _saveLab.textAlignment = NSTextAlignmentCenter;
  254. _saveLab.textColor = [UIColor colorWithHexString:@"#113632"];
  255. _saveLab.font = [UIFont fontWithName:Rob_Bold size:12];
  256. }
  257. return _saveLab;
  258. }
  259. - (GoodsDetailsBottomV *)bottomV {
  260. if (!_bottomV) {
  261. IPhoneXHeigh
  262. _bottomV = [[GoodsDetailsBottomV alloc] initWithFrame:CGRectMake(0, KScreenHeight - securityBottom_H-65, KScreenWidth, securityBottom_H+65)];
  263. _bottomV.backgroundColor = Col_FFF;
  264. }
  265. return _bottomV;
  266. }
  267. @end