123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- //
- // FKExchangeCouponController.m
- // FirstLink
- //
- // Created by ascii on 16/4/7.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKExchangeCouponController.h"
- #import "FKExchangeCouponRequest.h"
- #import "FKCashCouponReform.h"
- #import "FKCouponViewModel.h"
- @interface FKExchangeCouponController ()
- <UITextFieldDelegate, FLNetworkDelegate>
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UITextField *textField;
- @property (nonatomic, strong) UIButton *exchangeButton;
- @end
- static int const FKExchangeCouponRequestExchange = 30;
- @implementation FKExchangeCouponController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.view.backgroundColor = UIColorFromRGB(0xf4f4f4);
-
- [self addAllSubviews];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- self.navigationItem.title = @"兑换优惠券";
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- #pragma mark - Response
- - (void)networkDidSuccessResponse:(NSDictionary *)response identify:(int)identify header:(MSGHeader *)header {
- [self.hudView hide:YES];
-
- if ([header.code intValue] == RESPONSE_MSG_NORMAL) {
- if (identify == FKExchangeCouponRequestExchange) {
- [FLProgressHUDHelper showText:@"兑换成功" inView:self.view.window];
- FKCouponItem *item = [[FKCashCouponReform parseCouponItems:response] firstObject];
- if (self.exchangeSuccessCallBack) {
- self.exchangeSuccessCallBack(item);
- }
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- } else {
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- }
- - (void)networkDidReceiveError:(NSError *)error identify:(int)identify header:(MSGHeader *)header {
- [self.hudView hide:YES];
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- #pragma mark - UITextFieldDelegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return YES;
- }
- #pragma mark - Action
- - (IBAction)clickExchangeCodeAction:(id)sender {
- NSString *code = [self.textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
- if (code.length > 0) {
- [self.hudView show:YES];
- [FKExchangeCouponRequest requestExchange:FKExchangeCouponRequestExchange code:code deleagate:self];
- } else {
- [FLProgressHUDHelper showText:@"请输入邀请码或兑换码" inView:self.view];
- }
- }
- #pragma mark - Layout
- - (void)addAllSubviews {
- [self.view addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.view).offset(20);
- make.top.equalTo(self.view).offset(15);
- make.right.equalTo(self.view).offset(-20);
- make.height.mas_equalTo(44);
- }];
-
- [self.bgView addSubview:self.textField];
- [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bgView).offset(15);
- make.right.equalTo(self.bgView).offset(-15);
- make.top.bottom.equalTo(self.bgView);
- }];
-
- [self.view addSubview:self.exchangeButton];
- [self.exchangeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.bgView);
- make.top.equalTo(self.bgView.mas_bottom).offset(14);
- make.height.mas_equalTo(44);
- }];
- }
- #pragma mark - Property
- - (UIView *)bgView {
- if (!_bgView) {
- _bgView = [UIView new];
- _bgView.backgroundColor = UIColorFromRGB(0xffffff);
- _bgView.layer.cornerRadius = 4;
- }
- return _bgView;
- }
- - (UITextField *)textField {
- if (!_textField) {
- _textField = [[UITextField alloc] init];
- _textField.backgroundColor = UIColorFromRGB(0xffffff);
- _textField.placeholder = @"请输入邀请码或兑换码";
- _textField.delegate = self;
- _textField.font = [UIFont systemFontOfSize:15];
- _textField.returnKeyType = UIReturnKeyDone;
- _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
- }
- return _textField;
- }
- - (UIButton *)exchangeButton {
- if (!_exchangeButton) {
- _exchangeButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _exchangeButton.layer.cornerRadius = 4;
- _exchangeButton.backgroundColor = UIColorFromRGB(0xf85a5a);
- [_exchangeButton setTitle:@"兑换优惠券" forState:UIControlStateNormal];
- [_exchangeButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
- [_exchangeButton setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
-
- [_exchangeButton addTarget:self action:@selector(clickExchangeCodeAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _exchangeButton;
- }
- @end
|