MyCartGrandTotalCell.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. //
  2. // MyCartGrandTotalCell.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2024/2/2.
  6. //
  7. #import "MyCartGrandTotalCell.h"
  8. @implementation MyCartGrandTotalCellData
  9. @end
  10. @interface MyCartGrandTotalCell ()
  11. @property (nonatomic, strong) UIView *bgV;
  12. @property (nonatomic, strong) UIStackView *stackV;
  13. @property (nonatomic, strong) UIStackView *stackSubTopV;
  14. @property (nonatomic, strong) SubLoastSelectItemV *subLostV;
  15. @property (nonatomic, strong) SubtotalCellItemV *subBottomV;
  16. //总金额
  17. @property (nonatomic, copy) NSString *totalPriceStr;
  18. //丢件金额
  19. @property (nonatomic, copy) NSString *lostPriceStr;
  20. @end
  21. @implementation MyCartGrandTotalCell
  22. - (void)awakeFromNib {
  23. [super awakeFromNib];
  24. // Initialization code
  25. }
  26. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  27. [super setSelected:selected animated:animated];
  28. // Configure the view for the selected state
  29. }
  30. - (void)setupSubviewS{
  31. self.contentView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  32. [self.contentView addSubview:self.bgV];
  33. [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10, 10, 0, 10));
  35. }];
  36. [self.bgV addSubview:self.stackV];
  37. [self.stackV mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.edges.equalTo(self.bgV).insets(UIEdgeInsetsMake(0, 10, 0, 10));
  39. }];
  40. [self.stackV addArrangedSubview:self.stackSubTopV];
  41. [self.stackV addArrangedSubview:self.subLostV];
  42. [self.stackV addArrangedSubview:self.subBottomV];
  43. [self.subLostV mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.height.mas_equalTo(60);
  45. }];
  46. [self.subBottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.height.mas_equalTo(60);
  48. }];
  49. }
  50. - (void)configData:(id)Data{
  51. MyCartGrandTotalCellData *model = (MyCartGrandTotalCellData *)Data;
  52. ///当一个元素被 removeFromSuperview ,则 arrangedSubviews也会同步移除
  53. [self.stackSubTopV.arrangedSubviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  54. for (int i=0; i<model.total_segments.count; i++) {
  55. NSDictionary *dic = model.total_segments[i];
  56. NSString *code = MM_str(dic[@"code"]);
  57. if([code isEqualToString:@"amasty_extrafee"]){ //subLostV
  58. NSString *tips = [NSString stringWithFormat:@"%@%@%@",dic[@"title"],model.currency_symbol,dic[@"value"]];
  59. //wm_todo 需要 获取丢件险状态 carts/mine/fees-information
  60. [self.subLostV xxx_configTips:tips isLost:[dic[@"value"] qmui_CGFloatValue] > 0 ? YES : NO];
  61. }else if ([code isEqualToString:@"grand_total"]){ //subBottomV
  62. NSString *priceStr = [NSString stringWithFormat:@"%@%@",model.currency_symbol,dic[@"value"]];
  63. [self.subBottomV xxx_configTips:dic[@"title"] price:priceStr];
  64. }else{ //stackSubTopV
  65. NSString *priceStr = @"0";
  66. if([code isEqualToString:@"discount"]){
  67. if([dic[@"value"] floatValue] <0.00){
  68. CGFloat temF =fabsf([dic[@"value"] floatValue]);
  69. priceStr = [NSString stringWithFormat:@"-%@%.2f",model.currency_symbol,temF];
  70. }
  71. }else{
  72. priceStr = [NSString stringWithFormat:@"%@%@",model.currency_symbol,dic[@"value"]];
  73. }
  74. SubtotalCellItemV *itemV = [[SubtotalCellItemV alloc] init];
  75. [self.stackSubTopV addArrangedSubview:itemV];
  76. [itemV xxx_configTips:dic[@"title"] price:priceStr];
  77. [itemV mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.height.mas_equalTo(30);
  79. }];
  80. }
  81. }
  82. }
  83. - (UIView *)bgV {
  84. if (!_bgV) {
  85. _bgV = [[UIView alloc] init];
  86. _bgV.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  87. _bgV.layer.cornerRadius = 4;
  88. _bgV.clipsToBounds = YES;
  89. }
  90. return _bgV;
  91. }
  92. - (UIStackView *)stackV { ///根据高度进行变化
  93. if (!_stackV) {
  94. UIStackView *stv = [[UIStackView alloc] init];
  95. stv.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
  96. stv.axis = UILayoutConstraintAxisVertical;
  97. stv.distribution = UIStackViewDistributionFill;
  98. stv.alignment = UIStackViewAlignmentFill;
  99. stv.spacing = 1;
  100. _stackV = stv;
  101. }
  102. return _stackV;
  103. }
  104. - (UIStackView *)stackSubTopV {
  105. if (!_stackSubTopV) {
  106. UIStackView *stv = [[UIStackView alloc] init];
  107. stv.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  108. stv.axis = UILayoutConstraintAxisVertical;
  109. stv.distribution = UIStackViewDistributionFill;
  110. stv.alignment = UIStackViewAlignmentFill;
  111. stv.spacing = 5;
  112. _stackSubTopV = stv;
  113. }
  114. return _stackSubTopV;
  115. }
  116. - (SubLoastSelectItemV *)subLostV {
  117. if (!_subLostV) {
  118. _subLostV = [[SubLoastSelectItemV alloc] init];
  119. _subLostV.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  120. _subLostV.ViewtapClose = ^(NSInteger num, id _Nonnull data) {
  121. NSLog(@"=====%ld=====%@", num, data);
  122. };
  123. }
  124. return _subLostV;
  125. }
  126. - (SubtotalCellItemV *)subBottomV {
  127. if (!_subBottomV) {
  128. _subBottomV = [[SubtotalCellItemV alloc] init];
  129. _subBottomV.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  130. _subBottomV.tipsLab.font = [UIFont fontWithName:Rob_Bold size:14];
  131. _subBottomV.priceLab.font = [UIFont fontWithName:Rob_Bold size:24];
  132. }
  133. return _subBottomV;
  134. }
  135. @end
  136. @interface SubtotalCellItemV ()
  137. @end
  138. @implementation SubtotalCellItemV
  139. - (void)tt_setupViews{
  140. [self addSubview:self.tipsLab];
  141. [self addSubview:self.priceLab];
  142. [self.tipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
  143. make.left.mas_equalTo(0);
  144. make.top.mas_equalTo(0);
  145. make.height.mas_equalTo(30);
  146. }];
  147. [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.left.equalTo(self.tipsLab.mas_right).offset(10);
  149. make.right.mas_equalTo(0);
  150. make.top.mas_equalTo(0);
  151. make.height.mas_equalTo(30);
  152. }];
  153. }
  154. -(void)xxx_configTips:(NSString *)tips price:(NSString *)priceStr{
  155. self.tipsLab.text = tips;
  156. self.priceLab.text = priceStr;
  157. }
  158. -(UILabel *)tipsLab{
  159. if(!_tipsLab){
  160. _tipsLab = [[UILabel alloc]init];
  161. _tipsLab.textColor = [UIColor colorWithHexString:@"#0B0B0B"];
  162. _tipsLab.font = [UIFont fontWithName:Rob_Regular size:14];
  163. _tipsLab.numberOfLines =2;
  164. }
  165. return _tipsLab;
  166. }
  167. -(UILabel *)priceLab{
  168. if(!_priceLab){
  169. _priceLab = [[UILabel alloc]init];
  170. _priceLab.textColor = [UIColor colorWithHexString:@"#0B0B0B"];
  171. _priceLab.font = [UIFont fontWithName:Rob_Regular size:14];
  172. _priceLab.textAlignment = NSTextAlignmentRight;
  173. }
  174. return _priceLab;
  175. }
  176. @end
  177. ///点击cell
  178. @interface SubLoastSelectItemV ()
  179. @end
  180. @implementation SubLoastSelectItemV
  181. - (void)tt_setupViews{
  182. [self addSubview:self.tipsLab];
  183. [self addSubview:self.ridoBtn];
  184. [self.tipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
  185. make.left.equalTo(self);
  186. make.centerY.equalTo(self);
  187. make.right.mas_equalTo(-50);
  188. }];
  189. [self.ridoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.width.mas_equalTo(50);
  191. make.height.mas_equalTo(50);
  192. make.right.equalTo(self);
  193. }];
  194. }
  195. -(void)handle_ridoBtnEvent:(UIButton *)btn{
  196. btn.selected = !btn.selected;
  197. if(self.ViewtapClose){
  198. self.ViewtapClose(btn.selected, @"");
  199. }
  200. }
  201. - (void)xxx_configTips:(NSString *)tips isLost:(BOOL)isLost{
  202. self.tipsLab.text = tips;
  203. self.ridoBtn.selected = isLost;
  204. }
  205. -(UILabel *)tipsLab{
  206. if(!_tipsLab){
  207. _tipsLab = [[UILabel alloc]init];
  208. _tipsLab.textColor = [UIColor colorWithHexString:@"#0B0B0B"];
  209. _tipsLab.font = [UIFont fontWithName:Rob_Regular size:14];
  210. _tipsLab.numberOfLines =2;
  211. }
  212. return _tipsLab;
  213. }
  214. -(UIButton *)ridoBtn{
  215. if(!_ridoBtn){
  216. _ridoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  217. [_ridoBtn setImage:[UIImage imageNamed:@"base_radio_unselect"] forState:UIControlStateNormal];
  218. [_ridoBtn setImage:[UIImage imageNamed:@"base_radio_select"] forState:UIControlStateSelected];
  219. [_ridoBtn addTarget:self action:@selector(handle_ridoBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
  220. }
  221. return _ridoBtn;
  222. }
  223. @end