Files
mier_ios/SweetParty/主类/Homepage/View/SPHomepageInfoView.m
2025-08-11 10:43:19 +08:00

285 lines
11 KiB
Objective-C
Executable File

//
// SPHomepageInfoView.m
// SweetParty
//
// Created by bj_szd on 2022/6/2.
//
#import "SPHomepageInfoView.h"
#import "SPPickPhotoCell.h"
#import "MLNetWorkHelper.h"
#import "KNPhotoBrowser.h"
#import "YYHomepageGiftVC.h"
#import "LMGonghuiDetailsViewController.h"
@interface SPHomepageInfoView () <TZImagePickerControllerDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, KNPhotoBrowserDelegate>
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, assign) BOOL isSelf;
@property (weak, nonatomic) IBOutlet UILabel *gonghuiTitleLab;
@property (weak, nonatomic) IBOutlet UIView *guildCover;
@property (weak, nonatomic) IBOutlet UIImageView *gonghuiCover;
@property (weak, nonatomic) IBOutlet UILabel *gonghuiNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *gonghuiNumLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;
@end
@implementation SPHomepageInfoView
- (void)awakeFromNib {
[super awakeFromNib];
self.dataArray = [NSMutableArray arrayWithCapacity:0];
[self createUI];
}
- (void)setModel:(SPHomepageModel *)model {
_model = model;
if ([model.uid integerValue] == [BJUserManager.userInfo.uid integerValue]) {
self.isSelf = YES;
}
self.sexLab.text = model.sex == 1 ? @"" : @"";
self.ageLab.text = model.birthday;
self.xingzuoLab.text = model.constellation;
if ([model.special_uid integerValue] > 0) {
self.IDLab.text = model.special_uid;
}else {
self.IDLab.text = model.uid;
}
self.signLab.text = model.autograph;
self.locationLab.text = model.ip_address;
[self.gxImgV sd_setImageWithURL:[NSURL URLWithString:model.user_charm_contribution_info.contribution_level_image]];
[self.mlImgV sd_setImageWithURL:[NSURL URLWithString:model.user_charm_contribution_info.charm_level_image]];
[self.jueweiImgV sd_setImageWithURL:[NSURL URLWithString:model.nobility_image]];
NSArray *giftImgVArr = @[_giftImgV_1, _giftImgV_2, _giftImgV_3];
for (NSInteger i = 0; i < model.receive_gift_list.count; i++) {
if (i < giftImgVArr.count) {
SPHomepageGiftModel *obj = model.receive_gift_list[i];
UIImageView *imgV = giftImgVArr[i];
[imgV sd_setImageWithURL:[NSURL URLWithString:obj.base_image]];
}
}
[self.dataArray removeAllObjects];
[self.dataArray addObjectsFromArray:model.user_albums_list];
[self.collectionView reloadData];
if (model.is_join_guild == 1) {
self.gonghuiTitleLab.hidden = NO;
self.guildCover.hidden = NO;
self.topConstraint.constant = 140;
self.gonghuiNameLabel.text = model.guild_info.guild_name;
self.gonghuiNumLabel.text = [NSString stringWithFormat:@"%@人",model.guild_info.num];
[self.guildCover dg_Tapped:^{
LMGonghuiDetailsViewController *vc = [[LMGonghuiDetailsViewController alloc] init];
vc.guild_id = model.guild_info.gid;
[vc pushSelf];
}];
}else {
self.gonghuiTitleLab.hidden = YES;
self.guildCover.hidden = YES;
self.topConstraint.constant = 10;
}
}
- (void)createUI {
[self.giftBgView styleShadowWithRedius:10];
[self.bottomBgImgV styleShadowWithRedius:10];
WEAK_SELF
[self.giftBgView dg_Tapped:^{
YYHomepageGiftVC *vc = [[YYHomepageGiftVC alloc] init];
vc.model = weakSelf.model;
[vc pushSelf];
}];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
CGFloat itemW = (ScreenWidth-30-10*3)/4;
layout.itemSize = CGSizeMake(itemW, itemW);
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 10;
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
_collectionView.collectionViewLayout = layout;
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerNib:[UINib nibWithNibName:@"SPPickPhotoCell" bundle:nil] forCellWithReuseIdentifier:@"SPPickPhotoCell"];
}
#pragma mark -------- collectionView代理方法 ------
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (self.isSelf) {
if (self.dataArray.count < 6) {
return self.dataArray.count + 1;
}else {
return 6;
}
}else {
return self.dataArray.count;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
SPPickPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SPPickPhotoCell" forIndexPath:indexPath];
if (indexPath.row < self.dataArray.count) {
SPHomepageAlbumModel *model = self.dataArray[indexPath.row];
cell.deleteBtn.hidden = YES;
[cell.imgV sd_setImageWithURL:[NSURL URLWithString:model.image]];
if (self.isSelf) {
cell.deleteBtn.hidden = NO;
cell.deleteBtn.tag = indexPath.row;
[cell.deleteBtn addTarget:self action:@selector(deleteBtnClik:) forControlEvents:UIControlEventTouchUpInside];
}
}else {
cell.imgV.image = [UIImage imageNamed:@"trend_pick_photo"];
cell.deleteBtn.hidden = YES;
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row >= self.dataArray.count) {
[self pushTZImagePickerController];
}else {
[self onPreviewImage:indexPath.row];
}
}
#pragma mark - TZImagePickerController
- (void)pushTZImagePickerController {
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:6-self.dataArray.count columnNumber:4 delegate:self pushPhotoPickerVc:YES];
// 4. 照片排列按修改时间升序
imagePickerVc.sortAscendingByModificationDate = YES;
imagePickerVc.statusBarStyle = UIStatusBarStyleLightContent;
imagePickerVc.showSelectedIndex = YES;
imagePickerVc.allowPickingOriginalPhoto = NO;
imagePickerVc.allowPickingImage = YES;
imagePickerVc.allowPickingVideo = NO;
// imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
[[self getCurrentVC] presentViewController:imagePickerVc animated:YES completion:nil];
}
#pragma mark - TZImagePickerControllerDelegate
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos {
[self onUploadImages:photos];
}
-(void)onUploadImages:(NSArray *)photos {
NSString *urlStr = [NSString stringWithFormat:@"%@api/upload/img_upload", VERSION_HTTPS_SERVER];
NSDictionary *params = @{@"login_token":GVUSER.token};
[MLNetWorkHelper uploadImagesWithURL:urlStr parameters:params name:@"file[]" images:photos fileNames:nil imageScale:0.5 imageType:@"png" progress:nil success:^(id responseObject) {
NSArray *imgArr = responseObject[@"data"];
NSString *imgsUrl = [imgArr componentsJoinedByString:@","];
[self onAddPhotos:imgsUrl];
} failure:^(NSError *error) {
}];
}
-(void)onAddPhotos:(NSString *)imagesStr {
NSDictionary *params = @{@"image":imagesStr};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"api/user/add_user_albums" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
[self onReloadAlbumData];
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)deleteBtnClik:(UIButton *)sender {
if (sender.tag < self.dataArray.count) {
NSInteger index = sender.tag;
SPHomepageAlbumModel *model = self.dataArray[index];
NSDictionary *params = @{@"aid":model.aid};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"api/user/delete_user_albums" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
[self.dataArray removeObjectAtIndex:index];
[self.collectionView reloadData];
} Failure:^(id _Nonnull errorData) {
}];
}
}
-(void)onReloadAlbumData {
NSDictionary *params = @{@"from_id":C_string(self.model.uid)};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"api/player/player_home_page" Loading:YES Hud:NO Success:^(id _Nonnull responseDic) {
SPHomepageModel *model = [SPHomepageModel mj_objectWithKeyValues:responseDic[@"data"]];
self.model = model;
} Failure:^(id _Nonnull errorData) {
}];
}
-(void)onPreviewImage:(NSInteger)index {
NSMutableArray *mArr = [NSMutableArray arrayWithCapacity:0];
for (SPHomepageAlbumModel *model in self.dataArray) {
KNPhotoItems *items = [[KNPhotoItems alloc] init];
items.url = model.image;
[mArr addObject:items];
}
KNPhotoBrowser *photoBrowser = [[KNPhotoBrowser alloc] init];
photoBrowser.itemsArr = [mArr copy];
photoBrowser.currentIndex = index;
photoBrowser.delegate = self;
photoBrowser.isNeedPageNumView = YES;
photoBrowser.isNeedRightTopBtn = YES;
[photoBrowser present];
}
- (void)photoBrowser:(KNPhotoBrowser *)photoBrowser rightBtnOperationActionWithIndex:(NSInteger)index{
KNActionSheet *actionSheet = [[KNActionSheet share] initWithTitle:@""
cancelTitle:@"取消"
titleArray:@[@"保存到相册"].mutableCopy
destructiveArray:@[].mutableCopy
actionSheetBlock:^(NSInteger buttonIndex) {
if (buttonIndex == 0) {
[UIDevice deviceAlbumAuth:^(BOOL isAuthor) {
if (isAuthor == NO) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"无法访问相册" message:@"请在iPhone的""设置-隐私-相册""中允许访问相册" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
[alertController addAction:[UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}]];
[[UIViewController currentViewController] presentViewController:alertController animated:YES completion:nil];
}else {
[photoBrowser downloadImageOrVideoToAlbum];
}
}];
}
}];
[actionSheet showOnView:photoBrowser.view];
}
- (void)photoBrowser:(KNPhotoBrowser *)photoBrowser
state:(KNPhotoDownloadState)state
progress:(float)progress
photoItemRelative:(KNPhotoItems *)photoItemRe
photoItemAbsolute:(KNPhotoItems *)photoItemAb {
if (progress >= 1) {
[HelpPageDefine showMessage:@"保存成功"];
}
}
@end