SPSBRefundViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //
  2. // SPSBRefundViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/5/31.
  6. //
  7. #import "SPSBRefundViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBWarningtipsView.h"
  10. #import "SPSBQueryListModel.h"
  11. #import "SPSBTitleAndContentTableViewCell.h"
  12. #import <UITextView+JXHPlaceHolder.h>
  13. #import "SPSBPickerViewController.h"
  14. #import "SPSBPickerView.h"
  15. #import "UIViewController+SPSBNetworkManager.h"
  16. #import "SPSBNotificationDelegateManager.h"
  17. #import <NSObject+JXHNotification.h>
  18. @interface SPSBRefundViewController ()<UITextViewDelegate> {
  19. NSArray *_refundReasonArray;
  20. UIScrollView *_bgView;
  21. NSString *_reason;
  22. SPSBTitleAndContentTableViewCell *_reasonCell;
  23. UITextView *_textView;
  24. UIButton *_confirmButton;
  25. }
  26. @end
  27. @implementation SPSBRefundViewController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. [self initData];
  31. [self setupUI];
  32. @weakify(self)
  33. [self addNotificationName:UIKeyboardWillChangeFrameNotification block:^(id object, NSDictionary *userInfo) {
  34. @strongify(self)
  35. [self keyboardWillChangeFrame:userInfo];
  36. }];
  37. }
  38. - (void)dealloc {
  39. [self removeAllNotification];
  40. }
  41. - (void)initData {
  42. _refundReasonArray = @[@"已有新单位缴费", @"填写信息有误,重新下单", @"在领失业救济中,不能参保", @"其他原因"];
  43. }
  44. #pragma mark - Action
  45. - (void)keyboardWillChangeFrame:(NSDictionary *)sender {
  46. debugLog(@"======================%@", sender);
  47. #pragma clang diagnostic push
  48. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  49. SEL f = NSSelectorFromString([NSString stringWithFormat:@"%@%@", @"first", @"Responder"]);
  50. id firstResponder = [spsb_keyWindow() performSelector:f];
  51. #pragma clang diagnostic pop
  52. if (firstResponder == _textView) {
  53. CGFloat keyboardY = [sender[UIKeyboardFrameEndUserInfoKey] CGRectValue].origin.y;
  54. if (keyboardY == jxh_screenHeight()) {
  55. [_confirmButton makeConstraints:^(JXHConstraintMaker *make) {
  56. make.bottom.update(-50);
  57. }];
  58. return;
  59. }
  60. if (_bgView.contentSize.height < jxh_viewHeight(_bgView) + jxh_viewY(_textView.superview)) {
  61. CGFloat d = jxh_viewHeight(_bgView) + jxh_viewY(_textView.superview) - _bgView.contentSize.height;
  62. [_confirmButton makeConstraints:^(JXHConstraintMaker *make) {
  63. make.bottom.update(-50 - d);
  64. }];
  65. [_bgView setContentOffset:(CGPoint){0, jxh_viewY(_textView.superview)} animated:true];
  66. }
  67. }
  68. }
  69. #pragma mark - Action
  70. - (void)confirmAction {
  71. jxh_endEdit();
  72. if (!_reason) {
  73. [self.view showToastWithTitle:@"请选择退款原因"];
  74. return;
  75. }
  76. NSString *reason = _reason;
  77. NSString *refundDescription = jxh_deleteBothSidesSpace(_textView.text);
  78. if (![refundDescription isEqualToString:@""]) {
  79. reason = [NSString stringWithFormat:@"%@#%@", reason, refundDescription];
  80. }
  81. [self refundActionWithReason:reason];
  82. }
  83. - (void)chooseReason {
  84. SPSBPickerViewController *vc = SPSBPickerViewController.new;
  85. vc.spsb_dataArray = @[_refundReasonArray];
  86. @weakify(self)
  87. vc.spsb_finishChose = ^(SPSBPickerView * _Nonnull pickerView) {
  88. @strongify(self)
  89. [self completeToChoseReasonWithPickerView:pickerView];
  90. };
  91. vc.spsb_willDisplay = ^(SPSBPickerView * _Nonnull pickerView) {
  92. [pickerView chooseRow:0 inComponent:0 animated:false];
  93. };
  94. [self presentViewController:vc animated:false completion:nil];
  95. }
  96. - (void)completeToChoseReasonWithPickerView:(SPSBPickerView *)pickerView {
  97. NSInteger index = [pickerView.spsb_choseArray[0] integerValue];
  98. _reason = _refundReasonArray[index];
  99. _reasonCell.spsb_contentLabel.text = _reason;
  100. }
  101. #pragma mark - Network Action
  102. - (void)refundActionWithReason:(NSString *)reason {
  103. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在申请" isLogin:true url:spsb_appUrl(SPSBUrlRefund) urlParameters:nil parameters:^NSDictionary * _Nonnull{
  104. return @{@"order_no" : self->_spsb_data.spsb_order_no, @"reason" : reason};
  105. } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  106. spsb_postNotification(SPSBPurchaseNotificationKey, @selector(spsb_refundSuccuss), spsb_refundSuccuss);
  107. return @"申请退款成功";
  108. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  109. return @"申请退款失败";
  110. }];
  111. }
  112. #pragma mark - UITextViewDelegate
  113. - (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
  114. jxh_handleInputTextView(textView, textView.font, 4, 0, NSTextAlignmentLeft);
  115. return true;
  116. }
  117. - (void)textViewDidChange:(UITextView *)textView {
  118. UITextRange *selectedRange = [textView markedTextRange];
  119. if (!selectedRange) {
  120. if (textView.text.length > 120) {
  121. textView.text = [textView.text substringToIndex:120];
  122. }
  123. }
  124. }
  125. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  126. if (scrollView == _bgView) {
  127. jxh_endEdit();
  128. }
  129. }
  130. #pragma mark - UI
  131. - (void)setupUI {
  132. self.title = @"退款理由";
  133. [self createBgView];
  134. [self createContentView];
  135. }
  136. - (void)createBgView {
  137. _bgView = [UIScrollView convenienceWithBackgroundColor:spsb_F5F5F5_color()];
  138. if (@available(iOS 11.0, *)) {
  139. _bgView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
  140. }
  141. _bgView.delegate = self;
  142. [self.view addSubview:_bgView];
  143. [_bgView makeConstraints:^(JXHConstraintMaker *make) {
  144. make.edges.equalTo(0);
  145. }];
  146. }
  147. - (void)createContentView {
  148. UIView *headerView = UIView.new;
  149. headerView.backgroundColor = spsb_FFFFFF_color(1.f);
  150. [_bgView addSubview:headerView];
  151. [headerView makeConstraints:^(JXHConstraintMaker *make) {
  152. make.top.and.leading.and.trailing.equalTo(0);
  153. make.width.equalTo(jxh_screenWidth());
  154. }];
  155. SPSBWarningtipsView *warningView = [[SPSBWarningtipsView alloc] initWithTitles:@[@"退款时,支付宝或微信平台收取0.6%的手续费需由您承担"]];
  156. [headerView addSubview:warningView];
  157. [warningView makeConstraints:^(JXHConstraintMaker *make) {
  158. make.top.and.leading.and.trailing.equalTo(0);
  159. }];
  160. UIView *amountView = UIView.new;
  161. [headerView addSubview:amountView];
  162. [amountView makeConstraints:^(JXHConstraintMaker *make) {
  163. make.leading.and.trailing.equalTo(0);
  164. make.top.equalTo(warningView.bottom);
  165. make.height.equalTo(50);
  166. }];
  167. UILabel *title = [UILabel convenienceWithFont:spsb_font(16) text:@"退款金额" textColor:spsb_333333_color()];
  168. [amountView addSubview:title];
  169. [title makeConstraints:^(JXHConstraintMaker *make) {
  170. make.leading.equalTo(15);
  171. make.centerY.equalTo(amountView);
  172. }];
  173. UILabel *content = [UILabel convenienceWithFont:spsb_font(16) text:[NSString stringWithFormat:@"¥%.2lf", _spsb_data.spsb_pay_actual.floatValue] textColor:spsb_FF5E5E_color() textAlignment:NSTextAlignmentRight];
  174. [amountView addSubview:content];
  175. [content makeConstraints:^(JXHConstraintMaker *make) {
  176. make.trailing.equalTo(-15);
  177. make.centerY.equalTo(amountView);
  178. }];
  179. UIView *tipsView = UIView.new;
  180. tipsView.backgroundColor = spsb_F5F5F5_color();
  181. [headerView addSubview:tipsView];
  182. [tipsView makeConstraints:^(JXHConstraintMaker *make) {
  183. make.leading.and.trailing.equalTo(0);
  184. make.top.equalTo(amountView.bottom);
  185. make.height.equalTo(45);
  186. make.bottom.equalTo(0);
  187. }];
  188. UILabel *label = [UILabel convenienceWithFont:spsb_font(13) text:@"申请后会7个工作日内原路退款,请耐心等待" textColor:spsb_999999_color()];
  189. [tipsView addSubview:label];
  190. [label makeConstraints:^(JXHConstraintMaker *make) {
  191. make.leading.equalTo(15);
  192. make.top.equalTo(20);
  193. }];
  194. _reasonCell = [SPSBTitleAndContentTableViewCell createSelectCellWithTitle:@"退款原因" content:@"请选择"];
  195. [_reasonCell addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseReason)]];
  196. _reasonCell.contentView.backgroundColor = spsb_FFFFFF_color(1.f);
  197. [_bgView addSubview:_reasonCell];
  198. [_reasonCell makeConstraints:^(JXHConstraintMaker *make) {
  199. make.leading.and.trailing.equalTo(0);
  200. make.top.equalTo(headerView.bottom);
  201. make.height.equalTo(50);
  202. }];
  203. UIView *footerView = UIView.new;
  204. footerView.backgroundColor = spsb_FFFFFF_color(1.f);
  205. [_bgView addSubview:footerView];
  206. [footerView makeConstraints:^(JXHConstraintMaker *make) {
  207. make.top.equalTo(self->_reasonCell.bottom).offset(12);
  208. make.leading.and.trailing.equalTo(0);
  209. make.height.equalTo(200);
  210. }];
  211. title = [UILabel convenienceWithFont:spsb_font(16) text:@"退款说明" textColor:spsb_333333_color()];
  212. [footerView addSubview:title];
  213. [title makeConstraints:^(JXHConstraintMaker *make) {
  214. make.leading.equalTo(15);
  215. make.top.equalTo(15);
  216. }];
  217. _textView = UITextView.new;
  218. _textView.font = spsb_font(16);
  219. _textView.textColor = spsb_333333_color();
  220. _textView.delegate = self;
  221. [_textView setPlaceholder:@"请填写退款理由" placeholdColor:spsb_CCCCCC_color()];
  222. [footerView addSubview:_textView];
  223. [_textView makeConstraints:^(JXHConstraintMaker *make) {
  224. make.top.equalTo(title.bottom).offset(10);
  225. make.leading.equalTo(10);
  226. make.trailing.equalTo(-10);
  227. make.bottom.equalTo(-15);
  228. }];
  229. _confirmButton = [UIButton convenienceWithFont:spsb_semiboldFont(16) target:self action:@selector(confirmAction)];
  230. [_confirmButton setTitle:@"提交" titleColor:spsb_FFFFFF_color(1.f) image:nil backgroundImage:jxh_getImage(confirm_n) state:JXHButtonControlStateNormal];
  231. [_confirmButton setBackgroundImage:jxh_getImage(confirm_h) state:JXHButtonControlStateHighlighted];
  232. [_confirmButton setLayerCornerRadius:22.5 clipToBounds:true];
  233. [_bgView addSubview:_confirmButton];
  234. [_confirmButton makeConstraints:^(JXHConstraintMaker *make) {
  235. make.leading.equalTo(15);
  236. make.trailing.equalTo(-15);
  237. make.top.equalTo(footerView.bottom).offset(24);
  238. make.height.equalTo(45);
  239. make.bottom.equalTo(-50);
  240. }];
  241. }
  242. @end