MyCartGrandTotalCell.m 8.0 KB

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