YOUPAILCReportVC.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. //
  2. // YOUPAILCReportVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/10.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCReportVC.h"
  9. #import "YOUPAILCReportModel.h"
  10. #import "YOUPAILZTextView.h"
  11. #import "UIViewController+TFPresent.h"
  12. #import "YOUPAILCIMSessionVC.h"
  13. #import "YOUPAILZReportCell.h"
  14. #import "LZAlertWindow.h"
  15. #import "YOUPAIBrowserPhotoCell.h"
  16. #import "TZImagePickerController.h"
  17. #import "UIView+NTES.h"
  18. #import "TZImageManager.h"
  19. @interface YOUPAILCReportVC ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,TZImagePickerControllerDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
  20. @property(nonatomic,strong)UITableView* tableView;
  21. //@property(nonatomic,strong)NSIndexPath *lastPath;
  22. @property(nonatomic,strong)NSArray* reportArray;
  23. @property(nonatomic,strong)UIButton* uploadBtn;
  24. @property(nonatomic,strong)YOUPAILZTextView *liveTextView;
  25. @property (nonatomic, strong)YOUPAILCReportModel *currentModel;
  26. @property (nonatomic, strong) UICollectionView *collectionView;
  27. @property (nonatomic, strong) NSMutableArray *selectedPhotos;
  28. @property (nonatomic, strong) NSMutableArray *selectedAssets;
  29. @property (nonatomic, strong) UIImagePickerController *imagePickerVc;
  30. @property(nonatomic,strong)NSString *youpaipimageUrl;//上传后返回的图片数组
  31. @end
  32. @implementation YOUPAILCReportVC
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. self.title = @"举报";
  36. self.selectedPhotos = [NSMutableArray new];
  37. self.selectedAssets = [NSMutableArray new];
  38. [self youpaifsetupView];
  39. [self youpaifinitData];
  40. }
  41. - (void)youpaifinitData{
  42. [LCHttpHelper requestWithURLString:ReportInit parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  43. NSDictionary* dict = (NSDictionary*)responseObject;
  44. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  45. if (code==0) {//成功
  46. self.reportArray = [YOUPAILCReportModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  47. [self.tableView reloadData];
  48. }
  49. } failure:^(NSError *error) {
  50. }];
  51. }
  52. - (void)youpaifsetupView{
  53. self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) style:(UITableViewStylePlain)];
  54. self.tableView.showsVerticalScrollIndicator = NO;
  55. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  56. self.tableView.backgroundColor = [UIColor whiteColor];
  57. self.tableView.rowHeight = 54.0f;
  58. self.tableView.delegate = self;
  59. self.tableView.dataSource= self;
  60. if (@available(iOS 15.0, *)) {
  61. self.tableView.sectionHeaderTopPadding = 0;
  62. }
  63. [self.view addSubview:self.tableView];
  64. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth, 54.0f)];
  65. self.tableView.tableHeaderView = headerView;
  66. UILabel *headerL = [[UILabel alloc] initWithFrame:CGRectMake(14.0f, 0.0f, KScreenWidth - 28.0f, 54.0f)];
  67. headerL.font = LCBoldFont(16.0f);
  68. headerL.textColor = LZ273145Color;
  69. headerL.text = @"选择举报原因";
  70. [headerView addSubview:headerL];
  71. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth, 54.0f + 148 + 50.0f + 49.0f * 2.0f+63)];
  72. self.tableView.tableFooterView = footerView;
  73. UILabel *footerL = [[UILabel alloc] initWithFrame:CGRectMake(14.0f, 0.0f, KScreenWidth - 28.0f, 54.0f)];
  74. footerL.font = LCBoldFont(16.0f);
  75. footerL.textColor = LZ273145Color;
  76. [footerView addSubview:footerL];
  77. NSString *footerText = @"举报描述(选填)";
  78. NSRange range = [footerText rangeOfString:@"(选填)"];
  79. NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc]initWithString:footerText];
  80. [attrStr addAttribute:NSFontAttributeName value:LCFont(14) range:range];
  81. [attrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x9F9DA5) range:range];
  82. footerL.attributedText = attrStr;
  83. //图片选择
  84. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  85. layout.itemSize = CGSizeMake(63, 63);
  86. layout.minimumInteritemSpacing = 9;
  87. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  88. [footerView addSubview:collectionView];
  89. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.top.mas_equalTo(footerL.mas_bottom);
  91. make.left.mas_equalTo(12);
  92. make.right.mas_equalTo(-12);
  93. make.height.mas_equalTo(63);
  94. }];
  95. self.collectionView = collectionView;
  96. collectionView.alwaysBounceVertical = YES;
  97. collectionView.backgroundColor = [UIColor whiteColor];
  98. collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
  99. collectionView.dataSource = self;
  100. collectionView.delegate = self;
  101. collectionView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  102. [self.collectionView registerClass:[YOUPAIBrowserPhotoCell class] forCellWithReuseIdentifier:@"YOUPAIBrowserPhotoCell"];
  103. // self.liveTextView = [[ZCLiveTextView alloc]initWithFrame:CGRectMake(14, 54.0f, KScreenWidth - 28.0f, 148) TopMargin:8.0 LeftMargin:5.0];
  104. // self.liveTextView.layer.cornerRadius = 5.0f;
  105. // self.liveTextView.backgroundColor = HexColorFromRGB(0x4F4B5B);
  106. // self.liveTextView.placeholderColor = HexColorFromRGB(0x6C6B70);
  107. // self.liveTextView.textView.textColor = [UIColor whiteColor];
  108. // self.liveTextView.placeholder = @"更详细说明举报内容(选填)";
  109. // self.liveTextView.textView.text = @"";
  110. // self.liveTextView.textLength = 120;
  111. // self.liveTextView.timeoutAlertColor = LCRedColor;
  112. // [footerView addSubview:self.liveTextView];
  113. YOUPAILZTextView *textView = [[YOUPAILZTextView alloc] initWithMaxCount:120];
  114. textView.frame = CGRectMake(14, 54.0f+63+9, KScreenWidth - 28.0f, 148);
  115. textView.youpaiptextViewPadding = UIEdgeInsetsMake(14.0f, 14.0f, 10.0f, 14.0f);
  116. textView.youpaiptextLengthDefaultColor = HexColorFromRGB(0xD3D1D7);
  117. textView.youpaiptextLengthHigtColor = ZYPinkColor;
  118. textView.youpaiptextLengthFont = LCFont(14.0f);
  119. textView.youpaiptextLengthRight = 14.0f;
  120. textView.youpaiptextLengthBottom = 14.0f;
  121. textView.youpaiptextView.placeholderFont = LCFont(14.0f);
  122. textView.youpaiptextView.placeholderTextColor = HexColorFromRGB(0xD3D1D7);
  123. textView.youpaiptextView.placeholderText = @"更详细说明举报内容(选填)";
  124. textView.youpaiptextView.font = LCFont(14.0f);
  125. textView.layer.cornerRadius = 5.0f;
  126. textView.clipsToBounds = YES;
  127. textView.tintColor = ZYPinkColor;
  128. [footerView addSubview:textView];
  129. textView.youpaiptextView.textColor = LZ273145Color;
  130. self.liveTextView = textView;
  131. textView.backgroundColor = LZF7F8FAColor;
  132. UIButton* uploadBtn = [[UIButton alloc]initWithFrame:CGRectMake(47.5, footerView.mj_h - 49.0f * 2.0f, KScreenWidth-47.5*2, 49.0f)];
  133. uploadBtn.titleLabel.font = LCFont16;
  134. uploadBtn.backgroundColor = HexColorFromRGB(0xD3D1D7);
  135. uploadBtn.layer.cornerRadius = 24.5f;
  136. uploadBtn.layer.masksToBounds = YES;
  137. [uploadBtn setTitle:@"提交" forState:(UIControlStateNormal)];
  138. [uploadBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  139. [uploadBtn addTarget:self action:@selector(youpaifuploadBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  140. uploadBtn.userInteractionEnabled = NO;
  141. self.uploadBtn = uploadBtn;
  142. [footerView addSubview:uploadBtn];
  143. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  144. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  145. }
  146. #pragma mark UICollectionView
  147. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  148. if (_selectedPhotos.count >= 5) {
  149. return _selectedPhotos.count;
  150. }
  151. return _selectedPhotos.count + 1;
  152. }
  153. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  154. YOUPAIBrowserPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAIBrowserPhotoCell" forIndexPath:indexPath];
  155. if (indexPath.item == _selectedPhotos.count) {
  156. cell.imageView.image = [UIImage imageNamed:@"vqu_images_AlbumAddBtn"];
  157. cell.deleteBtn.hidden = YES;
  158. } else {
  159. cell.imageView.image = _selectedPhotos[indexPath.item];
  160. cell.asset = _selectedAssets[indexPath.item];
  161. cell.deleteBtn.hidden = NO;
  162. }
  163. cell.deleteBtn.tag = indexPath.item;
  164. [cell.deleteBtn addTarget:self action:@selector(deleteBtnClik:) forControlEvents:UIControlEventTouchUpInside];
  165. return cell;
  166. }
  167. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  168. if (indexPath.item == _selectedPhotos.count) {
  169. NSString *takePhotoTitle = @"拍照";
  170. UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  171. UIAlertAction *takePhotoAction = [UIAlertAction actionWithTitle:takePhotoTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  172. [self takePhoto];
  173. }];
  174. [alertVc addAction:takePhotoAction];
  175. UIAlertAction *imagePickerAction = [UIAlertAction actionWithTitle:@"去相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  176. [self pushTZImagePickerController];
  177. }];
  178. [alertVc addAction:imagePickerAction];
  179. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
  180. [alertVc addAction:cancelAction];
  181. UIPopoverPresentationController *popover = alertVc.popoverPresentationController;
  182. UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
  183. if (popover) {
  184. popover.sourceView = cell;
  185. popover.sourceRect = cell.bounds;
  186. popover.permittedArrowDirections = UIPopoverArrowDirectionAny;
  187. }
  188. [self presentViewController:alertVc animated:YES completion:nil];
  189. } else { // preview photos or video / 预览照片或者视频
  190. // preview photos / 预览照片
  191. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithSelectedAssets:_selectedAssets selectedPhotos:_selectedPhotos index:indexPath.item];
  192. imagePickerVc.maxImagesCount = 4;
  193. imagePickerVc.allowPickingGif = NO;
  194. imagePickerVc.allowPickingOriginalPhoto = YES;
  195. imagePickerVc.allowPickingMultipleVideo = YES;
  196. imagePickerVc.showSelectedIndex = YES;
  197. imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
  198. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  199. self->_selectedPhotos = [NSMutableArray arrayWithArray:photos];
  200. self->_selectedAssets = [NSMutableArray arrayWithArray:assets];
  201. [self->_collectionView reloadData];
  202. }];
  203. [self presentViewController:imagePickerVc animated:YES completion:nil];
  204. }
  205. }
  206. #pragma mark - UIImagePickerController
  207. - (void)takePhoto {
  208. AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  209. if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
  210. // 无相机权限 做一个友好的提示
  211. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"打开相册失败" message:@"相机打开失败。设备不支持访问相机,请在设置->花蝶->相机中进行设置" preferredStyle:UIAlertControllerStyleAlert];
  212. [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  213. [alertController addAction:[UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  214. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  215. }]];
  216. [self presentViewController:alertController animated:YES completion:nil];
  217. } else if (authStatus == AVAuthorizationStatusNotDetermined) {
  218. // fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏
  219. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
  220. if (granted) {
  221. dispatch_async(dispatch_get_main_queue(), ^{
  222. [self takePhoto];
  223. });
  224. }
  225. }];
  226. // 拍照之前还需要检查相册权限
  227. } else if ([PHPhotoLibrary authorizationStatus] == 2) { // 已被拒绝,没有相册权限,将无法保存拍的照片
  228. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"无法访问相册" message:@"相册打开失败。设备不支持访问相册,请在设置->隐私->照片中进行设置" preferredStyle:UIAlertControllerStyleAlert];
  229. [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  230. [alertController addAction:[UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  231. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  232. }]];
  233. [self presentViewController:alertController animated:YES completion:nil];
  234. } else if ([PHPhotoLibrary authorizationStatus] == 0) { // 未请求过相册权限
  235. [[TZImageManager manager] requestAuthorizationWithCompletion:^{
  236. [self takePhoto];
  237. }];
  238. } else {
  239. [self pushImagePickerController];
  240. }
  241. }
  242. // 调用相机
  243. - (void)pushImagePickerController {
  244. UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
  245. if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
  246. self.imagePickerVc.sourceType = sourceType;
  247. NSMutableArray *mediaTypes = [NSMutableArray array];
  248. [mediaTypes addObject:(NSString *)kUTTypeMovie];
  249. [mediaTypes addObject:(NSString *)kUTTypeImage];
  250. if (mediaTypes.count) {
  251. _imagePickerVc.mediaTypes = mediaTypes;
  252. }
  253. [self presentViewController:_imagePickerVc animated:YES completion:nil];
  254. } else {
  255. NSLog(@"模拟器中无法打开照相机,请在真机中使用");
  256. }
  257. }
  258. #pragma mark - Click Event
  259. - (void)deleteBtnClik:(UIButton *)sender {
  260. if ([self collectionView:self.collectionView numberOfItemsInSection:0] <= _selectedPhotos.count) {
  261. [_selectedPhotos removeObjectAtIndex:sender.tag];
  262. [_selectedAssets removeObjectAtIndex:sender.tag];
  263. [self.collectionView reloadData];
  264. return;
  265. }
  266. [_selectedPhotos removeObjectAtIndex:sender.tag];
  267. [_selectedAssets removeObjectAtIndex:sender.tag];
  268. [_collectionView performBatchUpdates:^{
  269. NSIndexPath *indexPath = [NSIndexPath indexPathForItem:sender.tag inSection:0];
  270. [self->_collectionView deleteItemsAtIndexPaths:@[indexPath]];
  271. } completion:^(BOOL finished) {
  272. [self->_collectionView reloadData];
  273. }];
  274. }
  275. #pragma mark - TZImagePickerController
  276. - (UIImagePickerController *)imagePickerVc {
  277. if (_imagePickerVc == nil) {
  278. _imagePickerVc = [[UIImagePickerController alloc] init];
  279. _imagePickerVc.delegate = self;
  280. // set appearance / 改变相册选择页的导航栏外观
  281. _imagePickerVc.navigationBar.barTintColor = self.navigationController.navigationBar.barTintColor;
  282. _imagePickerVc.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
  283. UIBarButtonItem *tzBarItem, *BarItem;
  284. if (@available(iOS 9, *)) {
  285. tzBarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]];
  286. BarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]];
  287. } else {
  288. tzBarItem = [UIBarButtonItem appearanceWhenContainedIn:[TZImagePickerController class], nil];
  289. BarItem = [UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil];
  290. }
  291. NSDictionary *titleTextAttributes = [tzBarItem titleTextAttributesForState:UIControlStateNormal];
  292. [BarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
  293. }
  294. return _imagePickerVc;
  295. }
  296. - (void)pushTZImagePickerController {
  297. // 设置languageBundle以使用其它语言,必须在TZImagePickerController初始化前设置 / Set languageBundle to use other language
  298. // [TZImagePickerConfig sharedInstance].languageBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"tz-ru" ofType:@"lproj"]];
  299. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:5 columnNumber:5 delegate:self pushPhotoPickerVc:YES];
  300. imagePickerVc.iconThemeColor = [UIColor colorWithRed:31 / 255.0 green:185 / 255.0 blue:34 / 255.0 alpha:1.0];
  301. imagePickerVc.showPhotoCannotSelectLayer = YES;
  302. imagePickerVc.cannotSelectLayerColor = [[UIColor whiteColor] colorWithAlphaComponent:0.8];
  303. // 1.设置目前已经选中的图片数组
  304. imagePickerVc.selectedAssets = _selectedAssets;
  305. // 3. 设置是否可以选择视频/图片/原图
  306. imagePickerVc.allowPickingVideo = NO;
  307. imagePickerVc.allowPickingImage = YES;
  308. imagePickerVc.allowPickingOriginalPhoto = NO;
  309. imagePickerVc.allowPickingGif = NO;
  310. imagePickerVc.allowPickingMultipleVideo = NO; // 是否可以多选视频
  311. // 4. 照片排列按修改时间升序
  312. imagePickerVc.sortAscendingByModificationDate = YES;
  313. // imagePickerVc.minImagesCount = 3;
  314. // imagePickerVc.alwaysEnableDoneBtn = YES;
  315. // imagePickerVc.minPhotoWidthSelectable = 3000;
  316. // imagePickerVc.minPhotoHeightSelectable = 2000;
  317. /// 5. Single selection mode, valid when maxImagesCount = 1
  318. /// 5. 单选模式,maxImagesCount为1时才生效
  319. // imagePickerVc.showSelectBtn = NO;
  320. // 设置竖屏下的裁剪尺寸
  321. NSInteger left = 30;
  322. NSInteger widthHeight = self.view.width - 2 * left;
  323. NSInteger top = (self.view.height - widthHeight) / 2;
  324. imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight);
  325. // 设置横屏下的裁剪尺寸
  326. // imagePickerVc.cropRectLandscape = CGRectMake((self.view.tz_height - widthHeight) / 2, left, widthHeight, widthHeight);
  327. /*
  328. [imagePickerVc setCropViewSettingBlock:^(UIView *cropView) {
  329. cropView.layer.borderColor = [UIColor redColor].CGColor;
  330. cropView.layer.borderWidth = 2.0;
  331. }];*/
  332. // imagePickerVc.allowPreview = NO;
  333. // 自定义导航栏上的返回按钮
  334. /*
  335. [imagePickerVc setNavLeftBarButtonSettingBlock:^(UIButton *leftButton){
  336. [leftButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  337. [leftButton setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 20)];
  338. }];
  339. imagePickerVc.delegate = self;
  340. */
  341. // Deprecated, Use statusBarStyle
  342. // imagePickerVc.isStatusBarDefault = NO;
  343. imagePickerVc.statusBarStyle = UIStatusBarStyleLightContent;
  344. // 设置是否显示图片序号
  345. imagePickerVc.showSelectedIndex = YES;
  346. // 设置拍照时是否需要定位,仅对选择器内部拍照有效,外部拍照的,请拷贝demo时手动把pushImagePickerController里定位方法的调用删掉
  347. // imagePickerVc.allowCameraLocation = NO;
  348. // 设置首选语言 / Set preferred language
  349. // imagePickerVc.preferredLanguage = @"zh-Hans";
  350. #pragma mark - 到这里为止
  351. // You can get the photos by block, the same as by delegate.
  352. // 你可以通过block或者代理,来得到用户选择的照片.
  353. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  354. }];
  355. imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
  356. [self presentViewController:imagePickerVc animated:YES completion:nil];
  357. }
  358. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos {
  359. _selectedPhotos = [NSMutableArray arrayWithArray:photos];
  360. _selectedAssets = [NSMutableArray arrayWithArray:assets];
  361. [_collectionView reloadData];
  362. // _collectionView.contentSize = CGSizeMake(0, ((_selectedPhotos.count + 2) / 3 ) * (_margin + _itemWH));
  363. [self updataImagesOSS:_selectedPhotos];
  364. // 1.打印图片名字
  365. [self printAssetsName:assets];
  366. // 2.图片位置信息
  367. for (PHAsset *phAsset in assets) {
  368. NSLog(@"location:%@",phAsset.location);
  369. }
  370. }
  371. - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  372. [picker dismissViewControllerAnimated:YES completion:nil];
  373. NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
  374. TZImagePickerController *tzImagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
  375. tzImagePickerVc.sortAscendingByModificationDate = YES;
  376. [tzImagePickerVc showProgressHUD];
  377. if ([type isEqualToString:@"public.image"]) {
  378. UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
  379. NSDictionary *meta = [info objectForKey:UIImagePickerControllerMediaMetadata];
  380. // save photo and get asset / 保存图片,获取到asset
  381. [[TZImageManager manager] savePhotoWithImage:image meta:meta location:nil completion:^(PHAsset *asset, NSError *error){
  382. [tzImagePickerVc hideProgressHUD];
  383. if (error) {
  384. NSLog(@"图片保存失败 %@",error);
  385. } else {
  386. TZAssetModel *assetModel = [TZAssetModel modelWithAsset:asset type:TZAssetModelMediaTypePhoto];
  387. [self refreshCollectionViewWithAddedAsset:assetModel.asset image:image];
  388. }
  389. }];
  390. }
  391. }
  392. - (void)refreshCollectionViewWithAddedAsset:(PHAsset *)asset image:(UIImage *)image {
  393. [_selectedAssets addObject:asset];
  394. [_selectedPhotos addObject:image];
  395. [_collectionView reloadData];
  396. [self updataImagesOSS:_selectedPhotos];
  397. }
  398. -(void)updataImagesOSS:(NSArray*)imagesArr{
  399. // 1通过,0待审核,2,未通过
  400. @weakify(self)
  401. [LCCommonHttp uploadWithImages:imagesArr Type:@"album" successBlock:^(NSArray<NSString *> *ossImagePaths) {
  402. @strongify(self)
  403. ;
  404. self.youpaipimageUrl =[ossImagePaths componentsJoinedByString:@","];
  405. }];
  406. }
  407. /// 打印图片名字
  408. - (void)printAssetsName:(NSArray *)assets {
  409. NSString *fileName;
  410. for (PHAsset *asset in assets) {
  411. fileName = [asset valueForKey:@"filename"];
  412. // NSLog(@"图片名字:%@",fileName);
  413. }
  414. }
  415. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
  416. if ([picker isKindOfClass:[UIImagePickerController class]]) {
  417. [picker dismissViewControllerAnimated:YES completion:nil];
  418. }
  419. }
  420. #pragma mark - 键盘交互事件
  421. //键盘即将隐藏
  422. - (void)youpaifkeyboardWillHide:(NSNotification *)note
  423. {
  424. // CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  425. [UIView animateWithDuration:0.25 animations:^{
  426. //KScreenHeight-KScreenHeight/3-60
  427. self.view.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
  428. }];
  429. }
  430. //键盘即将弹出
  431. - (void)youpaifkeyboardWillShow:(NSNotification *)note
  432. {
  433. CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  434. CGFloat keyboardH = keyboardF.size.height;
  435. [UIView animateWithDuration:0.25 animations:^{
  436. self.view.frame = CGRectMake(0, 0-keyboardH, KScreenWidth, KScreenHeight);
  437. }];
  438. }
  439. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  440. [self.view endEditing:YES];
  441. }
  442. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  443. return self.reportArray.count;
  444. }
  445. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  446. return 50;
  447. }
  448. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  449. YOUPAILCReportModel* model = self.reportArray[indexPath.row];
  450. NSString *cellID = @"YOUPAILZReportCell";
  451. YOUPAILZReportCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  452. if (cell == nil) {
  453. cell = [[YOUPAILZReportCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  454. }
  455. [cell youpaifreloadWithModel:model];
  456. // UITableViewCell* cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"reportCell"];
  457. // cell.backgroundColor = [UIColor whiteColor];
  458. // cell.textLabel.text = model.name;
  459. // cell.textLabel.font = LCFont17;
  460. // cell.textLabel.textColor = LCTextBlack;
  461. // cell.textLabel.textAlignment = NSTextAlignmentLeft;
  462. //
  463. // NSInteger row = [indexPath row];
  464. // NSInteger oldRow = [self.lastPath row];
  465. // if (row == oldRow && self.lastPath!=nil) {
  466. // cell.accessoryType = UITableViewCellAccessoryCheckmark;
  467. // }else{
  468. // cell.accessoryType = UITableViewCellAccessoryNone;
  469. // }
  470. return cell;
  471. }
  472. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  473. self.currentModel.youpaipisSelected = NO;
  474. YOUPAILCReportModel* model = self.reportArray[indexPath.row];
  475. self.currentModel = model;
  476. self.currentModel.youpaipisSelected = YES;
  477. // NSInteger newRow = [indexPath row];
  478. // NSInteger oldRow = (self .lastPath !=nil)?[self .lastPath row]:-1;
  479. // if (newRow != oldRow) {
  480. // UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
  481. // newCell.accessoryType = UITableViewCellAccessoryCheckmark;
  482. // UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:self.lastPath];
  483. // oldCell.accessoryType = UITableViewCellAccessoryNone;
  484. // self .lastPath = indexPath;
  485. // }
  486. [tableView reloadData];
  487. [self youpaifupdateBtnStatus];
  488. }
  489. - (void)youpaifupdateBtnStatus{
  490. if (self.currentModel != nil) {
  491. [self.uploadBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth-47.5*2, 49) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  492. self.uploadBtn.userInteractionEnabled = YES;
  493. }
  494. }
  495. - (void)youpaifuploadBtnClick{
  496. YOUPAILCReportModel* model = self.currentModel;
  497. @weakify(self);
  498. NSMutableDictionary *dict = [NSMutableDictionary new];
  499. [dict setObject:@(self.youpaiptype) forKey:@"type"];
  500. [dict setObject:model.youpaipid forKey:@"cate_id"];
  501. if (self.youpaipimageUrl.length == 0) {
  502. self.youpaipimageUrl = @"";
  503. }
  504. [dict setObject:self.youpaipimageUrl forKey:@"images"];
  505. [dict setObject:self.youpaipreport_uid forKey:@"report_uid"];
  506. [dict setObject:self.liveTextView.youpaiptextView.text forKey:@"content"];
  507. [LCHttpHelper requestWithURLString:ReportUpload parameters:dict needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  508. @strongify(self);
  509. NSDictionary* dict = (NSDictionary*)responseObject;
  510. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  511. if (code==0) {//成功
  512. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"需紧急处理" handler:^(LZAlertAction *action) {
  513. NIMSession *session = [NIMSession session:@"4" type:NIMSessionTypeP2P];
  514. [ZCHUDHelper show];
  515. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  516. @strongify(self);
  517. [ZCHUDHelper dismiss];
  518. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  519. [self.navigationController pushViewController:vc animated:YES];
  520. }];
  521. }];
  522. cancelAction.cornerRadius = 24.0f;
  523. cancelAction.color = LZ273145Color;
  524. cancelAction.bgColor = LZF5F4F7Color;
  525. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"返回" handler:^(LZAlertAction *action) {
  526. @strongify(self);
  527. [self.navigationController popViewControllerAnimated:YES];
  528. }];
  529. confimAction.cornerRadius = 24.0f;
  530. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  531. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"举报成功" content:@" 我们已接收到您的举报内容,非常重视您的举报。每一条举报都会被认真核实,并依据国家法律法规及本平台条款积极处理,感谢您的配合。" action:@[cancelAction,confimAction]];
  532. [self TFPresentVC:alert completion:^{}];
  533. }
  534. } failure:^(NSError *error) {
  535. }];
  536. }
  537. -(void)youpaifclickconfirmAction
  538. {
  539. NIMSession *session = [NIMSession session:[LCSaveData getServerId] type:NIMSessionTypeP2P];
  540. if (session) {
  541. @weakify(self);
  542. [ZCHUDHelper show];
  543. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  544. @strongify(self);
  545. [ZCHUDHelper dismiss];
  546. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  547. [self.navigationController pushViewController:vc animated:YES];
  548. }];
  549. }
  550. }
  551. @end