//
|
// PBEditPersonView.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2018/8/17.
|
// Copyright © 2018年 ProBIM. All rights reserved.
|
//
|
|
#import "PBEditPersonView.h"
|
#import "PBEditPersonCollectionViewCell.h"
|
#import "PBRoleTableViewCell.h"
|
#import "PBIssueAddModel.h"
|
#import "PBPersonModel.h"
|
#import "PBProjectModel.h"
|
#import "PBExamineAddModel.h"
|
#import "PBIssueListModel.h"
|
#define ItemWidth 160
|
#define ItemHeight 34
|
#define LineSpacing 6
|
#define InteritemSpacing 6
|
static NSString *const cellID = @"cellID";
|
static NSString *const roleCellID = @"roleCellID";
|
@interface PBEditPersonView()<UICollectionViewDataSource, UITableViewDataSource, UITableViewDelegate>
|
@property (nonatomic, strong) UIView *bgView;
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
@property (nonatomic, assign) NSInteger aLineCount;
|
@property (nonatomic, strong) NSArray *rightArr;
|
@property (nonatomic, strong) UITableView *rightTableView;
|
@property (nonatomic, assign) NSInteger leftSelectIndex;
|
@property (nonatomic, strong) NSMutableArray *personListM;
|
@property (nonatomic, assign) BOOL isIssue;
|
@property (nonatomic, weak) UIButton *determineBtn;
|
@property (nonatomic, weak) UIButton *packupBtn;
|
@end
|
@implementation PBEditPersonView
|
- (instancetype)initWithFrame:(CGRect)frame {
|
if (self = [super initWithFrame:frame]) {
|
self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0];
|
[self addSubview:self.bgView];
|
[self setupUI];
|
}
|
return self;
|
}
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
CGPoint point=[[touches anyObject]locationInView:self];
|
CALayer *layer=[self.layer hitTest:point];
|
if (layer ==self.layer) {
|
if (_isIssue) {
|
[self saveData];
|
}else {
|
[self hidden];
|
}
|
}
|
}
|
- (void)hidden {
|
[UIView animateWithDuration:0.3 animations:^{
|
self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0];
|
self.bgView.y = PBScreenHeight;
|
}completion:^(BOOL finished) {
|
for (UIView *cover in PBKeyWindow.subviews) {
|
if ([cover isKindOfClass:[PBEditPersonView class]]) {
|
[cover removeFromSuperview];
|
}
|
}
|
}];
|
}
|
- (void)show {
|
[UIView animateWithDuration:0.3 animations:^{
|
self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
|
self.bgView.y = PBScreenHeight - self.visualViewHeight;
|
}];
|
}
|
#pragma mark - 懒加载
|
- (UIView *)bgView {
|
if (_bgView == nil) {
|
_bgView = [[UIView alloc]initWithFrame:CGRectMake(0, PBScreenHeight, PBScreenWidth, PBScreenHeight)];
|
_bgView.backgroundColor = [UIColor whiteColor];
|
}
|
return _bgView;
|
}
|
- (void)setVisualViewHeight:(NSInteger)visualViewHeight {
|
_visualViewHeight = visualViewHeight;
|
}
|
|
- (void)setupUI {
|
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, 3)];
|
topView.backgroundColor = WarningColor;
|
[self.bgView addSubview:topView];
|
|
// UIButton *searchBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"Doc_list_searchItem"]];
|
// [searchBtn addTarget:self action:@selector(searchBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
// [self.bgView addSubview:searchBtn];
|
// [searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
// make.top.equalTo(topView.mas_bottom).offset(13);
|
// make.left.equalTo(topView).offset(24);
|
// }];
|
UILabel *titleL = [UILabel z_labelWithText:@"请选择人员" Color:IgnoreColor isBold:NO Font:TitleFontSize];
|
[self.bgView addSubview:titleL];
|
[titleL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(topView.mas_bottom).offset(14);
|
make.centerX.equalTo(self);
|
make.size.mas_equalTo(CGSizeMake(120, 22));
|
}];
|
UIButton *determineBtn = [UIButton z_textButton:@"确定" fontSize:MarkedFontSize normalColor:WarningColor];
|
UIButton *packupBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"Issue_ retrieve_default"]] ;
|
[packupBtn addTarget:self action:@selector(packupBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
[determineBtn addTarget:self action:@selector(determineBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.bgView addSubview:packupBtn];
|
[self.bgView addSubview:determineBtn];
|
[determineBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(topView.mas_bottom).offset(13);
|
make.right.equalTo(topView).offset(-24);
|
}];
|
[packupBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(topView.mas_bottom).offset(13);
|
make.right.equalTo(topView).offset(-24);
|
}];
|
self.determineBtn = determineBtn;
|
self.packupBtn = packupBtn;
|
if (PBScreenWidth > 320) {
|
_aLineCount = 2;
|
}else {
|
_aLineCount = 2;
|
}
|
CGFloat margin = (PBScreenWidth - ((ItemWidth * _aLineCount) + ((_aLineCount - 1) * LineSpacing))) / 2;
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
layout.itemSize = CGSizeMake(ItemWidth, ItemHeight);
|
layout.minimumLineSpacing = LineSpacing;
|
layout.minimumInteritemSpacing = InteritemSpacing;
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
self.collectionView = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout];
|
self.collectionView.backgroundColor = [UIColor clearColor];
|
[self.collectionView registerClass:[PBEditPersonCollectionViewCell class] forCellWithReuseIdentifier:cellID];
|
self.collectionView.dataSource = self;
|
[self.bgView addSubview:self.collectionView];
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.bgView).offset(63);
|
make.left.equalTo(self.bgView).offset(margin);
|
make.right.equalTo(self.bgView).offset(-margin);
|
make.height.equalTo(@114);
|
}];
|
|
UILabel *membersTitleL = [UILabel z_labelWithText:@"成员" Color:IgnoreColor isBold:NO Font:DescFontSize];
|
[self.bgView addSubview:membersTitleL];
|
[membersTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.collectionView.mas_bottom).offset(21);
|
make.left.equalTo(self).offset(14);
|
}];
|
UIButton *allSelectBtn = [UIButton z_textButton:@"全选" fontSize:DescFontSize normalColor:WarningColor];
|
[allSelectBtn addTarget:self action:@selector(allSelectBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.bgView addSubview:allSelectBtn];
|
[allSelectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(membersTitleL);
|
make.right.equalTo(self.bgView).offset(-11);
|
}];
|
|
self.rightTableView = [[UITableView alloc] init];
|
self.rightTableView.bounces = NO;
|
self.rightTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
[self.rightTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
|
self.rightTableView.rowHeight = 58.f;
|
self.rightTableView.delegate = self;
|
self.rightTableView.dataSource = self;
|
[self.bgView addSubview:self.rightTableView];
|
[self.rightTableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(membersTitleL.mas_bottom).offset(34);
|
make.height.equalTo(@210);
|
make.left.right.equalTo(self);
|
}];
|
}
|
- (void)searchBtnAction {
|
|
|
}
|
- (void)packupBtnAction {
|
[self saveData];
|
}
|
- (void)determineBtnAction {
|
[self saveData];
|
}
|
- (void)saveData {
|
if (_isIssue) {
|
self.issueAddModel.personArr = self.personListM.copy;
|
}else {
|
self.examineAddModel.personArr = self.personListM.copy;
|
}
|
if (self.EditCompleteBlock) {
|
self.EditCompleteBlock();
|
}
|
[self hidden];
|
}
|
- (void)allSelectBtnAction {
|
NSMutableArray *personArrM = [[NSMutableArray alloc] init];
|
for (NSDictionary *dict in self.rightArr) {
|
BOOL isAdd = NO;
|
PBPersonModel *rightPersonModel = [PBPersonModel yy_modelWithDictionary:dict];
|
for (PBPersonModel *personModel in self.personListM) {
|
if ([rightPersonModel.UserId isEqualToString:personModel.UserId]) {
|
isAdd = YES;
|
break;
|
}
|
}
|
if (!isAdd) {
|
[personArrM addObject:rightPersonModel];
|
}
|
}
|
[self.personListM addObjectsFromArray:personArrM.copy];
|
[self.collectionView reloadData];
|
}
|
#pragma mark - UICollectionViewDataSource
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
return self.personListM.count;
|
}
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
PBEditPersonCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
|
PBPersonModel *personModel = self.personListM[indexPath.row];
|
if ([personModel.UserId isEqualToString:self.issueListModel.CreateUserId]) {
|
cell.isHiddenDelete = YES;
|
}else {
|
cell.isHiddenDelete = NO;
|
}
|
cell.name = personModel.RealName;
|
__weak typeof(self) weakSelf = self;
|
cell.deletePersonBlock = ^{
|
NSLog(@"=====%zd",indexPath.row);
|
if (weakSelf.isIssue && weakSelf.issueListModel.IssueId) {
|
[self RemoveIssueJoinerWithIndexPath:indexPath];
|
}else {
|
[self.personListM removeObjectAtIndex:indexPath.row];
|
[self.collectionView reloadData];
|
}
|
};
|
return cell;
|
}
|
|
#pragma mark - UITableViewDataSource
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
return self.rightArr.count;
|
}
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
|
cell.textLabel.font = [UIFont systemFontOfSize:TitleFontSize];
|
cell.textLabel.text = [self.rightArr[indexPath.row] valueForKey:@"RealName"];
|
cell.textLabel.textColor = TitleColor;
|
return cell;
|
}
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
NSDictionary *dict = self.rightArr[indexPath.row];
|
PBPersonModel *addPersonModel = [PBPersonModel yy_modelWithDictionary:dict];
|
if (self.isChooseOne) {
|
[self.personListM removeAllObjects];
|
[self.personListM addObject:addPersonModel];
|
[self.collectionView reloadData];
|
}else {
|
for (PBPersonModel *personModel in self.personListM) {
|
if ([personModel.UserId isEqualToString:addPersonModel.UserId]) {
|
return;
|
}
|
}
|
if (_isIssue && self.issueListModel.IssueId) {
|
[self AddIssueJoinerWithID:addPersonModel];
|
}else {
|
[self.personListM addObject:addPersonModel];
|
[self.collectionView reloadData];
|
}
|
}
|
}
|
- (void)loadPersonData {
|
if (self.isExamineChoose) {
|
[[PBNetworkTools sharedTools] RequestGetToAddIssueJoiners_WithOperatorWithProjectID:self.projectModel.organizeid andEncodedKeyWord:@"" andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
[YJProgressHUD showMessage:@"加载成员信息失败" inView:self];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
self.rightArr = networkModel.Data;
|
[self.rightTableView reloadData];
|
}else {
|
[YJProgressHUD showMessage:networkModel.Msg inView:self];
|
}
|
}];
|
}else {
|
[[PBNetworkTools sharedTools] RequestGetToAddIssueJoinersWithProjectID:self.projectModel.organizeid andEncodedKeyWord:@"" andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
[YJProgressHUD showMessage:@"加载成员信息失败" inView:self];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
self.rightArr = networkModel.Data;
|
[self.rightTableView reloadData];
|
}else {
|
[YJProgressHUD showMessage:networkModel.Msg inView:self];
|
}
|
}];
|
}
|
}
|
|
- (void)setIssueAddModel:(PBIssueAddModel *)issueAddModel {
|
_issueAddModel = issueAddModel;
|
_isIssue = YES;
|
self.determineBtn.hidden = YES;
|
self.packupBtn.hidden = NO;
|
[self.personListM removeAllObjects];
|
[self.personListM addObjectsFromArray:issueAddModel.personArr];
|
[self.collectionView reloadData];
|
}
|
|
- (void)setExamineAddModel:(PBExamineAddModel *)examineAddModel {
|
_examineAddModel = examineAddModel;
|
_isIssue = NO;
|
self.determineBtn.hidden = NO;
|
self.packupBtn.hidden = YES;
|
[self.personListM removeAllObjects];
|
[self.personListM addObjectsFromArray:examineAddModel.personArr];
|
[self.collectionView reloadData];
|
}
|
- (void)setProjectModel:(PBProjectModel *)projectModel {
|
_projectModel = projectModel;
|
[self loadPersonData];
|
}
|
- (NSMutableArray *)personListM {
|
if (_personListM == nil) {
|
_personListM = [[NSMutableArray alloc] init];
|
}
|
return _personListM;
|
}
|
- (void)setIssueListModel:(PBIssueListModel *)issueListModel {
|
_issueListModel = issueListModel;
|
}
|
- (void)AddIssueJoinerWithID:(PBPersonModel *)personModel {
|
[YJProgressHUD showProgress:@"" inView:self];
|
[[PBNetworkTools sharedTools] AddIssueJoinerWithIssueID:self.issueListModel.IssueId andID:personModel.UserId andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
[YJProgressHUD showMessage:@"添加失败" inView:self];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
[YJProgressHUD hide];
|
[self.personListM addObject:personModel];
|
[self.collectionView reloadData];
|
self.issueAddModel.personArr = self.personListM.copy;
|
if (self.EditCompleteBlock) {
|
self.EditCompleteBlock();
|
}
|
}else {
|
[YJProgressHUD showMessage:@"添加失败" inView:self];
|
}
|
}];
|
}
|
- (void)RemoveIssueJoinerWithIndexPath:(NSIndexPath *)indexPath {
|
[YJProgressHUD showProgress:@"" inView:self];
|
PBPersonModel *personModel = self.personListM[indexPath.row];
|
[[PBNetworkTools sharedTools] RemoveIssueJoinerWithIssueID:self.issueListModel.IssueId andID:personModel.UserId andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
[YJProgressHUD showMessage:@"删除失败" inView:self];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
[YJProgressHUD hide];
|
[self.personListM removeObjectAtIndex:indexPath.row];
|
[self.collectionView reloadData];
|
self.issueAddModel.personArr = self.personListM.copy;
|
if (self.EditCompleteBlock) {
|
self.EditCompleteBlock();
|
}
|
}else {
|
[YJProgressHUD showMessage:@"删除失败" inView:self];
|
}
|
}];
|
}
|
- (void)setIsChooseOne:(BOOL)isChooseOne {
|
_isChooseOne = isChooseOne;
|
}
|
- (void)setIsExamineChoose:(BOOL)isExamineChoose {
|
_isExamineChoose = isExamineChoose;
|
}
|
@end
|