PublishEvaluateVC.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. //
  2. // PublishEvaluateVC.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/3/16.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "PublishEvaluateVC.h"
  9. #import "CWStarRateView.h"
  10. #import "TZImagePickerController.h"
  11. #import <Qiniu/QiniuSDK.h>
  12. #import "YBImageView.h"
  13. #import "ShowDetailVC.h"
  14. #import "YBStorageObj.h"
  15. @interface PublishEvaluateVC ()<CWStarRateViewDelegate,TZImagePickerControllerDelegate>
  16. {
  17. UIScrollView *_backScroll;
  18. CWStarRateView *rateView;
  19. NSString *rateStr;
  20. CWStarRateView *deliveryView;
  21. NSString *deliveryStr;
  22. CWStarRateView *attitudeView;//态度
  23. NSString *attitudeStr;
  24. NSInteger starCool;
  25. MyTextView *evaluateText;
  26. UIView *_photoView;
  27. UIView *_bottomView;
  28. BOOL isOpen;
  29. NSMutableArray *imageArray;
  30. UIButton *imageBtn;
  31. UIButton *videoBtn;
  32. UILabel *phoneline;
  33. UIButton *subVideoBtn;
  34. CGFloat imgWidth;
  35. NSString *videoPath;
  36. UIImage *videoCoverImage;
  37. NSString *videoCorverStr;
  38. NSString *videoHerfStr;
  39. NSString *picThumbsStr;
  40. NSMutableArray *imageUrlArray;
  41. }
  42. @end
  43. @implementation PublishEvaluateVC
  44. -(void)initData{
  45. starCool = 0;
  46. imgWidth = (_window_width - 75)/4;
  47. imageArray = [NSMutableArray array];
  48. rateStr = @"0";
  49. deliveryStr = @"0";
  50. attitudeStr = @"0";
  51. videoPath = @"";
  52. picThumbsStr = @"";
  53. videoHerfStr = @"";
  54. videoCorverStr =@"";
  55. }
  56. - (void)viewDidLoad {
  57. [super viewDidLoad];
  58. self.titleL.text = YZMsg(@"发表评价");
  59. self.rightBtn.hidden = NO;
  60. [self.rightBtn setTitle:YZMsg(@"发布") forState:0];
  61. [self.rightBtn setTitleColor:Pink_Cor forState:0];
  62. [self initData];
  63. [self createUI];
  64. }
  65. -(void)clickNaviRightBtn
  66. {
  67. if (evaluateText.text.length < 1) {
  68. [MBProgressHUD showError:YZMsg(@"请填写评价内容")];
  69. return;
  70. }
  71. [MBProgressHUD showMessage:@""];
  72. NSLog(@"-------image:%@ \n===---video:%@",imageArray,videoPath);
  73. if (videoPath.length > 0 || imageArray.count > 0) {
  74. YBWeakSelf;
  75. [[YBStorageObj storageManeger]getCOSType:^(int code) {
  76. dispatch_async(dispatch_get_main_queue(), ^{
  77. if (code == 0) {
  78. [weakSelf startUpload];
  79. }
  80. });
  81. }];
  82. }else{
  83. [self doUploadEvaluate];
  84. }
  85. }
  86. -(void)startUpload{
  87. YBWeakSelf;
  88. dispatch_group_t group = dispatch_group_create();
  89. dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
  90. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  91. //如果有视频或图片先上传视频
  92. if (videoPath.length > 0) {
  93. dispatch_group_async(group, queue, ^{
  94. NSData *imageData = UIImagePNGRepresentation(videoCoverImage);
  95. if (!imageData) {
  96. [MBProgressHUD hideHUD];
  97. [MBProgressHUD showError:YZMsg(@"请重新选择")];
  98. return;
  99. }
  100. UIImage *herfImg = [UIImage imageWithData:imageData];
  101. NSString *imageName = [PublicObj getNameBaseCurrentTime:@"_action_video_cover.png"];
  102. [[YBStorageObj storageManeger]yb_storageImg:herfImg andName:imageName progress:^(CGFloat percent) {
  103. }complete:^(int code, NSString *key) {
  104. //图片成功
  105. videoCorverStr = key;
  106. dispatch_semaphore_signal(semaphore);
  107. }];
  108. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  109. });
  110. dispatch_group_async(group, queue, ^{
  111. //传视频
  112. NSString *videoName = [PublicObj getNameBaseCurrentTime:@"_action_video.mp4"];
  113. [[YBStorageObj storageManeger]yb_storageVideoOrVoice:videoPath andName:videoName progress:^(CGFloat percent) {
  114. } complete:^(int code, NSString *key) {
  115. videoHerfStr = key;
  116. dispatch_semaphore_signal(semaphore);
  117. }];
  118. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  119. });
  120. }
  121. if (imageArray.count > 0) {
  122. imageUrlArray = [NSMutableArray array];
  123. picThumbsStr = @"";
  124. for (int i = 0; i < imageArray.count ; i ++) {
  125. UIImage *image =imageArray[i];
  126. NSData *imageData = UIImagePNGRepresentation(image);
  127. if (!imageData) {
  128. [MBProgressHUD hideHUD];
  129. [MBProgressHUD showError:YZMsg(@"图片错误")];
  130. return;
  131. }
  132. dispatch_group_async(group, queue, ^{
  133. NSString *imageName = [PublicObj getNameBaseCurrentTime:[NSString stringWithFormat:@"_action_image%d_cover.png", i]];
  134. [[YBStorageObj storageManeger]yb_storageImg:image andName:imageName progress:^(CGFloat percent) {
  135. }complete:^(int code, NSString *key) {
  136. [imageUrlArray addObject:key];
  137. dispatch_semaphore_signal(semaphore);
  138. }];
  139. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  140. });
  141. }
  142. }
  143. dispatch_group_notify(group, queue, ^{
  144. dispatch_async(dispatch_get_main_queue(), ^{
  145. for (NSString *str in imageUrlArray) {
  146. if (picThumbsStr.length == 0) {
  147. picThumbsStr = str;
  148. }else{
  149. picThumbsStr = [NSString stringWithFormat:@"%@,%@",picThumbsStr,str];
  150. }
  151. }
  152. [weakSelf doUploadEvaluate];
  153. });
  154. NSLog(@"任务完成执行");
  155. });
  156. }
  157. -(void)createUI{
  158. _backScroll = [[UIScrollView alloc]init];
  159. _backScroll.frame = CGRectMake(0, 64+statusbarHeight, _window_width, _window_height);
  160. _backScroll.backgroundColor = Normal_SubColor;
  161. [self.view addSubview:_backScroll];
  162. UIImageView *headImg = [[UIImageView alloc]init];
  163. headImg.frame = CGRectMake(15, 10, 60, 60);
  164. headImg.layer.cornerRadius = 5;
  165. headImg.layer.masksToBounds = YES;
  166. headImg.contentMode = UIViewContentModeScaleAspectFill;
  167. [headImg sd_setImageWithURL:[NSURL URLWithString:self.model.spec_thumb]];
  168. [_backScroll addSubview:headImg];
  169. UILabel *goodsname = [[UILabel alloc]init];
  170. goodsname.frame = CGRectMake(headImg.right+10, headImg.top+10, 200, 20);
  171. goodsname.font = [UIFont systemFontOfSize:14];
  172. goodsname.textColor = [UIColor whiteColor];
  173. goodsname.text = self.model.goods_name;
  174. [_backScroll addSubview:goodsname];
  175. UILabel *specname = [[UILabel alloc]init];
  176. specname.frame = CGRectMake(headImg.right+10, goodsname.bottom+5, 200, 20);
  177. specname.font = [UIFont systemFontOfSize:13];
  178. specname.textColor = Normal_TextColor;
  179. specname.text =[NSString stringWithFormat:@"%@ x%@",self.model.spec_name,self.model.nums];
  180. [_backScroll addSubview:specname];
  181. UILabel *title1 = [[UILabel alloc]init];
  182. title1.frame = CGRectMake(headImg.left, headImg.bottom+15, 60, 20);
  183. title1.font = [UIFont systemFontOfSize:14];
  184. title1.textColor = [UIColor whiteColor];
  185. title1.text =YZMsg(@"描述相符");
  186. [_backScroll addSubview:title1];
  187. rateView = [[CWStarRateView alloc]initWithFrame:CGRectMake(title1.right+10, title1.top, 120, 20) numberOfStars:5 andSelImg:FOREGROUND_STAR_IMAGE_NAME andNormalImg:BACKGROUND_STAR_IMAGE_NAME];
  188. rateView.delegate = self;
  189. rateView.scorePercent = 0;
  190. [_backScroll addSubview:rateView];
  191. [PublicObj lineViewWithFrame:CGRectMake(0, title1.bottom+15, _window_width, 1) andColor:Line_Cor andView:_backScroll];
  192. evaluateText = [[MyTextView alloc]init];
  193. evaluateText.frame = CGRectMake(10, title1.bottom+30, _window_width-20, 125);
  194. evaluateText.placeholderColor = Normal_TextColor;
  195. evaluateText.placeholder =YZMsg(@"宝贝满足你的期望吗?说说它的优点和不足吧");
  196. evaluateText.font = [UIFont systemFontOfSize:14];
  197. evaluateText.backgroundColor = Normal_SubColor;
  198. evaluateText.textColor = [UIColor whiteColor];
  199. [_backScroll addSubview:evaluateText];
  200. _photoView = [[UIView alloc]init];
  201. _photoView.frame = CGRectMake(0, evaluateText.bottom, _window_width, imgWidth+10);
  202. [_backScroll addSubview:_photoView];
  203. NSArray *arr = @[@"添加图片",@"添加视频"];
  204. NSArray *titlearr = @[YZMsg(@"添加图片"),YZMsg(@"添加视频")];
  205. imageBtn = [UIButton buttonWithType:0];
  206. imageBtn.frame = CGRectMake(15,0, imgWidth, imgWidth);
  207. CAShapeLayer *border = [CAShapeLayer layer];
  208. //虚线的颜色
  209. border.strokeColor = Normal_TextColor.CGColor;
  210. //填充的颜色
  211. border.fillColor = [UIColor clearColor].CGColor;
  212. //设置路径
  213. border.path = [UIBezierPath bezierPathWithRect:imageBtn.bounds].CGPath;
  214. border.frame = imageBtn.bounds;
  215. //虚线的宽度
  216. border.lineWidth = 1.f;
  217. //虚线的间隔
  218. border.lineDashPattern = @[@4, @2];
  219. [imageBtn.layer addSublayer:border];
  220. [imageBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"evaluate%@",arr[0]]] forState:0];
  221. [imageBtn setTitle:titlearr[0] forState:0];
  222. [imageBtn setTitleColor:Normal_TextColor forState:0];
  223. imageBtn.titleLabel.font = [UIFont systemFontOfSize:10];
  224. imageBtn = [PublicObj setUpImgDownText:imageBtn];
  225. imageBtn.tag = 1000;
  226. [imageBtn addTarget:self action:@selector(imageBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  227. [_photoView addSubview:imageBtn];
  228. videoBtn = [UIButton buttonWithType:0];
  229. videoBtn.frame = CGRectMake(15+(1%4)*(imgWidth + 15),0, imgWidth, imgWidth);
  230. CAShapeLayer *border2 = [CAShapeLayer layer];
  231. //虚线的颜色
  232. border2.strokeColor = Normal_TextColor.CGColor;
  233. //填充的颜色
  234. border2.fillColor = [UIColor clearColor].CGColor;
  235. //设置路径
  236. border2.path = [UIBezierPath bezierPathWithRect:videoBtn.bounds].CGPath;
  237. border2.frame = videoBtn.bounds;
  238. //虚线的宽度
  239. border2.lineWidth = 1.f;
  240. //虚线的间隔
  241. border2.lineDashPattern = @[@4, @2];
  242. [videoBtn.layer addSublayer:border2];
  243. [videoBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"evaluate%@",arr[1]]] forState:0];
  244. [videoBtn setTitle:titlearr[1] forState:0];
  245. [videoBtn setTitleColor:Normal_TextColor forState:0];
  246. videoBtn.titleLabel.font = [UIFont systemFontOfSize:10];
  247. videoBtn = [PublicObj setUpImgDownText:videoBtn];
  248. videoBtn.tag = 1001;
  249. [videoBtn addTarget:self action:@selector(imageBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  250. [_photoView addSubview:videoBtn];
  251. phoneline = [[UILabel alloc]initWithFrame:CGRectMake(0, _photoView.height-1, _window_width, 1)];
  252. phoneline.backgroundColor = Line_Cor;
  253. [_photoView addSubview:phoneline];
  254. _bottomView = [[UIView alloc]init];
  255. _bottomView.frame =CGRectMake(0, _photoView.bottom, _window_width, 175);
  256. [_backScroll addSubview:_bottomView];
  257. UIButton *openBtn = [UIButton buttonWithType:0];
  258. openBtn.frame =CGRectMake(15, 10, 80, 20);
  259. openBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  260. [openBtn setTitle:YZMsg(@"公开") forState:UIControlStateNormal];
  261. [openBtn setTitle:YZMsg(@"匿名") forState:UIControlStateSelected];
  262. [openBtn setTitleColor:Pink_Cor forState:UIControlStateNormal];
  263. [openBtn setTitleColor:Normal_TextColor forState:UIControlStateSelected];
  264. [openBtn setImage:[UIImage imageNamed:@"evaluate公开"] forState:UIControlStateNormal];
  265. [openBtn setImage:[UIImage imageNamed:@"evaluate匿名"] forState:UIControlStateSelected];
  266. [openBtn addTarget:self action:@selector(openBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  267. openBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
  268. [_bottomView addSubview:openBtn];
  269. [PublicObj lineViewWithFrame:CGRectMake(0, openBtn.bottom+10, _window_width, 5) andColor:Normal_BackColor andView:_bottomView];
  270. UILabel *shoptitle = [[UILabel alloc]init];
  271. shoptitle.frame = CGRectMake(headImg.left, openBtn.bottom+25, 60, 20);
  272. shoptitle.font = [UIFont systemFontOfSize:14];
  273. shoptitle.textColor = [UIColor whiteColor];
  274. shoptitle.text =YZMsg(@"店铺评价");
  275. [_bottomView addSubview:shoptitle];
  276. UILabel *sendtitle = [[UILabel alloc]init];
  277. sendtitle.frame = CGRectMake(headImg.left, shoptitle.bottom+10, 60, 20);
  278. sendtitle.font = [UIFont systemFontOfSize:14];
  279. sendtitle.textColor = Normal_TextColor;
  280. sendtitle.text =YZMsg(@"送货服务");
  281. [_bottomView addSubview:sendtitle];
  282. deliveryView = [[CWStarRateView alloc]initWithFrame:CGRectMake(sendtitle.right+10, sendtitle.top, 120, 20) numberOfStars:5 andSelImg:FOREGROUND_STAR_IMAGE_NAME andNormalImg:BACKGROUND_STAR_IMAGE_NAME];
  283. deliveryView.delegate = self;
  284. deliveryView.scorePercent = 0;
  285. [_bottomView addSubview:deliveryView];
  286. UILabel *attitudetitle = [[UILabel alloc]init];
  287. attitudetitle.frame = CGRectMake(headImg.left, sendtitle.bottom+10, 60, 20);
  288. attitudetitle.font = [UIFont systemFontOfSize:14];
  289. attitudetitle.textColor = Normal_TextColor;
  290. attitudetitle.text =YZMsg(@"服务态度");
  291. [_bottomView addSubview:attitudetitle];
  292. attitudeView = [[CWStarRateView alloc]initWithFrame:CGRectMake(attitudetitle.right+10, attitudetitle.top, 120, 20) numberOfStars:5 andSelImg:FOREGROUND_STAR_IMAGE_NAME andNormalImg:BACKGROUND_STAR_IMAGE_NAME];
  293. attitudeView.delegate = self;
  294. attitudeView.scorePercent = 0;
  295. [_bottomView addSubview:attitudeView];
  296. }
  297. -(void)openBtnClick:(UIButton *)sender{
  298. sender.selected = !sender.selected;
  299. isOpen = sender.selected;
  300. }
  301. - (void)starRateView:(CWStarRateView *)starRateView scroePercentDidChange:(CGFloat)newScorePercent{
  302. NSLog(@"%f",newScorePercent);
  303. starCool = (NSInteger)newScorePercent;
  304. if (newScorePercent == 0.2) {
  305. starCool = 1;
  306. }else if (newScorePercent == 0.4) {
  307. starCool = 2;
  308. }else if (newScorePercent == 0.6) {
  309. starCool = 3;
  310. }else if (newScorePercent == 0.8) {
  311. starCool = 4;
  312. }else if (newScorePercent == 1) {
  313. starCool = 5;
  314. }
  315. if (starRateView == rateView) {
  316. rateStr = [NSString stringWithFormat:@"%ld",starCool];
  317. }else if (starRateView == deliveryView){
  318. deliveryStr =[NSString stringWithFormat:@"%ld",starCool];
  319. }else if (starRateView == attitudeView){
  320. attitudeStr =[NSString stringWithFormat:@"%ld",starCool];
  321. }
  322. NSLog(@"%ld",starCool);
  323. // [self checkContent];
  324. }
  325. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  326. {
  327. [self.view endEditing:YES];
  328. }
  329. -(void)imageBtnClick:(UIButton *)sender
  330. {
  331. if (sender.tag == 1000) {
  332. TZImagePickerController *imagePC = [[TZImagePickerController alloc]initWithMaxImagesCount:5-imageArray.count delegate:self];
  333. imagePC.preferredLanguage = [lagType isEqual:ZH_CN] ? @"zh-Hans":@"en";
  334. imagePC.modalPresentationStyle = 0;
  335. imagePC.showSelectBtn = YES;
  336. imagePC.allowCrop = NO;
  337. imagePC.allowPickingOriginalPhoto = NO;
  338. imagePC.oKButtonTitleColorNormal = Pink_Cor;
  339. imagePC.allowTakePicture = YES;
  340. imagePC.allowTakeVideo = NO;
  341. imagePC.allowPickingVideo = NO;
  342. imagePC.allowPickingMultipleVideo = NO;
  343. [[[YBBaseAppDelegate sharedAppDelegate] topViewController]presentViewController:imagePC animated:YES completion:nil];
  344. }else if (sender.tag == 1001){
  345. BOOL isShowLive = [[NSUserDefaults standardUserDefaults]boolForKey:@"isShowChatLive"];
  346. if (isShowLive) {
  347. [MBProgressHUD showError:YZMsg(@"直播间开启期间不可使用该操作")];
  348. return;
  349. }
  350. TZImagePickerController *imagePC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
  351. imagePC.preferredLanguage = [lagType isEqual:ZH_CN] ? @"zh-Hans":@"en";
  352. imagePC.modalPresentationStyle = 0;
  353. imagePC.showSelectBtn = NO;
  354. imagePC.allowCrop = NO;
  355. imagePC.allowPickingOriginalPhoto = NO;
  356. imagePC.oKButtonTitleColorNormal = Pink_Cor;
  357. imagePC.allowPickingImage = NO;
  358. imagePC.allowTakePicture = NO;
  359. imagePC.allowTakeVideo = YES;
  360. imagePC.allowPickingVideo = YES;
  361. imagePC.allowPickingMultipleVideo = NO;
  362. imagePC.videoMaximumDuration = live_MAX_RECORD_TIME;
  363. [[[YBBaseAppDelegate sharedAppDelegate] topViewController]presentViewController:imagePC animated:YES completion:nil];
  364. }
  365. }
  366. #pragma mark - TZImagePickerControllerDelegate
  367. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(PHAsset *)asset {
  368. NSLog(@"-dsddddddddd--%@\n===%@",asset,coverImage);
  369. [MBProgressHUD showMessage:@""];
  370. [[TZImageManager manager] getVideoOutputPathWithAsset:asset presetName:AVAssetExportPresetMediumQuality success:^(NSString *outputPath) {
  371. NSLog(@"视频导出到本地完成,沙盒路径为:%@",outputPath);
  372. if (outputPath) {
  373. [MBProgressHUD hideHUD];
  374. videoPath = outputPath;
  375. videoCoverImage = coverImage;
  376. [self addVideoimage];
  377. }else{
  378. [MBProgressHUD hideHUD];
  379. [MBProgressHUD showError:@"请重新选择(iCloud视频请先在本地相册下载后上传)"];
  380. }
  381. } failure:^(NSString *errorMessage, NSError *error) {
  382. [MBProgressHUD hideHUD];
  383. [MBProgressHUD showError:errorMessage];
  384. NSLog(@"视频导出失败:%@,error:%@",errorMessage, error);
  385. }];
  386. }
  387. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto{
  388. NSLog(@"------多选择图片--:%@",photos);
  389. [imageArray addObjectsFromArray:photos];
  390. [self setImageFrame];
  391. }
  392. -(void)addVideoimage{
  393. subVideoBtn = [UIButton buttonWithType:0];
  394. subVideoBtn.frame = CGRectMake(0, 0, videoBtn.width, videoBtn.height);
  395. [subVideoBtn setBackgroundImage:videoCoverImage forState:0];
  396. subVideoBtn.contentMode = UIViewContentModeScaleAspectFill;
  397. subVideoBtn.clipsToBounds = YES;
  398. [subVideoBtn setImage:[UIImage imageNamed:@"evaluate_播放"] forState:0];
  399. [subVideoBtn addTarget:self action:@selector(showVideo) forControlEvents:UIControlEventTouchUpInside];
  400. [videoBtn addSubview:subVideoBtn];
  401. UIButton *delBtn = [UIButton buttonWithType:0];
  402. delBtn.frame = CGRectMake(subVideoBtn.width-25, 5, 20, 20);
  403. [delBtn setBackgroundImage:[UIImage imageNamed:@"comm_del"] forState:0];
  404. [delBtn addTarget:self action:@selector(delVideoClick) forControlEvents:UIControlEventTouchUpInside];
  405. [subVideoBtn addSubview:delBtn];
  406. }
  407. -(void)delVideoClick{
  408. videoPath = @"";
  409. [subVideoBtn removeFromSuperview];
  410. subVideoBtn = nil;
  411. }
  412. -(void)showVideo{
  413. ShowDetailVC *detail = [[ShowDetailVC alloc]init];
  414. NSLog(@"=-=-=-=-=-=-=-:%@",videoPath);
  415. detail.videoPath =videoPath;
  416. detail.deleteEvent = ^(NSString *type) {
  417. };
  418. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:detail animated:NO];
  419. }
  420. -(void)setImageFrame{
  421. for (UIButton *btn in _photoView.subviews) {
  422. if (btn.tag >=3000) {
  423. [btn removeFromSuperview];
  424. }
  425. }
  426. if (imageArray.count > 0) {
  427. if (imageArray.count < 3) {
  428. _photoView.size= CGSizeMake(_window_width, imgWidth+10);
  429. _bottomView.frame =CGRectMake(0, _photoView.bottom, _window_width, 175);
  430. }else if (imageArray.count>=3){
  431. _photoView.size= CGSizeMake(_window_width, imgWidth*2+20);
  432. _bottomView.frame =CGRectMake(0, _photoView.bottom, _window_width, 175);
  433. }
  434. for (int i = 0; i < imageArray.count ; i ++) {
  435. UIButton *btn = [UIButton buttonWithType:0];
  436. btn.backgroundColor = RGB(250, 250, 250);
  437. if (i < 4) {
  438. btn.frame = CGRectMake(15+(i%4)*(imgWidth + 15), 0, imgWidth, imgWidth);
  439. }else{
  440. btn.frame = CGRectMake(15+(i%4)*(imgWidth + 15), (imgWidth+10), imgWidth, imgWidth);
  441. }
  442. btn.tag = 3000+i;
  443. [btn setImage:imageArray[i] forState:0];
  444. btn.imageView.contentMode = UIViewContentModeScaleAspectFill;
  445. btn.imageView.clipsToBounds = YES;
  446. [btn addTarget:self action:@selector(showImg:) forControlEvents:UIControlEventTouchUpInside];
  447. [_photoView addSubview:btn];
  448. UIButton *delBtn = [UIButton buttonWithType:0];
  449. delBtn.frame = CGRectMake(imgWidth-25, 5, 20, 20);
  450. [delBtn setBackgroundImage:[UIImage imageNamed:@"comm_del"] forState:0];
  451. delBtn.tag = 4000+i;
  452. [delBtn addTarget:self action:@selector(delImageClick:) forControlEvents:UIControlEventTouchUpInside];
  453. [btn addSubview:delBtn];
  454. }
  455. if (imageArray.count < 3) {
  456. imageBtn.frame = CGRectMake(15+(imageArray.count%4)*(imgWidth + 15), 0, imgWidth, imgWidth);
  457. videoBtn.frame = CGRectMake(15+((imageArray.count+1)%4)*(imgWidth + 15), 0, imgWidth, imgWidth);
  458. }else if (imageArray.count == 3){
  459. imageBtn.frame = CGRectMake(15+(imageArray.count%4)*(imgWidth + 15), 0, imgWidth, imgWidth);
  460. videoBtn.frame = CGRectMake(15+((imageArray.count+1)%4)*(imgWidth + 15), (imgWidth+10), imgWidth, imgWidth);
  461. }else if (imageArray.count > 3){
  462. imageBtn.frame = CGRectMake(15+(imageArray.count%4)*(imgWidth + 15), (imgWidth+10), imgWidth, imgWidth);
  463. videoBtn.frame = CGRectMake(15+((imageArray.count+1)%4)*(imgWidth + 15), (imgWidth+10), imgWidth, imgWidth);
  464. }
  465. [imageBtn setTitle:[NSString stringWithFormat:@"%ld/5",imageArray.count] forState:0];
  466. imageBtn = [PublicObj setUpImgDownText:imageBtn];
  467. }else{
  468. imageBtn.frame = CGRectMake(15,0, imgWidth, imgWidth);
  469. [imageBtn setTitle:YZMsg(@"添加图片") forState:0];
  470. videoBtn.frame = CGRectMake(15+(1%4)*(imgWidth + 15),0, imgWidth, imgWidth);
  471. }
  472. if (imageArray.count == 5) {
  473. imageBtn.hidden = YES;
  474. videoBtn.frame = CGRectMake(15+(imageArray.count%4)*(imgWidth + 15), (imgWidth+10), imgWidth, imgWidth);
  475. }else{
  476. imageBtn.hidden = NO;
  477. }
  478. phoneline.frame = CGRectMake(0, _photoView.height-1, _window_width, 1);
  479. }
  480. #pragma mark-----删除图片-------
  481. -(void)delImageClick:(UIButton *)sender{
  482. NSInteger index = sender.tag-4000;
  483. [imageArray removeObjectAtIndex:index];
  484. [self setImageFrame];
  485. }
  486. #pragma mark------显示图片--------
  487. -(void)showImg:(UIButton *)sender{
  488. NSInteger index = sender.tag-3000;
  489. YBImageView *imgView = [[YBImageView alloc] initWithImageArray:imageArray andIndex:index andMine:NO isDtCell:NO andBlock:^(NSArray * _Nonnull array) {
  490. }];
  491. [imgView hideDelete];
  492. [[UIApplication sharedApplication].keyWindow addSubview:imgView];
  493. }
  494. #pragma mark-----正式发布-----------
  495. -(void)doUploadEvaluate{
  496. NSString *is_anonym = @"0";
  497. if (isOpen) {
  498. is_anonym = @"1";
  499. }else{
  500. is_anonym = @"0";
  501. }
  502. NSString *url = [purl stringByAppendingFormat:@"?service=Buyer.evaluateGoodsOrder"];
  503. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"orderid":self.model.idStr,@"is_anonym":is_anonym,@"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  504. NSString *sign = [PublicObj sortString:signdic];
  505. NSDictionary *dic = @{
  506. @"uid":[Config getOwnID],
  507. @"token":[Config getOwnToken],
  508. @"orderid":self.model.idStr,
  509. @"content":evaluateText.text,
  510. @"thumbs":picThumbsStr,
  511. @"video_url":videoHerfStr,
  512. @"video_thumb":videoCorverStr,
  513. @"is_anonym":is_anonym,
  514. @"quality_points":rateStr,
  515. @"service_points":attitudeStr,
  516. @"express_points":deliveryStr,
  517. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  518. @"sign":sign
  519. };
  520. [YBNetworking postWithUrl:@"Buyer.evaluateGoodsOrder" Dic:dic Suc:^(int code, id info, NSString *msg) {
  521. [MBProgressHUD hideHUD];
  522. if (code == 0) {
  523. [MBProgressHUD showError: msg];
  524. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  525. }else{
  526. [MBProgressHUD showError:msg];
  527. }
  528. } Fail:^(id fail) {
  529. [MBProgressHUD hideHUD];
  530. }];
  531. }
  532. @end