SignUpViewController.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // ActivityDetailViewController.m
  3. // 千模
  4. //
  5. // Created by MUMEI on 2018/5/18.
  6. // Copyright © 2018年 MUMEI. All rights reserved.
  7. //
  8. #import "SignUpViewController.h"
  9. #import "SignInfoCell.h"
  10. #import "Masonry.h"
  11. @interface SignUpViewController () <UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource>
  12. @property(strong, nonatomic) UITableView *tableView;
  13. @property(nonatomic, strong) UIImageView *headView;
  14. @end
  15. @implementation SignUpViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.navigationItem.title = @"活动报名";
  19. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)];
  20. self.navigationItem.leftBarButtonItem = leftItem;
  21. self.navigationController.navigationBar.tintColor = [UIColor blackColor];
  22. self.tableView = [[UITableView alloc] init];
  23. [self.view addSubview:self.tableView];
  24. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.left.right.equalTo(self.view);
  26. make.top.equalTo(self.mas_topLayoutGuide);
  27. make.bottom.equalTo(self.mas_bottomLayoutGuide);
  28. }];
  29. self.tableView.delegate = self;
  30. self.tableView.dataSource = self;
  31. self.tableView.tableHeaderView = self.headView;
  32. self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0);
  33. UIButton *signBtn = [[UIButton alloc] init];
  34. [self.view addSubview:signBtn];
  35. [signBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.left.equalTo(self.view).offset(20);
  37. make.right.equalTo(self.view).offset(-20);
  38. make.bottom.equalTo(self.mas_bottomLayoutGuide).offset(-10);
  39. make.height.mas_equalTo(44);
  40. }];
  41. signBtn.layer.backgroundColor = [UIColor colorWithRed:1.f green:64 / 255.f blue:149 / 255.f alpha:1.0].CGColor;
  42. signBtn.layer.cornerRadius = 22;
  43. signBtn.layer.shadowColor = [UIColor colorWithRed:1.f green:64 / 255.f blue:149 / 255.f alpha:0.36].CGColor;
  44. signBtn.layer.shadowOffset = CGSizeMake(0, 8);
  45. signBtn.layer.shadowOpacity = 1;
  46. signBtn.layer.shadowRadius = 10;
  47. [signBtn addTarget:self action:@selector(sign:) forControlEvents:UIControlEventTouchUpInside];
  48. }
  49. - (UIImageView *)headView {
  50. if (!_headView) {
  51. _headView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth)];
  52. [_headView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", imageURl, _model.pic]] placeholderImage:[UIImage imageNamed:@"jiazai"]];
  53. }
  54. return _headView;
  55. }
  56. - (void)sign:(UIButton *)sender {
  57. SignInfoCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
  58. NSString *people = cell.name.text;
  59. NSString *tel = cell.phone.text;
  60. NSString *pcount = cell.num.text;
  61. NSString *fee = [cell.totoalPrice.text componentsSeparatedByString:@"元"][0];
  62. NSString *parttypk = cell.model.pk;
  63. NSString *pk = [ModelUser user].pk;
  64. NSString *str = [NSString stringWithFormat:@"%@/activity?action=doEnroll&PK=%@&ParttyPK=%@&people=%@&Tel=%@&pCount=%@&Fee=%@", PublicUrl, pk, parttypk, people, tel, pcount, fee];
  65. [[AHHttpManager sharedManager] POST:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(id responseObject) {
  66. NSLog(@"%@", responseObject);
  67. if ([[responseObject objectForKey:@"msg"] isEqualToString:@"success"]) {
  68. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"报名成功" preferredStyle:UIAlertControllerStyleAlert];
  69. NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"报名成功"];
  70. int num = (int) hogan.length;
  71. [hogan addAttribute:NSFontAttributeName
  72. value:[UIFont systemFontOfSize:16.0]
  73. range:NSMakeRange(0, num)];
  74. [alertController setValue:hogan forKey:@"attributedMessage"];
  75. UIImageView *alertImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Complete_Img"]];
  76. [alertController.view addSubview:alertImg];
  77. [alertImg mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.centerY.equalTo(alertController.view.mas_centerY);
  79. make.left.equalTo(alertController.view.mas_left).offset(num / 4);
  80. }]; // [self.tableView reloadData];
  81. [self presentViewController:alertController animated:YES completion:nil];
  82. [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(backPop:) userInfo:alertController repeats:NO];
  83. } else {
  84. if ([[responseObject objectForKey:@"desc"] isEqualToString:@"余额不足"]) {
  85. [MBProgressHUD showTextHUD:@"余额不足" inView:self.view hideAfterDelay:1];
  86. } else {
  87. [MBProgressHUD showTextHUD:@"请填写正确报名资料" inView:self.view hideAfterDelay:1];
  88. }
  89. }
  90. } failure:^(NSError *error) {
  91. NSLog(@"error = %@", error);
  92. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  93. }];
  94. }
  95. - (void)backPop:(NSTimer *)timer {
  96. UIAlertController *alert = [timer userInfo];
  97. [alert dismissViewControllerAnimated:YES completion:^{
  98. [self.navigationController popViewControllerAnimated:YES];
  99. }];
  100. alert = nil;
  101. }
  102. - (void)backClick {
  103. [self.navigationController popViewControllerAnimated:YES];
  104. }
  105. - (void)viewWillAppear:(BOOL)animated {
  106. [self.navigationController setNavigationBarHidden:NO animated:YES];
  107. self.navigationController.navigationBar.tintColor = [UIColor blackColor];
  108. }
  109. #pragma mark - deleDate
  110. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  111. return 1;
  112. }
  113. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  114. SignInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SignInfoCell"];
  115. if (!cell) {
  116. cell = [[[UINib nibWithNibName:@"SignInfoCell" bundle:nil] instantiateWithOwner:self options:nil] lastObject];
  117. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  118. cell.model = _model;
  119. cell.name.delegate = self;
  120. cell.phone.delegate = self;
  121. }
  122. return cell;
  123. }
  124. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  125. return 1;
  126. }
  127. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  128. return 465;
  129. }
  130. - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  131. [theTextField resignFirstResponder];
  132. return YES;
  133. }
  134. - (void)didReceiveMemoryWarning {
  135. [super didReceiveMemoryWarning];
  136. // Dispose of any resources that can be recreated.
  137. }
  138. @end