MyCartItemCell.m 11 KB

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