Files
mier_ios/SweetParty/主类/Dynamic/Controller/SPTrendReportVC.m
2025-08-11 10:43:19 +08:00

258 lines
9.6 KiB
Objective-C
Executable File

//
// SPTrendReportVC.m
// SweetParty
//
// Created by bj_szd on 2022/6/17.
//
#import "SPTrendReportVC.h"
#import "SPTrendReportCell.h"
#import "SPPickPhotoCell.h"
#import "UITextView+ZWPlaceHolder.h"
#import "MLNetWorkHelper.h"
#import "HXTagsView.h"
#import "HXTagAttribute.h"
@interface SPTrendReportVC ()<TZImagePickerControllerDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *reasonCollectionV;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UICollectionView *photoCollectionV;
@property (weak, nonatomic) IBOutlet UIButton *reportBtn;
@property (nonatomic, strong) NSMutableArray *selectedPhotos;
@property (nonatomic, strong) NSMutableArray *selectedAssets;
@property (nonatomic, copy)NSString *imgsUrl;
@property (nonatomic, strong) NSArray *reasonArray;
@property (nonatomic, assign) NSInteger selectReasonIndex;
@property (nonatomic, strong) HXTagsView *tagsView;
@end
@implementation SPTrendReportVC
- (void)viewDidLoad {
[super viewDidLoad];
[self showNaviBarWithTitle:@"举报"];
self.selectedPhotos = [NSMutableArray arrayWithCapacity:0];
self.selectedAssets = [NSMutableArray arrayWithCapacity:0];
self.selectReasonIndex = -1;
[self createUI];
[self fetchReasonData];
}
- (void)fetchReasonData {
NSDictionary *params = @{};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"api/user_report/report_list" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
NSArray *arr = [SPTrendReportModel mj_objectArrayWithKeyValuesArray:responseDic[@"data"]];
self.reasonArray = arr;
[self.reasonCollectionV reloadData];
NSMutableArray *mArr = [[NSMutableArray alloc] init];
for (SPTrendReportModel *model in arr) {
[mArr addObject:model.type_name];
}
self.tagsView.tags = [mArr copy];
[self.tagsView reloadData];
} Failure:^(id _Nonnull errorData) {
}];
}
- (IBAction)onReport:(id)sender {
[self.view endEditing:YES];
if (self.selectReasonIndex == -1) {
[HelpPageDefine showMessage:@"请选择举报类型"];
return;
}
if (_selectedAssets.count > 0) {
[self onUploadImages];
}else {
[self onCallInterface];
}
}
-(void)onUploadImages {
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:_selectedPhotos fileNames:nil imageScale:0.5 imageType:@"png" progress:nil success:^(id responseObject) {
NSArray *imgArr = responseObject[@"data"];
self.imgsUrl = [imgArr componentsJoinedByString:@","];
[self onCallInterface];
} failure:^(NSError *error) {
}];
}
-(void)onCallInterface {
SPTrendReportModel *model = self.reasonArray[self.selectReasonIndex];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:@{@"to_uid":C_string(self.userId), @"type_id":model.id}];
if (self.textView.text.length > 0) {
[params setValue:self.textView.text forKey:@"content"];
}
if (self.imgsUrl.length > 0) {
[params setValue:self.imgsUrl forKey:@"image"];
}
[AFNetworkRequset.shared postRequestWithParams:params Path:@"api/user_report/user_report" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)createUI {
self.textView.zw_placeHolder = @"请描述理由";
self.textView.zw_placeHolderColor = HEXCOLOR(0x999999);
[self.reportBtn setJianBianWithCGSize:CGSizeMake(ScreenWidth-30*2, 44)];
{
UICollectionViewFlowLayout *collectionLayout = [[UICollectionViewFlowLayout alloc] init];
CGFloat itemW = (ScreenWidth-15*2)/3;
collectionLayout.itemSize = CGSizeMake(itemW, 30);
collectionLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
collectionLayout.minimumInteritemSpacing = 0;
collectionLayout.minimumLineSpacing = 5;
_reasonCollectionV.collectionViewLayout = collectionLayout;
_reasonCollectionV.backgroundColor = kClearColor;
_reasonCollectionV.delegate = self;
_reasonCollectionV.dataSource = self;
[_reasonCollectionV registerNib:[UINib nibWithNibName:@"SPTrendReportCell" bundle:nil] forCellWithReuseIdentifier:@"SPTrendReportCell"];
}
{
UICollectionViewFlowLayout *collectionLayout = [[UICollectionViewFlowLayout alloc] init];
CGFloat itemW = (ScreenWidth-15*2-10*2)/3;
collectionLayout.itemSize = CGSizeMake(itemW, itemW);
collectionLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
collectionLayout.minimumInteritemSpacing = 0;
collectionLayout.minimumLineSpacing = 0;
_photoCollectionV.collectionViewLayout = collectionLayout;
_photoCollectionV.backgroundColor = kClearColor;
_photoCollectionV.delegate = self;
_photoCollectionV.dataSource = self;
[_photoCollectionV registerNib:[UINib nibWithNibName:@"SPPickPhotoCell" bundle:nil] forCellWithReuseIdentifier:@"SPPickPhotoCell"];
}
HXTagsView *tagsView = [[HXTagsView alloc] init];
tagsView.backgroundColor = kClearColor;
tagsView.layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
tagsView.tagAttribute.textColor = HEXCOLOR(0x333333);
tagsView.tagAttribute.normalBackgroundColor = HEXCOLOR(0xF5F5F5);
tagsView.tagAttribute.selectedBackgroundColor = mainDeepColor;
WEAK_SELF
tagsView.completion = ^(NSArray *selectTags, NSInteger currentIndex) {
self.selectReasonIndex = currentIndex;
};
[self.view addSubview:tagsView];
self.tagsView = tagsView;
[tagsView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(_reasonCollectionV);
}];
}
#pragma mark UICollectionView 代理方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (collectionView == _reasonCollectionV) {
return self.reasonArray.count;
}else {
if (_selectedAssets.count < 3) {
return _selectedAssets.count + 1;
}else {
return 3;
}
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if (collectionView == _reasonCollectionV) {
SPTrendReportCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SPTrendReportCell" forIndexPath:indexPath];
SPTrendReportModel *model = self.reasonArray[indexPath.row];
cell.selBtn.selected = self.selectReasonIndex == indexPath.row;
cell.reasonLab.text = model.type_name;
return cell;
}else {
SPPickPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SPPickPhotoCell" forIndexPath:indexPath];
if(indexPath.row < _selectedAssets.count) {
cell.imgV.image = _selectedPhotos[indexPath.row];
cell.deleteBtn.hidden = NO;
}else {
cell.imgV.image = [UIImage imageNamed:@"trend_pick_photo"];
cell.deleteBtn.hidden = YES;
}
cell.deleteBtn.tag = indexPath.row;
[cell.deleteBtn addTarget:self action:@selector(deleteBtnClik:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (collectionView == _reasonCollectionV) {
self.selectReasonIndex = indexPath.row;
[self.reasonCollectionV reloadData];
}else {
if (indexPath.row >= _selectedAssets.count) {
[self pushTZImagePickerController];
}
}
}
- (void)deleteBtnClik:(UIButton *)sender {
if (sender.tag < _selectedPhotos.count) {
NSInteger index = sender.tag;
[_selectedPhotos removeObjectAtIndex:index];
[_selectedAssets removeObjectAtIndex:index];
}
[_photoCollectionV reloadData];
}
#pragma mark - TZImagePickerController
- (void)pushTZImagePickerController {
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:3 columnNumber:4 delegate:self pushPhotoPickerVc:YES];
imagePickerVc.selectedAssets = _selectedAssets; // 目前已经选中的图片数组
// 4. 照片排列按修改时间升序
imagePickerVc.sortAscendingByModificationDate = YES;
imagePickerVc.statusBarStyle = UIStatusBarStyleLightContent;
imagePickerVc.showSelectedIndex = YES;
imagePickerVc.allowPickingOriginalPhoto = NO;
imagePickerVc.allowPickingImage = YES;
imagePickerVc.allowPickingVideo = NO;
// imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
[self 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 {
_selectedPhotos = [NSMutableArray arrayWithArray:photos];
_selectedAssets = [NSMutableArray arrayWithArray:assets];
[_photoCollectionV reloadData];
}
@end