SPSBUseDiscountCouponViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // SPSBUseDiscountCouponViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/6/21.
  6. //
  7. #import "SPSBUseDiscountCouponViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBDiscountCouponTableViewController.h"
  10. #import "SPSBDiscountCouponModel.h"
  11. @interface SPSBUseDiscountCouponViewController () {
  12. SPSBDiscountCouponTableViewController *_tableVC;
  13. UIView *_headerView;
  14. }
  15. @end
  16. @implementation SPSBUseDiscountCouponViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self setupUI];
  20. }
  21. #pragma mark - Action
  22. - (void)confirmAction {
  23. if (_spsb_completeChose) {
  24. _spsb_completeChose(_tableVC.spsb_chose, _tableVC.spsb_data);
  25. }
  26. [self.navigationController popViewControllerAnimated:true];
  27. }
  28. #pragma mark - Network Action
  29. #pragma mark - UI
  30. - (void)setupUI {
  31. self.title = @"优惠券";
  32. [self createConfirmView];
  33. [self createHeaderView];
  34. [self createTableView];
  35. }
  36. - (void)createConfirmView {
  37. UIView *confirmView = UIView.new;
  38. [self.view addSubview:confirmView];
  39. [confirmView makeConstraints:^(JXHConstraintMaker *make) {
  40. make.left.and.right.equalTo(0);
  41. make.bottom.equalTo(self.view.safebottom);
  42. make.height.equalTo(56);
  43. }];
  44. UIButton *confirmButton = [UIButton convenienceWithFont:spsb_semiboldFont(16) target:self action:@selector(confirmAction)];
  45. [confirmButton setTitle:@"确定" titleColor:spsb_FFFFFF_color(1.f) image:nil backgroundImage:jxh_getImage(confirm_n) state:JXHButtonControlStateNormal];
  46. [confirmButton setBackgroundImage:jxh_getImage(confirm_h) state:JXHButtonControlStateHighlighted];
  47. [confirmButton setLayerCornerRadius:22.5 clipToBounds:true];
  48. [confirmView addSubview:confirmButton];
  49. [confirmButton makeConstraints:^(JXHConstraintMaker *make) {
  50. make.centerY.equalTo(0);
  51. make.leading.equalTo(10);
  52. make.trailing.equalTo(-10);
  53. make.height.equalTo(45);
  54. }];
  55. }
  56. - (void)createHeaderView {
  57. _headerView = UIView.new;
  58. _headerView.backgroundColor = spsb_F1F8FF_color();
  59. [self.view addSubview:_headerView];
  60. [_headerView makeConstraints:^(JXHConstraintMaker *make) {
  61. make.top.equalTo(self.view.safetop);
  62. make.leading.and.trailing.equalTo(0);
  63. make.height.equalTo(50);
  64. }];
  65. UILabel *firstLabel = [UILabel convenienceWithFont:spsb_font(12) text:[NSString stringWithFormat:@"您当前下了 %ld 个月订单,可同时选", (long)_spsb_maxUseCount] textColor:spsb_666666_color()];
  66. firstLabel.tag = 3001;
  67. [_headerView addSubview:firstLabel];
  68. [firstLabel makeConstraints:^(JXHConstraintMaker *make) {
  69. make.leading.equalTo(15);
  70. make.centerY.equalTo(0);
  71. }];
  72. UILabel *secondLabel = [UILabel convenienceWithFont:spsb_font(12) text:[NSString stringWithFormat:@" %ld ", (long)_spsb_maxUseCount] textColor:spsb_FF5E5E_color()];
  73. secondLabel.tag = 3002;
  74. [_headerView addSubview:secondLabel];
  75. [secondLabel makeConstraints:^(JXHConstraintMaker *make) {
  76. make.leading.equalTo(firstLabel.trailing);
  77. make.centerY.equalTo(0);
  78. }];
  79. UILabel *thirdLabel = [UILabel convenienceWithFont:spsb_font(12) text:@"张优惠券" textColor:spsb_666666_color()];
  80. thirdLabel.tag = 3003;
  81. [_headerView addSubview:thirdLabel];
  82. [thirdLabel makeConstraints:^(JXHConstraintMaker *make) {
  83. make.leading.equalTo(secondLabel.trailing);
  84. make.centerY.equalTo(0);
  85. }];
  86. }
  87. - (void)createTableView {
  88. _tableVC = SPSBDiscountCouponTableViewController.new;
  89. _tableVC.spsb_viewType = SPSBDiscountCouponViewTypeUse;
  90. _tableVC.spsb_canUse = true;
  91. _tableVC.spsb_maxChose = _spsb_maxUseCount;
  92. @weakify(self)
  93. _tableVC.spsb_afterChoose = ^{
  94. @strongify(self)
  95. [self reloadHeaderView];
  96. };
  97. [self addChildViewController:_tableVC];
  98. [self.view addSubview:_tableVC.tableView];
  99. [_tableVC.tableView makeConstraints:^(JXHConstraintMaker *make) {
  100. make.top.equalTo(self->_headerView.bottom);
  101. make.leading.and.trailing.equalTo(0);
  102. make.bottom.equalTo(self.view.safebottom).offset(-56);
  103. }];
  104. }
  105. - (void)reloadHeaderView {
  106. UILabel *firstLabel = [_headerView viewWithTag:3001];
  107. UILabel *secondLabel = [_headerView viewWithTag:3002];
  108. UILabel *thirdLabel = [_headerView viewWithTag:3003];
  109. if (_tableVC.spsb_chose.count > 0) {
  110. firstLabel.text = [NSString stringWithFormat:@"您已选中优惠券 %ld 张,共可抵用", (long)_tableVC.spsb_chose.count];
  111. CGFloat reduce = 0;
  112. for (NSNumber *index in _tableVC.spsb_chose) {
  113. SPSBDiscountCouponModel *model = _tableVC.spsb_data[index.integerValue];
  114. reduce += [model.spsb_coupon_price floatValue];
  115. }
  116. secondLabel.text = [NSString stringWithFormat:@"¥%.2lf", reduce];
  117. thirdLabel.text = @"";
  118. } else {
  119. firstLabel.text = [NSString stringWithFormat:@"您当前下了 %ld 个月订单,可同时选", (long)_spsb_maxUseCount];
  120. secondLabel.text = [NSString stringWithFormat:@" %ld ", (long)_spsb_maxUseCount];
  121. thirdLabel.text = @"张优惠券";
  122. }
  123. }
  124. @end