MyCartItemCell.m 11 KB

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