//
//  telephoneViewController.m
//  Open
//
//  Created by gao on 2017/1/16.
//  Copyright © 2017年 黄江涛 . All rights reserved.
//

#import "telephoneViewController.h"
#import "phoneModel.h"
#import "getPhonePriceList.h"
#import "telephotoVM.h"
@interface telephoneViewController ()<UITextFieldDelegate>
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *AllNumberFirst;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *AllNumberSecond;
//确定按钮
@property (weak, nonatomic) IBOutlet UIButton *editBU;

@property (weak, nonatomic) IBOutlet UITextField *telTextField;
//电话号码错了
@property (weak, nonatomic) IBOutlet UILabel *errorNumber;
//选择的按钮
@property(nonatomic,strong)UIButton *selectButton;
@property(nonatomic,strong)telephotoVM *telVM;

@end

@implementation telephoneViewController
-(telephotoVM *)telVM
{
    if (!_telVM) {
        _telVM =[[telephotoVM alloc]init];
    }
    return _telVM;
}

- (void)viewDidLoad {
      self.errorNumber.hidden =YES;
    [super viewDidLoad];
    [self drawALine];
    [self senderData];
    self.telTextField.delegate =self;
    self.selectButton.selected = NO;
}

-(void)senderData
{
    self.editBU.layer.masksToBounds=YES;
    self.editBU.layer.cornerRadius =8.0;
//1.把数据传入字段
    NSInteger numberI = 0;
    //输入电话号码
    self.telTextField.text =[getPeopleID PeopleIphoneNmber];
    //导入价格
    for (phoneResultModel *models in self.photoModel) {
        [self.AllNumberFirst[numberI] setTitle:[NSString stringWithFormat:@"%.0lf元",models.productPrice]];
        [self.AllNumberSecond[numberI] setTitle:[NSString stringWithFormat:@"售价:%.1lf元",models.productRealPrice]];
         numberI ++;
        if (numberI== 8) {
            return;
        }
    }
}

-(void)drawALine{
//    UIBezierPath *linePath = [UIBezierPath bezierPath];
//    // 起点
//    [linePath moveToPoint:CGPointMake(10, 131)];
//    // 其他点
//    [linePath addLineToPoint:CGPointMake(354, 131)];
//    CAShapeLayer *lineLayer = [CAShapeLayer layer];
//    lineLayer.lineWidth = 1;
//    lineLayer.strokeColor = [UIColor colorWithRed:152/255.0 green:152/255.0 blue:152/255.0 alpha:0.8].CGColor;
//    lineLayer.path = linePath.CGPath;
//    lineLayer.fillColor =nil; // 默认为blackColor
//    
//    [self.view.layer addSublayer:lineLayer];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
//监听电话号码是否正确
- (IBAction)editTelephone:(UITextField*)sender {
    //如果不为11位返回
    if (sender.text.length !=11) {
        self.errorNumber.hidden =NO;
        return;
    }else
    {
      self.errorNumber.hidden =YES;
    [self.telVM getTelNumber:self.telTextField.text Handle:^(NSError *error) {
        NSInteger numberI = 0;
        for (phoneResultModel *models in self.telVM.dataArr) {
            [self.AllNumberFirst[numberI] setTitle:[NSString stringWithFormat:@"%.0lf元",models.productPrice]];
            [self.AllNumberSecond[numberI] setTitle:[NSString stringWithFormat:@"售价:%.1lf元",models.productRealPrice]];
            numberI ++;
            if (numberI== 8) {
                return;
            }
        }
        
    }];
        
        
    }

    
    
}

-(UIButton *)selectButton
    {
        if (!_selectButton) {
            _selectButton =[UIButton buttonWithType:UIButtonTypeCustom];

        }
        return _selectButton;
}



//所有按钮的触发事件
- (IBAction)allbutton:(UIButton*)sender {
    for (int i = 0; i < self.AllNumberFirst.count; i++) {
        UIButton *btn = self.AllNumberFirst[i];
        [btn setSelected:NO];
    }
  UIButton *button = (UIButton *)sender;
    [button setSelected:YES];
    self.selectButton=sender;
    self.selectButton.selected =YES;
    if (sender && self.errorNumber.hidden== YES) {
        self.editBU.backgroundColor =kRGBColor(34, 167, 222);

    }

}

//提交按钮
- (IBAction)senderMessage:(id)sender {
    if (self.errorNumber.hidden ==NO) {
        SVProgressHUD.minimumDismissTimeInterval=1.0;
        [SVProgressHUD showErrorWithStatus:@"手机号不正确"];
          return;
    }
    if (self.selectButton.selected == NO) {
        SVProgressHUD.minimumDismissTimeInterval=1.0;
        [SVProgressHUD showErrorWithStatus:@"请选择充值金额"];
        return;
    }
    SVProgressHUD.minimumDismissTimeInterval=1.0;
    [SVProgressHUD showErrorWithStatus:@"暂时无法使用"];
    return;
    //等接口出来
//      [self performSegueWithIdentifier:@"telephonePay2" sender:self];

    
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{

    [self.view endEditing:YES];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    //    if ([segue.identifier isEqualToString:@"socialSecurity"])  {
    //        ViewController *blueVC = segue.destinationViewController;
    //        blueVC.hidesBottomBarWhenPushed=YES;
    //    }
    if ([segue.identifier isEqualToString:@"telephonePay2"]) {
        weatherViewController *BVC =segue.destinationViewController;
        BVC.hidesBottomBarWhenPushed =YES;
    }
}
//设置代理方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}


@end
