NewSignUpPointVC.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // NewSignUpPointVC.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/12/12.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "NewSignUpPointVC.h"
  9. #import <XLForm.h>
  10. NSString *const signSchoolName = @"schoolName";
  11. NSString *const signName = @"name";
  12. NSString *const signAddress = @"address";
  13. NSString *const signPhone = @"phone";
  14. NSString *const signMemo = @"memo";
  15. @interface NewSignUpPointVC ()
  16. @end
  17. @implementation NewSignUpPointVC
  18. -(instancetype)init
  19. {
  20. self = [super init];
  21. if (self){
  22. [self initializeForm];
  23. }
  24. return self;
  25. }
  26. -(void)initializeForm
  27. {
  28. XLFormDescriptor *form = [XLFormDescriptor formDescriptor];//创建表单
  29. form = [XLFormDescriptor formDescriptorWithTitle:@"新增报名点"];
  30. XLFormSectionDescriptor *section = [XLFormSectionDescriptor formSectionWithTitle:@"必填项"]; //创建区
  31. [form addFormSection:section];
  32. //机构名
  33. XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:signSchoolName rowType:XLFormRowDescriptorTypeInfo title:@"所属机构"]; //创建cell
  34. row.value = defUser.userDict[@"schoolName"];
  35. [section addFormRow:row];
  36. //教练名
  37. row = [XLFormRowDescriptor formRowDescriptorWithTag:signName rowType:XLFormRowDescriptorTypeText title:@"名称"];
  38. [row.cellConfigAtConfigure setObject:@"请输入名称" forKey:@"textField.placeholder"];
  39. row.required = YES;
  40. [section addFormRow:row];
  41. // 电话号码
  42. row = [XLFormRowDescriptor formRowDescriptorWithTag:signPhone rowType:XLFormRowDescriptorTypeText title:@"电话"];
  43. row.required = YES;
  44. [row.cellConfigAtConfigure setObject:@"请输入电话号码" forKey:@"textField.placeholder"];
  45. NSString * mobil = @"[0-9 -]{7,}";//限制7位数最低
  46. [row addValidator:[XLFormRegexValidator formRegexValidatorWithMsg:@"请输入正确电话号码" regex:mobil]];
  47. [section addFormRow:row];
  48. //联系地址
  49. row = [XLFormRowDescriptor formRowDescriptorWithTag:signAddress rowType:XLFormRowDescriptorTypeText title:@"地址"];
  50. [row.cellConfigAtConfigure setObject:@"请输入联系地址" forKey:@"textField.placeholder"];
  51. row.required = YES;
  52. [section addFormRow:row];
  53. XLFormSectionDescriptor *section2 = [XLFormSectionDescriptor formSectionWithTitle:@"可选填项"]; //创建区
  54. [form addFormSection:section2];
  55. //备注
  56. row = [XLFormRowDescriptor formRowDescriptorWithTag:signMemo rowType:XLFormRowDescriptorTypeTextView title:@"备注"];
  57. [section2 addFormRow:row];
  58. //创建完所有cell后还要
  59. self.form = form;
  60. }
  61. - (void)viewDidLoad {
  62. [super viewDidLoad];
  63. [self goBackByNavigation];
  64. CGFloat bottomBtnH = 50;
  65. self.tableView.height = kSize.height-bottomBtnH-SafeAreaBottomHeight;
  66. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  67. btn.frame = CGRectMake(0, kSize.height-kNavOffSet-bottomBtnH- SafeAreaBottomHeight, kSize.width, bottomBtnH);
  68. [btn setTitle:@"保存" textColor:[UIColor whiteColor] font:Font17 fotState:UIControlStateNormal];
  69. btn.backgroundColor = defGreen;
  70. [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
  71. [self.view addSubview:btn];
  72. }
  73. -(void)btnClick{
  74. //校验数据
  75. NSArray *arr = [self formValidationErrors];
  76. if ([arr count] != 0) {
  77. NSError *error = arr[0];
  78. ShowMsg(error.userInfo[@"NSLocalizedDescription"]);
  79. return;
  80. }
  81. NSDictionary *dataDic = [self formValues];
  82. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dataDic];
  83. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  84. [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"];
  85. if (dic[signMemo] == [NSNull null]) {
  86. [dic setObject:@"" forKey:signMemo];
  87. }
  88. [dic removeObjectForKey:signSchoolName];
  89. NSString *method = @"addSchoolPoint";
  90. [MBProgressHUD showLoadToView:self.view];
  91. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  92. [MBProgressHUD hideHUDForView:self.view];
  93. if (!root) {
  94. ShowMsg(@"数据请求失败,请重试");
  95. return;
  96. }
  97. if ([root[@"code"] integerValue] == 1) {
  98. ShowMsg(root[@"msg"]);
  99. return;
  100. }
  101. ShowMsg([NSString stringWithFormat:@"已成功添加%@报名点",dataDic[signName]]);
  102. [self.navigationController popViewControllerAnimated:YES];
  103. }];
  104. }
  105. - (void)didReceiveMemoryWarning {
  106. [super didReceiveMemoryWarning];
  107. // Dispose of any resources that can be recreated.
  108. }
  109. /*
  110. #pragma mark - Navigation
  111. // In a storyboard-based application, you will often want to do a little preparation before navigation
  112. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  113. // Get the new view controller using [segue destinationViewController].
  114. // Pass the selected object to the new view controller.
  115. }
  116. */
  117. @end