// // SPSBRefundViewController.m // 我的社保 // // Created by shanp on 2021/5/31. // #import "SPSBRefundViewController.h" #import "SPSBUIGeneralHeader.h" #import "SPSBWarningtipsView.h" #import "SPSBQueryListModel.h" #import "SPSBTitleAndContentTableViewCell.h" #import #import "SPSBPickerViewController.h" #import "SPSBPickerView.h" #import "UIViewController+SPSBNetworkManager.h" #import "SPSBNotificationDelegateManager.h" #import @interface SPSBRefundViewController () { NSArray *_refundReasonArray; UIScrollView *_bgView; NSString *_reason; SPSBTitleAndContentTableViewCell *_reasonCell; UITextView *_textView; UIButton *_confirmButton; } @end @implementation SPSBRefundViewController - (void)viewDidLoad { [super viewDidLoad]; [self initData]; [self setupUI]; @weakify(self) [self addNotificationName:UIKeyboardWillChangeFrameNotification block:^(id object, NSDictionary *userInfo) { @strongify(self) [self keyboardWillChangeFrame:userInfo]; }]; } - (void)dealloc { [self removeAllNotification]; } - (void)initData { _refundReasonArray = @[@"已有新单位缴费", @"填写信息有误,重新下单", @"在领失业救济中,不能参保", @"其他原因"]; } #pragma mark - Action - (void)keyboardWillChangeFrame:(NSDictionary *)sender { debugLog(@"======================%@", sender); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" SEL f = NSSelectorFromString([NSString stringWithFormat:@"%@%@", @"first", @"Responder"]); id firstResponder = [spsb_keyWindow() performSelector:f]; #pragma clang diagnostic pop if (firstResponder == _textView) { CGFloat keyboardY = [sender[UIKeyboardFrameEndUserInfoKey] CGRectValue].origin.y; if (keyboardY == jxh_screenHeight()) { [_confirmButton makeConstraints:^(JXHConstraintMaker *make) { make.bottom.update(-50); }]; return; } if (_bgView.contentSize.height < jxh_viewHeight(_bgView) + jxh_viewY(_textView.superview)) { CGFloat d = jxh_viewHeight(_bgView) + jxh_viewY(_textView.superview) - _bgView.contentSize.height; [_confirmButton makeConstraints:^(JXHConstraintMaker *make) { make.bottom.update(-50 - d); }]; [_bgView setContentOffset:(CGPoint){0, jxh_viewY(_textView.superview)} animated:true]; } } } #pragma mark - Action - (void)confirmAction { jxh_endEdit(); if (!_reason) { [self.view showToastWithTitle:@"请选择退款原因"]; return; } NSString *reason = _reason; NSString *refundDescription = jxh_deleteBothSidesSpace(_textView.text); if (![refundDescription isEqualToString:@""]) { reason = [NSString stringWithFormat:@"%@#%@", reason, refundDescription]; } [self refundActionWithReason:reason]; } - (void)chooseReason { SPSBPickerViewController *vc = SPSBPickerViewController.new; vc.spsb_dataArray = @[_refundReasonArray]; @weakify(self) vc.spsb_finishChose = ^(SPSBPickerView * _Nonnull pickerView) { @strongify(self) [self completeToChoseReasonWithPickerView:pickerView]; }; vc.spsb_willDisplay = ^(SPSBPickerView * _Nonnull pickerView) { [pickerView chooseRow:0 inComponent:0 animated:false]; }; [self presentViewController:vc animated:false completion:nil]; } - (void)completeToChoseReasonWithPickerView:(SPSBPickerView *)pickerView { NSInteger index = [pickerView.spsb_choseArray[0] integerValue]; _reason = _refundReasonArray[index]; _reasonCell.spsb_contentLabel.text = _reason; } #pragma mark - Network Action - (void)refundActionWithReason:(NSString *)reason { [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在申请" isLogin:true url:spsb_appUrl(SPSBUrlRefund) urlParameters:nil parameters:^NSDictionary * _Nonnull{ return @{@"order_no" : self->_spsb_data.spsb_order_no, @"reason" : reason}; } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) { spsb_postNotification(SPSBPurchaseNotificationKey, @selector(spsb_refundSuccuss), spsb_refundSuccuss); return @"申请退款成功"; } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) { return @"申请退款失败"; }]; } #pragma mark - UITextViewDelegate - (BOOL)textViewShouldBeginEditing:(UITextView *)textView { jxh_handleInputTextView(textView, textView.font, 4, 0, NSTextAlignmentLeft); return true; } - (void)textViewDidChange:(UITextView *)textView { UITextRange *selectedRange = [textView markedTextRange]; if (!selectedRange) { if (textView.text.length > 120) { textView.text = [textView.text substringToIndex:120]; } } } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { if (scrollView == _bgView) { jxh_endEdit(); } } #pragma mark - UI - (void)setupUI { self.title = @"退款理由"; [self createBgView]; [self createContentView]; } - (void)createBgView { _bgView = [UIScrollView convenienceWithBackgroundColor:spsb_F5F5F5_color()]; if (@available(iOS 11.0, *)) { _bgView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic; } _bgView.delegate = self; [self.view addSubview:_bgView]; [_bgView makeConstraints:^(JXHConstraintMaker *make) { make.edges.equalTo(0); }]; } - (void)createContentView { UIView *headerView = UIView.new; headerView.backgroundColor = spsb_FFFFFF_color(1.f); [_bgView addSubview:headerView]; [headerView makeConstraints:^(JXHConstraintMaker *make) { make.top.and.leading.and.trailing.equalTo(0); make.width.equalTo(jxh_screenWidth()); }]; SPSBWarningtipsView *warningView = [[SPSBWarningtipsView alloc] initWithTitles:@[@"退款时,支付宝或微信平台收取0.6%的手续费需由您承担"]]; [headerView addSubview:warningView]; [warningView makeConstraints:^(JXHConstraintMaker *make) { make.top.and.leading.and.trailing.equalTo(0); }]; UIView *amountView = UIView.new; [headerView addSubview:amountView]; [amountView makeConstraints:^(JXHConstraintMaker *make) { make.leading.and.trailing.equalTo(0); make.top.equalTo(warningView.bottom); make.height.equalTo(50); }]; UILabel *title = [UILabel convenienceWithFont:spsb_font(16) text:@"退款金额" textColor:spsb_333333_color()]; [amountView addSubview:title]; [title makeConstraints:^(JXHConstraintMaker *make) { make.leading.equalTo(15); make.centerY.equalTo(amountView); }]; UILabel *content = [UILabel convenienceWithFont:spsb_font(16) text:[NSString stringWithFormat:@"¥%.2lf", _spsb_data.spsb_pay_actual.floatValue] textColor:spsb_FF5E5E_color() textAlignment:NSTextAlignmentRight]; [amountView addSubview:content]; [content makeConstraints:^(JXHConstraintMaker *make) { make.trailing.equalTo(-15); make.centerY.equalTo(amountView); }]; UIView *tipsView = UIView.new; tipsView.backgroundColor = spsb_F5F5F5_color(); [headerView addSubview:tipsView]; [tipsView makeConstraints:^(JXHConstraintMaker *make) { make.leading.and.trailing.equalTo(0); make.top.equalTo(amountView.bottom); make.height.equalTo(45); make.bottom.equalTo(0); }]; UILabel *label = [UILabel convenienceWithFont:spsb_font(13) text:@"申请后会7个工作日内原路退款,请耐心等待" textColor:spsb_999999_color()]; [tipsView addSubview:label]; [label makeConstraints:^(JXHConstraintMaker *make) { make.leading.equalTo(15); make.top.equalTo(20); }]; _reasonCell = [SPSBTitleAndContentTableViewCell createSelectCellWithTitle:@"退款原因" content:@"请选择"]; [_reasonCell addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseReason)]]; _reasonCell.contentView.backgroundColor = spsb_FFFFFF_color(1.f); [_bgView addSubview:_reasonCell]; [_reasonCell makeConstraints:^(JXHConstraintMaker *make) { make.leading.and.trailing.equalTo(0); make.top.equalTo(headerView.bottom); make.height.equalTo(50); }]; UIView *footerView = UIView.new; footerView.backgroundColor = spsb_FFFFFF_color(1.f); [_bgView addSubview:footerView]; [footerView makeConstraints:^(JXHConstraintMaker *make) { make.top.equalTo(self->_reasonCell.bottom).offset(12); make.leading.and.trailing.equalTo(0); make.height.equalTo(200); }]; title = [UILabel convenienceWithFont:spsb_font(16) text:@"退款说明" textColor:spsb_333333_color()]; [footerView addSubview:title]; [title makeConstraints:^(JXHConstraintMaker *make) { make.leading.equalTo(15); make.top.equalTo(15); }]; _textView = UITextView.new; _textView.font = spsb_font(16); _textView.textColor = spsb_333333_color(); _textView.delegate = self; [_textView setPlaceholder:@"请填写退款理由" placeholdColor:spsb_CCCCCC_color()]; [footerView addSubview:_textView]; [_textView makeConstraints:^(JXHConstraintMaker *make) { make.top.equalTo(title.bottom).offset(10); make.leading.equalTo(10); make.trailing.equalTo(-10); make.bottom.equalTo(-15); }]; _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]; [_bgView addSubview:_confirmButton]; [_confirmButton makeConstraints:^(JXHConstraintMaker *make) { make.leading.equalTo(15); make.trailing.equalTo(-15); make.top.equalTo(footerView.bottom).offset(24); make.height.equalTo(45); make.bottom.equalTo(-50); }]; } @end