// // NewSignUpPointVC.m // LN_School // // Created by apple on 2017/12/12. // Copyright © 2017年 Danson. All rights reserved. // #import "NewSignUpPointVC.h" #import NSString *const signSchoolName = @"schoolName"; NSString *const signName = @"name"; NSString *const signAddress = @"address"; NSString *const signPhone = @"phone"; NSString *const signMemo = @"memo"; @interface NewSignUpPointVC () @end @implementation NewSignUpPointVC -(instancetype)init { self = [super init]; if (self){ [self initializeForm]; } return self; } -(void)initializeForm { XLFormDescriptor *form = [XLFormDescriptor formDescriptor];//创建表单 form = [XLFormDescriptor formDescriptorWithTitle:@"新增报名点"]; XLFormSectionDescriptor *section = [XLFormSectionDescriptor formSectionWithTitle:@"必填项"]; //创建区 [form addFormSection:section]; //机构名 XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:signSchoolName rowType:XLFormRowDescriptorTypeInfo title:@"所属机构"]; //创建cell row.value = defUser.userDict[@"schoolName"]; [section addFormRow:row]; //教练名 row = [XLFormRowDescriptor formRowDescriptorWithTag:signName rowType:XLFormRowDescriptorTypeText title:@"名称"]; [row.cellConfigAtConfigure setObject:@"请输入名称" forKey:@"textField.placeholder"]; row.required = YES; [section addFormRow:row]; // 电话号码 row = [XLFormRowDescriptor formRowDescriptorWithTag:signPhone rowType:XLFormRowDescriptorTypeText title:@"电话"]; row.required = YES; [row.cellConfigAtConfigure setObject:@"请输入电话号码" forKey:@"textField.placeholder"]; NSString * mobil = @"[0-9 -]{7,}";//限制7位数最低 [row addValidator:[XLFormRegexValidator formRegexValidatorWithMsg:@"请输入正确电话号码" regex:mobil]]; [section addFormRow:row]; //联系地址 row = [XLFormRowDescriptor formRowDescriptorWithTag:signAddress rowType:XLFormRowDescriptorTypeText title:@"地址"]; [row.cellConfigAtConfigure setObject:@"请输入联系地址" forKey:@"textField.placeholder"]; row.required = YES; [section addFormRow:row]; XLFormSectionDescriptor *section2 = [XLFormSectionDescriptor formSectionWithTitle:@"可选填项"]; //创建区 [form addFormSection:section2]; //备注 row = [XLFormRowDescriptor formRowDescriptorWithTag:signMemo rowType:XLFormRowDescriptorTypeTextView title:@"备注"]; [section2 addFormRow:row]; //创建完所有cell后还要 self.form = form; } - (void)viewDidLoad { [super viewDidLoad]; [self goBackByNavigation]; CGFloat bottomBtnH = 50; self.tableView.height = kSize.height-bottomBtnH-SafeAreaBottomHeight; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(0, kSize.height-kNavOffSet-bottomBtnH- SafeAreaBottomHeight, kSize.width, bottomBtnH); [btn setTitle:@"保存" textColor:[UIColor whiteColor] font:Font17 fotState:UIControlStateNormal]; btn.backgroundColor = defGreen; [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } -(void)btnClick{ //校验数据 NSArray *arr = [self formValidationErrors]; if ([arr count] != 0) { NSError *error = arr[0]; ShowMsg(error.userInfo[@"NSLocalizedDescription"]); return; } NSDictionary *dataDic = [self formValues]; NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dataDic]; [dic setObject:defUser.userDict[@"id"] forKey:@"userId"]; [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"]; if (dic[signMemo] == [NSNull null]) { [dic setObject:@"" forKey:signMemo]; } [dic removeObjectForKey:signSchoolName]; NSString *method = @"addSchoolPoint"; [MBProgressHUD showLoadToView:self.view]; [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowMsg(@"数据请求失败,请重试"); return; } if ([root[@"code"] integerValue] == 1) { ShowMsg(root[@"msg"]); return; } ShowMsg([NSString stringWithFormat:@"已成功添加%@报名点",dataDic[signName]]); [self.navigationController popViewControllerAnimated:YES]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end