MyWorkAppApprovalCell.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // MyWorkAppApprovalCell.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/11/23.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "MyWorkAppApprovalCell.h"
  9. #import "MyWordCell.h"
  10. #import "MyWorkSpaceCell.h"
  11. #import "MailListDetailVC.h"
  12. @interface MyWorkAppApprovalCell()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  13. @end
  14. @implementation MyWorkAppApprovalCell
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. [self.collectView registerNib:[UINib nibWithNibName:@"MyWordCell" bundle:nil] forCellWithReuseIdentifier:@"MyWordCell"];
  18. [self.collectView registerNib:[UINib nibWithNibName:@"MyWorkSpaceCell" bundle:nil] forCellWithReuseIdentifier:@"MyWorkSpaceCell"];
  19. }
  20. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  21. [super setSelected:selected animated:animated];
  22. // Configure the view for the selected state
  23. }
  24. #pragma mark - UICollectionViewDelegate UICollectionViewDataSource
  25. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  26. return 1;
  27. }
  28. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  29. if (self.approvalSection.count == 0) {
  30. return 1 ;
  31. }else{
  32. return self.approvalSection.count * 2 + 1 ;
  33. }
  34. }
  35. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  36. if ((indexPath.item % 2 ) == 1) {
  37. return CGSizeMake(30.f, 65.f);
  38. }
  39. return CGSizeMake(50.f, 65.f);
  40. }
  41. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  42. return 0.f;
  43. }
  44. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  45. return 0.f;
  46. }
  47. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  48. WS(weakSelf);
  49. if (self.approvalSection.count == 0 ) {
  50. MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath];
  51. [cell looadDataHiden:YES];
  52. cell.indexPath = indexPath;
  53. cell.nameLbl.text = @"";
  54. [cell.deleteButton setAction:^{
  55. [weakSelf deleteHanderBack:indexPath];
  56. }];
  57. cell.iconImage.image = IMG(@"添加审批人");
  58. return cell;
  59. }else{
  60. if((self.approvalSection.count * 2 + 1) == (indexPath.item + 1)) {
  61. MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath];
  62. [cell looadDataHiden:YES];
  63. cell.indexPath = indexPath;
  64. cell.nameLbl.text = @"";
  65. cell.iconImage.image = IMG(@"添加审批人");
  66. [cell.deleteButton setAction:^{
  67. [weakSelf deleteHanderBack:indexPath];
  68. }];
  69. return cell;
  70. }else if ((indexPath.item % 2 ) == 1) {
  71. MyWorkSpaceCell *sapceCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWorkSpaceCell" forIndexPath:indexPath];
  72. return sapceCell;
  73. }else {
  74. MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath];
  75. [cell looadDataHiden:NO];
  76. NSInteger item = indexPath.item / 2;
  77. SelectModel *model = self.approvalSection[item];
  78. cell.nameLbl.text = model.UserName;
  79. WS(weakSelf);
  80. [cell.deleteButton setAction:^{
  81. [weakSelf deleteHanderBack:indexPath];
  82. }];
  83. [cell.iconImage sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:IMG(@"王丽")];
  84. cell.indexPath = indexPath;
  85. return cell;
  86. }
  87. }
  88. }
  89. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  90. if ((self.approvalSection.count == 0) || (self.approvalSection.count * 2 + 1) == (indexPath.item + 1)) {
  91. if ([self.delegate respondsToSelector:@selector(addApprovalPeopleSuccess:failure:)]) {
  92. [self.delegate addApprovalPeopleSuccess:^(id _Nullable responseObject) {
  93. } failure:^(NSError * _Nonnull error) {
  94. }];
  95. }
  96. }else{
  97. if (self.approvalSection.count == indexPath.item) {
  98. }else{
  99. [self gotoPeople:indexPath];
  100. }
  101. }
  102. }
  103. #pragma mark - MyWordCellDelegate
  104. - (void)deleteHanderBack:(NSIndexPath *)indexPath{
  105. NSLog(@"MyWordCell 3");
  106. [self.approvalSection removeObjectAtIndex:(indexPath.item / 2)];
  107. [self.collectView reloadData];
  108. }
  109. - (void)gotoPeople:(NSIndexPath *)indexPath{
  110. // SelectModel *model = self.approvalSection[indexPath.item];
  111. // MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC];
  112. // vc.indexId = model.Id;
  113. // vc.modalPresentationStyle = UIModalPresentationFullScreen;
  114. // [[UIApplication sharedApplication].windows.firstObject.rootViewController presentViewController:vc animated:YES completion:nil];
  115. }
  116. -(NSMutableArray *)approvalSection{
  117. if (!_approvalSection) {
  118. _approvalSection = [NSMutableArray array];
  119. }
  120. return _approvalSection;
  121. }
  122. @end