| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- //
- // ExchangeCoinView.m
- // BuguLive
- //
- // Created by yy on 17/2/16.
- // Copyright © 2017年 xfg. All rights reserved.
- //
- #import "ExchangeCoinView.h"
- @implementation ExchangeCoinView
- + (instancetype)EditNibFromXib
- {
- return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
- }
- - (void)createSomething
- {
- _httpManager = [NetHttpsManager manager];
- _BuguLive = [GlobalVariables sharedInstance];
- [self createStyle];
- }
- - (void)createStyle
- {
- [self.confirmButton addTarget:self
- action:@selector(confirmButtonActon)
- forControlEvents:UIControlEventTouchUpInside];
- [self.confirmButton setTitleColor:[UIColor colorWithHexString:@"#9152F8"]
- forState:UIControlStateNormal];
- [self.cancelButton setTitleColor:kAppGrayColor1
- forState:UIControlStateNormal];
- self.diamondLeftTextfield.layer.borderColor = [[UIColor whiteColor]CGColor];
- self.diamondLeftTextfield.keyboardType = UIKeyboardTypeNumberPad;
- self.textfieldBgView.layer.masksToBounds = YES;
- self.textfieldBgView.layer.cornerRadius = 5;
- self.textfieldBgView.layer.borderColor = kAppGrayColor4.CGColor;
- self.textfieldBgView.layer.borderWidth = 0.5;
- self.diamondLeftTextfield.delegate = self;
- self.confirmButton.backgroundColor = [UIColor whiteColor];
- self.cancelButton.backgroundColor = [UIColor whiteColor];
- self.verticalLine.backgroundColor = kAppGrayColor4;
- self.horizonLine.backgroundColor = kAppGrayColor4;
- self.titleBgView.backgroundColor = kClearColor;
- // = kAppMainColor;
- self.exchangeTitle.textColor = kWhiteColor;
- self.diamondLabel.textColor = kAppGrayColor1;
- self.scaleLabel.textColor = kAppGrayColor1;
- // self.coinLabel.textColor = kAppGrayColor1;
- self.layer.masksToBounds = YES;
- self.layer.cornerRadius = 10;
-
- self.bgImgView.layer.masksToBounds = YES;
- self.bgImgView.clipsToBounds = YES;
- self.bgImgView.frame = self.bounds;
- [self.cancelButton setLocalizedString];
- if (_exchangeType == 1)
- {
- self.exchangeTitle.text = ASLocalizedString(@"兑换游戏币");
- self.coinLabel.text = ASLocalizedString(@"0游戏币");
- [self.confirmButton setTitle:ASLocalizedString(@"兑换")forState:UIControlStateNormal];
- }
- else if (_exchangeType == 2)
- {
- self.exchangeTitle.text = [NSString stringWithFormat:ASLocalizedString(@"兑换%@"),self.BuguLive.appModel.diamond_name];
- // [NSString stringWithFormat:@"0%@",self.BuguLive.appModel.diamond_name];
- self.coinLabel.text = [NSString stringWithFormat:@"0%@",self.BuguLive.appModel.diamond_name];
- // [NSString stringWithFormat:@"0%@",self.BuguLive.appModel.diamond_name];
- [self.confirmButton setTitle:ASLocalizedString(@"兑换")forState:UIControlStateNormal];
- }
- else if (_exchangeType == 3)
- {
- self.exchangeTitle.text = ASLocalizedString(@"赠送游戏币");
- self.scaleLabel.hidden = YES;
- self.coinLabel.hidden = YES;
- [self.confirmButton setTitle:ASLocalizedString(@"赠送")forState:UIControlStateNormal];
- }
- else if (_exchangeType == 4)
- {
- self.exchangeTitle.text = [NSString stringWithFormat:ASLocalizedString(@"赠送%@"),self.BuguLive.appModel.diamond_name];
- self.scaleLabel.hidden = YES;
- self.coinLabel.hidden = YES;
- [self.confirmButton setTitle:ASLocalizedString(@"赠送")forState:UIControlStateNormal];
- }
- }
- #pragma marlk textfieldDelegate代理
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
-
- return YES;
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
-
- NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
-
- if (toBeString.length > 6 && range.length!= 1){
- textField.text = [toBeString substringToIndex:6];
-
- return NO;
- }
-
- // if ([toBeString integerValue] > [_ticket integerValue])
- // {
- // [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"输入金额大于账户余额")];
- //
- // return NO;
- // }
-
- _rat = [toBeString integerValue] * [ratio floatValue];
- if (_exchangeType == 3 || _exchangeType == 4)
- {
- NSLog(@"%f",[_diamondLeftTextfield.text floatValue]);
- if ([toBeString integerValue] > 0)
- {
- [_confirmButton setTitleColor:[UIColor colorWithHexString:@"#9152F8"] forState:UIControlStateNormal];
- }
- else
- {
- [_confirmButton setTitleColor:[UIColor colorWithHexString:@"#9152F8"] forState:UIControlStateNormal];
- }
- }
- else
- {
- if (_rat >0)
- {
- [_confirmButton setTitleColor:[UIColor colorWithHexString:@"#9152F8"] forState:UIControlStateNormal];
- }
- else
- {
- [_confirmButton setTitleColor:[UIColor colorWithHexString:@"#9152F8"] forState:UIControlStateNormal];
- }
-
- if (_exchangeType == 1) {
- _coinLabel.text = [NSString stringWithFormat:ASLocalizedString(@"%ld游戏币"),(long)_rat];
- }
- else
- {
- _coinLabel.text = [NSString stringWithFormat:@"%ld%@",(long)_rat,self.BuguLive.appModel.diamond_name];
- }
- }
-
- NSLog(@"++++++++++++++++++++++++%ld", (long)_rat);
- return [self validateNumber:string];
- }
- //限制只输入数字
- - (BOOL)validateNumber:(NSString*)number {
- BOOL res = YES;
- NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
- int i = 0;
- while (i < number.length) {
- NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
- NSRange range = [string rangeOfCharacterFromSet:tmpSet];
- if (range.length == 0) {
- res = NO;
- break;
- }
- i++;
- }
- return res;
- }
- #pragma mark 获取游戏币兑换比例
- - (void)obtainCoinProportion
- {
- NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
- [parmDict setObject:@"games" forKey:@"ctl"];
- [parmDict setObject:@"exchangeRate" forKey:@"act"];
- [_httpManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
- {
- if ([responseJson toInt:@"status"] ==1)
- {
- ratio = [responseJson objectForKey:@"exchange_rate"];
- //兑换比例
- if (ratio != nil&& ![ratio isEqual:[NSNull null]])
- {
- _scaleLabel.text = [NSString stringWithFormat:ASLocalizedString(@"兑换比例: %@"),ratio];
- }
- }
-
- } FailureBlock:^(NSError *error)
- {
-
- }];
- }
- #pragma marlk 获得钻石兑换比例
- - (void)requetRatio
- {
-
- NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
-
-
- [parmDict setObject:@"user_center" forKey:@"ctl"];
- [parmDict setObject:@"exchange" forKey:@"act"];
- [_httpManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
- {
- if ((NSNull *)responseJson != [NSNull null])
- {
- if ([responseJson toInt:@"status"] ==1)
- {
- FreshAcountModel *model3 =[[FreshAcountModel alloc]init];
- model3 =[FreshAcountModel mj_objectWithKeyValues:responseJson];
-
- ratio =model3.ratio;
- //兑换比例
- if (ratio != nil&& ![ratio isEqual:[NSNull null]]) {
- _scaleLabel.text = [NSString stringWithFormat:ASLocalizedString(@"兑换比例: %@"),ratio];
- }
- }
- }
-
- } FailureBlock:^(NSError *error)
- {
-
- }];
-
- }
- #pragma mark 钻石兑换游戏币
- - (void)exchangeCoin
- {
- NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
- [parmDict setObject:@"games" forKey:@"ctl"];
- [parmDict setObject:@"exchangeCoin" forKey:@"act"];
- [parmDict setObject:[NSString stringWithFormat:@"%@",_diamondLeftTextfield.text] forKey:@"diamonds"];
- [_httpManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
- {
- if ([responseJson toInt:@"status"]==1)
- {
- [[NSNotificationCenter defaultCenter]postNotificationName:@"updateCoin" object:nil];
- [_diamondLeftTextfield resignFirstResponder];
- [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"兑换成功")];
- }
-
- } FailureBlock:^(NSError *error)
- {
- [FanweMessage alert:ASLocalizedString(@"请求失败")];
- }];
-
- }
- #pragma marlk 兑换钻石
- - (void)converDiamondsRequest
- {
- NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
- [parmDict setObject:@"user_center" forKey:@"ctl"];
- [parmDict setObject:@"do_exchange" forKey:@"act"];
- [parmDict setObject:[NSString stringWithFormat:@"%@",_diamondLeftTextfield.text] forKey:@"ticket"];
- [_httpManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
- {
- if ([responseJson toInt:@"status"]==1)
- {
- [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshAcount" object:nil];
-
- [[FDHUDManager defaultManager]show:[responseJson valueForKey:@"error"] ToView:self.superview];
- }
-
- } FailureBlock:^(NSError *error)
- {
- [FanweMessage alert:ASLocalizedString(@"请求失败")];
- }];
- }
- - (void)confirmButtonActon
- {
- if (_exchangeType == 3 || _exchangeType == 4)
- {
- if ([_diamondLeftTextfield.text integerValue] < 1) {
- [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"请输入足够的金额")];
- return;
- }
- }
- else
- {
- //当输入金额 不足兑换 1钻石
- if(ratio.floatValue != 0)
- {
- if (_rat < 1 || [_diamondLeftTextfield.text integerValue] < 1)
- {
- // [SVProgressHUD showInfoWithStatus:ASLocalizedString(@"请输入足够的金额")];
- [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"请输入足够的金额")];
- return;
- }
- }
- }
- //当输入金额 大于账户
- if(_diamondLeftTextfield.text.integerValue > _ticket.floatValue)
- {
- _diamondLeftTextfield.text = nil;
- if (_exchangeType == 1) {
- _coinLabel.text = ASLocalizedString(@"0游戏币");
- }
- else
- {
- _coinLabel.text = [NSString stringWithFormat:@"0%@",self.BuguLive.appModel.diamond_name];
- }
- [_confirmButton setTitleColor:[UIColor colorWithHexString:@"#9152F8"] forState:UIControlStateNormal];
-
- [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"输入金额不得大于账户余额")];
-
- return;
- }
-
- if (_exchangeType == 3 || _exchangeType == 4)
- {
- if (_delegate && [_delegate respondsToSelector:@selector(comfirmClickWithExchangeCoinView:)])
- {
- [_delegate comfirmClickWithExchangeCoinView:self];
- }
-
- [self backToBefore];
- if (_delegate && [_delegate respondsToSelector:@selector(exchangeViewDownWithExchangeCoinView:)])
- {
- [_delegate exchangeViewDownWithExchangeCoinView:self];
- }
- }
- else
- {
- if (_rat > 0)
- {
- if (_exchangeType == 1)
- {
- [self exchangeCoin];
- }
- else if (_exchangeType == 2)
- {
- [self converDiamondsRequest];
- }
-
- [self backToBefore];
- if (_delegate && [_delegate respondsToSelector:@selector(exchangeViewDownWithExchangeCoinView:)])
- {
- [_delegate exchangeViewDownWithExchangeCoinView:self];
- }
- }else{
- [SVProgressHUD showInfoWithStatus:ASLocalizedString(@"兑换比例为0,不能兑换")];
- }
- }
- }
- - (void)backToBefore
- {
- if (_exchangeType == 1)
- {
- _coinLabel.text = ASLocalizedString(@"0游戏币");
- }
- else if (_exchangeType == 2)
- {
- _coinLabel.text = [NSString stringWithFormat:@"0%@",self.BuguLive.appModel.diamond_name];
- }
-
- [self.confirmButton setTitleColor:[UIColor colorWithHexString:@"#9152F8"] forState:UIControlStateNormal];
- }
- - (IBAction)cancelButtonAction:(id)sender
- {
- if (_delegate && [_delegate respondsToSelector:@selector(exchangeViewDownWithExchangeCoinView:)])
- {
- [_delegate exchangeViewDownWithExchangeCoinView:self];
- }
- [self backToBefore];
- }
- @end
|