123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781 |
- //
- // SPSBOrderListPayViewController.m
- // 我的社保
- //
- // Created by shanp on 2021/6/19.
- //
- #import "SPSBOrderListPayViewController.h"
- #import "SPSBUIGeneralHeader.h"
- #import "SPSBOrderListShowItem.h"
- #import "SPSBBusinessManager.h"
- #import "SPSBDiscountCouponTableViewController.h"
- #import "UIViewController+SPSBNetworkManager.h"
- #import "SPSBDiscountCouponModel.h"
- #import "SPSBPayResultViewController.h"
- #define spsb_orderListPayViewButtonViewHeight 55
- @interface SPSBOrderListPayViewController () {
- CGFloat _totalFee;
- BOOL _showDetails;
- SPSBOrderType _orderType;
- NSUInteger _cashCouponCount;//可用数量
- UIView *_headerView;
- SPSBOrderListPayButtonType _buttonType;
-
- UIView *_buttonLoadingView;
- SPSBDiscountCouponTableViewController *_discountCouponVC;
- }
- @end
- @implementation SPSBOrderListPayViewController
- - (instancetype)init {
- self = [super init];
- if (!self) return nil;
- self.modalPresentationStyle = UIModalPresentationCustom;
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setupAnimation];
- [self setupUI];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (!self.isBeingPresented) {
- [self.presentingViewController viewWillAppear:animated];
- }
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- if (!self.isBeingPresented) {
- [self.presentingViewController viewDidAppear:animated];
- } else {
- [self.view setNeedsLayout];
- [self.view layoutIfNeeded];
- [self showAnimation];
- }
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- if (!self.isBeingDismissed) {
- [self.presentingViewController viewWillDisappear:animated];
- }
- }
- - (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
- if (!self.isBeingDismissed) {
- [self.presentingViewController viewDidDisappear:animated];
- }
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- UIViewController *vc = self.presentingViewController;
- if ([vc isKindOfClass:[UINavigationController class]]) {
- return ((UIViewController *)((UINavigationController *)self.presentingViewController).viewControllers.lastObject).preferredStatusBarStyle;
- } else {
- return vc.preferredStatusBarStyle;
- }
- return self.presentingViewController.preferredStatusBarStyle;
- }
- #pragma mark - Action
- - (void)setOrderBaseWithOrderType:(SPSBOrderType)type totalFee:(CGFloat)totalFee discountCount:(NSUInteger)discountCount orderNumber:(NSUInteger)orderNumber showData:(nullable SPSBOrderListShowItem *)data buttonType:(SPSBOrderListPayButtonType)buttonType {
- _spsb_showData = data;
- _orderType = type;
- _totalFee = totalFee;
- _cashCouponCount = discountCount;
- self.spsb_orderBase.spsb_cashCouponMaxCount = orderNumber;
- _showDetails = data != nil;
- _buttonType = buttonType;
- }
- - (void)queryAction {}
- - (void)payAction {}
- - (void)payAction:(UIButton *)sender {
- UILabel *titleView = [_headerView viewWithTag:spsb_headerViewLabelTag];
- if (sender.tag == 4000) {
- sender.tag = 4001;
- [sender setTitle:@"确定付款" state:JXHButtonControlStateNormal];
- [_spsb_bgScrollView setContentOffset:CGPointMake(jxh_screenWidth(), 0) animated:true];
- titleView.text = @"选择支付方式";
- } else if (sender.tag == 4001) {
- [_spsb_contentView bringSubviewToFront:_buttonLoadingView];
- @weakify(self)
- self.spsb_orderBase.spsb_payFailure = ^(NSError *error) {
- @strongify(self)
- [self->_spsb_contentView bringSubviewToFront:sender];
- if (error) {
- [self handleFailureTipsWithError:error tips:@"生成订单失败"];
- } else {
- [self.view showToastWithTitle:@"支付失败"];
- }
- };
- [self payAction];
-
- } else if (sender.tag == 4002) {
- sender.tag = 4001;
- [sender setTitle:@"确定付款" state:JXHButtonControlStateNormal];
- if (_showDetails) {
- [_spsb_bgScrollView setContentOffset:CGPointMake(jxh_screenWidth(), 0) animated:true];
- } else {
- [_spsb_bgScrollView setContentOffset:CGPointMake(0, 0) animated:true];
- }
-
- titleView.text = @"选择支付方式";
-
- self.spsb_orderBase.spsb_cashCouponTotal = 0;
- self.spsb_orderBase.spsb_cashCouponIds = NSMutableString.new;
- for (NSNumber *num in _discountCouponVC.spsb_chose) {
- SPSBDiscountCouponModel *model = _discountCouponVC.spsb_data[[num unsignedIntegerValue]];
- self.spsb_orderBase.spsb_cashCouponTotal += [model.spsb_coupon_price integerValue];
- [self.spsb_orderBase.spsb_cashCouponIds appendFormat:@"%@,", model.spsb_id];
- }
- if (![self.spsb_orderBase.spsb_cashCouponIds isEqualToString:@""]) {
- [self.spsb_orderBase.spsb_cashCouponIds deleteCharactersInRange:NSMakeRange(self.spsb_orderBase.spsb_cashCouponIds.length - 1, 1)];
- }
-
- UIImageView *zfbImage = [[self.spsb_orderBase.spsb_reducePriceLabel.superview.superview viewWithTag:3000] viewWithTag:4000];
- UIImageView *wxImage = [[self.spsb_orderBase.spsb_reducePriceLabel.superview.superview viewWithTag:3001] viewWithTag:4000];
- if (_totalFee - self.spsb_orderBase.spsb_cashCouponTotal > spsb_wxpayLimit()) {
- self.spsb_orderBase.spsb_chosePay = 0;
- zfbImage.image = jxh_getImage(filter_s);
- wxImage.image = jxh_getImage(filter_unc);
- } else {
- if (self.spsb_orderBase.spsb_chosePay == 0) {
- wxImage.image = jxh_getImage(filter_n);
- }
- }
-
- if (self.spsb_orderBase.spsb_cashCouponTotal > 0) {
- self.spsb_orderBase.spsb_reducePriceLabel.text = [NSString stringWithFormat:@"-¥%.2lf", (CGFloat)self.spsb_orderBase.spsb_cashCouponTotal];
- } else {
- self.spsb_orderBase.spsb_reducePriceLabel.text = @"未使用";
- }
- }
- }
- - (void)choosePay:(UIButton *)sender {
- if (sender.tag == 3000) {
- self.spsb_orderBase.spsb_chosePay = sender.tag - 3000;
- ((UIImageView *)[sender viewWithTag:4000]).image = jxh_getImage(filter_s);
- ((UIImageView *)[[sender.superview viewWithTag:3001] viewWithTag:4000]).image = jxh_getImage(filter_n);
- } else if (sender.tag == 3001) {
- if (_totalFee - self.spsb_orderBase.spsb_cashCouponTotal > spsb_wxpayLimit()) {
- return;
- }
- self.spsb_orderBase.spsb_chosePay = sender.tag - 3000;
- ((UIImageView *)[sender viewWithTag:4000]).image = jxh_getImage(filter_s);
- ((UIImageView *)[[sender.superview viewWithTag:3000] viewWithTag:4000]).image = jxh_getImage(filter_n);
- }
- }
- - (void)chooseDiscountAction {
- if (_cashCouponCount <= 0) return;
- UILabel *titleView = [_headerView viewWithTag:spsb_headerViewLabelTag];
- UIButton *button = [_spsb_contentView viewWithTag:4001];
-
- button.tag = 4002;
- [button setTitle:@"确定" state:JXHButtonControlStateNormal];
- if (_showDetails) {
- [_spsb_bgScrollView setContentOffset:CGPointMake(jxh_screenWidth() * 2, 0) animated:true];
- } else {
- [_spsb_bgScrollView setContentOffset:CGPointMake(jxh_screenWidth(), 0) animated:true];
- }
-
- titleView.text = @"优惠券";
- [self reloadHeaderView];
-
- }
- - (void)pushResultVC:(SPSBPayResultViewController *)vc {
- [self dismissContentViewCompletion:^{
- UIViewController *v = jxh_findPresentedViewControllerStartingFrom(spsb_keyWindow().rootViewController);
- if (v.navigationController) {
- [v.navigationController pushViewController:vc animated:true];
- }
- }];
- }
- - (void)dismissContentView {
- [self dismissContentViewCompletion:nil];
- }
- - (void)dismissContentViewCompletion:(void (^ _Nullable)(void))completion {
- [_spsb_contentView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.update(0);
- }];
-
- [UIView animateWithDuration:0.3 animations:^{
- [self.view layoutSubviews];
- self.view.backgroundColor = spsb_000000_color(0);
- } completion:^(BOOL finished) {
- [self dismissViewControllerAnimated:false completion:completion];
- }];
- }
- - (void)setupAnimation {
- self.view.backgroundColor = spsb_000000_color(0.f);
- }
- - (void)showAnimation {
- [_spsb_contentView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.update(-jxh_viewHeight(self->_spsb_contentView));
- }];
-
- [UIView animateWithDuration:0.3 animations:^{
- [self.view layoutSubviews];
- self.view.backgroundColor = spsb_000000_color(SPSBPopupViewBackgroundAlpha);
- }];
- }
- #pragma mark - Network Action
- #pragma mark - UI
- - (void)setupUI {
- _spsb_contentView = UIView.new;
- _spsb_contentView.backgroundColor = spsb_FFFFFF_color(1.f);
- [self.view addSubview:_spsb_contentView];
- [_spsb_contentView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(480);
- make.top.equalTo(self.view.bottom);
- }];
-
- UIButton *dismissButton = [UIButton convenienceWithTarget:self action:@selector(dismissContentView)];
- [self.view addSubview:dismissButton];
- [dismissButton makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.leading.and.trailing.equalTo(0);
- make.bottom.equalTo(self->_spsb_contentView.top);
- }];
-
- #ifdef DEBUG
- [self addTestButton];
- #endif
-
- _spsb_bgScrollView = [UIScrollView convenienceWithBackgroundColor:spsb_FFFFFF_color(1.f)];
- _spsb_bgScrollView.scrollEnabled = false;
- _spsb_mScrollView = [UIScrollView convenienceWithBackgroundColor:spsb_FFFFFF_color(1.f)];
- }
- - (void)createPayView {
- if (_cashCouponCount > 0) {
- _headerView = [self createHeaderView];
- }
-
- NSString *title;
- if (_orderType == SPSBOrderTypeSalary) {
- title = @"社保流水订单详情";
- } else {
- title = _spsb_showData ? @"订单详情" : @"选择支付方式";
- }
- [self setTitleView:title];
-
- if (_spsb_showData) {
- [_spsb_mScrollView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.top.and.bottom.equalTo(0);
- make.width.equalTo(jxh_screenWidth());
- make.height.equalTo(self->_spsb_bgScrollView);
- }];
- if (_orderType == SPSBOrderTypeSalary) {
- [self addMessageViewWithStatusTitle:_buttonType == SPSBOrderListPayButtonTypePay ? @"待付款" : @"已付款" tips:@"用作流水记录,逾期未缴费可能会导致参保失败。成功付款后,将会于退还至参保人银行卡,部分城市例如北京,可能分两笔返还,第一笔通过银行卡转账返还,第二笔通过退款返还。"];
- } else {
- [self addMessageViewWithStatusTitle:_buttonType == SPSBOrderListPayButtonTypePay ? @"待付款" : @"已付款" tips:nil];
- }
-
- } else {
- [_spsb_mScrollView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.top.and.bottom.equalTo(0);
- make.width.equalTo(0);
- make.height.equalTo(self->_spsb_bgScrollView);
- }];
- }
- UIView *payView = UIView.new;
- payView.backgroundColor = spsb_FFFFFF_color(1.f);
- [_spsb_bgScrollView addSubview:payView];
- [payView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.bottom.equalTo(0);
- make.leading.equalTo(self->_spsb_mScrollView.trailing);
- make.trailing.equalTo(-jxh_screenWidth());
- make.width.equalTo(jxh_screenWidth());
- make.height.equalTo(self->_spsb_bgScrollView);
- }];
- [self addPayViewWithPayView:payView];
- if (_cashCouponCount > 0) {
- [self addDiscountView];
- }
-
- if (_buttonType == SPSBOrderListPayButtonTypePay) {
-
- UIView *buttonView = UIView.new;
- buttonView.backgroundColor = spsb_FFFFFF_color(1.f);
- [_spsb_contentView addSubview:buttonView];
- [buttonView makeConstraints:^(JXHConstraintMaker *make) {
- make.bottom.equalTo(self->_spsb_contentView.safebottom);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(spsb_orderListPayViewButtonViewHeight);
- }];
-
- _buttonLoadingView = UIView.new;
- _buttonLoadingView.backgroundColor = spsb_3296FB_color();
- [_buttonLoadingView setLayerCornerRadius:22.5 clipToBounds:false];
- [buttonView addSubview:_buttonLoadingView];
- [_buttonLoadingView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(5);
- make.leading.equalTo(10);
- make.trailing.equalTo(-10);
- make.height.equalTo(45);
- }];
-
- UIView *contentView = UIView.new;
- [_buttonLoadingView addSubview:contentView];
- [contentView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.bottom.equalTo(0);
- make.centerX.equalTo(0);
- }];
-
- NSMutableArray *imageArray = NSMutableArray.new;
- for (NSInteger i = 0; i < 12; i ++) {
- NSString *str = [NSString stringWithFormat:@"ne_map_position_loading%lu", (long)i + 1];
- UIImage *image = [UIImage imageNamed:str];
- [imageArray addObject:image];
- }
- UIImageView *loadingImageView = UIImageView.new;
- loadingImageView.animationDuration = 1;
- loadingImageView.animationImages = imageArray;
- [loadingImageView startAnimating];
- [contentView addSubview:loadingImageView];
- [loadingImageView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(0);
- make.centerY.equalTo(contentView);
- make.size.equalTo(CGSizeMake(16, 16));
- }];
-
- UILabel *title = [UILabel convenienceWithFont:spsb_semiboldFont(16) text:@"确定付款" textColor:spsb_FFFFFF_color(1.f) textAlignment:NSTextAlignmentCenter];
- [contentView addSubview:title];
- [title makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(loadingImageView.trailing).offset(10);
- make.trailing.equalTo(0);
- make.centerY.equalTo(contentView);
- }];
-
- //button
- UIButton *payButton = [UIButton convenienceWithFont:spsb_semiboldFont(16) target:self action:@selector(payAction:)];
- [payButton setTitle:_spsb_showData ? @"立即付款" : @"确定付款" titleColor:spsb_FFFFFF_color(1.f) image:nil backgroundImage:jxh_getImage(confirm_n) state:JXHButtonControlStateNormal];
- [payButton setBackgroundImage:jxh_getImage(confirm_h) state:JXHButtonControlStateHighlighted];
- [payButton setLayerCornerRadius:22.5 clipToBounds:true];
- payButton.tag = _spsb_showData ? 4000 : 4001;
- [buttonView addSubview:payButton];
- [payButton makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(5);
- make.leading.equalTo(10);
- make.trailing.equalTo(-10);
- make.height.equalTo(45);
- }];
- } else if (_buttonType == SPSBOrderListPayButtonTypeQuery) {
- UIButton *queryButton = [UIButton convenienceWithFont:spsb_font(17) target:self action:@selector(queryAction)];
- [queryButton setTitle:@"查询月缴费状态" titleColor:spsb_3296FB_color() state:JXHButtonControlStateNormal];
- queryButton.backgroundColor = spsb_FFFFFF_color(1.f);
- [_spsb_contentView addSubview:queryButton];
- [queryButton makeConstraints:^(JXHConstraintMaker *make) {
- make.bottom.equalTo(self->_spsb_contentView.safebottom);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(spsb_orderListPayViewButtonViewHeight);
- }];
-
- [queryButton createLineWithLocation:JXHLineLocationTop];
- }
- }
- - (void)setTitleView:(NSString *)title {
- //headerview
- UIView *headerView = spsb_createShotViewHeaderWithTitle(title, @selector(dismissContentView), self);
- [_spsb_contentView addSubview:headerView];
- [headerView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.leading.and.trailing.equalTo(0);
- }];
-
- [_spsb_contentView addSubview:_spsb_bgScrollView];
- [_spsb_bgScrollView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(headerView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.bottom.equalTo(self->_spsb_contentView.safebottom);
- }];
- [_spsb_bgScrollView addSubview:_spsb_mScrollView];
- }
- - (void)addMessageViewWithStatusTitle:(NSString *)statusTitle tips:(nullable NSString *)tips {
-
- //messageView
- UIView *messageView = UIView.new;
- messageView.backgroundColor = spsb_FFFFFF_color(1.f);
- [_spsb_mScrollView addSubview:messageView];
- if (tips) {
- UIView *tipsView = UIView.new;
- tipsView.backgroundColor = spsb_FDF8EC_color();
- [_spsb_mScrollView addSubview:tipsView];
- [tipsView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.leading.and.trailing.equalTo(0);
- }];
- UILabel *tipsLabel = [UILabel convenienceWithFont:spsb_font(12) textColor:spsb_FF801A_color() limitWidth:jxh_screenWidth() - 30];
- [tipsLabel setAttributedStringWithText:tips lineSpacing:5];
- [tipsView addSubview:tipsLabel];
- [tipsLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.top.equalTo(15);
- make.trailing.and.bottom.equalTo(-15);
- }];
- [messageView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(tipsView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.width.equalTo(jxh_screenWidth());
- }];
- } else {
- [messageView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(0);
- make.leading.and.trailing.equalTo(0);
- make.width.equalTo(jxh_screenWidth());
- }];
- }
-
- NSArray *arr = _spsb_showData.spsb_message;
- NSInteger count = arr.count / 2;
- UILabel *tempLabel = nil;
- for (NSInteger i = 0; i < count; i ++) {
- UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(14) text:arr[i] textColor:spsb_999999_color()];
- [messageView addSubview:titleLabel];
- [titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
- [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- if (tempLabel) {
- make.top.equalTo(tempLabel.bottom).offset(12);
- } else {
- make.top.equalTo(24);
- }
- }];
-
- UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(14) text:arr[i + count] textColor:spsb_666666_color() textAlignment:NSTextAlignmentRight];
- [messageView addSubview:contentLabel];
- [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.greaterThanOrEqualTo(titleLabel.trailing).offset(10);
- make.trailing.equalTo(-15);
- make.centerY.equalTo(titleLabel);
- }];
-
- tempLabel = titleLabel;
- }
- if (tempLabel) {
- [tempLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.bottom.equalTo(-24);
- }];
- }
-
-
-
- //amountView
- UIView *intervalView = UIView.new;
- intervalView.backgroundColor = spsb_F5F5F5_color();
- [_spsb_mScrollView addSubview:intervalView];
- [intervalView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(messageView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(12);
- }];
-
- UIView *amountView = UIView.new;
- amountView.backgroundColor = spsb_FFFFFF_color(1.f);
- [_spsb_mScrollView addSubview:amountView];
-
- UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(15) text:statusTitle textColor:spsb_333333_color()];
- [amountView addSubview:titleLabel];
- [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- make.centerY.equalTo(amountView);
- }];
-
- UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(17) text:[NSString stringWithFormat:@"¥%@", _spsb_showData.spsb_amount] textColor:spsb_FF5E5E_color() textAlignment:NSTextAlignmentRight];
- [amountView addSubview:contentLabel];
- [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-15);
- make.centerY.equalTo(amountView);
- }];
-
- //detailsView
- if (_spsb_showData.spsb_title && _spsb_showData.spsb_content) {
- [amountView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(intervalView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(50);
- }];
-
- UIView *detailsView = UIView.new;
- [_spsb_mScrollView addSubview:detailsView];
- [detailsView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(amountView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.bottom.equalTo(- spsb_orderListPayViewButtonViewHeight);
- }];
-
- UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(14) textColor:spsb_999999_color() limitWidth:jxh_screenWidth()];
- [titleLabel setAttributedStringWithText:_spsb_showData.spsb_title lineSpacing:10 lines:_spsb_showData.spsb_lines];
- [detailsView addSubview:titleLabel];
- [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- make.top.equalTo(21);
- make.bottom.equalTo(-21);
- }];
-
- UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(14) textColor:spsb_666666_color() limitWidth:jxh_screenWidth()];
- [contentLabel setAttributedStringWithText:_spsb_showData.spsb_content textAlignment:NSTextAlignmentRight lineSpacing:10 lineHeight:0 paragraphSpacing:0 lineBreakMode:NSLineBreakByTruncatingTail lines:_spsb_showData.spsb_lines];
- [detailsView addSubview:contentLabel];
- [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-15);
- make.top.equalTo(21);
- make.bottom.equalTo(-21);
- }];
-
- UIView *line = [_spsb_mScrollView createLine];
- [line makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(amountView.bottom);
- make.leading.equalTo(15);
- make.trailing.equalTo(0);
- make.height.equalTo(jxh_onePixe());
- }];
-
- } else {
- [amountView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(intervalView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(50);
- make.bottom.equalTo(-spsb_orderListPayViewButtonViewHeight);
- }];
- }
- }
- - (void)addPayViewWithPayView:(UIView *)payView {
- NSArray *array = @[@"alipay", @"wepay", @"支付宝支付", @"微信支付"];
- for (NSInteger i = 0; i < 2; i ++) {
- UIButton *button = [UIButton convenienceWithTarget:self action:@selector(choosePay:)];
- button.tag = 3000 + i;
- button.backgroundColor = spsb_FFFFFF_color(1.f);
- [payView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.trailing.equalTo(0);
- make.top.equalTo(70 * i);
- make.height.equalTo(70);
- }];
-
- UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:array[i]]];
- [button addSubview:icon];
- [icon makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- make.centerY.equalTo(0);
- }];
-
- UILabel *title = [UILabel convenienceWithFont:spsb_font(16) text:array[i + 2] textColor:spsb_333333_color()];
- [button addSubview:title];
- [title makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(64);
- make.centerY.equalTo(0);
- }];
-
- UIImageView *chooseImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:i == 0 ? @"filter_s" : @"filter_n"]];
- chooseImageView.tag = 4000;
- [button addSubview:chooseImageView];
- [chooseImageView makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-15);
- make.centerY.equalTo(0);
- }];
-
- if (i == 0) {
- [button createLineWithLocation:JXHLineLocationBottom headOffset:15 footOffset:0];
- } else if (_totalFee - self.spsb_orderBase.spsb_cashCouponTotal > spsb_wxpayLimit()) {
- chooseImageView.image = jxh_getImage(filter_unc);
- }
- }
-
- UIView *contentView = UIView.new;
- contentView.backgroundColor = spsb_FAFAFA_color();
- [payView addSubview:contentView];
- [contentView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(0);
- make.top.equalTo(140);
- make.trailing.equalTo(0);
- }];
-
- UIImageView *info = [[UIImageView alloc] initWithImage:jxh_getImage(order_info)];
- [contentView addSubview:info];
- [info makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(14);
- make.top.equalTo(14);
- }];
-
- UILabel *tips = [UILabel convenienceWithFont:spsb_font(12) textColor:spsb_999999_color() limitWidth:jxh_screenWidth() - 37 - 15];
- [tips setAttributedStringWithText:[NSString stringWithFormat:@"微信支付的非实物商品单日交易限额¥%ld, 超额后建议选择支付宝付款或拆分订单购买。", (long)spsb_wxpayLimit()] lineSpacing:6];
- [contentView addSubview:tips];
- [tips makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(37);
- make.trailing.equalTo(-15);
- make.top.equalTo(14);
- make.bottom.equalTo(-14);
- }];
-
- UIView *intervalView = UIView.new;
- intervalView.backgroundColor = spsb_F5F5F5_color();
- [payView addSubview:intervalView];
- [intervalView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(contentView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(12);
- }];
-
- if (_orderType != SPSBOrderTypeOrderBalance && _orderType != SPSBOrderTypeSalary) {
- UIButton *discountView = [UIButton convenienceWithTarget:self action:@selector(chooseDiscountAction)];
- [payView addSubview:discountView];
- [discountView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(intervalView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(60);
- }];
-
- UILabel *title = [UILabel convenienceWithFont:spsb_font(14) text:@"优惠券" textColor:spsb_333333_color()];
- [discountView addSubview:title];
- [title makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- make.centerY.equalTo(discountView);
- }];
-
- if (_cashCouponCount > 0) {
- UIView *countView = UIView.new;
- [countView setLayerCornerRadius:2 clipToBounds:true];
- [countView setLayerBorderWidth:jxh_onePixe() borderColor:spsb_FF5E5E_color()];
- [discountView addSubview:countView];
- [countView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(72);
- make.centerY.equalTo(discountView);
- make.height.equalTo(17);
- }];
- UILabel *count = [UILabel convenienceWithFont:spsb_font(11) text:[NSString stringWithFormat:@"%lu张可用", (unsigned long)_cashCouponCount] textColor:spsb_FF5E5E_color() textAlignment:NSTextAlignmentCenter];
- [countView addSubview:count];
- [count makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(4);
- make.trailing.equalTo(-4);
- make.top.and.bottom.equalTo(0);
- }];
- }
-
- UILabel *useLabel = [UILabel convenienceWithFont:spsb_font(14) text:_cashCouponCount > 0 ? @"未使用" : @"暂无可用优惠券" textColor:spsb_666666_color() textAlignment:NSTextAlignmentRight];
- [discountView addSubview:useLabel];
- [useLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-34);
- make.centerY.equalTo(discountView);
- }];
- self.spsb_orderBase.spsb_reducePriceLabel = useLabel;
-
- UIImageView *arrow = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
- [discountView addSubview:arrow];
- [arrow makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-15);
- make.centerY.equalTo(discountView);
- }];
-
- intervalView = UIView.new;
- intervalView.backgroundColor = spsb_F5F5F5_color();
- [payView addSubview:intervalView];
- [intervalView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(discountView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(12);
- }];
- }
- }
- - (void)addDiscountView {
- [_spsb_bgScrollView addSubview:_headerView];
- [_headerView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(0);
- make.trailing.equalTo(0);
- make.size.equalTo(CGSizeMake(jxh_screenWidth(), 50));
- }];
-
- _discountCouponVC = SPSBDiscountCouponTableViewController.new;
- _discountCouponVC.spsb_canUse = true;
- _discountCouponVC.spsb_viewType = SPSBDiscountCouponViewTypeUse;
- _discountCouponVC.spsb_maxChose = self.spsb_orderBase.spsb_cashCouponMaxCount;
- @weakify(self)
- _discountCouponVC.spsb_afterChoose = ^{
- @strongify(self)
- [self reloadHeaderView];
- };
- _discountCouponVC.tableView.tableFooterView = [[UIView alloc] initWithFrame:(CGRect){0, 0, jxh_screenWidth(), spsb_orderListPayViewButtonViewHeight}];
- [self addChildViewController:_discountCouponVC];
- [_spsb_bgScrollView addSubview:_discountCouponVC.tableView];
- [_discountCouponVC.tableView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(50);
- make.bottom.equalTo(0);
- make.trailing.equalTo(0);
- make.width.equalTo(jxh_screenWidth());
- }];
- }
- - (UIView *)createHeaderView {
- UIView *headerView = UIView.new;
- headerView.backgroundColor = spsb_F1F8FF_color();
-
- UILabel *firstLabel = [UILabel convenienceWithFont:spsb_font(12) text:[NSString stringWithFormat:@"您当前下了 %ld 个月订单,可同时选", (long)self.spsb_orderBase.spsb_cashCouponMaxCount] textColor:spsb_666666_color()];
- firstLabel.tag = 3001;
- [headerView addSubview:firstLabel];
- [firstLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- make.centerY.equalTo(headerView);
- }];
-
- UILabel *secondLabel = [UILabel convenienceWithFont:spsb_font(12) text:[NSString stringWithFormat:@" %ld ", (long)self.spsb_orderBase.spsb_cashCouponMaxCount] textColor:spsb_FF5E5E_color()];
- secondLabel.tag = 3002;
- [headerView addSubview:secondLabel];
- [secondLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(firstLabel.trailing);
- make.centerY.equalTo(headerView);
- }];
-
- 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(headerView);
- }];
- return headerView;
- }
- - (void)reloadHeaderView {
- UILabel *firstLabel = [_headerView viewWithTag:3001];
- UILabel *secondLabel = [_headerView viewWithTag:3002];
- UILabel *thirdLabel = [_headerView viewWithTag:3003];
-
- if (_discountCouponVC.spsb_chose.count > 0) {
- firstLabel.text = [NSString stringWithFormat:@"您已选中优惠券 %ld 张,共可抵用", (long)_discountCouponVC.spsb_chose.count];
- CGFloat reduce = 0;
- for (NSNumber *index in _discountCouponVC.spsb_chose) {
- SPSBDiscountCouponModel *model = _discountCouponVC.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)self.spsb_orderBase.spsb_cashCouponMaxCount];
- secondLabel.text = [NSString stringWithFormat:@" %ld ", (long)self.spsb_orderBase.spsb_cashCouponMaxCount];
- thirdLabel.text = @"张优惠券";
- }
- }
- @end
|