SPSBOrderListPayViewController.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. //
  2. // SPSBOrderListPayViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/6/19.
  6. //
  7. #import "SPSBOrderListPayViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBOrderListShowItem.h"
  10. #import "SPSBBusinessManager.h"
  11. #import "SPSBDiscountCouponTableViewController.h"
  12. #import "UIViewController+SPSBNetworkManager.h"
  13. #import "SPSBDiscountCouponModel.h"
  14. #import "SPSBPayResultViewController.h"
  15. #define spsb_orderListPayViewButtonViewHeight 55
  16. @interface SPSBOrderListPayViewController () {
  17. CGFloat _totalFee;
  18. BOOL _showDetails;
  19. SPSBOrderType _orderType;
  20. NSUInteger _cashCouponCount;//可用数量
  21. UIView *_headerView;
  22. SPSBOrderListPayButtonType _buttonType;
  23. UIView *_buttonLoadingView;
  24. SPSBDiscountCouponTableViewController *_discountCouponVC;
  25. }
  26. @end
  27. @implementation SPSBOrderListPayViewController
  28. - (instancetype)init {
  29. self = [super init];
  30. if (!self) return nil;
  31. self.modalPresentationStyle = UIModalPresentationCustom;
  32. return self;
  33. }
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. [self setupAnimation];
  37. [self setupUI];
  38. }
  39. - (void)viewWillAppear:(BOOL)animated {
  40. [super viewWillAppear:animated];
  41. if (!self.isBeingPresented) {
  42. [self.presentingViewController viewWillAppear:animated];
  43. }
  44. }
  45. - (void)viewDidAppear:(BOOL)animated {
  46. [super viewDidAppear:animated];
  47. if (!self.isBeingPresented) {
  48. [self.presentingViewController viewDidAppear:animated];
  49. } else {
  50. [self.view setNeedsLayout];
  51. [self.view layoutIfNeeded];
  52. [self showAnimation];
  53. }
  54. }
  55. - (void)viewWillDisappear:(BOOL)animated {
  56. [super viewWillDisappear:animated];
  57. if (!self.isBeingDismissed) {
  58. [self.presentingViewController viewWillDisappear:animated];
  59. }
  60. }
  61. - (void)viewDidDisappear:(BOOL)animated {
  62. [super viewDidDisappear:animated];
  63. if (!self.isBeingDismissed) {
  64. [self.presentingViewController viewDidDisappear:animated];
  65. }
  66. }
  67. - (UIStatusBarStyle)preferredStatusBarStyle {
  68. UIViewController *vc = self.presentingViewController;
  69. if ([vc isKindOfClass:[UINavigationController class]]) {
  70. return ((UIViewController *)((UINavigationController *)self.presentingViewController).viewControllers.lastObject).preferredStatusBarStyle;
  71. } else {
  72. return vc.preferredStatusBarStyle;
  73. }
  74. return self.presentingViewController.preferredStatusBarStyle;
  75. }
  76. #pragma mark - Action
  77. - (void)setOrderBaseWithOrderType:(SPSBOrderType)type totalFee:(CGFloat)totalFee discountCount:(NSUInteger)discountCount orderNumber:(NSUInteger)orderNumber showData:(nullable SPSBOrderListShowItem *)data buttonType:(SPSBOrderListPayButtonType)buttonType {
  78. _spsb_showData = data;
  79. _orderType = type;
  80. _totalFee = totalFee;
  81. _cashCouponCount = discountCount;
  82. self.spsb_orderBase.spsb_cashCouponMaxCount = orderNumber;
  83. _showDetails = data != nil;
  84. _buttonType = buttonType;
  85. }
  86. - (void)queryAction {}
  87. - (void)payAction {}
  88. - (void)payAction:(UIButton *)sender {
  89. UILabel *titleView = [_headerView viewWithTag:spsb_headerViewLabelTag];
  90. if (sender.tag == 4000) {
  91. sender.tag = 4001;
  92. [sender setTitle:@"确定付款" state:JXHButtonControlStateNormal];
  93. [_spsb_bgScrollView setContentOffset:CGPointMake(jxh_screenWidth(), 0) animated:true];
  94. titleView.text = @"选择支付方式";
  95. } else if (sender.tag == 4001) {
  96. [_spsb_contentView bringSubviewToFront:_buttonLoadingView];
  97. @weakify(self)
  98. self.spsb_orderBase.spsb_payFailure = ^(NSError *error) {
  99. @strongify(self)
  100. [self->_spsb_contentView bringSubviewToFront:sender];
  101. if (error) {
  102. [self handleFailureTipsWithError:error tips:@"生成订单失败"];
  103. } else {
  104. [self.view showToastWithTitle:@"支付失败"];
  105. }
  106. };
  107. [self payAction];
  108. } else if (sender.tag == 4002) {
  109. sender.tag = 4001;
  110. [sender setTitle:@"确定付款" state:JXHButtonControlStateNormal];
  111. if (_showDetails) {
  112. [_spsb_bgScrollView setContentOffset:CGPointMake(jxh_screenWidth(), 0) animated:true];
  113. } else {
  114. [_spsb_bgScrollView setContentOffset:CGPointMake(0, 0) animated:true];
  115. }
  116. titleView.text = @"选择支付方式";
  117. self.spsb_orderBase.spsb_cashCouponTotal = 0;
  118. self.spsb_orderBase.spsb_cashCouponIds = NSMutableString.new;
  119. for (NSNumber *num in _discountCouponVC.spsb_chose) {
  120. SPSBDiscountCouponModel *model = _discountCouponVC.spsb_data[[num unsignedIntegerValue]];
  121. self.spsb_orderBase.spsb_cashCouponTotal += [model.spsb_coupon_price integerValue];
  122. [self.spsb_orderBase.spsb_cashCouponIds appendFormat:@"%@,", model.spsb_id];
  123. }
  124. if (![self.spsb_orderBase.spsb_cashCouponIds isEqualToString:@""]) {
  125. [self.spsb_orderBase.spsb_cashCouponIds deleteCharactersInRange:NSMakeRange(self.spsb_orderBase.spsb_cashCouponIds.length - 1, 1)];
  126. }
  127. UIImageView *zfbImage = [[self.spsb_orderBase.spsb_reducePriceLabel.superview.superview viewWithTag:3000] viewWithTag:4000];
  128. UIImageView *wxImage = [[self.spsb_orderBase.spsb_reducePriceLabel.superview.superview viewWithTag:3001] viewWithTag:4000];
  129. if (_totalFee - self.spsb_orderBase.spsb_cashCouponTotal > spsb_wxpayLimit()) {
  130. self.spsb_orderBase.spsb_chosePay = 0;
  131. zfbImage.image = jxh_getImage(filter_s);
  132. wxImage.image = jxh_getImage(filter_unc);
  133. } else {
  134. if (self.spsb_orderBase.spsb_chosePay == 0) {
  135. wxImage.image = jxh_getImage(filter_n);
  136. }
  137. }
  138. if (self.spsb_orderBase.spsb_cashCouponTotal > 0) {
  139. self.spsb_orderBase.spsb_reducePriceLabel.text = [NSString stringWithFormat:@"-¥%.2lf", (CGFloat)self.spsb_orderBase.spsb_cashCouponTotal];
  140. } else {
  141. self.spsb_orderBase.spsb_reducePriceLabel.text = @"未使用";
  142. }
  143. }
  144. }
  145. - (void)choosePay:(UIButton *)sender {
  146. if (sender.tag == 3000) {
  147. self.spsb_orderBase.spsb_chosePay = sender.tag - 3000;
  148. ((UIImageView *)[sender viewWithTag:4000]).image = jxh_getImage(filter_s);
  149. ((UIImageView *)[[sender.superview viewWithTag:3001] viewWithTag:4000]).image = jxh_getImage(filter_n);
  150. } else if (sender.tag == 3001) {
  151. if (_totalFee - self.spsb_orderBase.spsb_cashCouponTotal > spsb_wxpayLimit()) {
  152. return;
  153. }
  154. self.spsb_orderBase.spsb_chosePay = sender.tag - 3000;
  155. ((UIImageView *)[sender viewWithTag:4000]).image = jxh_getImage(filter_s);
  156. ((UIImageView *)[[sender.superview viewWithTag:3000] viewWithTag:4000]).image = jxh_getImage(filter_n);
  157. }
  158. }
  159. - (void)chooseDiscountAction {
  160. if (_cashCouponCount <= 0) return;
  161. UILabel *titleView = [_headerView viewWithTag:spsb_headerViewLabelTag];
  162. UIButton *button = [_spsb_contentView viewWithTag:4001];
  163. button.tag = 4002;
  164. [button setTitle:@"确定" state:JXHButtonControlStateNormal];
  165. if (_showDetails) {
  166. [_spsb_bgScrollView setContentOffset:CGPointMake(jxh_screenWidth() * 2, 0) animated:true];
  167. } else {
  168. [_spsb_bgScrollView setContentOffset:CGPointMake(jxh_screenWidth(), 0) animated:true];
  169. }
  170. titleView.text = @"优惠券";
  171. [self reloadHeaderView];
  172. }
  173. - (void)pushResultVC:(SPSBPayResultViewController *)vc {
  174. [self dismissContentViewCompletion:^{
  175. UIViewController *v = jxh_findPresentedViewControllerStartingFrom(spsb_keyWindow().rootViewController);
  176. if (v.navigationController) {
  177. [v.navigationController pushViewController:vc animated:true];
  178. }
  179. }];
  180. }
  181. - (void)dismissContentView {
  182. [self dismissContentViewCompletion:nil];
  183. }
  184. - (void)dismissContentViewCompletion:(void (^ _Nullable)(void))completion {
  185. [_spsb_contentView makeConstraints:^(JXHConstraintMaker *make) {
  186. make.top.update(0);
  187. }];
  188. [UIView animateWithDuration:0.3 animations:^{
  189. [self.view layoutSubviews];
  190. self.view.backgroundColor = spsb_000000_color(0);
  191. } completion:^(BOOL finished) {
  192. [self dismissViewControllerAnimated:false completion:completion];
  193. }];
  194. }
  195. - (void)setupAnimation {
  196. self.view.backgroundColor = spsb_000000_color(0.f);
  197. }
  198. - (void)showAnimation {
  199. [_spsb_contentView makeConstraints:^(JXHConstraintMaker *make) {
  200. make.top.update(-jxh_viewHeight(self->_spsb_contentView));
  201. }];
  202. [UIView animateWithDuration:0.3 animations:^{
  203. [self.view layoutSubviews];
  204. self.view.backgroundColor = spsb_000000_color(SPSBPopupViewBackgroundAlpha);
  205. }];
  206. }
  207. #pragma mark - Network Action
  208. #pragma mark - UI
  209. - (void)setupUI {
  210. _spsb_contentView = UIView.new;
  211. _spsb_contentView.backgroundColor = spsb_FFFFFF_color(1.f);
  212. [self.view addSubview:_spsb_contentView];
  213. [_spsb_contentView makeConstraints:^(JXHConstraintMaker *make) {
  214. make.leading.and.trailing.equalTo(0);
  215. make.height.equalTo(480);
  216. make.top.equalTo(self.view.bottom);
  217. }];
  218. UIButton *dismissButton = [UIButton convenienceWithTarget:self action:@selector(dismissContentView)];
  219. [self.view addSubview:dismissButton];
  220. [dismissButton makeConstraints:^(JXHConstraintMaker *make) {
  221. make.top.and.leading.and.trailing.equalTo(0);
  222. make.bottom.equalTo(self->_spsb_contentView.top);
  223. }];
  224. #ifdef DEBUG
  225. [self addTestButton];
  226. #endif
  227. _spsb_bgScrollView = [UIScrollView convenienceWithBackgroundColor:spsb_FFFFFF_color(1.f)];
  228. _spsb_bgScrollView.scrollEnabled = false;
  229. _spsb_mScrollView = [UIScrollView convenienceWithBackgroundColor:spsb_FFFFFF_color(1.f)];
  230. }
  231. - (void)createPayView {
  232. if (_cashCouponCount > 0) {
  233. _headerView = [self createHeaderView];
  234. }
  235. NSString *title;
  236. if (_orderType == SPSBOrderTypeSalary) {
  237. title = @"社保流水订单详情";
  238. } else {
  239. title = _spsb_showData ? @"订单详情" : @"选择支付方式";
  240. }
  241. [self setTitleView:title];
  242. if (_spsb_showData) {
  243. [_spsb_mScrollView makeConstraints:^(JXHConstraintMaker *make) {
  244. make.leading.and.top.and.bottom.equalTo(0);
  245. make.width.equalTo(jxh_screenWidth());
  246. make.height.equalTo(self->_spsb_bgScrollView);
  247. }];
  248. if (_orderType == SPSBOrderTypeSalary) {
  249. [self addMessageViewWithStatusTitle:_buttonType == SPSBOrderListPayButtonTypePay ? @"待付款" : @"已付款" tips:@"用作流水记录,逾期未缴费可能会导致参保失败。成功付款后,将会于退还至参保人银行卡,部分城市例如北京,可能分两笔返还,第一笔通过银行卡转账返还,第二笔通过退款返还。"];
  250. } else {
  251. [self addMessageViewWithStatusTitle:_buttonType == SPSBOrderListPayButtonTypePay ? @"待付款" : @"已付款" tips:nil];
  252. }
  253. } else {
  254. [_spsb_mScrollView makeConstraints:^(JXHConstraintMaker *make) {
  255. make.leading.and.top.and.bottom.equalTo(0);
  256. make.width.equalTo(0);
  257. make.height.equalTo(self->_spsb_bgScrollView);
  258. }];
  259. }
  260. UIView *payView = UIView.new;
  261. payView.backgroundColor = spsb_FFFFFF_color(1.f);
  262. [_spsb_bgScrollView addSubview:payView];
  263. [payView makeConstraints:^(JXHConstraintMaker *make) {
  264. make.top.and.bottom.equalTo(0);
  265. make.leading.equalTo(self->_spsb_mScrollView.trailing);
  266. make.trailing.equalTo(-jxh_screenWidth());
  267. make.width.equalTo(jxh_screenWidth());
  268. make.height.equalTo(self->_spsb_bgScrollView);
  269. }];
  270. [self addPayViewWithPayView:payView];
  271. if (_cashCouponCount > 0) {
  272. [self addDiscountView];
  273. }
  274. if (_buttonType == SPSBOrderListPayButtonTypePay) {
  275. UIView *buttonView = UIView.new;
  276. buttonView.backgroundColor = spsb_FFFFFF_color(1.f);
  277. [_spsb_contentView addSubview:buttonView];
  278. [buttonView makeConstraints:^(JXHConstraintMaker *make) {
  279. make.bottom.equalTo(self->_spsb_contentView.safebottom);
  280. make.leading.and.trailing.equalTo(0);
  281. make.height.equalTo(spsb_orderListPayViewButtonViewHeight);
  282. }];
  283. _buttonLoadingView = UIView.new;
  284. _buttonLoadingView.backgroundColor = spsb_3296FB_color();
  285. [_buttonLoadingView setLayerCornerRadius:22.5 clipToBounds:false];
  286. [buttonView addSubview:_buttonLoadingView];
  287. [_buttonLoadingView makeConstraints:^(JXHConstraintMaker *make) {
  288. make.top.equalTo(5);
  289. make.leading.equalTo(10);
  290. make.trailing.equalTo(-10);
  291. make.height.equalTo(45);
  292. }];
  293. UIView *contentView = UIView.new;
  294. [_buttonLoadingView addSubview:contentView];
  295. [contentView makeConstraints:^(JXHConstraintMaker *make) {
  296. make.top.and.bottom.equalTo(0);
  297. make.centerX.equalTo(0);
  298. }];
  299. NSMutableArray *imageArray = NSMutableArray.new;
  300. for (NSInteger i = 0; i < 12; i ++) {
  301. NSString *str = [NSString stringWithFormat:@"ne_map_position_loading%lu", (long)i + 1];
  302. UIImage *image = [UIImage imageNamed:str];
  303. [imageArray addObject:image];
  304. }
  305. UIImageView *loadingImageView = UIImageView.new;
  306. loadingImageView.animationDuration = 1;
  307. loadingImageView.animationImages = imageArray;
  308. [loadingImageView startAnimating];
  309. [contentView addSubview:loadingImageView];
  310. [loadingImageView makeConstraints:^(JXHConstraintMaker *make) {
  311. make.leading.equalTo(0);
  312. make.centerY.equalTo(contentView);
  313. make.size.equalTo(CGSizeMake(16, 16));
  314. }];
  315. UILabel *title = [UILabel convenienceWithFont:spsb_semiboldFont(16) text:@"确定付款" textColor:spsb_FFFFFF_color(1.f) textAlignment:NSTextAlignmentCenter];
  316. [contentView addSubview:title];
  317. [title makeConstraints:^(JXHConstraintMaker *make) {
  318. make.leading.equalTo(loadingImageView.trailing).offset(10);
  319. make.trailing.equalTo(0);
  320. make.centerY.equalTo(contentView);
  321. }];
  322. //button
  323. UIButton *payButton = [UIButton convenienceWithFont:spsb_semiboldFont(16) target:self action:@selector(payAction:)];
  324. [payButton setTitle:_spsb_showData ? @"立即付款" : @"确定付款" titleColor:spsb_FFFFFF_color(1.f) image:nil backgroundImage:jxh_getImage(confirm_n) state:JXHButtonControlStateNormal];
  325. [payButton setBackgroundImage:jxh_getImage(confirm_h) state:JXHButtonControlStateHighlighted];
  326. [payButton setLayerCornerRadius:22.5 clipToBounds:true];
  327. payButton.tag = _spsb_showData ? 4000 : 4001;
  328. [buttonView addSubview:payButton];
  329. [payButton makeConstraints:^(JXHConstraintMaker *make) {
  330. make.top.equalTo(5);
  331. make.leading.equalTo(10);
  332. make.trailing.equalTo(-10);
  333. make.height.equalTo(45);
  334. }];
  335. } else if (_buttonType == SPSBOrderListPayButtonTypeQuery) {
  336. UIButton *queryButton = [UIButton convenienceWithFont:spsb_font(17) target:self action:@selector(queryAction)];
  337. [queryButton setTitle:@"查询月缴费状态" titleColor:spsb_3296FB_color() state:JXHButtonControlStateNormal];
  338. queryButton.backgroundColor = spsb_FFFFFF_color(1.f);
  339. [_spsb_contentView addSubview:queryButton];
  340. [queryButton makeConstraints:^(JXHConstraintMaker *make) {
  341. make.bottom.equalTo(self->_spsb_contentView.safebottom);
  342. make.leading.and.trailing.equalTo(0);
  343. make.height.equalTo(spsb_orderListPayViewButtonViewHeight);
  344. }];
  345. [queryButton createLineWithLocation:JXHLineLocationTop];
  346. }
  347. }
  348. - (void)setTitleView:(NSString *)title {
  349. //headerview
  350. UIView *headerView = spsb_createShotViewHeaderWithTitle(title, @selector(dismissContentView), self);
  351. [_spsb_contentView addSubview:headerView];
  352. [headerView makeConstraints:^(JXHConstraintMaker *make) {
  353. make.top.and.leading.and.trailing.equalTo(0);
  354. }];
  355. [_spsb_contentView addSubview:_spsb_bgScrollView];
  356. [_spsb_bgScrollView makeConstraints:^(JXHConstraintMaker *make) {
  357. make.top.equalTo(headerView.bottom);
  358. make.leading.and.trailing.equalTo(0);
  359. make.bottom.equalTo(self->_spsb_contentView.safebottom);
  360. }];
  361. [_spsb_bgScrollView addSubview:_spsb_mScrollView];
  362. }
  363. - (void)addMessageViewWithStatusTitle:(NSString *)statusTitle tips:(nullable NSString *)tips {
  364. //messageView
  365. UIView *messageView = UIView.new;
  366. messageView.backgroundColor = spsb_FFFFFF_color(1.f);
  367. [_spsb_mScrollView addSubview:messageView];
  368. if (tips) {
  369. UIView *tipsView = UIView.new;
  370. tipsView.backgroundColor = spsb_FDF8EC_color();
  371. [_spsb_mScrollView addSubview:tipsView];
  372. [tipsView makeConstraints:^(JXHConstraintMaker *make) {
  373. make.top.and.leading.and.trailing.equalTo(0);
  374. }];
  375. UILabel *tipsLabel = [UILabel convenienceWithFont:spsb_font(12) textColor:spsb_FF801A_color() limitWidth:jxh_screenWidth() - 30];
  376. [tipsLabel setAttributedStringWithText:tips lineSpacing:5];
  377. [tipsView addSubview:tipsLabel];
  378. [tipsLabel makeConstraints:^(JXHConstraintMaker *make) {
  379. make.leading.and.top.equalTo(15);
  380. make.trailing.and.bottom.equalTo(-15);
  381. }];
  382. [messageView makeConstraints:^(JXHConstraintMaker *make) {
  383. make.top.equalTo(tipsView.bottom);
  384. make.leading.and.trailing.equalTo(0);
  385. make.width.equalTo(jxh_screenWidth());
  386. }];
  387. } else {
  388. [messageView makeConstraints:^(JXHConstraintMaker *make) {
  389. make.top.equalTo(0);
  390. make.leading.and.trailing.equalTo(0);
  391. make.width.equalTo(jxh_screenWidth());
  392. }];
  393. }
  394. NSArray *arr = _spsb_showData.spsb_message;
  395. NSInteger count = arr.count / 2;
  396. UILabel *tempLabel = nil;
  397. for (NSInteger i = 0; i < count; i ++) {
  398. UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(14) text:arr[i] textColor:spsb_999999_color()];
  399. [messageView addSubview:titleLabel];
  400. [titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  401. [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
  402. make.leading.equalTo(15);
  403. if (tempLabel) {
  404. make.top.equalTo(tempLabel.bottom).offset(12);
  405. } else {
  406. make.top.equalTo(24);
  407. }
  408. }];
  409. UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(14) text:arr[i + count] textColor:spsb_666666_color() textAlignment:NSTextAlignmentRight];
  410. [messageView addSubview:contentLabel];
  411. [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
  412. make.leading.greaterThanOrEqualTo(titleLabel.trailing).offset(10);
  413. make.trailing.equalTo(-15);
  414. make.centerY.equalTo(titleLabel);
  415. }];
  416. tempLabel = titleLabel;
  417. }
  418. if (tempLabel) {
  419. [tempLabel makeConstraints:^(JXHConstraintMaker *make) {
  420. make.bottom.equalTo(-24);
  421. }];
  422. }
  423. //amountView
  424. UIView *intervalView = UIView.new;
  425. intervalView.backgroundColor = spsb_F5F5F5_color();
  426. [_spsb_mScrollView addSubview:intervalView];
  427. [intervalView makeConstraints:^(JXHConstraintMaker *make) {
  428. make.top.equalTo(messageView.bottom);
  429. make.leading.and.trailing.equalTo(0);
  430. make.height.equalTo(12);
  431. }];
  432. UIView *amountView = UIView.new;
  433. amountView.backgroundColor = spsb_FFFFFF_color(1.f);
  434. [_spsb_mScrollView addSubview:amountView];
  435. UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(15) text:statusTitle textColor:spsb_333333_color()];
  436. [amountView addSubview:titleLabel];
  437. [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
  438. make.leading.equalTo(15);
  439. make.centerY.equalTo(amountView);
  440. }];
  441. UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(17) text:[NSString stringWithFormat:@"¥%@", _spsb_showData.spsb_amount] textColor:spsb_FF5E5E_color() textAlignment:NSTextAlignmentRight];
  442. [amountView addSubview:contentLabel];
  443. [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
  444. make.trailing.equalTo(-15);
  445. make.centerY.equalTo(amountView);
  446. }];
  447. //detailsView
  448. if (_spsb_showData.spsb_title && _spsb_showData.spsb_content) {
  449. [amountView makeConstraints:^(JXHConstraintMaker *make) {
  450. make.top.equalTo(intervalView.bottom);
  451. make.leading.and.trailing.equalTo(0);
  452. make.height.equalTo(50);
  453. }];
  454. UIView *detailsView = UIView.new;
  455. [_spsb_mScrollView addSubview:detailsView];
  456. [detailsView makeConstraints:^(JXHConstraintMaker *make) {
  457. make.top.equalTo(amountView.bottom);
  458. make.leading.and.trailing.equalTo(0);
  459. make.bottom.equalTo(- spsb_orderListPayViewButtonViewHeight);
  460. }];
  461. UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(14) textColor:spsb_999999_color() limitWidth:jxh_screenWidth()];
  462. [titleLabel setAttributedStringWithText:_spsb_showData.spsb_title lineSpacing:10 lines:_spsb_showData.spsb_lines];
  463. [detailsView addSubview:titleLabel];
  464. [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
  465. make.leading.equalTo(15);
  466. make.top.equalTo(21);
  467. make.bottom.equalTo(-21);
  468. }];
  469. UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(14) textColor:spsb_666666_color() limitWidth:jxh_screenWidth()];
  470. [contentLabel setAttributedStringWithText:_spsb_showData.spsb_content textAlignment:NSTextAlignmentRight lineSpacing:10 lineHeight:0 paragraphSpacing:0 lineBreakMode:NSLineBreakByTruncatingTail lines:_spsb_showData.spsb_lines];
  471. [detailsView addSubview:contentLabel];
  472. [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
  473. make.trailing.equalTo(-15);
  474. make.top.equalTo(21);
  475. make.bottom.equalTo(-21);
  476. }];
  477. UIView *line = [_spsb_mScrollView createLine];
  478. [line makeConstraints:^(JXHConstraintMaker *make) {
  479. make.top.equalTo(amountView.bottom);
  480. make.leading.equalTo(15);
  481. make.trailing.equalTo(0);
  482. make.height.equalTo(jxh_onePixe());
  483. }];
  484. } else {
  485. [amountView makeConstraints:^(JXHConstraintMaker *make) {
  486. make.top.equalTo(intervalView.bottom);
  487. make.leading.and.trailing.equalTo(0);
  488. make.height.equalTo(50);
  489. make.bottom.equalTo(-spsb_orderListPayViewButtonViewHeight);
  490. }];
  491. }
  492. }
  493. - (void)addPayViewWithPayView:(UIView *)payView {
  494. NSArray *array = @[@"alipay", @"wepay", @"支付宝支付", @"微信支付"];
  495. for (NSInteger i = 0; i < 2; i ++) {
  496. UIButton *button = [UIButton convenienceWithTarget:self action:@selector(choosePay:)];
  497. button.tag = 3000 + i;
  498. button.backgroundColor = spsb_FFFFFF_color(1.f);
  499. [payView addSubview:button];
  500. [button makeConstraints:^(JXHConstraintMaker *make) {
  501. make.leading.and.trailing.equalTo(0);
  502. make.top.equalTo(70 * i);
  503. make.height.equalTo(70);
  504. }];
  505. UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:array[i]]];
  506. [button addSubview:icon];
  507. [icon makeConstraints:^(JXHConstraintMaker *make) {
  508. make.leading.equalTo(15);
  509. make.centerY.equalTo(0);
  510. }];
  511. UILabel *title = [UILabel convenienceWithFont:spsb_font(16) text:array[i + 2] textColor:spsb_333333_color()];
  512. [button addSubview:title];
  513. [title makeConstraints:^(JXHConstraintMaker *make) {
  514. make.leading.equalTo(64);
  515. make.centerY.equalTo(0);
  516. }];
  517. UIImageView *chooseImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:i == 0 ? @"filter_s" : @"filter_n"]];
  518. chooseImageView.tag = 4000;
  519. [button addSubview:chooseImageView];
  520. [chooseImageView makeConstraints:^(JXHConstraintMaker *make) {
  521. make.trailing.equalTo(-15);
  522. make.centerY.equalTo(0);
  523. }];
  524. if (i == 0) {
  525. [button createLineWithLocation:JXHLineLocationBottom headOffset:15 footOffset:0];
  526. } else if (_totalFee - self.spsb_orderBase.spsb_cashCouponTotal > spsb_wxpayLimit()) {
  527. chooseImageView.image = jxh_getImage(filter_unc);
  528. }
  529. }
  530. UIView *contentView = UIView.new;
  531. contentView.backgroundColor = spsb_FAFAFA_color();
  532. [payView addSubview:contentView];
  533. [contentView makeConstraints:^(JXHConstraintMaker *make) {
  534. make.leading.equalTo(0);
  535. make.top.equalTo(140);
  536. make.trailing.equalTo(0);
  537. }];
  538. UIImageView *info = [[UIImageView alloc] initWithImage:jxh_getImage(order_info)];
  539. [contentView addSubview:info];
  540. [info makeConstraints:^(JXHConstraintMaker *make) {
  541. make.leading.equalTo(14);
  542. make.top.equalTo(14);
  543. }];
  544. UILabel *tips = [UILabel convenienceWithFont:spsb_font(12) textColor:spsb_999999_color() limitWidth:jxh_screenWidth() - 37 - 15];
  545. [tips setAttributedStringWithText:[NSString stringWithFormat:@"微信支付的非实物商品单日交易限额¥%ld, 超额后建议选择支付宝付款或拆分订单购买。", (long)spsb_wxpayLimit()] lineSpacing:6];
  546. [contentView addSubview:tips];
  547. [tips makeConstraints:^(JXHConstraintMaker *make) {
  548. make.leading.equalTo(37);
  549. make.trailing.equalTo(-15);
  550. make.top.equalTo(14);
  551. make.bottom.equalTo(-14);
  552. }];
  553. UIView *intervalView = UIView.new;
  554. intervalView.backgroundColor = spsb_F5F5F5_color();
  555. [payView addSubview:intervalView];
  556. [intervalView makeConstraints:^(JXHConstraintMaker *make) {
  557. make.top.equalTo(contentView.bottom);
  558. make.leading.and.trailing.equalTo(0);
  559. make.height.equalTo(12);
  560. }];
  561. if (_orderType != SPSBOrderTypeOrderBalance && _orderType != SPSBOrderTypeSalary) {
  562. UIButton *discountView = [UIButton convenienceWithTarget:self action:@selector(chooseDiscountAction)];
  563. [payView addSubview:discountView];
  564. [discountView makeConstraints:^(JXHConstraintMaker *make) {
  565. make.top.equalTo(intervalView.bottom);
  566. make.leading.and.trailing.equalTo(0);
  567. make.height.equalTo(60);
  568. }];
  569. UILabel *title = [UILabel convenienceWithFont:spsb_font(14) text:@"优惠券" textColor:spsb_333333_color()];
  570. [discountView addSubview:title];
  571. [title makeConstraints:^(JXHConstraintMaker *make) {
  572. make.leading.equalTo(15);
  573. make.centerY.equalTo(discountView);
  574. }];
  575. if (_cashCouponCount > 0) {
  576. UIView *countView = UIView.new;
  577. [countView setLayerCornerRadius:2 clipToBounds:true];
  578. [countView setLayerBorderWidth:jxh_onePixe() borderColor:spsb_FF5E5E_color()];
  579. [discountView addSubview:countView];
  580. [countView makeConstraints:^(JXHConstraintMaker *make) {
  581. make.leading.equalTo(72);
  582. make.centerY.equalTo(discountView);
  583. make.height.equalTo(17);
  584. }];
  585. UILabel *count = [UILabel convenienceWithFont:spsb_font(11) text:[NSString stringWithFormat:@"%lu张可用", (unsigned long)_cashCouponCount] textColor:spsb_FF5E5E_color() textAlignment:NSTextAlignmentCenter];
  586. [countView addSubview:count];
  587. [count makeConstraints:^(JXHConstraintMaker *make) {
  588. make.leading.equalTo(4);
  589. make.trailing.equalTo(-4);
  590. make.top.and.bottom.equalTo(0);
  591. }];
  592. }
  593. UILabel *useLabel = [UILabel convenienceWithFont:spsb_font(14) text:_cashCouponCount > 0 ? @"未使用" : @"暂无可用优惠券" textColor:spsb_666666_color() textAlignment:NSTextAlignmentRight];
  594. [discountView addSubview:useLabel];
  595. [useLabel makeConstraints:^(JXHConstraintMaker *make) {
  596. make.trailing.equalTo(-34);
  597. make.centerY.equalTo(discountView);
  598. }];
  599. self.spsb_orderBase.spsb_reducePriceLabel = useLabel;
  600. UIImageView *arrow = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
  601. [discountView addSubview:arrow];
  602. [arrow makeConstraints:^(JXHConstraintMaker *make) {
  603. make.trailing.equalTo(-15);
  604. make.centerY.equalTo(discountView);
  605. }];
  606. intervalView = UIView.new;
  607. intervalView.backgroundColor = spsb_F5F5F5_color();
  608. [payView addSubview:intervalView];
  609. [intervalView makeConstraints:^(JXHConstraintMaker *make) {
  610. make.top.equalTo(discountView.bottom);
  611. make.leading.and.trailing.equalTo(0);
  612. make.height.equalTo(12);
  613. }];
  614. }
  615. }
  616. - (void)addDiscountView {
  617. [_spsb_bgScrollView addSubview:_headerView];
  618. [_headerView makeConstraints:^(JXHConstraintMaker *make) {
  619. make.top.equalTo(0);
  620. make.trailing.equalTo(0);
  621. make.size.equalTo(CGSizeMake(jxh_screenWidth(), 50));
  622. }];
  623. _discountCouponVC = SPSBDiscountCouponTableViewController.new;
  624. _discountCouponVC.spsb_canUse = true;
  625. _discountCouponVC.spsb_viewType = SPSBDiscountCouponViewTypeUse;
  626. _discountCouponVC.spsb_maxChose = self.spsb_orderBase.spsb_cashCouponMaxCount;
  627. @weakify(self)
  628. _discountCouponVC.spsb_afterChoose = ^{
  629. @strongify(self)
  630. [self reloadHeaderView];
  631. };
  632. _discountCouponVC.tableView.tableFooterView = [[UIView alloc] initWithFrame:(CGRect){0, 0, jxh_screenWidth(), spsb_orderListPayViewButtonViewHeight}];
  633. [self addChildViewController:_discountCouponVC];
  634. [_spsb_bgScrollView addSubview:_discountCouponVC.tableView];
  635. [_discountCouponVC.tableView makeConstraints:^(JXHConstraintMaker *make) {
  636. make.top.equalTo(50);
  637. make.bottom.equalTo(0);
  638. make.trailing.equalTo(0);
  639. make.width.equalTo(jxh_screenWidth());
  640. }];
  641. }
  642. - (UIView *)createHeaderView {
  643. UIView *headerView = UIView.new;
  644. headerView.backgroundColor = spsb_F1F8FF_color();
  645. UILabel *firstLabel = [UILabel convenienceWithFont:spsb_font(12) text:[NSString stringWithFormat:@"您当前下了 %ld 个月订单,可同时选", (long)self.spsb_orderBase.spsb_cashCouponMaxCount] textColor:spsb_666666_color()];
  646. firstLabel.tag = 3001;
  647. [headerView addSubview:firstLabel];
  648. [firstLabel makeConstraints:^(JXHConstraintMaker *make) {
  649. make.leading.equalTo(15);
  650. make.centerY.equalTo(headerView);
  651. }];
  652. UILabel *secondLabel = [UILabel convenienceWithFont:spsb_font(12) text:[NSString stringWithFormat:@" %ld ", (long)self.spsb_orderBase.spsb_cashCouponMaxCount] textColor:spsb_FF5E5E_color()];
  653. secondLabel.tag = 3002;
  654. [headerView addSubview:secondLabel];
  655. [secondLabel makeConstraints:^(JXHConstraintMaker *make) {
  656. make.leading.equalTo(firstLabel.trailing);
  657. make.centerY.equalTo(headerView);
  658. }];
  659. UILabel *thirdLabel = [UILabel convenienceWithFont:spsb_font(12) text:@"张优惠券" textColor:spsb_666666_color()];
  660. thirdLabel.tag = 3003;
  661. [headerView addSubview:thirdLabel];
  662. [thirdLabel makeConstraints:^(JXHConstraintMaker *make) {
  663. make.leading.equalTo(secondLabel.trailing);
  664. make.centerY.equalTo(headerView);
  665. }];
  666. return headerView;
  667. }
  668. - (void)reloadHeaderView {
  669. UILabel *firstLabel = [_headerView viewWithTag:3001];
  670. UILabel *secondLabel = [_headerView viewWithTag:3002];
  671. UILabel *thirdLabel = [_headerView viewWithTag:3003];
  672. if (_discountCouponVC.spsb_chose.count > 0) {
  673. firstLabel.text = [NSString stringWithFormat:@"您已选中优惠券 %ld 张,共可抵用", (long)_discountCouponVC.spsb_chose.count];
  674. CGFloat reduce = 0;
  675. for (NSNumber *index in _discountCouponVC.spsb_chose) {
  676. SPSBDiscountCouponModel *model = _discountCouponVC.spsb_data[index.integerValue];
  677. reduce += [model.spsb_coupon_price floatValue];
  678. }
  679. secondLabel.text = [NSString stringWithFormat:@"¥%.2lf", reduce];
  680. thirdLabel.text = @"";
  681. } else {
  682. firstLabel.text = [NSString stringWithFormat:@"您当前下了 %ld 个月订单,可同时选", (long)self.spsb_orderBase.spsb_cashCouponMaxCount];
  683. secondLabel.text = [NSString stringWithFormat:@" %ld ", (long)self.spsb_orderBase.spsb_cashCouponMaxCount];
  684. thirdLabel.text = @"张优惠券";
  685. }
  686. }
  687. @end