zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
//  PBImageCommentsCell.m
//  IphoneBIMe
//
//  Created by ZJF on 2020/3/18.
//  Copyright © 2020 ProBIM. All rights reserved.
//
 
#import "PBImageCommentsCell.h"
#import "PBProjectModel.h"
#import "PBCommentsModel.h"
#import "PBImageCollectionViewCell.h"
 
static NSString *const ImageCellID = @"ImageCellID";
@interface PBImageCommentsCell()<UICollectionViewDataSource, UICollectionViewDelegate, SDPhotoBrowserDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, weak) UIImageView *iconImageV;
@property (nonatomic, weak) UILabel *creatorL;
@property (nonatomic, weak) UILabel *creatimeL;
@property (nonatomic, weak) UIButton *deleteBtn;
@property (nonatomic, weak) UILabel *iconL;
@end
@implementation PBImageCommentsCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    UIImageView *iconImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Issue_comments_iconbg"]];
    [self.contentView addSubview:iconImageV];
    [iconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(8);
        make.left.equalTo(self.contentView).offset(16);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    UILabel *iconL = [UILabel z_labelWithText:@"" Color:[UIColor whiteColor] isBold:YES Font:DescFontSize];
    iconL.textAlignment = NSTextAlignmentCenter;
    [iconImageV addSubview:iconL];
    [iconL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(iconImageV);
        make.height.equalTo(@20);
        make.center.equalTo(iconImageV);
    }];
    UILabel *creatorL = [UILabel z_labelWithText:@"" Color:TitleColor isBold:YES Font:TitleFontSize];
    [self.contentView addSubview:creatorL];
    [creatorL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(8);
        make.left.equalTo(iconImageV.mas_right).offset(8);
        make.height.equalTo(@22);
        make.right.equalTo(self.contentView).offset(-16);
    }];
    UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout.alloc init];
    layout.itemSize = CGSizeMake(120, 120);
    layout.minimumLineSpacing = 10;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionView = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout];
    [self.collectionView registerClass:[PBImageCollectionViewCell class] forCellWithReuseIdentifier:ImageCellID];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.bounces = NO;
    self.collectionView.scrollEnabled = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(creatorL.mas_bottom).offset(8);
        make.left.equalTo(self.contentView).offset(54);
        make.size.mas_equalTo(CGSizeMake(120, 120));
    }];
 
    UILabel *creatimeL = [UILabel z_labelWithText:@"" Color:PromptColor isBold:NO Font:DescFontSize];
    [self.contentView addSubview:creatimeL];
    [creatimeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.collectionView.mas_bottom).offset(12);
        make.bottom.equalTo(self.contentView).offset(-18);
        make.left.equalTo(self.contentView).offset(54);
        make.height.equalTo(@20);
    }];
    UIButton *deleteBtn = [[UIButton alloc] init];
    [deleteBtn setImage:[UIImage imageNamed:@"Issue_comment_deleteBtn"] forState:UIControlStateNormal];
    [deleteBtn addTarget:self action:@selector(deletecomment) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:deleteBtn];
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(creatimeL);
        make.right.equalTo(self.contentView).offset(-16);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    UIView *linV = [[UIView alloc] init];
    linV.backgroundColor = PBColor(242, 242, 242);
    [self.contentView addSubview:linV];
    [linV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.contentView);
        make.height.equalTo(@10);
    }];
    self.iconImageV = iconImageV;
    self.creatorL = creatorL;
    self.creatimeL = creatimeL;
    self.deleteBtn = deleteBtn;
    self.iconL = iconL;
}
//删除
- (void)deletecomment {
    if (self.deleteCommentsBlock) {
        self.deleteCommentsBlock();
    }
}
- (void)setCommentsModel:(PBCommentsModel *)commentsModel {
    _commentsModel = commentsModel;
    self.iconL.text = commentsModel.realname;
    self.creatorL.text = commentsModel.realname;
    if ([commentsModel.userid isEqualToString:UserID]) {
        self.deleteBtn.hidden = NO;
    }else {
        self.deleteBtn.hidden = YES;
    }
    NSRange range = [commentsModel.createdate rangeOfString:@":"];
    NSString *timeStr = [commentsModel.createdate substringToIndex:range.location + 3];
    timeStr = [timeStr stringByReplacingOccurrencesOfString:@" " withString:@" "];
    self.creatimeL.text = [timeStr stringByReplacingOccurrencesOfString:@"-" withString:@"/"];
    [self.collectionView reloadData];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 1;
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    PBImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ImageCellID forIndexPath:indexPath];
    NSString *url = [NSString stringWithFormat:@"%@/api/Doc/GetHideFile?ProjectID=%@&FileId=%@&FileType=Issue",BimUrl,self.projectModel.bimcomposerid,[self.commentsModel.contenttypeJson valueForKey:@"contentImgId"]];
    cell.roleType = PARTICIPANT;
    cell.imageUrl = url;
    return cell;
}
 
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    SDPhotoBrowser *photoBrowser = [SDPhotoBrowser new];
    photoBrowser.delegate = self;
    photoBrowser.currentImageIndex = indexPath.item;
    photoBrowser.imageCount = 1;
    photoBrowser.sourceImagesContainerView = self.collectionView;
    [photoBrowser show];
}
 
#pragma mark  SDPhotoBrowserDelegate
// 返回临时占位图片(即原来的小图)
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index
{
    // 不建议用此种方式获取小图,这里只是为了简单实现展示而已
    PBImageCollectionViewCell *cell = (PBImageCollectionViewCell *)[self collectionView:self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:cell.imageUrl]];
    UIImage *image = [UIImage imageWithData:data];;
    return image;
}
- (void)setProjectModel:(PBProjectModel *)projectModel {
    _projectModel = projectModel;
}
 
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
 
    // Configure the view for the selected state
}
 
@end