ASCheckoutGoodsItemCell.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. //
  2. // ASCheckoutGoodsItemCell.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/10.
  6. //
  7. #import "ASCheckoutGoodsItemCell.h"
  8. #import "QtyCountV.h"
  9. #import "AlertMyCartDeleteV.h"
  10. @interface ASCheckoutGoodsItemCell ()
  11. @property (nonatomic, strong) CartTotalsItemsM *itemM;
  12. @property (nonatomic, strong) UIView *bgV;
  13. @property (nonatomic, strong) UIStackView *stackV;
  14. @property (nonatomic, strong) UIView *topV;
  15. @property (nonatomic, strong) UIImageView *leftImg;
  16. @property (nonatomic, strong) UILabel *nameLab;
  17. @property (nonatomic, strong) UIButton *closeBtn;
  18. @property (nonatomic, strong) QMUILabel *optionsLab;
  19. @property (nonatomic, strong) QMUILabel *gitfLab;
  20. @property (nonatomic, strong) UIStackView *rowStackV;
  21. @property (nonatomic, strong) QMUILabel *priceLab;
  22. @property (nonatomic, strong) QtyCountV *countV;
  23. @property (nonatomic, strong) QMUILabel *bgDesLab;
  24. @end
  25. @implementation ASCheckoutGoodsItemCell
  26. - (void)awakeFromNib {
  27. [super awakeFromNib];
  28. // Initialization code
  29. }
  30. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  31. [super setSelected:selected animated:animated];
  32. }
  33. - (void)setupSubviewS{
  34. // self.contentView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  35. self.contentView.backgroundColor = ThemeLightColor;
  36. [self.contentView addSubview:self.bgV];
  37. [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, 10, 10, 10));
  39. }];
  40. [self.bgV addSubview:self.stackV];
  41. [self.stackV mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.edges.equalTo(self.bgV).insets(UIEdgeInsetsMake(20, 10, 15, 10));
  43. }];
  44. [self.stackV addArrangedSubview:self.topV];
  45. [self.stackV addArrangedSubview:self.rowStackV];
  46. [self.stackV addArrangedSubview:self.bgDesLab];
  47. [self.topV mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.width.mas_equalTo(KScreenWidth-40);
  49. make.height.mas_equalTo(86+10);
  50. }];
  51. [self.rowStackV mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.right.equalTo(self.stackV);
  53. make.height.mas_equalTo(32);
  54. }];
  55. [self.bgDesLab mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.height.mas_equalTo(23);
  57. make.width.mas_greaterThanOrEqualTo(86);
  58. }];
  59. [self.topV addSubview:self.leftImg];
  60. [self.topV addSubview:self.nameLab];
  61. [self.topV addSubview:self.closeBtn];
  62. [self.topV addSubview:self.optionsLab];
  63. [self.topV addSubview:self.gitfLab];
  64. [self.leftImg mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.top.mas_equalTo(0);
  66. make.width.height.mas_equalTo(86);
  67. }];
  68. [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.top.mas_equalTo(0);
  70. make.right.mas_equalTo(-5);
  71. make.width.height.mas_offset(22);
  72. }];
  73. [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.mas_equalTo(4);
  75. make.left.equalTo(self.leftImg.mas_right).offset(10);
  76. make.right.equalTo(self.closeBtn.mas_left).offset(-10);
  77. make.height.mas_lessThanOrEqualTo(40);
  78. }];
  79. [self.optionsLab mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.top.equalTo(self.nameLab.mas_bottom).offset(10);;
  81. make.left.equalTo(self.leftImg.mas_right).offset(10);
  82. make.right.equalTo(self.closeBtn.mas_left).offset(-10);
  83. }];
  84. [self.gitfLab mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.equalTo(self.leftImg.mas_right).offset(10);
  86. make.bottom.equalTo(self.leftImg);
  87. make.width.mas_equalTo(86);
  88. make.height.mas_equalTo(23);
  89. }];
  90. [self.rowStackV addArrangedSubview:self.priceLab];
  91. [self.rowStackV addArrangedSubview:self.countV];
  92. [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.height.mas_equalTo(20);
  94. }];
  95. [self.countV mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.width.mas_equalTo(self.countV.mj_w);
  97. make.height.mas_equalTo(self.countV.mj_h);
  98. }];
  99. [self subViewsTapBlock];
  100. }
  101. - (void)subViewsTapBlock{
  102. @weakify(self)
  103. self.countV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {//0 - ; 1+
  104. @strongify(self)
  105. NSString *qtyStr = (NSString *)data;
  106. CartTotalsItemsM *itemM =[[CartTotalsItemsM alloc]init];
  107. itemM = self.itemM;
  108. itemM.qty = qtyStr;
  109. if(self.currencyparameterClose){
  110. self.currencyparameterClose(1,itemM);
  111. }
  112. };
  113. }
  114. - (void)configData:(id)Data{
  115. CartTotalsItemsM *itemM = (CartTotalsItemsM *)Data;
  116. self.itemM = itemM;
  117. NSString *imgStr = [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,itemM.image];
  118. [self.leftImg sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:UIImageDefaultImg_SD];
  119. self.nameLab.text = itemM.name;
  120. NSArray *array = [Current_normalTool arrFromjsonStr:itemM.options];
  121. NSString *optionStr = @"";
  122. for (int i = 0; i < array.count; i++) {
  123. NSDictionary *dic = [array objectAtIndex:i];
  124. optionStr = [NSString stringWithFormat:@"%@%@:%@", optionStr, dic[@"label"], dic[@"value"]];
  125. if (i < array.count - 1) {
  126. optionStr = [NSString stringWithFormat:@"%@\n", optionStr];
  127. }
  128. }
  129. self.optionsLab.text = optionStr;
  130. self.priceLab.attributedText = [ASCheckoutGoodsItemCell tool_changePriceAtr:itemM];
  131. self.closeBtn.hidden = itemM.isGift;
  132. self.optionsLab.hidden = itemM.isGift;
  133. self.gitfLab.hidden = !itemM.isGift;
  134. self.rowStackV.hidden = itemM.isGift;
  135. if(itemM.isGift){
  136. self.bgDesLab.hidden = YES;
  137. }else{
  138. self.bgDesLab.hidden = YES;
  139. // self.bgDesLab.text = [NSString stringWithFormat:@"SAVE %@%.2f",itemM.currency_symbol,[itemM.initial_price floatValue]-[itemM.price floatValue]];
  140. self.countV.numLab.text = MM_str(itemM.qty);
  141. [self.countV xxx_changeBtnIsEnable:YES num:[self.countV.numLab.text integerValue]];
  142. }
  143. }
  144. #pragma mark - **************** handle ****************
  145. -(void)handle_CloseEvent:(UIButton *)btn{ //进入删除弹窗
  146. AlertMyCartDeleteV *alertV = [[AlertMyCartDeleteV alloc]initWithAlertVtitle:[[NSMutableAttributedString alloc] initWithString:@"Do You Want To Remove It?"]];
  147. alertV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {
  148. if(num ==1){
  149. if(self.currencyparameterClose){
  150. self.currencyparameterClose(0,self.itemM);
  151. }
  152. }
  153. };
  154. }
  155. #pragma mark - **************** tool ****************
  156. +(NSMutableAttributedString *)tool_changePriceAtr:(CartTotalsItemsM *)model{
  157. NSMutableAttributedString *priceAtr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",model.currency_symbol,model.price_incl_tax]];
  158. [priceAtr addAttribute: NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#0B0B0B"] range:NSMakeRange(0, priceAtr.length)];
  159. [priceAtr addAttribute:NSFontAttributeName value:[UIFont fontWithName:Rob_Bold size:20] range:NSMakeRange(0, priceAtr.length)];
  160. [priceAtr appendAttributedString:[[NSAttributedString alloc]initWithString:@" "]];
  161. NSMutableAttributedString *priceAtrSub1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%.2f",model.currency_symbol, [model.initial_price floatValue]]];
  162. [priceAtrSub1 addAttribute:NSForegroundColorAttributeName
  163. value:[UIColor colorWithHexString:@"#8c8c8c"]
  164. range:NSMakeRange(0, priceAtrSub1.length)];
  165. [priceAtrSub1 addAttribute:NSFontAttributeName
  166. value:[UIFont fontWithName:Rob_Regular size:14]
  167. range:NSMakeRange(0, priceAtrSub1.length)];
  168. [priceAtrSub1 addAttribute:NSStrikethroughStyleAttributeName
  169. value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
  170. range:NSMakeRange(0, priceAtrSub1.length)];
  171. [priceAtr appendAttributedString:priceAtrSub1];
  172. return priceAtr;
  173. }
  174. #pragma mark - **************** lazy ****************
  175. - (UIView *)bgV {
  176. if (!_bgV) {
  177. _bgV = [[UIView alloc] init];
  178. _bgV.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  179. _bgV.layer.cornerRadius = 4;
  180. _bgV.clipsToBounds = YES;
  181. }
  182. return _bgV;
  183. }
  184. - (UIStackView *)stackV { ///根据高度进行变化
  185. if (!_stackV) {
  186. UIStackView *stv = [[UIStackView alloc] init];
  187. stv.axis = UILayoutConstraintAxisVertical;
  188. stv.distribution = UIStackViewDistributionFill;
  189. stv.alignment = UIStackViewAlignmentLeading;
  190. stv.spacing = 5;
  191. _stackV = stv;
  192. }
  193. return _stackV;
  194. }
  195. -(UIImageView *)leftImg{
  196. if(!_leftImg){
  197. _leftImg = [[UIImageView alloc]init];
  198. }
  199. return _leftImg;
  200. }
  201. -(UILabel *)nameLab{
  202. if(!_nameLab){
  203. _nameLab = [[UILabel alloc]init];
  204. _nameLab.font = [UIFont fontWithName:Rob_Regular size:12];
  205. _nameLab.textColor = [UIColor colorWithHexString:@"#000000"];
  206. _nameLab.numberOfLines =2;
  207. }
  208. return _nameLab;
  209. }
  210. -(UIButton *)closeBtn{
  211. if(!_closeBtn){
  212. _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  213. [_closeBtn setBackgroundImage:[UIImage imageNamed:@"base_close_black"] forState:UIControlStateNormal];
  214. [_closeBtn addTarget:self action:@selector(handle_CloseEvent:) forControlEvents:UIControlEventTouchUpInside];
  215. }
  216. return _closeBtn;
  217. }
  218. -(QtyCountV *)countV{
  219. if(!_countV){
  220. _countV = [[QtyCountV alloc]initWithFrame:CGRectMake(0, 0, 32*2+46, 32)];
  221. _countV.goodsmaxNum = 10;
  222. }
  223. return _countV;
  224. }
  225. - (QMUILabel *)optionsLab {
  226. if (!_optionsLab) {
  227. _optionsLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  228. _optionsLab.textAlignment = NSTextAlignmentLeft;
  229. _optionsLab.textColor = [UIColor colorWithHexString:@"#B2B2B2"];
  230. _optionsLab.numberOfLines = 0;
  231. _optionsLab.font = [UIFont fontWithName:Rob_Regular size:12];
  232. }
  233. return _optionsLab;
  234. }
  235. - (QMUILabel *)priceLab {
  236. if (!_priceLab) {
  237. _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  238. _priceLab.textAlignment = NSTextAlignmentLeft;
  239. _priceLab.textColor = [UIColor colorWithHexString:@"#0B0B0B"];
  240. _priceLab.font = [UIFont fontWithName:Rob_Bold size:14];
  241. }
  242. return _priceLab;
  243. }
  244. - (QMUILabel *)bgDesLab {
  245. if (!_bgDesLab) {
  246. _bgDesLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  247. _bgDesLab.textAlignment = NSTextAlignmentCenter;
  248. _bgDesLab.backgroundColor = ThemeLightColor;
  249. _bgDesLab.textColor = [UIColor colorWithHexString:@"#000000"];
  250. _bgDesLab.font = [UIFont fontWithName:Rob_Regular size:12];
  251. _bgDesLab.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 15);
  252. }
  253. return _bgDesLab;
  254. }
  255. - (QMUILabel *)gitfLab {
  256. if (!_gitfLab) {
  257. _gitfLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  258. _gitfLab.textAlignment = NSTextAlignmentCenter;
  259. _gitfLab.textColor = [UIColor colorWithHexString:@"#000000"];
  260. _gitfLab.font = [UIFont fontWithName:Rob_Regular size:12];
  261. _gitfLab.text = @"Gift";
  262. _gitfLab.backgroundColor = ThemeLightColor;
  263. }
  264. return _gitfLab;
  265. }
  266. - (UIView *)topV {
  267. if (!_topV) {
  268. _topV = [[UIView alloc] init];
  269. }
  270. return _topV;
  271. }
  272. - (UIStackView *)rowStackV {
  273. if (!_rowStackV) {
  274. _rowStackV = [[UIStackView alloc] init];
  275. UIStackView *stv = [[UIStackView alloc] init];
  276. stv.axis = UILayoutConstraintAxisHorizontal;
  277. stv.distribution = UIStackViewDistributionFill;
  278. stv.alignment = UIStackViewAlignmentCenter;
  279. }
  280. return _rowStackV;
  281. }
  282. @end