// // ActivityDetailViewController.m // 千模 // // Created by MUMEI on 2018/5/18. // Copyright © 2018年 MUMEI. All rights reserved. // #import "SignUpViewController.h" #import "SignInfoCell.h" #import "Masonry.h" @interface SignUpViewController () @property(strong, nonatomic) UITableView *tableView; @property(nonatomic, strong) UIImageView *headView; @end @implementation SignUpViewController - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"活动报名"; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)]; self.navigationItem.leftBarButtonItem = leftItem; self.navigationController.navigationBar.tintColor = [UIColor blackColor]; self.tableView = [[UITableView alloc] init]; [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); make.top.equalTo(self.mas_topLayoutGuide); make.bottom.equalTo(self.mas_bottomLayoutGuide); }]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.tableHeaderView = self.headView; self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0); UIButton *signBtn = [[UIButton alloc] init]; [self.view addSubview:signBtn]; [signBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view).offset(20); make.right.equalTo(self.view).offset(-20); make.bottom.equalTo(self.mas_bottomLayoutGuide).offset(-10); make.height.mas_equalTo(44); }]; signBtn.layer.backgroundColor = [UIColor colorWithRed:1.f green:64 / 255.f blue:149 / 255.f alpha:1.0].CGColor; signBtn.layer.cornerRadius = 22; signBtn.layer.shadowColor = [UIColor colorWithRed:1.f green:64 / 255.f blue:149 / 255.f alpha:0.36].CGColor; signBtn.layer.shadowOffset = CGSizeMake(0, 8); signBtn.layer.shadowOpacity = 1; signBtn.layer.shadowRadius = 10; [signBtn addTarget:self action:@selector(sign:) forControlEvents:UIControlEventTouchUpInside]; } - (UIImageView *)headView { if (!_headView) { _headView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth)]; [_headView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", imageURl, _model.pic]] placeholderImage:[UIImage imageNamed:@"jiazai"]]; } return _headView; } - (void)sign:(UIButton *)sender { SignInfoCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; NSString *people = cell.name.text; NSString *tel = cell.phone.text; NSString *pcount = cell.num.text; NSString *fee = [cell.totoalPrice.text componentsSeparatedByString:@"元"][0]; NSString *parttypk = cell.model.pk; NSString *pk = [ModelUser user].pk; NSString *str = [NSString stringWithFormat:@"%@/activity?action=doEnroll&PK=%@&ParttyPK=%@&people=%@&Tel=%@&pCount=%@&Fee=%@", PublicUrl, pk, parttypk, people, tel, pcount, fee]; [[AHHttpManager sharedManager] POST:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(id responseObject) { NSLog(@"%@", responseObject); if ([[responseObject objectForKey:@"msg"] isEqualToString:@"success"]) { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"报名成功" preferredStyle:UIAlertControllerStyleAlert]; NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"报名成功"]; int num = (int) hogan.length; [hogan addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.0] range:NSMakeRange(0, num)]; [alertController setValue:hogan forKey:@"attributedMessage"]; UIImageView *alertImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Complete_Img"]]; [alertController.view addSubview:alertImg]; [alertImg mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(alertController.view.mas_centerY); make.left.equalTo(alertController.view.mas_left).offset(num / 4); }]; // [self.tableView reloadData]; [self presentViewController:alertController animated:YES completion:nil]; [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(backPop:) userInfo:alertController repeats:NO]; } else { if ([[responseObject objectForKey:@"desc"] isEqualToString:@"余额不足"]) { [MBProgressHUD showTextHUD:@"余额不足" inView:self.view hideAfterDelay:1]; } else { [MBProgressHUD showTextHUD:@"请填写正确报名资料" inView:self.view hideAfterDelay:1]; } } } failure:^(NSError *error) { NSLog(@"error = %@", error); [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1]; }]; } - (void)backPop:(NSTimer *)timer { UIAlertController *alert = [timer userInfo]; [alert dismissViewControllerAnimated:YES completion:^{ [self.navigationController popViewControllerAnimated:YES]; }]; alert = nil; } - (void)backClick { [self.navigationController popViewControllerAnimated:YES]; } - (void)viewWillAppear:(BOOL)animated { [self.navigationController setNavigationBarHidden:NO animated:YES]; self.navigationController.navigationBar.tintColor = [UIColor blackColor]; } #pragma mark - deleDate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SignInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SignInfoCell"]; if (!cell) { cell = [[[UINib nibWithNibName:@"SignInfoCell" bundle:nil] instantiateWithOwner:self options:nil] lastObject]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.model = _model; cell.name.delegate = self; cell.phone.delegate = self; } return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 1; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 465; } - (BOOL)textFieldShouldReturn:(UITextField *)theTextField { [theTextField resignFirstResponder]; return YES; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end