No Description

FKExchangeCouponController.m 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // FKExchangeCouponController.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/4/7.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKExchangeCouponController.h"
  9. #import "FKExchangeCouponRequest.h"
  10. #import "FKCashCouponReform.h"
  11. #import "FKCouponViewModel.h"
  12. @interface FKExchangeCouponController ()
  13. <UITextFieldDelegate, FLNetworkDelegate>
  14. @property (nonatomic, strong) UIView *bgView;
  15. @property (nonatomic, strong) UITextField *textField;
  16. @property (nonatomic, strong) UIButton *exchangeButton;
  17. @end
  18. static int const FKExchangeCouponRequestExchange = 30;
  19. @implementation FKExchangeCouponController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.view.backgroundColor = UIColorFromRGB(0xf4f4f4);
  24. [self addAllSubviews];
  25. }
  26. - (void)didReceiveMemoryWarning {
  27. [super didReceiveMemoryWarning];
  28. // Dispose of any resources that can be recreated.
  29. }
  30. - (void)viewWillAppear:(BOOL)animated {
  31. [super viewWillAppear:animated];
  32. self.navigationItem.title = @"兑换优惠券";
  33. }
  34. /*
  35. #pragma mark - Navigation
  36. // In a storyboard-based application, you will often want to do a little preparation before navigation
  37. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  38. // Get the new view controller using [segue destinationViewController].
  39. // Pass the selected object to the new view controller.
  40. }
  41. */
  42. #pragma mark - Response
  43. - (void)networkDidSuccessResponse:(NSDictionary *)response identify:(int)identify header:(MSGHeader *)header {
  44. [self.hudView hide:YES];
  45. if ([header.code intValue] == RESPONSE_MSG_NORMAL) {
  46. if (identify == FKExchangeCouponRequestExchange) {
  47. [FLProgressHUDHelper showText:@"兑换成功" inView:self.view.window];
  48. FKCouponItem *item = [[FKCashCouponReform parseCouponItems:response] firstObject];
  49. if (self.exchangeSuccessCallBack) {
  50. self.exchangeSuccessCallBack(item);
  51. }
  52. [self.navigationController popViewControllerAnimated:YES];
  53. }
  54. } else {
  55. [FLProgressHUDHelper showText:header.msg inView:self.view];
  56. }
  57. }
  58. - (void)networkDidReceiveError:(NSError *)error identify:(int)identify header:(MSGHeader *)header {
  59. [self.hudView hide:YES];
  60. [FLProgressHUDHelper showText:header.msg inView:self.view];
  61. }
  62. #pragma mark - UITextFieldDelegate
  63. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  64. [textField resignFirstResponder];
  65. return YES;
  66. }
  67. #pragma mark - Action
  68. - (IBAction)clickExchangeCodeAction:(id)sender {
  69. NSString *code = [self.textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  70. if (code.length > 0) {
  71. [self.hudView show:YES];
  72. [FKExchangeCouponRequest requestExchange:FKExchangeCouponRequestExchange code:code deleagate:self];
  73. } else {
  74. [FLProgressHUDHelper showText:@"请输入邀请码或兑换码" inView:self.view];
  75. }
  76. }
  77. #pragma mark - Layout
  78. - (void)addAllSubviews {
  79. [self.view addSubview:self.bgView];
  80. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.equalTo(self.view).offset(20);
  82. make.top.equalTo(self.view).offset(15);
  83. make.right.equalTo(self.view).offset(-20);
  84. make.height.mas_equalTo(44);
  85. }];
  86. [self.bgView addSubview:self.textField];
  87. [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.equalTo(self.bgView).offset(15);
  89. make.right.equalTo(self.bgView).offset(-15);
  90. make.top.bottom.equalTo(self.bgView);
  91. }];
  92. [self.view addSubview:self.exchangeButton];
  93. [self.exchangeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.left.right.equalTo(self.bgView);
  95. make.top.equalTo(self.bgView.mas_bottom).offset(14);
  96. make.height.mas_equalTo(44);
  97. }];
  98. }
  99. #pragma mark - Property
  100. - (UIView *)bgView {
  101. if (!_bgView) {
  102. _bgView = [UIView new];
  103. _bgView.backgroundColor = UIColorFromRGB(0xffffff);
  104. _bgView.layer.cornerRadius = 4;
  105. }
  106. return _bgView;
  107. }
  108. - (UITextField *)textField {
  109. if (!_textField) {
  110. _textField = [[UITextField alloc] init];
  111. _textField.backgroundColor = UIColorFromRGB(0xffffff);
  112. _textField.placeholder = @"请输入邀请码或兑换码";
  113. _textField.delegate = self;
  114. _textField.font = [UIFont systemFontOfSize:15];
  115. _textField.returnKeyType = UIReturnKeyDone;
  116. _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
  117. }
  118. return _textField;
  119. }
  120. - (UIButton *)exchangeButton {
  121. if (!_exchangeButton) {
  122. _exchangeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  123. _exchangeButton.layer.cornerRadius = 4;
  124. _exchangeButton.backgroundColor = UIColorFromRGB(0xf85a5a);
  125. [_exchangeButton setTitle:@"兑换优惠券" forState:UIControlStateNormal];
  126. [_exchangeButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
  127. [_exchangeButton setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
  128. [_exchangeButton addTarget:self action:@selector(clickExchangeCodeAction:) forControlEvents:UIControlEventTouchUpInside];
  129. }
  130. return _exchangeButton;
  131. }
  132. @end