Files
yuyin_ios/SweetParty/主类/Mine/设置/Controller/SPFeedbackVC.m
2025-08-08 11:05:33 +08:00

242 lines
9.2 KiB
Objective-C
Executable File

//
// SPFeedbackVC.m
// SweetParty
//
// Created by bj_szd on 2022/6/16.
//
#import "SPFeedbackVC.h"
#import "SPPickPhotoCell.h"
#import "UITextView+ZWPlaceHolder.h"
#import "MLNetWorkHelper.h"
#define itemW (ScreenWidth-12*2-12*2)/3
@interface SPFeedbackVC ()<TZImagePickerControllerDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UITextViewDelegate>
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UILabel *wordNumLab;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *selectedPhotos;
@property (nonatomic, strong) NSMutableArray *selectedAssets;
@property(nonatomic, copy)NSString *imgsUrl;
@end
@implementation SPFeedbackVC
- (void)viewDidLoad {
[super viewDidLoad];
self.selectedPhotos = [NSMutableArray arrayWithCapacity:0];
self.selectedAssets = [NSMutableArray arrayWithCapacity:0];
[self createUI];
}
- (void)createUI {
[self showNaviBarWithTitle:@"问题反馈"];
UIScrollView *bgScrollView = [[UIScrollView alloc] init];
[self.view addSubview:bgScrollView];
[bgScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(TOP_BAR_HEIGHT);
make.left.right.equalTo(self.view);
make.bottom.equalTo(self.view).offset(-SAFE_AREA_INSERTS_BOTTOM);
}];
UIView *contentView = [[UIView alloc] init];
[bgScrollView addSubview:contentView];
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(bgScrollView);
make.width.mas_equalTo(ScreenWidth);
}];
self.textView = [ControlCreator createTextView:nil rect:CGRectZero text:nil font:YBMediumFont(15) color:HEXCOLOR(0x333333) backguoundColor:HEXCOLOR(0xF5F5F5)];
self.textView.delegate = self;
self.textView.zw_placeHolder = @"请输入您要反馈的内容…";
self.textView.zw_placeHolderColor = [HEXCOLOR(0x333333) colorWithAlphaComponent:0.6];
self.textView.layer.cornerRadius = 6;
[contentView addSubview:self.textView];
UILabel *numLab = [ControlCreator createLabel:nil rect:CGRectZero text:@"0/500" font:YBMediumFont(12) color:HEXCOLOR(0x999999) backguoundColor:nil align:NSTextAlignmentLeft lines:1];
[contentView addSubview:numLab];
numLab.hidden = YES;
self.wordNumLab = numLab;
// UICollectionViewFlowLayout *collectionLayout = [[UICollectionViewFlowLayout alloc] init];
// collectionLayout.itemSize = CGSizeMake(itemW, itemW);
// collectionLayout.sectionInset = UIEdgeInsetsMake(0, 12, 0, 12);
// collectionLayout.minimumInteritemSpacing = 0;
// collectionLayout.minimumLineSpacing = 12;
//
// UICollectionView *collectionV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:collectionLayout];
// collectionV.backgroundColor = kClearColor;
// collectionV.delegate = self;
// collectionV.dataSource = self;
// [collectionV registerNib:[UINib nibWithNibName:@"SAPickImageCell" bundle:nil] forCellWithReuseIdentifier:@"SAPickImageCell"];
// [contentView addSubview:collectionV];
// self.collectionView = collectionV;
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(contentView).offset(12);
make.right.equalTo(contentView).offset(-12);
make.top.equalTo(contentView).offset(12);
make.height.mas_equalTo(200);
}];
[numLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.bottom.equalTo(self.textView);
}];
// [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.equalTo(self.textView.mas_bottom).offset(12);
// make.left.right.equalTo(contentView);
// make.height.mas_equalTo((itemW+12)*2);
// make.bottom.equalTo(contentView);
// }];
UIButton *publishBtn = [ControlCreator createButton:nil rect:CGRectZero text:@"提交" font:YBMediumFont(15) color:HEXCOLOR(0x000000) backguoundColor:mainDeepColor imageName:nil target:self action:@selector(onPublish)];
publishBtn.layer.masksToBounds = YES;
publishBtn.layer.cornerRadius = 22;
[contentView addSubview:publishBtn];
[publishBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.textView.mas_bottom).offset(30);
make.left.equalTo(contentView).offset(30);
make.right.equalTo(contentView).offset(-30);
make.height.mas_equalTo(44);
make.bottom.equalTo(contentView).offset(-34);
}];
}
- (void)textViewDidChange:(UITextView *)textView {
NSInteger maxLength = 500;
if (textView.text.length > maxLength) {
[HelpPageDefine showMessage:[NSString stringWithFormat:@"最多输入%ld字", maxLength]];
textView.text = [textView.text substringToIndex:maxLength];
}
self.wordNumLab.text = [NSString stringWithFormat:@"%ld/%ld", textView.text.length, maxLength];
}
#pragma mark UICollectionView 代理方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (_selectedAssets.count < 6) {
return _selectedAssets.count + 1;
}else {
return 6;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
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 (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];
}
[self.collectionView reloadData];
}
#pragma mark - TZImagePickerController
- (void)pushTZImagePickerController {
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:6 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];
[_collectionView reloadData];
}
#pragma mark ------------- 发布 --------------
-(void)onPublish {
if (self.textView.text.length <= 0) {
[HelpPageDefine showMessage:@"请输入内容"];
return;
}
// if (_selectedAssets.count <= 0) {
// [HelpPageDefine showMessage:@"请选择图片"];
// return;
// }
[self.view endEditing:YES];
// [self onUploadImages];
[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 {
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setValue:self.textView.text forKey:@"content"];
if (self.imgsUrl.length > 0) {
[params setValue:self.imgsUrl forKey:@"images"];
}
[AFNetworkRequset.shared postRequestWithParams:params Path:@"api/suggest/create_suggest" 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) {
}];
}
@end