123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // SPSBUseDiscountCouponViewController.m
- // 我的社保
- //
- // Created by shanp on 2021/6/21.
- //
- #import "SPSBUseDiscountCouponViewController.h"
- #import "SPSBUIGeneralHeader.h"
- #import "SPSBDiscountCouponTableViewController.h"
- #import "SPSBDiscountCouponModel.h"
- @interface SPSBUseDiscountCouponViewController () {
- SPSBDiscountCouponTableViewController *_tableVC;
- UIView *_headerView;
- }
- @end
- @implementation SPSBUseDiscountCouponViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setupUI];
- }
- #pragma mark - Action
- - (void)confirmAction {
- if (_spsb_completeChose) {
- _spsb_completeChose(_tableVC.spsb_chose, _tableVC.spsb_data);
- }
- [self.navigationController popViewControllerAnimated:true];
- }
- #pragma mark - Network Action
- #pragma mark - UI
- - (void)setupUI {
- self.title = @"优惠券";
- [self createConfirmView];
- [self createHeaderView];
- [self createTableView];
- }
- - (void)createConfirmView {
- UIView *confirmView = UIView.new;
- [self.view addSubview:confirmView];
- [confirmView makeConstraints:^(JXHConstraintMaker *make) {
- make.left.and.right.equalTo(0);
- make.bottom.equalTo(self.view.safebottom);
- make.height.equalTo(56);
- }];
-
- UIButton *confirmButton = [UIButton convenienceWithFont:spsb_semiboldFont(16) target:self action:@selector(confirmAction)];
- [confirmButton setTitle:@"确定" titleColor:spsb_FFFFFF_color(1.f) image:nil backgroundImage:jxh_getImage(confirm_n) state:JXHButtonControlStateNormal];
- [confirmButton setBackgroundImage:jxh_getImage(confirm_h) state:JXHButtonControlStateHighlighted];
- [confirmButton setLayerCornerRadius:22.5 clipToBounds:true];
- [confirmView addSubview:confirmButton];
- [confirmButton makeConstraints:^(JXHConstraintMaker *make) {
- make.centerY.equalTo(0);
- make.leading.equalTo(10);
- make.trailing.equalTo(-10);
- make.height.equalTo(45);
- }];
- }
- - (void)createHeaderView {
- _headerView = UIView.new;
- _headerView.backgroundColor = spsb_F1F8FF_color();
- [self.view addSubview:_headerView];
- [_headerView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self.view.safetop);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(50);
- }];
-
- UILabel *firstLabel = [UILabel convenienceWithFont:spsb_font(12) text:[NSString stringWithFormat:@"您当前下了 %ld 个月订单,可同时选", (long)_spsb_maxUseCount] textColor:spsb_666666_color()];
- firstLabel.tag = 3001;
- [_headerView addSubview:firstLabel];
- [firstLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- make.centerY.equalTo(0);
- }];
-
- UILabel *secondLabel = [UILabel convenienceWithFont:spsb_font(12) text:[NSString stringWithFormat:@" %ld ", (long)_spsb_maxUseCount] textColor:spsb_FF5E5E_color()];
- secondLabel.tag = 3002;
- [_headerView addSubview:secondLabel];
- [secondLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(firstLabel.trailing);
- make.centerY.equalTo(0);
- }];
-
- UILabel *thirdLabel = [UILabel convenienceWithFont:spsb_font(12) text:@"张优惠券" textColor:spsb_666666_color()];
- thirdLabel.tag = 3003;
- [_headerView addSubview:thirdLabel];
- [thirdLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(secondLabel.trailing);
- make.centerY.equalTo(0);
- }];
- }
- - (void)createTableView {
- _tableVC = SPSBDiscountCouponTableViewController.new;
- _tableVC.spsb_viewType = SPSBDiscountCouponViewTypeUse;
- _tableVC.spsb_canUse = true;
- _tableVC.spsb_maxChose = _spsb_maxUseCount;
- @weakify(self)
- _tableVC.spsb_afterChoose = ^{
- @strongify(self)
- [self reloadHeaderView];
- };
- [self addChildViewController:_tableVC];
- [self.view addSubview:_tableVC.tableView];
- [_tableVC.tableView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self->_headerView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.bottom.equalTo(self.view.safebottom).offset(-56);
- }];
- }
- - (void)reloadHeaderView {
- UILabel *firstLabel = [_headerView viewWithTag:3001];
- UILabel *secondLabel = [_headerView viewWithTag:3002];
- UILabel *thirdLabel = [_headerView viewWithTag:3003];
-
- if (_tableVC.spsb_chose.count > 0) {
- firstLabel.text = [NSString stringWithFormat:@"您已选中优惠券 %ld 张,共可抵用", (long)_tableVC.spsb_chose.count];
- CGFloat reduce = 0;
- for (NSNumber *index in _tableVC.spsb_chose) {
- SPSBDiscountCouponModel *model = _tableVC.spsb_data[index.integerValue];
- reduce += [model.spsb_coupon_price floatValue];
- }
- secondLabel.text = [NSString stringWithFormat:@"¥%.2lf", reduce];
- thirdLabel.text = @"";
- } else {
- firstLabel.text = [NSString stringWithFormat:@"您当前下了 %ld 个月订单,可同时选", (long)_spsb_maxUseCount];
- secondLabel.text = [NSString stringWithFormat:@" %ld ", (long)_spsb_maxUseCount];
- thirdLabel.text = @"张优惠券";
- }
- }
- @end
|