MyCartGrandTotalCell.m 8.9 KB

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