123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- //
- // SignUpVC.m
- // LN_School
- //
- // Created by apple on 2017/4/11.
- // Copyright © 2017年 Danson. All rights reserved.
- //
- #import "SignUpVC.h"
- #import "applyCell.h"
- #import "PureCamera.h"
- #import "PhotosUploadViewController.h"
- @interface SignUpVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIActionSheetDelegate,UINavigationControllerDelegate>
- {
- UITableView *mainTableView;
-
- NSMutableArray *titleArray;
- NSArray *dataArray;
- NSArray *sheetsArray;
-
- NSString *bustype;
-
- }
- @property (nonatomic, strong) NSString *headImgPath;
- @property (nonatomic, strong) NSMutableArray *protocolImgArr;
- @property (nonatomic, strong) NSMutableArray *protocolImgPathArr;
- @end
- @implementation SignUpVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self myInit];
- }
- -(void)myInit
- {
- [self setTitle:@"学员报名"];
- self.view.backgroundColor = KBackGroundColor;
- [self goBackByNavigation];
-
-
-
- //报名类型 默认为 初领
- bustype = @"0";
- //@RQ-MARK 1.0.2修改:“学员报名”模块新增 协议上传(上传多张)
- NSArray *array = @[@[@"培训车型",@"证件类型",@"报名类型",@"获取照片"],@[@"协议上传"],@[@"姓名",@"性别",@"证件号码",@"手机号码",@"地址"],@[@"推荐人"]];
- titleArray = [NSMutableArray arrayWithArray:array];
-
- dataArray = @[[NSMutableArray arrayWithArray:@[@"C1-小型汽车 >",@"身份证 >",@"初领 >",@"点击拍照 >"]],[NSMutableArray arrayWithArray:@[@"请上传协议 >"]],[NSMutableArray arrayWithArray:@[@"请输入姓名",@"请输入性别",@"请输入证件号码",@"请输入手机号码",@"请输入地址"]],[NSMutableArray arrayWithArray:@[@"请输入推荐人"]],[NSMutableArray arrayWithArray:@[@"请输入原车型(例如:C1)",@"请输入原驾驶证号",@"请输入初领证日期"]]];
-
-
- mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStyleGrouped];
- mainTableView.height -= kNavOffSet;
- mainTableView.estimatedSectionHeaderHeight = 0;
- mainTableView.estimatedSectionFooterHeight = 0;
- [mainTableView setDelegate:self];
- [mainTableView setDataSource:self];
- [self.view addSubview:mainTableView];
-
- // UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
- // mainTableView.tableHeaderView = view;
-
-
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 100)];
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 25, kSize.width - 20, 50)];
- btn.backgroundColor = RQMianColor;
- [btn borderCornorRadios:5];
- [btn setTitle:@"提交" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
- [btn target:self Tag:1];
- [view addSubview:btn];
- mainTableView.tableFooterView = view;
- }
- - (void)btnClick:(UIButton *)sender
- {
- if (sender.tag == 1) {
- //提交
- [self.view endEditing:YES];
- // [mainTableView setEditing:YES];
- // [sender becomeFirstResponder];
- [self addStudent];
- }
- }
- #pragma mark 拍照
- - (void)takePhoto { //100*120
-
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"请选择获取图片方式" message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" otherButtonTitles:@[@"拍照", @"本地照片"] otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) {
- if (selectedOtherButtonIndex == 0) {
- [RQ_SHARE_FUNCTION getPhotosWithGetPhotosWay:GetPhotosWay_Camera size:CGSizeMake(100, 120) maxLength:100 maxImagesCount:1 photosBlock:^(NSArray * _Nonnull imagesArr, NSArray * _Nonnull imagesDataStrArr) {
- if (imagesDataStrArr.count > 0) {
- [self uploadHeadImg:imagesDataStrArr.firstObject];
- }
- }];
- }else if (selectedOtherButtonIndex == 1) {
- [RQ_SHARE_FUNCTION getPhotosWithGetPhotosWay:GetPhotosWay_Album size:CGSizeMake(100, 120) maxLength:100 maxImagesCount:1 photosBlock:^(NSArray * _Nonnull imagesArr, NSArray * _Nonnull imagesDataStrArr) {
- [self uploadHeadImg:imagesDataStrArr.firstObject];
- }];
- }
- }];
- }
- - (void)choosePhotos {
- [self navPushHideTabbarToVC:[[PhotosUploadViewController alloc] initWithNibName:@"PhotosUploadViewController" bundle:nil imagesArr:self.protocolImgArr imagesPathArr:self.protocolImgPathArr returnImagesBlock:^(NSMutableArray * _Nonnull imagesArr, NSMutableArray * _Nonnull imagesPathArr) {
- _protocolImgArr = imagesArr;
- _protocolImgPathArr = imagesPathArr;
- NSMutableArray *array = dataArray[1];
- [array replaceObjectAtIndex:0 withObject:@"上传协议成功,点击重新上传 >"];
- NSIndexPath *indexpath = [NSIndexPath indexPathForRow:0 inSection:1];
- [mainTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexpath,nil] withRowAnimation:UITableViewRowAnimationNone];
- }]];
- }
- #pragma mark - tableview delegate
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return titleArray.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [titleArray[section] count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (cell == nil)
- {
- cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- [cell.titLabel setText:[titleArray[indexPath.section] objectAtIndex:indexPath.row]];
-
- NSArray *detailArray = dataArray[indexPath.section];
-
- cell.detailField.delegate = self;
- cell.detailField.tag = indexPath.section * 10 + indexPath.row;
-
- if (indexPath.section == 0 || indexPath.section == 1)
- {
- cell.detailField.userInteractionEnabled = NO;
- cell.detailField.textColor = RQMianColor;
- cell.detailField.text = detailArray[indexPath.row];
- }else {
-
- if (indexPath.section == 2 ) {
- if(indexPath.row==2 || indexPath.row==3) {
- cell.detailField.keyboardType = UIKeyboardTypeNumberPad;
- }
- }
- cell.detailField.userInteractionEnabled = YES;
- NSArray *array = @[@"请输入姓名",@"请输入性别",@"请输入证件号码",@"请输入手机号码",@"请输入地址",@"请输入推荐人",@"请输入原车型(例如:C1)",@"请输入原驾驶证号",@"请输入初领证日期"];
- if ([array containsObject:detailArray[indexPath.row]]) {
- cell.detailField.text = @"";
- cell.detailField.placeholder = detailArray[indexPath.row];
- }else {
- cell.detailField.textColor = KTitleColor;
- cell.detailField.text = detailArray[indexPath.row];
- }
- }
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [self.view endEditing:YES];
-
- if (indexPath.section == 0)
- {
- if (indexPath.row == 3) {
- //拍照
- [self takePhoto];
- return;
- }
-
- UIActionSheet *myActionSheet;
- if (indexPath.row == 0) {
-
- sheetsArray = @[@"A1-大型客车", @"A2-牵引车",@"A3-城市公交车",@"B1-中型客车",@"B2-大型货车",@"C1-小型汽车",@"C2-小型自动挡汽车",@"C3-低速载货汽车",@"C4-三轮汽车",@"C5-残疾人专用小型自动挡载客汽车",@"D-普通三轮摩托车",@"E-普通二轮摩托车",@"F-轻便摩托车",@"M-轮式自行机械车",@"N-无轨电车",@"P-有轨电车"];
- myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"A1-大型客车", @"A2-牵引车",@"A3-城市公交车",@"B1-中型客车",@"B2-大型货车",@"C1-小型汽车",@"C2-小型自动挡汽车",@"C3-低速载货汽车",@"C4-三轮汽车",@"C5-残疾人专用小型自动挡载客汽车",@"D-普通三轮摩托车",@"E-普通二轮摩托车",@"F-轻便摩托车",@"M-轮式自行机械车",@"N-无轨电车",@"P-有轨电车", nil];
- }else if (indexPath.row == 1) {
-
- sheetsArray = @[@"身份证",@"护照",@"军官证",@"其它"];
- myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"身份证",@"护照",@"军官证",@"其它", nil];
- }else if (indexPath.row == 2) {
-
- sheetsArray = @[@"初领-0",@"增驾-1",@"其它-9"];
- myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"初领",@"增驾",@"其它", nil];
- }
-
- myActionSheet.tag = indexPath.row;
- [myActionSheet showInView:self.view];
- }else if (indexPath.section == 1) {
- if (indexPath.row == 0) {
- [self choosePhotos];
- }
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return .1;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 25;
- }
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
- //NSLog(@"1");
- [self.view endEditing:YES];
- }
- -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (buttonIndex == actionSheet.cancelButtonIndex) {
- return;
- }
-
- NSMutableArray *array = [dataArray firstObject];
-
- NSString *detailString = sheetsArray[buttonIndex];
-
- if (actionSheet.tag == 2) { //报名类型
- detailString = [[sheetsArray[buttonIndex] componentsSeparatedByString:@"-"] firstObject];
-
- bustype = [[sheetsArray[buttonIndex] componentsSeparatedByString:@"-"] lastObject];
-
- if ([bustype isEqualToString:@"1"]) { //mainTableView新增一个section
- [titleArray addObject:@[@"原车型",@"原驾驶证号",@"初领证日期"]];
- [array replaceObjectAtIndex:actionSheet.tag withObject:[NSString stringWithFormat:@"%@ >",detailString]];
-
- [mainTableView reloadData];
- return;
- }else{
- if (titleArray.count > 3) {
- [titleArray removeLastObject];
- }
- }
- }
-
- [array replaceObjectAtIndex:actionSheet.tag withObject:[NSString stringWithFormat:@"%@ >",detailString]];
-
- // NSIndexPath *indexpath = [NSIndexPath indexPathForRow:actionSheet.tag inSection:0];
- // [mainTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexpath,nil] withRowAnimation:UITableViewRowAnimationNone];
- [mainTableView reloadData];//上面方法二次调用引起崩溃
- }
- #pragma mark textField
- -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
- {
- NSIndexPath *indexpath = indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:textField.tag/10];;
-
- //获取当前cell在tableview中的位置
- CGRect rectintableview=[mainTableView rectForRowAtIndexPath:indexpath];
-
- [mainTableView setContentOffset:CGPointMake(mainTableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
- return YES;
- }
- -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
- {
-
- NSString *textString = textField.text;
-
- NSMutableArray *array = dataArray[textField.tag/10];
- [array replaceObjectAtIndex:textField.tag%10 withObject:textString];
-
- [mainTableView reloadData];
- return YES;
- }
- -(BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- [textField endEditing:YES];
- return YES;
- }
- #pragma mark 数据请求
- - (void)uploadHeadImg:(NSString *)image
- {
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- [dic setObject:image forKey:@"content"];
- [dic setObject:@"" forKey:@"keyword"];
- [dic setObject:@"2" forKey:@"type"];
-
- NSString *method = @"upload-2";
- [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- [self showUPloadImgAlertWithImg:image];
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- [self showUPloadImgAlertWithImg:image];
- return;
- }
- //上传头像成功
- _headImgPath = root[@"body"];
- NSMutableArray *array = [dataArray firstObject];
- [array replaceObjectAtIndex:3 withObject:@"拍照成功,点击重拍 >"];
- NSIndexPath *indexpath = [NSIndexPath indexPathForRow:3 inSection:0];
- [mainTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexpath,nil] withRowAnimation:UITableViewRowAnimationNone];
- }];
- }
- - (void)showUPloadImgAlertWithImg:(NSString *)image {
- [RQ_SHARE_FUNCTION showAlertWithTitle:nil message:@"图片上传失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"再试一次"] otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) {
- if (selectedOtherButtonIndex == 0) {
- [self uploadHeadImg:image];
- }
- }];
- }
- -(void)addStudent
- {
- if (_headImgPath.length < 1) {
- ShowMsg(@"请采集照片");
- _headImgPath = @"";
- return;
- }
-
- if (!_protocolImgPathArr || _protocolImgPathArr.count == 0) {
- ShowMsg(@"请上传协议");
- _protocolImgPathArr = [NSMutableArray array];
- return;
- }
-
- NSInteger num = 4;
- if ([bustype isEqualToString:@"1"]) {
- num = 5;
- }
-
- NSString *name, *idcard, *sex, *phone, *source, *cardtype, *traintype, *perdritype, *drilicnum, *fstdrilicdate, *address;
- name=idcard=sex=phone=source=cardtype=traintype=perdritype=drilicnum=fstdrilicdate=address = @"";
- for (int i = 0; i < num; i ++) {
- NSMutableArray *array = dataArray[i];
-
- for (int j = 0; j < array.count; j ++) {
- NSString *string = array[j];
- if ([string containsString:@"请输入"] || string.length == 0) {
- ShowMsg(@"您还有信息未录入");
- return;
- }
-
- switch (i) {
- case 0:
- if (j == 0) {
- traintype = [[string componentsSeparatedByString:@"-"] firstObject];
- }else if (j == 1) {
- cardtype = [[string componentsSeparatedByString:@" "] firstObject];
-
- //@[@"身份证",@"护照",@"军官证",@"其他"];
- if ([cardtype isEqualToString:@"身份证"]) {
- cardtype = @"1";
- }
- if ([cardtype isEqualToString:@"护照"]) {
- cardtype = @"2";
- }
- if ([cardtype isEqualToString:@"军官证"]) {
- cardtype = @"3";
- }
- if ([cardtype isEqualToString:@"其它"]) {
- cardtype = @"4";
- }
- }
- break;
- case 2:
- if (j == 0) {
- name = string;
- }
- if (j == 1) {
- if (![string isEqualToString:@"男"] && ![string isEqualToString:@"女"]) {
- ShowMsg(@"性别输入错误");
- return;
- }
- sex = [string isEqualToString:@"男"]?@"1":@"2";
- }
- if (j == 2) {
- idcard = string;
- }
- if (j == 3) {
- if (![Tools isMobileNumber:string]) {
- ShowMsg(@"请输入正确的手机号码");
- return;
- }
- phone = string;
- }
- if (j == 4) {
- address = string;
- }
-
- break;
- case 3:
- source = string;
- break;
- case 4:
- if (j == 0) {
- perdritype = string;
- }
- if (j == 1) {
- drilicnum = string;
- }
- if (j == 2) {
- fstdrilicdate = string;
- }
- break;
- default:
- break;
- }
- }
- }
-
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
- [dic setObject:name forKey:@"name"];
- [dic setObject:idcard forKey:@"idcard"];
- [dic setObject:sex forKey:@"sex"];
- [dic setObject:phone forKey:@"phone"];
- [dic setObject:source forKey:@"source"];
- [dic setObject:bustype forKey:@"bustype"];
- [dic setObject:traintype forKey:@"traintype"];
- [dic setObject:perdritype forKey:@"perdritype"];
- [dic setObject:drilicnum forKey:@"drilicnum"];
- [dic setObject:fstdrilicdate forKey:@"fstdrilicdate"];
- [dic setObject:address forKey:@"address"];
- [dic setObject:_headImgPath forKey:@"photo"];
- [dic setObject:cardtype forKey:@"cardtype"];
- [dic setObject:[_protocolImgPathArr componentsJoinedByString:@","] forKey:@"pactPath"];
-
- NSString *method = @"addStudent";
- [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- ShowMsg(@"提交失败,请重试");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"msg"]);
- return;
- }
-
- ShowMsg(@"报名成功!");
- [self.navigationController popViewControllerAnimated:YES];
- }];
- }
- #pragma mark - 限制输入字符
- -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
- NSCharacterSet *cs;
- //invertedSet方法是去反字符,把所有的除了NUMBERS 里的字符都找出来(包含去空格功能)
-
- cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789n"]invertedSet];
-
-
- // componentsJoinedByString 用于根据一个字符串来将数组连接成一个新的字符串。
- NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
-
- BOOL canChange = [string isEqualToString:filtered];
- if (textField.tag == 12 || textField.tag == 13) {
- return canChange;
- }
- return YES;
- //这样写了以后,输入非数字时不能输入
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|