151 lines
5.9 KiB
Mathematica
151 lines
5.9 KiB
Mathematica
|
|
//
|
||
|
|
// QXPhotosMoveListView.m
|
||
|
|
// QXLive
|
||
|
|
//
|
||
|
|
// Created by 启星 on 2025/6/6.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "QXPhotosMoveListView.h"
|
||
|
|
#import "QXUserPhotosView.h"
|
||
|
|
#import "QXMineNetwork.h"
|
||
|
|
|
||
|
|
@interface QXPhotosMoveListView()<UICollectionViewDelegate,UICollectionViewDataSource>
|
||
|
|
@property (nonatomic,strong)UILabel* titleLabel;
|
||
|
|
|
||
|
|
@property (nonatomic,strong)UIButton* cancelBtn;
|
||
|
|
@property (nonatomic,strong)UIButton* commitBtn;
|
||
|
|
|
||
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
||
|
|
@property (nonatomic,assign)NSInteger page;
|
||
|
|
@property (nonatomic,strong)NSMutableArray *dataArray;
|
||
|
|
@property (nonatomic,assign)NSInteger selectedIndex;
|
||
|
|
@end
|
||
|
|
|
||
|
|
@implementation QXPhotosMoveListView
|
||
|
|
|
||
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
||
|
|
{
|
||
|
|
self = [super initWithFrame:frame];
|
||
|
|
if (self) {
|
||
|
|
[self initSubviews];
|
||
|
|
}
|
||
|
|
return self;
|
||
|
|
}
|
||
|
|
-(void)initSubviews{
|
||
|
|
self.selectedIndex = -1;
|
||
|
|
self.backgroundColor = [UIColor whiteColor];
|
||
|
|
[self addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
|
||
|
|
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-100)/2, 16, 100, 27)];
|
||
|
|
self.titleLabel.text = QXText(@"选择相册");
|
||
|
|
self.titleLabel.textColor = QXConfig.textColor;
|
||
|
|
self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
|
||
|
|
[self addSubview:self.titleLabel];
|
||
|
|
|
||
|
|
|
||
|
|
self.cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 12, 65, 35)];
|
||
|
|
[self.cancelBtn setTitle:QXText(@"取消") forState:(UIControlStateNormal)];
|
||
|
|
[self.cancelBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateNormal)];
|
||
|
|
self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
||
|
|
[self.cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
|
|
[self addSubview:self.cancelBtn];
|
||
|
|
|
||
|
|
self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-65, 12, 65, 35)];
|
||
|
|
[self.commitBtn setTitle:QXText(@"确定") forState:(UIControlStateNormal)];
|
||
|
|
[self.commitBtn setTitleColor:QXConfig.themeColor forState:(UIControlStateNormal)];
|
||
|
|
self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
||
|
|
// self.commitBtn.backgroundColor = QXConfig.themeColor;
|
||
|
|
[self.commitBtn addRoundedCornersWithRadius:17.5];
|
||
|
|
[self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
|
|
[self addSubview:self.commitBtn];
|
||
|
|
|
||
|
|
|
||
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||
|
|
layout.itemSize = CGSizeMake((SCREEN_WIDTH-16*2-13*3)/4, (SCREEN_WIDTH-16*2-13*3)/4+46);
|
||
|
|
layout.minimumLineSpacing = 13;
|
||
|
|
layout.minimumInteritemSpacing = 13;
|
||
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
|
||
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
||
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom+8, self.width, self.height-16-self.titleLabel.bottom-8) collectionViewLayout:layout];
|
||
|
|
[self.collectionView registerClass:[QXUserPhotosCell class] forCellWithReuseIdentifier:@"QXUserPhotosCell"];
|
||
|
|
self.collectionView.delegate = self;
|
||
|
|
self.collectionView.dataSource = self;
|
||
|
|
self.collectionView.showsHorizontalScrollIndicator = NO;
|
||
|
|
self.collectionView.backgroundColor = RGB16(0xf6f6f6);
|
||
|
|
[self addSubview:self.collectionView];
|
||
|
|
MJWeakSelf
|
||
|
|
_collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
||
|
|
weakSelf.page++;
|
||
|
|
[weakSelf getPhotoList];
|
||
|
|
}];
|
||
|
|
[self getPhotoList];
|
||
|
|
}
|
||
|
|
-(void)cancelAction{
|
||
|
|
[[QXGlobal shareGlobal] hideViewBlock:^{}];
|
||
|
|
}
|
||
|
|
-(void)commitAction{
|
||
|
|
if (self.selectedIndex == -1) {
|
||
|
|
showToast(@"请选择相册");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
MJWeakSelf
|
||
|
|
[[QXGlobal shareGlobal] hideViewBlock:^{
|
||
|
|
if (weakSelf.selecctedModelBlock) {
|
||
|
|
weakSelf.selecctedModelBlock(weakSelf.dataArray[self.selectedIndex]);
|
||
|
|
}
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)getPhotoList{
|
||
|
|
MJWeakSelf
|
||
|
|
[QXMineNetwork photosListWithUserId:[QXGlobal shareGlobal].loginModel.user_id
|
||
|
|
page:self.page
|
||
|
|
successBlock:^(NSArray<QXPhotoModel *> * _Nonnull hotos) {
|
||
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
||
|
|
if (weakSelf.page == 1) {
|
||
|
|
[weakSelf.dataArray removeAllObjects];
|
||
|
|
}
|
||
|
|
[weakSelf.dataArray addObjectsFromArray:hotos];
|
||
|
|
if (hotos.count == 0) {
|
||
|
|
weakSelf.collectionView.mj_footer.state = MJRefreshStateNoMoreData;
|
||
|
|
}else{
|
||
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
||
|
|
}
|
||
|
|
[weakSelf.collectionView reloadData];
|
||
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
||
|
|
return self.dataArray.count;
|
||
|
|
}
|
||
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
|
QXUserPhotosCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXUserPhotosCell" forIndexPath:indexPath];
|
||
|
|
QXPhotoModel *model = self.dataArray[indexPath.row];
|
||
|
|
[cell.photoImageView sd_setImageWithURL:[NSURL URLWithString:model.image]];
|
||
|
|
cell.titleLabel.text = model.name;
|
||
|
|
cell.countLabel.text = [NSString stringWithFormat:@"浏览 %@",model.read_num];
|
||
|
|
cell.isLock = NO;
|
||
|
|
cell.selectedState = YES;
|
||
|
|
if (indexPath.row == self.selectedIndex) {
|
||
|
|
cell.selectedBtn.selected = YES;
|
||
|
|
}else{
|
||
|
|
cell.selectedBtn.selected = NO;
|
||
|
|
}
|
||
|
|
return cell;
|
||
|
|
}
|
||
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
|
self.selectedIndex = indexPath.row;
|
||
|
|
[collectionView reloadData];
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
-(NSMutableArray *)dataArray{
|
||
|
|
if (!_dataArray) {
|
||
|
|
_dataArray = [NSMutableArray array];
|
||
|
|
}
|
||
|
|
return _dataArray;
|
||
|
|
}
|
||
|
|
@end
|