|
| 1 | +// |
| 2 | +// ProjectTransferSettingViewController.m |
| 3 | +// Coding_iOS |
| 4 | +// |
| 5 | +// Created by Ease on 15/10/19. |
| 6 | +// Copyright © 2015年 Coding. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "ProjectTransferSettingViewController.h" |
| 10 | +#import "Coding_NetAPIManager.h" |
| 11 | + |
| 12 | +#import <SDCAlertController.h> |
| 13 | +#import <SDCAlertView.h> |
| 14 | +#import <UIView+SDCAutoLayout.h> |
| 15 | +#import "ProjectDeleteAlertControllerVisualStyle.h" |
| 16 | +#import "Ease_2FA.h" |
| 17 | +#import "ProjectMemberListViewController.h" |
| 18 | + |
| 19 | +@interface ProjectTransferSettingViewController ()<UITextFieldDelegate> |
| 20 | +@property (strong, nonatomic) User *selectedUser; |
| 21 | + |
| 22 | +@property (strong, nonatomic) SDCAlertController *alert; |
| 23 | +@property (weak, nonatomic) IBOutlet UIImageView *userIconView; |
| 24 | +@property (weak, nonatomic) IBOutlet UILabel *userNameLabel; |
| 25 | +@property (weak, nonatomic) IBOutlet UIButton *transferBtn; |
| 26 | +@end |
| 27 | + |
| 28 | +@implementation ProjectTransferSettingViewController |
| 29 | +- (void)viewDidLoad { |
| 30 | + [super viewDidLoad]; |
| 31 | + self.title = @"转让项目"; |
| 32 | + |
| 33 | + for (NSLayoutConstraint *cons in self.lines) { |
| 34 | + cons.constant = 0.5; |
| 35 | + } |
| 36 | + |
| 37 | + [self.tableView setSeparatorColor:[UIColor colorWithRGBHex:0xe5e5e5]]; |
| 38 | + [_userIconView doCircleFrame]; |
| 39 | + [_transferBtn successStyle]; |
| 40 | + _transferBtn.enabled = NO; |
| 41 | +} |
| 42 | +- (void)setSelectedUser:(User *)selectedUser{ |
| 43 | + if ([selectedUser.global_key isEqualToString:[Login curLoginUser].global_key]) { |
| 44 | + [NSObject showHudTipStr:@"项目不能转让给自己!"]; |
| 45 | + return; |
| 46 | + } |
| 47 | + _selectedUser = selectedUser; |
| 48 | + [_userIconView sd_setImageWithURL:[_selectedUser.avatar urlImageWithCodePathResizeToView:_userIconView] placeholderImage:[UIImage imageNamed:@"taskOwner"]]; |
| 49 | + _userNameLabel.text = selectedUser.name; |
| 50 | + _transferBtn.enabled = _selectedUser.global_key.length > 0; |
| 51 | +} |
| 52 | +#pragma mark UITableView |
| 53 | + |
| 54 | +-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ |
| 55 | + return [UIView new]; |
| 56 | +} |
| 57 | + |
| 58 | +//-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath |
| 59 | +//{ |
| 60 | +// if (indexPath.section == 1 && indexPath.row == 0) { |
| 61 | +// cell.separatorInset = UIEdgeInsetsMake(0.f, cell.bounds.size.width, 0.f, 0.f); |
| 62 | +// return; |
| 63 | +// } |
| 64 | +// |
| 65 | +// // Remove seperator inset |
| 66 | +// if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { |
| 67 | +// [cell setSeparatorInset:UIEdgeInsetsZero]; |
| 68 | +// } |
| 69 | +// |
| 70 | +// // Prevent the cell from inheriting the Table View's margin settings |
| 71 | +// if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) { |
| 72 | +// [cell setPreservesSuperviewLayoutMargins:NO]; |
| 73 | +// } |
| 74 | +// |
| 75 | +// // Explictly set your cell's layout margins |
| 76 | +// if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { |
| 77 | +// [cell setLayoutMargins:UIEdgeInsetsZero]; |
| 78 | +// } |
| 79 | +//} |
| 80 | + |
| 81 | +-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 82 | + [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
| 83 | + if (indexPath.section == 1) { |
| 84 | + __weak typeof(self) weakSelf = self; |
| 85 | + ProjectMemberListViewController *vc = [[ProjectMemberListViewController alloc] init]; |
| 86 | + [vc setFrame:self.view.bounds project:_project type:ProMemTypeTaskOwner refreshBlock:nil selectBlock:^(ProjectMember *member) { |
| 87 | + weakSelf.selectedUser = member.user; |
| 88 | + } cellBtnBlock:nil]; |
| 89 | + [self.navigationController pushViewController:vc animated:YES]; |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | + |
| 94 | +#pragma mark Btn |
| 95 | + |
| 96 | +- (IBAction)transferBtnClicked:(id)sender { |
| 97 | + [[Coding_NetAPIManager sharedManager] request_VerifyTypeWithBlock:^(VerifyType type, NSError *error) { |
| 98 | + if (!error) { |
| 99 | + [self showDeleteAlertWithType:type]; |
| 100 | + } |
| 101 | + }]; |
| 102 | +} |
| 103 | + |
| 104 | +- (void)showDeleteAlertWithType:(VerifyType)type{ |
| 105 | + |
| 106 | + if (self.alert) {//正在显示 |
| 107 | + return; |
| 108 | + } |
| 109 | + |
| 110 | + NSString *title, *message, *placeHolder; |
| 111 | + if (type == VerifyTypePassword) { |
| 112 | + title = @"需要验证密码"; |
| 113 | + message = @"这是一个危险的操作,请提供登录密码确认!"; |
| 114 | + placeHolder = @"请输入密码"; |
| 115 | + }else if (type == VerifyTypeTotp){ |
| 116 | + title = @"需要动态验证码"; |
| 117 | + message = @"这是一个危险操作,需要进行身份验证!"; |
| 118 | + placeHolder = @"请输入动态验证码"; |
| 119 | + }else{//不知道啥类型,不处理 |
| 120 | + return; |
| 121 | + } |
| 122 | + |
| 123 | + _alert = [SDCAlertController alertControllerWithTitle:title message:message preferredStyle:SDCAlertControllerStyleAlert]; |
| 124 | + |
| 125 | + UITextField *passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(15, 0, 240.0, 30.0)]; |
| 126 | + passwordTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)]; |
| 127 | + passwordTextField.leftViewMode = UITextFieldViewModeAlways; |
| 128 | + passwordTextField.layer.borderColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.6].CGColor; |
| 129 | + passwordTextField.layer.borderWidth = 1; |
| 130 | + passwordTextField.secureTextEntry = (type == VerifyTypePassword); |
| 131 | + passwordTextField.backgroundColor = [UIColor whiteColor]; |
| 132 | + passwordTextField.placeholder = placeHolder; |
| 133 | + if (type == VerifyTypeTotp) { |
| 134 | + passwordTextField.text = [OTPListViewController otpCodeWithGK:[Login curLoginUser].global_key]; |
| 135 | + } |
| 136 | + passwordTextField.delegate = self; |
| 137 | + |
| 138 | + [_alert.contentView addSubview:passwordTextField]; |
| 139 | + |
| 140 | + NSDictionary* passwordViews = NSDictionaryOfVariableBindings(passwordTextField); |
| 141 | + |
| 142 | + [_alert.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[passwordTextField]-(>=14)-|" options:0 metrics:nil views:passwordViews]]; |
| 143 | + |
| 144 | + // Style |
| 145 | + _alert.visualStyle = [ProjectDeleteAlertControllerVisualStyle new]; |
| 146 | + |
| 147 | + // 添加密码框 |
| 148 | + // [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { |
| 149 | + // textField.secureTextEntry = YES; |
| 150 | + // }]; |
| 151 | + |
| 152 | + // 添加按钮 |
| 153 | + @weakify(self); |
| 154 | + _alert.actionLayout = SDCAlertControllerActionLayoutHorizontal; |
| 155 | + [_alert addAction:[SDCAlertAction actionWithTitle:@"取消" style:SDCAlertActionStyleDefault handler:^(SDCAlertAction *action) { |
| 156 | + @strongify(self); |
| 157 | + self.alert = nil; |
| 158 | + }]]; |
| 159 | + [_alert addAction:[SDCAlertAction actionWithTitle:@"确定" style:SDCAlertActionStyleDefault handler:^(SDCAlertAction *action) { |
| 160 | + @strongify(self); |
| 161 | + self.alert = nil; |
| 162 | + NSString *passCode = passwordTextField.text; |
| 163 | + if ([passCode length] > 0) { |
| 164 | + // 转让项目 |
| 165 | + [[Coding_NetAPIManager sharedManager] request_TransferProject:self.project toUser:self.selectedUser passCode:passCode type:type andBlock:^(Project *data, NSError *error) { |
| 166 | + if (!error) { |
| 167 | + [self.navigationController popToRootViewControllerAnimated:YES]; |
| 168 | + } |
| 169 | + }]; |
| 170 | + } |
| 171 | + }]]; |
| 172 | + |
| 173 | + [_alert presentWithCompletion:^{ |
| 174 | + [passwordTextField becomeFirstResponder]; |
| 175 | + }]; |
| 176 | +} |
| 177 | + |
| 178 | + |
| 179 | +-(BOOL)textFieldShouldReturn:(UITextField *)textField{ |
| 180 | + [textField resignFirstResponder]; |
| 181 | + return YES; |
| 182 | +} |
| 183 | + |
| 184 | +#pragma mark - Orientations |
| 185 | +- (BOOL)shouldAutorotate{ |
| 186 | + return UIInterfaceOrientationIsLandscape(self.interfaceOrientation); |
| 187 | +} |
| 188 | + |
| 189 | +- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { |
| 190 | + return UIInterfaceOrientationPortrait; |
| 191 | +} |
| 192 | + |
| 193 | +- (UIInterfaceOrientationMask)supportedInterfaceOrientations { |
| 194 | + return UIInterfaceOrientationMaskPortrait; |
| 195 | +} |
| 196 | +@end |
0 commit comments