123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- //
- // KSChatComplainController.m
- // TeacherDaya
- //
- // Created by Kyle on 2021/5/12.
- // Copyright © 2021 DayaMusic. All rights reserved.
- //
- #import "KSChatComplainController.h"
- #import "ChatComplainBodyView.h"
- #import "LLPhotoBrowser.h"
- #import "KSImageButton.h"
- #import "KSMediaManager.h"
- #import "UIImage+ResizeImage.h"
- #import "MSSBrowseDefine.h"
- #define MAXBIGPHOTONUMBER (3)
- #define MAXPHOTONUMBER (3)
- #define COLUMNNUMBER (3)
- #define KBUTTON_LEFTSPACE (22)
- #define DELETEIMAGENAME @"fb_icon_tpsc"
- @interface KSChatComplainController ()<LLPhotoBrowserDelegate>
- @property (nonatomic, strong) KSMediaManager *mediaManager;
- @property (nonatomic, strong) ChatComplainBodyView *bodyView;
- @property (nonatomic, strong) NSMutableArray *imageArray; // 图片数组
- @property (nonatomic, strong) NSMutableArray *imageAsset; // 图片 asset
- @end
- @implementation KSChatComplainController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"投诉"];
- [self configUI];
- }
- - (void)configUI {
- _bodyView = [ChatComplainBodyView shareInstance];
-
- _bodyView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
- MJWeakSelf;
- [_bodyView submitAction:^(NSString *content) {
- [weakSelf complainAction:content];
- }];
- [self.view addSubview:_bodyView];
-
- [self createImageButtonAndPhotosButton];
- }
- - (void)complainAction:(NSString *)content {
- // 先判断
- if (self.imageArray.count == 0) {
- [self MBPShow:@"请选择要上传的照片"];
- return;
- }
-
- [self showhud];
- NSMutableArray *imageDataArray = [NSMutableArray array];
- for (UIImage *image in self.imageArray) {
- NSData *imgData = [UIImage turnsImaegDataByImage:image];
- [imageDataArray addObject:imgData];
- }
- [[KSUploadManager shareInstance] mutilUploadImage:imageDataArray fileName:@"complainImg" successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- NSMutableArray *urlArray = [NSMutableArray array];
- for (NSString *url in fileUrlArray) {
- [urlArray addObject:url];
- }
- NSString *attachments = [urlArray componentsJoinedByString:@","];
- [self uplodMessage:attachments content:content];
- } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
- [self removehub];
- [self MBPShow:descMessaeg];
- }];
- }
- - (void)uplodMessage:(NSString *)attachments content:(NSString *)content {
- NSString *type = self.fromGroup ? @"GROUP" : @"PERSON";
-
- // [KSRequestManager sysImComplaintRequest:KS_POST type:type fileUrl:attachments memo:content targetId:self.targetId success:^(NSDictionary * _Nonnull dic) {
- // [self removehub];
- // if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- // MJWeakSelf;
- // [self KSShowMsg:@"已收到您的投诉,我们会认真审核并处理" promptCompletion:^{
- // [weakSelf.navigationController popViewControllerAnimated:YES];
- // }];
- // }
- // else {
- // [self MBPShow:MESSAGEKEY];
- // }
- // } faliure:^(NSError * _Nonnull error) {
- // [self removehub];
- // }];
-
- }
- /**
- 图片和按钮的布局
- */
- #pragma marl 图片和按钮布局
- - (void)createImageButtonAndPhotosButton {
- for (UIView *subView in self.bodyView.imageContentView.subviews) {
- [subView removeFromSuperview];
- }
- CGFloat space = 15;
- CGFloat buttonWidth = (kScreenWidth - KBUTTON_LEFTSPACE * 2 - space * 2) / 3.0f;
- CGFloat buttonHeight = 80;
- NSInteger section = self.imageArray.count/3 + 1;
- if (self.imageArray.count==MAXPHOTONUMBER) {
- section = MAXPHOTONUMBER / 3;
- }
- CGFloat currentX = 0;
- CGFloat currentY = 0;
- for (NSInteger i = 0; i < self.imageArray.count; i++) {
- currentX = i % 3 * (buttonWidth + space);
- currentY = i / 3 * (buttonHeight + space);
- UIImage *image = self.imageArray [i];
-
- CGRect frame = CGRectMake(currentX + KBUTTON_LEFTSPACE, currentY, buttonWidth, buttonHeight);
- MJWeakSelf;
- KSImageButton *imgButton;
- id asset = self.imageAsset[i];
- imgButton = [KSImageButton createButtonWithFrame:frame displayImage:image imgAsset:asset tag:1000 + i clickReturnWithBlock:^(UIImage *image, id asset, BUTTON_CLICK_ACTION actionType, NSInteger index) {
- // 展示大图
- LLPhotoBrowser *photoBrowser = [[LLPhotoBrowser alloc] initWithImages:weakSelf.imageArray currentIndex:index-1000];
- photoBrowser.delegate = weakSelf;
- photoBrowser.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:photoBrowser animated:YES completion:nil];
-
- }];
-
- [self.bodyView.imageContentView addSubview:imgButton];
- imgButton = nil;
- }
- currentX = self.imageArray .count % 3 * (buttonWidth + space);
- if (self.imageArray.count != MAXPHOTONUMBER) {
- //计算下一个添加按钮位置
- if (self.imageArray.count % 3 == 0) {
- currentY = (self.imageArray.count+1) / 3 * (buttonHeight + space);
- }
- UIButton *cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];
- cameraButton.frame = CGRectMake(currentX + KBUTTON_LEFTSPACE, currentY, buttonWidth, buttonHeight);
- CAShapeLayer *border = [CAShapeLayer layer];
- border.strokeColor = HexRGB(0xCFCFCF).CGColor;
- border.fillColor = nil;
- border.path = [UIBezierPath bezierPathWithRoundedRect:cameraButton.bounds cornerRadius:5.0f].CGPath;
- ;
- border.frame = cameraButton.bounds;
- border.lineWidth = 1.f;
- border.lineCap = @"square";
- border.lineDashPattern = @[@4, @4];
- [cameraButton.layer addSublayer:border];
- [cameraButton setImage:[UIImage imageNamed:@"image_add"] forState:UIControlStateNormal];
- [cameraButton addTarget:self action:@selector(addImgAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.bodyView.imageContentView addSubview:cameraButton];
- }
-
- // 刷新scroll contentsize
- CGFloat imageContentHeight = buttonHeight * section + (section-1) * space;
- CGFloat height = kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin > 590 + imageContentHeight ? kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin : 590 + imageContentHeight;
- CGRect frame = self.bodyView.frame;
- frame.size.height = height;
- self.bodyView.frame = frame;
- self.scrollView.contentSize = CGSizeMake(kScreenWidth, height);
- }
- #pragma mark 点击+按钮
- - (void)addImgAction:(UIButton *)sender {
- [self.view endEditing:YES];
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:IS_IPAD ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
- [alertVC addAction:[UIAlertAction actionWithTitle:@"相机拍摄" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // 调用相机
- [self takePhotos];
- }]];
-
- [alertVC addAction:[UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // 调用相册
- [self pushImagePickerController];
-
- }]];
- [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }]];
- alertVC.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:alertVC animated:true completion:nil];
- }
- - (void)takePhotos {
- // 调用相册
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = MEDIATYPE_PHOTO;
- self.mediaManager.maxPhotoNumber = MAXPHOTONUMBER;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.imageArray = [self.imageArray mutableCopy];
- self.mediaManager.imageAsset = [self.imageAsset mutableCopy];
- self.mediaManager.needCropImage = NO;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
- [weakSelf displayChooseImage:imageArray imageAsset:imageAsset];
- }];
- [self.mediaManager takePhoto];
- }
- - (void)pushImagePickerController {
- // 调用相册
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = MEDIATYPE_PHOTO;
- self.mediaManager.maxPhotoNumber = MAXPHOTONUMBER;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.imageArray = [self.imageArray mutableCopy];
- self.mediaManager.imageAsset = [self.imageAsset mutableCopy];
- self.mediaManager.needCropImage = NO;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
- [weakSelf displayChooseImage:imageArray imageAsset:imageAsset];
- }];
- [self.mediaManager pushImagePickerController];
- }
- - (void)displayChooseImage:(NSMutableArray *)imageArray imageAsset:(NSMutableArray *)imageAsset {
- // 添加图片
- self.imageArray = [imageArray mutableCopy];
- self.imageAsset = [imageAsset mutableCopy];
- // 重新布局
- [self createImageButtonAndPhotosButton];
- }
- - (void)deleteImageWithIndex:(NSInteger)index {
- [self.view endEditing:YES];
- [self.imageArray removeObjectAtIndex:index];
- [self.imageAsset removeObjectAtIndex:index];
-
- // 重新布局
- [self createImageButtonAndPhotosButton];
- }
- #pragma mark -- LLPhotoBrowserDelegate
- - (void)photoBrowser:(LLPhotoBrowser *)photoBrowser backImages:(NSMutableArray *)images {
- NSMutableArray * returnImgArray = [images mutableCopy];
- NSMutableArray *imageArray = [NSMutableArray array];
- NSMutableArray *imageAsset = [NSMutableArray array];
- for (NSInteger i = 0; i < returnImgArray.count; i++) {
- id source = returnImgArray[i];
- for (NSInteger i = 0; i < self.imageArray.count; i++) {
- UIImage *imagePic = self.imageArray[i];
- if ([imagePic isEqual:source]) {
- [imageArray addObject:imagePic];
- [imageAsset addObject:self.imageAsset[i]];
- }
- }
- }
- self.imageArray = [imageArray mutableCopy];
- self.imageAsset = [imageAsset mutableCopy];
- //布局
- [self createImageButtonAndPhotosButton];
- }
- #pragma mark - 懒加载
- - (NSMutableArray *)imageArray {
- if (!_imageArray) {
- _imageArray = [NSMutableArray array];
- }
- return _imageArray;
- }
- - (NSMutableArray *)imageAsset {
- if (!_imageAsset) {
- _imageAsset = [NSMutableArray array];
- }
- return _imageAsset;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|