PlatformInterventionVC.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. //
  2. // PlatformInterventionVC.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/3/23.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "PlatformInterventionVC.h"
  9. #import "TZImagePickerController.h"
  10. #import <Qiniu/QiniuSDK.h>
  11. #import "YBStorageObj.h"
  12. @interface PlatformInterventionVC ()<UIPickerViewDelegate,UIPickerViewDataSource,UITextViewDelegate,TZImagePickerControllerDelegate>
  13. {
  14. UIScrollView *_backScroll;
  15. MyTextView *contentText;
  16. UIButton *imageBtn;
  17. UILabel *wordCountLb;
  18. UIButton *delBtn;
  19. NSMutableArray *imageArray;
  20. UIView *reasonPickBack;
  21. UIPickerView *reasonPicker;
  22. NSString *selReasonStr;
  23. NSString *selReasonID;
  24. NSArray *reasonArr;
  25. UILabel *selLb;
  26. NSInteger selRow;
  27. NSString *picThumbsStr;
  28. }
  29. @end
  30. @implementation PlatformInterventionVC
  31. -(void)requestReason{
  32. NSDictionary *dic = @{
  33. @"uid":[Config getOwnID],
  34. @"token":[Config getOwnToken],
  35. };
  36. [YBNetworking postWithUrl:@"Buyer.getPlatformReasonList" Dic:dic Suc:^(int code, id info, NSString *msg) {
  37. if (code ==0) {
  38. reasonArr = info;
  39. }else{
  40. [MBProgressHUD showError:msg];
  41. }
  42. } Fail:^(id fail) {
  43. }];
  44. }
  45. - (UIStatusBarStyle)preferredStatusBarStyle {
  46. if (@available(iOS 13.0,*)) {
  47. return UIStatusBarStyleDarkContent;
  48. }
  49. return UIStatusBarStyleDefault;
  50. }
  51. - (void)viewDidLoad {
  52. [super viewDidLoad];
  53. self.titleL.text = YZMsg(@"平台介入");
  54. imageArray = [NSMutableArray array];
  55. picThumbsStr = @"";
  56. selReasonID = @"-999999";
  57. self.view.backgroundColor = UIColor.whiteColor;
  58. self.subNavi.backgroundColor = UIColor.whiteColor;
  59. self.titleL.textColor = UIColor.blackColor;
  60. [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
  61. self.naviLine.hidden = NO;
  62. self.naviLine.backgroundColor = RGB(245, 245, 245);
  63. _backScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64+statusbarHeight, _window_width, _window_height)];
  64. _backScroll.backgroundColor = UIColor.whiteColor;
  65. [self.view addSubview:_backScroll];
  66. UILabel *titleLb = [[UILabel alloc]init];
  67. titleLb.frame = CGRectMake(15, 10, 80, 30);
  68. titleLb.font = [UIFont systemFontOfSize:14];
  69. titleLb.textColor = UIColor.grayColor;
  70. titleLb.text = YZMsg(@"申诉原因");
  71. [_backScroll addSubview:titleLb];
  72. UIImageView *rightImg = [[UIImageView alloc]init];
  73. rightImg.frame = CGRectMake(_window_width-25, 10, 15, 15);
  74. rightImg.image = [UIImage imageNamed:@"shop_right"];
  75. [_backScroll addSubview:rightImg];
  76. rightImg.centerY = titleLb.centerY;
  77. selLb = [[UILabel alloc]init];
  78. selLb.frame = CGRectMake(rightImg.left-150, 10, 145, 30);
  79. selLb.font = [UIFont systemFontOfSize:14];
  80. selLb.textColor = UIColor.grayColor;
  81. selLb.text = YZMsg(@"请选择");
  82. selLb.textAlignment = NSTextAlignmentRight;
  83. [_backScroll addSubview:selLb];
  84. UIButton *selReason = [UIButton buttonWithType:0];
  85. selReason.frame = CGRectMake(0, 0, _window_width, 50);
  86. [selReason addTarget:self action:@selector(selReason) forControlEvents:UIControlEventTouchUpInside];
  87. [_backScroll addSubview:selReason];
  88. UILabel *line = [[UILabel alloc]init];
  89. line.frame =CGRectMake(0, titleLb.bottom+10, _window_width, 8);
  90. line.backgroundColor = RGB(245, 245, 245);
  91. [_backScroll addSubview:line];
  92. contentText = [[MyTextView alloc]init];
  93. contentText.frame = CGRectMake(10, line.bottom+5, _window_width-20, 150);
  94. contentText.placeholderColor = [UIColor grayColor];
  95. contentText.placeholder =YZMsg(@"请填写详细原因与证据描述,有助于快速解决你的问题");
  96. contentText.font = [UIFont systemFontOfSize:14];
  97. contentText.delegate = self;
  98. contentText.textColor = [UIColor blackColor];
  99. contentText.backgroundColor = RGB(245, 245, 245);
  100. [_backScroll addSubview:contentText];
  101. imageBtn = [UIButton buttonWithType:0];
  102. imageBtn.frame = CGRectMake(15, contentText.bottom+5, 70, 70);
  103. [imageBtn setBackgroundImage:[UIImage imageNamed:getImagename(@"refund_upimg")] forState:0];
  104. [imageBtn addTarget:self action:@selector(uploadImage) forControlEvents:UIControlEventTouchUpInside];
  105. [_backScroll addSubview:imageBtn];
  106. delBtn = [UIButton buttonWithType:0];
  107. delBtn.frame = CGRectMake(imageBtn.width-25, 5, 20, 20);
  108. [delBtn setBackgroundImage:[UIImage imageNamed:@"comm_del"] forState:0];
  109. [delBtn addTarget:self action:@selector(delVideoClick) forControlEvents:UIControlEventTouchUpInside];
  110. [imageBtn addSubview:delBtn];
  111. delBtn.hidden = YES;
  112. wordCountLb = [[UILabel alloc]init];
  113. wordCountLb.frame = CGRectMake(_window_width-100, 0, 90, 20);
  114. wordCountLb.centerY = imageBtn.centerY;
  115. wordCountLb.font = [UIFont systemFontOfSize:14];
  116. wordCountLb.textColor = UIColor.grayColor;
  117. wordCountLb.text = @"0/300";
  118. wordCountLb.textAlignment = NSTextAlignmentRight;
  119. [_backScroll addSubview:wordCountLb];
  120. _backScroll.size = CGSizeMake(_window_width, imageBtn.bottom+10);
  121. UIButton *submitBtn = [UIButton buttonWithType:0];
  122. submitBtn.frame = CGRectMake(0, _window_height-40-ShowDiff, _window_width, 40);
  123. [submitBtn setTitle:YZMsg(@"提交申请") forState:0];
  124. [submitBtn setTitleColor:[UIColor whiteColor] forState:0];
  125. submitBtn.titleLabel.font =[UIFont systemFontOfSize:14];
  126. [submitBtn setBackgroundColor:Pink_Cor];
  127. [submitBtn addTarget:self action:@selector(submitBtnClick) forControlEvents:UIControlEventTouchUpInside];
  128. [self.view addSubview:submitBtn];
  129. [self requestReason];
  130. }
  131. -(void)delVideoClick{
  132. delBtn.hidden = YES;
  133. [imageArray removeAllObjects];
  134. [imageBtn setBackgroundImage:[UIImage imageNamed:getImagename(@"refund_upimg")] forState:0];
  135. }
  136. //选择图片
  137. -(void)uploadImage{
  138. TZImagePickerController *imagePC = [[TZImagePickerController alloc]initWithMaxImagesCount:1-imageArray.count delegate:self];
  139. imagePC.preferredLanguage = [lagType isEqual:ZH_CN] ? @"zh-Hans":@"en";
  140. imagePC.modalPresentationStyle = 0;
  141. imagePC.showSelectBtn = YES;
  142. imagePC.allowCrop = NO;
  143. imagePC.allowPickingOriginalPhoto = NO;
  144. imagePC.oKButtonTitleColorNormal = Pink_Cor;
  145. imagePC.allowTakePicture = YES;
  146. imagePC.allowTakeVideo = NO;
  147. imagePC.allowPickingVideo = NO;
  148. imagePC.allowPickingMultipleVideo = NO;
  149. [[[YBBaseAppDelegate sharedAppDelegate] topViewController]presentViewController:imagePC animated:YES completion:nil];
  150. }
  151. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto{
  152. NSLog(@"------多选择图片--:%@",photos);
  153. [imageArray addObjectsFromArray:photos];
  154. [imageBtn setBackgroundImage:photos[0] forState:0];
  155. delBtn.hidden = NO;
  156. }
  157. #pragma mark------选择原因-------
  158. -(void)selReason{
  159. [self.view endEditing:YES];
  160. if (!reasonPickBack) {
  161. reasonPickBack = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
  162. reasonPickBack.backgroundColor = RGB_COLOR(@"#000000", 0.3);
  163. [self.view addSubview:reasonPickBack];
  164. UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height-240, _window_width, 40)];
  165. titleView.backgroundColor = [UIColor whiteColor];
  166. [reasonPickBack addSubview:titleView];
  167. [PublicObj lineViewWithFrame:CGRectMake(0, titleView.height-1, _window_width, 1) andColor:RGB(250, 250, 250) andView:titleView];
  168. UIButton *cancleBtn = [UIButton buttonWithType:0];
  169. cancleBtn.frame = CGRectMake(10, 0, 80, 40);
  170. cancleBtn.tag = 100;
  171. [cancleBtn setTitle:YZMsg(@"取消") forState:0];
  172. [cancleBtn setTitleColor:[UIColor blackColor] forState:0];
  173. cancleBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  174. [cancleBtn addTarget:self action:@selector(cityCancleOrSure:) forControlEvents:UIControlEventTouchUpInside];
  175. [titleView addSubview:cancleBtn];
  176. UIButton *sureBtn = [UIButton buttonWithType:0];
  177. sureBtn.frame = CGRectMake(_window_width-90, 0, 80, 40);
  178. sureBtn.tag = 101;
  179. [sureBtn setTitle:YZMsg(@"完成") forState:0];
  180. [sureBtn setTitleColor:[UIColor blackColor] forState:0];
  181. sureBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  182. [sureBtn addTarget:self action:@selector(cityCancleOrSure:) forControlEvents:UIControlEventTouchUpInside];
  183. [titleView addSubview:sureBtn];
  184. UILabel *titlelb = [[UILabel alloc]init];
  185. titlelb.frame = CGRectMake(_window_width/2-90, 0, 180, 40);
  186. titlelb.font = [UIFont systemFontOfSize:15];
  187. titlelb.text = YZMsg(@"退款原因");
  188. titlelb.textColor = [UIColor blackColor];
  189. [titleView addSubview:titlelb];
  190. reasonPicker = [[UIPickerView alloc]initWithFrame:CGRectMake(0, _window_height-200, _window_width, 200)];
  191. reasonPicker.backgroundColor = [UIColor whiteColor];
  192. reasonPicker.delegate = self;
  193. reasonPicker.dataSource = self;
  194. reasonPicker.showsSelectionIndicator = YES;
  195. [reasonPicker selectRow: 0 inComponent: 0 animated: YES];
  196. [reasonPickBack addSubview:reasonPicker];
  197. }else{
  198. reasonPickBack.hidden = NO;
  199. }
  200. }
  201. #pragma mark - UITextViewDelegate
  202. - (void)textViewDidChange:(UITextView*)textView {
  203. NSString *toBeString = textView.text;
  204. NSString *lang = [[[UITextInputMode activeInputModes]firstObject] primaryLanguage]; // 键盘输入模式
  205. if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写
  206. UITextRange *selectedRange = [textView markedTextRange];//获取高亮部分
  207. UITextPosition *position = [textView positionFromPosition:selectedRange.start offset:0];
  208. //没有高亮选择的字,则对已输入的文字进行字数统计和限制
  209. if (!position) {
  210. if (toBeString.length > 300) {
  211. textView.text = [toBeString substringToIndex:300];
  212. wordCountLb.text = [NSString stringWithFormat:@"%lu/300",textView.text.length];
  213. }else{
  214. wordCountLb.text = [NSString stringWithFormat:@"%lu/300",toBeString.length];
  215. }
  216. }else{
  217. //有高亮选择的字符串,则暂不对文字进行统计和限制
  218. }
  219. }else{
  220. // 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况
  221. if (toBeString.length > 300) {
  222. textView.text = [toBeString substringToIndex:300];
  223. wordCountLb.text = [NSString stringWithFormat:@"%lu/300",textView.text.length];
  224. }else{
  225. wordCountLb.text = [NSString stringWithFormat:@"%lu/300",toBeString.length];
  226. }
  227. }
  228. }
  229. - (void)cityCancleOrSure:(UIButton *)button{
  230. if (button.tag == 100) {
  231. //return;
  232. }else{
  233. selLb.text = selReasonStr;
  234. }
  235. reasonPickBack.hidden = YES;
  236. }
  237. #pragma mark--- Picker Data Source Methods-----
  238. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
  239. return 1;
  240. }
  241. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  242. return reasonArr.count;
  243. }
  244. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
  245. return [reasonArr[row] valueForKey:@"name"];
  246. }
  247. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
  248. selReasonStr = [reasonArr[row] valueForKey:@"name"];
  249. selReasonID =[reasonArr[row] valueForKey:@"id"];
  250. selRow = row;
  251. [reasonPicker reloadAllComponents];
  252. }
  253. - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
  254. UILabel* pickerLabel = (UILabel*)view;
  255. if (!pickerLabel){
  256. pickerLabel = [[UILabel alloc] init];
  257. pickerLabel.adjustsFontSizeToFitWidth = YES;
  258. [pickerLabel setTextAlignment:NSTextAlignmentCenter];
  259. [pickerLabel setBackgroundColor:[UIColor clearColor]];
  260. pickerLabel.font = [UIFont systemFontOfSize:15];
  261. }
  262. if (row == selRow) {
  263. pickerLabel.textColor = Normal_Color;
  264. selReasonStr =[reasonArr[selRow] valueForKey:@"name"];
  265. selReasonID =[reasonArr[row] valueForKey:@"id"];
  266. }
  267. pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
  268. return pickerLabel;
  269. }
  270. #pragma mark------提交申请---------
  271. -(void)submitBtnClick{
  272. if ([selReasonID isEqual:@"-999999"]) {
  273. [MBProgressHUD showPop:YZMsg(@"请选择申诉原因")];
  274. return;
  275. }
  276. [MBProgressHUD showMessage:@""];
  277. if (imageArray.count > 0) {
  278. YBWeakSelf;
  279. [[YBStorageObj storageManeger]getCOSType:^(int code) {
  280. dispatch_async(dispatch_get_main_queue(), ^{
  281. if (code == 0) {
  282. [weakSelf startUploadCer];
  283. }
  284. });
  285. }];
  286. }else{
  287. [self uploadService];
  288. }
  289. }
  290. -(void)startUploadCer{
  291. [MBProgressHUD showMessage:@""];
  292. dispatch_group_t group = dispatch_group_create();
  293. dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
  294. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  295. YBWeakSelf;
  296. UIImage *image =imageArray[0];
  297. if (image) {
  298. dispatch_group_async(group, queue, ^{
  299. NSString *imageName = [PublicObj getNameBaseCurrentTime:@"_action_image_cover.png"];
  300. [[YBStorageObj storageManeger]yb_storageImg:image andName:imageName progress:^(CGFloat percent) {
  301. }complete:^(int code, NSString *key) {
  302. picThumbsStr = minstr(key);
  303. dispatch_semaphore_signal(semaphore);
  304. }];
  305. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  306. });
  307. }
  308. dispatch_group_notify(group, queue, ^{
  309. dispatch_async(dispatch_get_main_queue(), ^{
  310. [weakSelf uploadService];
  311. });
  312. NSLog(@"任务完成执行");
  313. });
  314. }
  315. -(void)uploadService{
  316. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"orderid":self.orderIDStr,@"reasonid":selReasonID, @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  317. NSString *sign = [PublicObj sortString:signdic];
  318. NSDictionary *dic = @{
  319. @"uid":[Config getOwnID],
  320. @"token":[Config getOwnToken],
  321. @"orderid":self.orderIDStr,
  322. @"reasonid":selReasonID,
  323. @"content":contentText.text,
  324. @"thumb":picThumbsStr,
  325. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  326. @"sign":sign
  327. };
  328. [YBNetworking postWithUrl:@"Buyer.applyPlatformInterpose" Dic:dic Suc:^(int code, id info, NSString *msg) {
  329. [MBProgressHUD hideHUD];
  330. if (code ==0) {
  331. [MBProgressHUD showError:msg];
  332. [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers count] -3)] animated:YES];
  333. }else{
  334. [MBProgressHUD showError:msg];
  335. }
  336. } Fail:^(id fail) {
  337. [MBProgressHUD hideHUD];
  338. }];
  339. }
  340. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  341. {
  342. [self.view endEditing:YES];
  343. }
  344. @end