AdvertManagerVC.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. //
  2. // AdvertManagerVC.m
  3. // YBVideo
  4. //
  5. // Created by ybRRR on 2021/12/17.
  6. // Copyright © 2021 cat. All rights reserved.
  7. //
  8. #import "AdvertManagerVC.h"
  9. #import <MobileCoreServices/MobileCoreServices.h>
  10. #import "YBStorageObj.h"
  11. #import "MyAdvertVC.h"
  12. @interface AdvertManagerVC ()<TZImagePickerControllerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,UITextViewDelegate>
  13. {
  14. UITextField *_titleField;
  15. UITextField *_phoneField;
  16. MyTextView *_authText;
  17. UILabel *_authLb;
  18. UILabel *_authNumLb;
  19. UIButton *subBtn;
  20. NSDictionary *infosDic;
  21. NSArray *placeHolderArr;
  22. NSString *picFirstStr;
  23. NSString *picSecondStr;
  24. UIButton *deleteBtn;
  25. UILabel *zzLb;
  26. UIView *backWallView;
  27. NSMutableArray *backWallArr;
  28. NSMutableArray *upWallImgArr;//上传用标题数组
  29. }
  30. @end
  31. @implementation AdvertManagerVC
  32. -(void)getAdvertiserInfo{
  33. YBWeakSelf;
  34. [YBNetworking postWithUrl:@"User.getAdvertiserInfo" Dic:@{@"uid":[Config getOwnID],@"token":[Config getOwnToken]} Suc:^(int code, id info, NSString *msg) {
  35. if (code == 0) {
  36. infosDic = [info firstObject];
  37. }
  38. [weakSelf createBaseUI];
  39. if ([minstr([infosDic valueForKey:@"has_auth"]) isEqual:@"1"]) {
  40. NSDictionary *auth_info = [infosDic valueForKey:@"auth_info"];
  41. picFirstStr= minstr([auth_info valueForKey:@"img1_format"]);
  42. picSecondStr= minstr([auth_info valueForKey:@"img2_format"]);
  43. if (picFirstStr.length > 0) {
  44. [backWallArr addObject:picFirstStr];
  45. }
  46. if (picSecondStr.length > 0) {
  47. [backWallArr addObject:picSecondStr];
  48. }
  49. if ([minstr([auth_info valueForKey:@"status"]) isEqual:@"1"]) {
  50. self.rightBtn.hidden = NO;
  51. [self.rightBtn setTitle:YZMsg(@"我的广告") forState:0];
  52. [self.rightBtn setTitleColor:UIColor.whiteColor forState:0];
  53. }else if ([minstr([auth_info valueForKey:@"status"]) isEqual:@"-1"]){
  54. [backWallArr addObject:@""];
  55. }
  56. [self setAuthInfo:auth_info];
  57. [weakSelf addZZView];
  58. }else{
  59. [backWallArr addObject:@""];
  60. [weakSelf addZZView];
  61. }
  62. } Fail:^(id fail) {
  63. }];
  64. }
  65. -(void)setAuthInfo:(NSDictionary *)authDic{
  66. //0 认证等待审核中 1 已通过 -1 已拒绝
  67. NSString *status = minstr([authDic valueForKey:@"status"]);
  68. if ([status isEqual:@"0"] ||[status isEqual:@"1"]) {
  69. _titleField.userInteractionEnabled = NO;
  70. _phoneField.userInteractionEnabled = NO;
  71. _authText.userInteractionEnabled = NO;
  72. _authText.hidden = YES;
  73. _authNumLb.hidden = YES;
  74. _authLb.hidden = NO;
  75. zzLb.hidden = YES;
  76. _authLb.text =minstr([authDic valueForKey:@"auth_desc"]);
  77. [_authText mas_remakeConstraints:^(MASConstraintMaker *make) {
  78. make.left.equalTo(self.view).offset(27);
  79. make.right.equalTo(self.view.mas_right).offset(-27);
  80. make.top.equalTo(_authLb.mas_bottom).offset(10);
  81. make.height.mas_equalTo(1);
  82. }];
  83. }
  84. _titleField.text = minstr([authDic valueForKey:@"username"]);
  85. _phoneField.text = minstr([authDic valueForKey:@"mobile"]);
  86. _authText.text =minstr([authDic valueForKey:@"auth_desc"]);
  87. _authNumLb.text = [NSString stringWithFormat:@"%lu/50",_authText.text.length];
  88. }
  89. -(void)subBtnClick{
  90. //判断背景墙图片有木有
  91. BOOL iswallImg = NO;
  92. for (int i = 0; i < backWallArr.count; i ++) {
  93. if ([backWallArr[i] isKindOfClass:[UIImage class]]) {
  94. iswallImg = YES;
  95. break;
  96. }else{
  97. NSString *imgUrl =backWallArr[i];
  98. if (imgUrl.length > 1) {
  99. iswallImg = YES;
  100. break;
  101. }
  102. }
  103. }
  104. if (_titleField.text.length < 1) {
  105. [MBProgressHUD showError:placeHolderArr[0]];
  106. return;
  107. }else if (_phoneField.text.length < 1){
  108. [MBProgressHUD showError:placeHolderArr[1]];
  109. return;
  110. }else if(_authText.text.length < 1){
  111. [MBProgressHUD showError:placeHolderArr[2]];
  112. return;
  113. }else if (!iswallImg){
  114. [MBProgressHUD showError:YZMsg(@"请上传资质图片")];
  115. return;
  116. }
  117. [MBProgressHUD showMessage:@""];
  118. YBWeakSelf;
  119. [[YBStorageObj storageManeger]getCOSType:^(int code) {
  120. dispatch_async(dispatch_get_main_queue(), ^{
  121. if (code == 0) {
  122. [weakSelf uploadAllImage];
  123. }
  124. });
  125. }];
  126. }
  127. -(void)uploadAllImage{
  128. YBWeakSelf;
  129. dispatch_group_t group = dispatch_group_create();
  130. dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
  131. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  132. upWallImgArr = [NSMutableArray array];
  133. for (int i = 0; i < backWallArr.count; i ++) {
  134. if ([backWallArr[i] isKindOfClass:[UIImage class]]) {
  135. UIImage *image =backWallArr[i];
  136. NSData *imageData = UIImagePNGRepresentation(image);
  137. if (!imageData) {
  138. [MBProgressHUD hideHUD];
  139. [MBProgressHUD showError:YZMsg(@"图片错误")];
  140. return;
  141. }
  142. dispatch_group_async(group, queue, ^{
  143. NSString *countImgStr = [NSString stringWithFormat:@"_backImg%d.png",i];
  144. NSString *imageName = [PublicObj getNameBaseCurrentTime:countImgStr];
  145. [[YBStorageObj storageManeger]yb_storageImg:image andName:imageName progress:^(CGFloat percent) {
  146. }complete:^(int code, NSString *key) {
  147. [upWallImgArr addObject:minstr(key)];
  148. dispatch_semaphore_signal(semaphore);
  149. }];
  150. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  151. });
  152. }else{
  153. NSString *imgthumb =backWallArr[i];
  154. if (imgthumb.length > 1) {
  155. NSArray *imgArr = [imgthumb componentsSeparatedByString:@"/"];
  156. imgthumb = [imgArr lastObject];
  157. [upWallImgArr addObject:imgthumb];
  158. }
  159. }
  160. }
  161. dispatch_group_notify(group, queue, ^{
  162. dispatch_async(dispatch_get_main_queue(), ^{
  163. [self setAdvertiser];
  164. });
  165. NSLog(@"任务完成执行");
  166. });
  167. }
  168. -(void)setAdvertiser{
  169. NSString *img1Str = @"";
  170. NSString *img2Str = @"";
  171. if (upWallImgArr.count > 1) {
  172. img1Str = upWallImgArr[0];
  173. img2Str = upWallImgArr[1];
  174. }else{
  175. img1Str = upWallImgArr[0];
  176. }
  177. NSDictionary *parDic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"username":_titleField.text,@"mobile":_phoneField.text,@"auth_desc":_authText.text,@"img1":img1Str,@"img2":img2Str};
  178. [YBNetworking postWithUrl:@"User.setAdvertiser" Dic:parDic Suc:^(int code, id info, NSString *msg) {
  179. [MBProgressHUD hideHUD];
  180. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  181. [MBProgressHUD showError:msg];
  182. if (code == 0) {
  183. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  184. }
  185. });
  186. } Fail:^(id fail) {
  187. }];
  188. }
  189. -(void)clickNaviRightBtn
  190. {
  191. MyAdvertVC *myad = [[MyAdvertVC alloc]init];
  192. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:myad animated:YES];
  193. }
  194. - (void)viewDidLoad {
  195. [super viewDidLoad];
  196. self.titleL.text = YZMsg(@"广告管理");
  197. picFirstStr = @"";
  198. picSecondStr = @"";
  199. backWallArr = [NSMutableArray array];
  200. [self getAdvertiserInfo];
  201. }
  202. -(void)createBaseUI{
  203. placeHolderArr = @[YZMsg(@"请输入认证主体名称"),YZMsg(@"请输入联系方式"),YZMsg(@"请输入认证说明...")];
  204. UILabel *titleLb = [[UILabel alloc]init];
  205. titleLb.font = [UIFont systemFontOfSize:14];
  206. titleLb.textColor = UIColor.whiteColor;
  207. titleLb.text = YZMsg(@"认证主体名称");
  208. titleLb.adjustsFontSizeToFitWidth = YES;
  209. [titleLb setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  210. [self.view addSubview:titleLb];
  211. [titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  212. make.left.equalTo(self.view).offset(27);
  213. make.top.mas_equalTo(64+statusbarHeight+30);
  214. make.height.mas_equalTo(20);
  215. }];
  216. _titleField = [[UITextField alloc]init];
  217. _titleField.textColor = UIColor.whiteColor;
  218. _titleField.font =[UIFont systemFontOfSize:14];
  219. NSMutableAttributedString*holderString = [[NSMutableAttributedString alloc] initWithString:YZMsg(@"请输入认证主体名称") attributes:@{NSForegroundColorAttributeName:RGB(150,150,150)}];
  220. _titleField.attributedPlaceholder = holderString;
  221. [self.view addSubview:_titleField];
  222. [_titleField setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  223. [_titleField mas_makeConstraints:^(MASConstraintMaker *make) {
  224. make.left.equalTo(titleLb.mas_right).offset(10);
  225. make.centerY.equalTo(titleLb.mas_centerY);
  226. make.right.equalTo(self.view.mas_right).offset(-15);
  227. make.height.mas_equalTo(30);
  228. }];
  229. UIView *line1 = [[UIView alloc]init];
  230. line1.backgroundColor = RGB_COLOR(@"#2d2a3f", 1);// RGB(245, 245, 245);
  231. [self.view addSubview:line1];
  232. [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
  233. make.left.equalTo(titleLb.mas_left);
  234. make.right.equalTo(self.view.mas_right).offset(-27);
  235. make.top.equalTo(titleLb.mas_bottom).offset(15);
  236. make.height.mas_equalTo(1);
  237. }];
  238. UILabel *pTitleLb = [[UILabel alloc]init];
  239. pTitleLb.font = [UIFont systemFontOfSize:14];
  240. pTitleLb.textColor = UIColor.whiteColor;
  241. pTitleLb.text = YZMsg(@"联系方式");
  242. [pTitleLb setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  243. [self.view addSubview:pTitleLb];
  244. [pTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  245. make.left.equalTo(self.view).offset(27);
  246. make.top.equalTo(line1.mas_bottom).offset(15);
  247. make.height.mas_equalTo(20);
  248. }];
  249. _phoneField= [[UITextField alloc]init];
  250. _phoneField.textColor = UIColor.whiteColor;
  251. _phoneField.font =[UIFont systemFontOfSize:14];
  252. NSMutableAttributedString*phoneString = [[NSMutableAttributedString alloc] initWithString:YZMsg(@"请输入联系方式") attributes:@{NSForegroundColorAttributeName:RGB(150,150,150)}];
  253. _phoneField.attributedPlaceholder = phoneString;
  254. [self.view addSubview:_phoneField];
  255. [_phoneField setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  256. [_phoneField mas_makeConstraints:^(MASConstraintMaker *make) {
  257. make.left.equalTo(titleLb.mas_right).offset(10);
  258. make.centerY.equalTo(pTitleLb.mas_centerY);
  259. make.right.equalTo(self.view.mas_right).offset(-15);
  260. make.height.mas_equalTo(30);
  261. }];
  262. UIView *line2 = [[UIView alloc]init];
  263. line2.backgroundColor = RGB_COLOR(@"#2d2a3f", 1);// RGB(245, 245, 245);
  264. [self.view addSubview:line2];
  265. [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
  266. make.left.equalTo(pTitleLb.mas_left);
  267. make.right.equalTo(self.view.mas_right).offset(-27);
  268. make.top.equalTo(pTitleLb.mas_bottom).offset(15);
  269. make.height.mas_equalTo(1);
  270. }];
  271. UILabel *infoLb = [[UILabel alloc]init];
  272. infoLb.font = [UIFont systemFontOfSize:14];
  273. infoLb.textColor = UIColor.whiteColor;
  274. infoLb.text = YZMsg(@"认证说明");
  275. [infoLb setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  276. [self.view addSubview:infoLb];
  277. [infoLb mas_makeConstraints:^(MASConstraintMaker *make) {
  278. make.left.equalTo(self.view).offset(27);
  279. make.top.equalTo(line2.mas_bottom).offset(15);
  280. make.height.mas_equalTo(30);
  281. }];
  282. _authLb = [[UILabel alloc]init];
  283. _authLb.font = [UIFont systemFontOfSize:14];
  284. _authLb.textColor = UIColor.whiteColor;
  285. _authLb.hidden = YES;
  286. _authLb.numberOfLines = 0;
  287. _authLb.lineBreakMode = NSLineBreakByWordWrapping;
  288. [self.view addSubview:_authLb];
  289. [_authLb mas_makeConstraints:^(MASConstraintMaker *make) {
  290. make.left.equalTo(_phoneField);
  291. make.top.equalTo(infoLb);
  292. make.right.equalTo(self.view.mas_right).offset(-10);
  293. }];
  294. _authText = [[MyTextView alloc]init];
  295. _authText.placeholder = YZMsg(@"请输入认证说明...");
  296. _authText.placeholderColor = RGB(150,150,150);
  297. _authText.font = [UIFont systemFontOfSize:14];
  298. _authText.backgroundColor = RGB(21,17,44);
  299. _authText.textColor = UIColor.whiteColor;
  300. _authText.delegate = self;
  301. [self.view addSubview:_authText];
  302. [_authText mas_makeConstraints:^(MASConstraintMaker *make) {
  303. make.left.equalTo(pTitleLb.mas_left);
  304. make.right.equalTo(self.view.mas_right).offset(-27);
  305. make.top.equalTo(infoLb.mas_bottom).offset(10);
  306. make.height.mas_equalTo(108);
  307. }];
  308. _authNumLb = [[UILabel alloc]init];
  309. _authNumLb.textColor =RGB(150,150,150);
  310. _authNumLb.font = [UIFont systemFontOfSize:13];
  311. _authNumLb.text = @"0/50";
  312. [self.view addSubview:_authNumLb];
  313. [_authNumLb mas_makeConstraints:^(MASConstraintMaker *make) {
  314. make.right.equalTo(_authText.mas_right).offset(-5);
  315. make.bottom.equalTo(_authText.mas_bottom).offset(-5);
  316. }];
  317. zzLb = [[UILabel alloc]init];
  318. zzLb.font = [UIFont systemFontOfSize:14];
  319. zzLb.textColor = UIColor.whiteColor;
  320. zzLb.text = YZMsg(@"上传资质图片");
  321. [zzLb setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  322. [self.view addSubview:zzLb];
  323. [zzLb mas_makeConstraints:^(MASConstraintMaker *make) {
  324. make.left.equalTo(self.view).offset(27);
  325. make.top.equalTo(_authText.mas_bottom).offset(15);
  326. make.height.mas_equalTo(30);
  327. }];
  328. backWallView = [[UIView alloc]init];
  329. backWallView.backgroundColor = UIColor.clearColor;
  330. [self.view addSubview:backWallView];
  331. [backWallView mas_makeConstraints:^(MASConstraintMaker *make) {
  332. make.left.equalTo(self.view).offset(27);
  333. make.top.equalTo(zzLb.mas_bottom).offset(10);
  334. make.right.equalTo(self.view.mas_right).offset(-27);
  335. make.height.mas_equalTo(160);
  336. }];
  337. subBtn = [UIButton buttonWithType:0];
  338. [subBtn setTitleColor:UIColor.whiteColor forState:0];
  339. subBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  340. [subBtn setBackgroundColor:Pink_Cor];
  341. subBtn.layer.cornerRadius =5;
  342. subBtn.layer.masksToBounds = YES;
  343. [subBtn setTitle:YZMsg(@"开始认证") forState:0];
  344. if ([minstr([infosDic valueForKey:@"has_auth"]) isEqual:@"1"]) {
  345. //0 认证等待审核中 1 已通过 -1 已拒绝
  346. NSString *status = minstr([[infosDic valueForKey:@"auth_info"] valueForKey:@"status"]);
  347. if ([status isEqual:@"0"]) {
  348. [subBtn setTitle:YZMsg(@"审核中") forState:0];
  349. [subBtn setBackgroundColor:[UIColor grayColor]];
  350. subBtn.userInteractionEnabled = NO;
  351. }else if ([status isEqual:@"-1"]){
  352. [subBtn setTitle:YZMsg(@"审核失败,请重新上传") forState:0];
  353. }else if ([status isEqual:@"1"]){
  354. subBtn.hidden = YES;
  355. }
  356. }
  357. [self.view addSubview:subBtn];
  358. [subBtn addTarget:self action:@selector(subBtnClick) forControlEvents:UIControlEventTouchUpInside];
  359. [subBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  360. make.left.equalTo(backWallView);
  361. make.right.equalTo(backWallView);
  362. make.height.mas_equalTo(44);
  363. make.centerX.equalTo(self.view);
  364. make.top.equalTo(backWallView.mas_bottom).offset(30);
  365. }];
  366. }
  367. -(void)picBtnClick:(UIButton *)sender{
  368. YBWeakSelf;
  369. RKActionSheet *sheet = [[RKActionSheet alloc]initWithTitle:@""];
  370. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"相机") complete:^{
  371. [weakSelf clickTake];
  372. }];
  373. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"相册") complete:^{
  374. [weakSelf clickSel];
  375. }];
  376. [sheet addActionWithType:RKSheet_Cancle andTitle:YZMsg(@"取消") complete:^{
  377. }];
  378. [sheet showSheet];
  379. }
  380. -(void)addZZView{
  381. [backWallView removeAllSubViews];
  382. for (int i = 0; i < backWallArr.count; i ++) {
  383. if (i >1) {
  384. return;
  385. }
  386. UIView *backView = [[UIView alloc]init];
  387. backView.backgroundColor =UIColor.clearColor;
  388. [backWallView addSubview:backView];
  389. if (i == 0) {
  390. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  391. make.left.top.height.equalTo(backWallView);
  392. make.width.equalTo(backWallView.mas_width).multipliedBy(0.49);
  393. }];
  394. }else{
  395. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  396. make.top.right.height.equalTo(backWallView);
  397. make.width.equalTo(backWallView.mas_width).multipliedBy(0.49);
  398. }];
  399. }
  400. UIView *ImgBack = [[UIView alloc]init];
  401. ImgBack.backgroundColor =RGB(21,17,44);
  402. [backView addSubview:ImgBack];
  403. [ImgBack mas_makeConstraints:^(MASConstraintMaker *make) {
  404. make.left.top.right.equalTo(backView);
  405. make.height.equalTo(backView.mas_height).multipliedBy(0.8);
  406. }];
  407. UIImageView *addImg = [[UIImageView alloc]init];
  408. addImg.image = [UIImage imageNamed:@"zizhiadd"];
  409. [ImgBack addSubview:addImg];
  410. [addImg mas_makeConstraints:^(MASConstraintMaker *make) {
  411. make.center.equalTo(ImgBack);
  412. make.width.height.mas_equalTo(24);
  413. }];
  414. UILabel *tLb = [[UILabel alloc]init];
  415. tLb.font = [UIFont systemFontOfSize:14];
  416. tLb.textColor = RGB(150,150,150);
  417. tLb.text = YZMsg(@"资质图片");
  418. [backView addSubview:tLb];
  419. [tLb mas_makeConstraints:^(MASConstraintMaker *make) {
  420. make.centerX.equalTo(backView.mas_centerX);
  421. make.top.equalTo(ImgBack.mas_bottom).offset(10);
  422. }];
  423. UIButton *picClickBtn= [UIButton buttonWithType:0];
  424. [picClickBtn addTarget:self action:@selector(picBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  425. picClickBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
  426. [backView addSubview:picClickBtn];
  427. [picClickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  428. make.left.top.right.bottom.equalTo(ImgBack);
  429. }];
  430. BOOL haveImgBool = NO;
  431. if ([backWallArr[i] isKindOfClass:[UIImage class]]) {
  432. [picClickBtn setImage:backWallArr[i] forState:0];
  433. haveImgBool = YES;
  434. picClickBtn.userInteractionEnabled = NO;
  435. }else{
  436. NSString *imgUrl =backWallArr[i];
  437. if (imgUrl.length > 1) {
  438. [picClickBtn sd_setImageWithURL:[NSURL URLWithString:imgUrl] forState:0];
  439. haveImgBool = YES;
  440. picClickBtn.userInteractionEnabled = NO;
  441. }
  442. }
  443. UIButton *deleteBtn = [UIButton buttonWithType:0];
  444. [deleteBtn setBackgroundColor:RGB_COLOR(@"#FC3D3E", 1)];
  445. [deleteBtn setTitle:YZMsg(@"-") forState:0];
  446. [deleteBtn setTitleColor:UIColor.whiteColor forState:0];
  447. deleteBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
  448. deleteBtn.layer.cornerRadius = 10;
  449. deleteBtn.layer.masksToBounds = YES;
  450. [deleteBtn addTarget:self action:@selector(deleteimgBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  451. deleteBtn.tag = 20000+i;
  452. [backView addSubview:deleteBtn];
  453. [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  454. make.top.equalTo(ImgBack).offset(5);
  455. make.right.equalTo(ImgBack).offset(-5);
  456. make.width.height.mas_equalTo(20);
  457. }];
  458. if (haveImgBool) {
  459. deleteBtn.hidden = NO;
  460. }else{
  461. deleteBtn.hidden = YES;
  462. }
  463. if ([minstr([infosDic valueForKey:@"has_auth"]) isEqual:@"1"]) {
  464. NSDictionary *auth_info = [infosDic valueForKey:@"auth_info"];
  465. if (![minstr([auth_info valueForKey:@"status"]) isEqual:@"-1"]){
  466. deleteBtn.hidden = YES;
  467. }
  468. }
  469. }
  470. }
  471. -(void)deleteimgBtnClick:(UIButton *)sender{
  472. NSInteger tags =sender.tag-20000;
  473. NSMutableArray *arr =backWallArr;
  474. [arr removeObjectAtIndex:tags];
  475. backWallArr = arr;
  476. [self addZZView];
  477. }
  478. #pragma mark - UIImagePickerControllerDelegate
  479. //拍照
  480. -(void)clickTake {
  481. UIImagePickerController *imagePickerController = [UIImagePickerController new];
  482. imagePickerController.allowsEditing = YES;
  483. imagePickerController.delegate = self;
  484. imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  485. imagePickerController.allowsEditing = YES;
  486. imagePickerController.showsCameraControls = YES;
  487. imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
  488. //imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
  489. imagePickerController.modalPresentationStyle = 0;
  490. [self presentViewController:imagePickerController animated:YES completion:nil];
  491. }
  492. //选照
  493. -(void)clickSel {
  494. /*
  495. UIImagePickerController *imagePickerController = [UIImagePickerController new];
  496. imagePickerController.allowsEditing = YES;
  497. imagePickerController.delegate = self;
  498. imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  499. imagePickerController.allowsEditing = YES;
  500. imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
  501. [UIApplication sharedApplication].statusBarHidden = YES;
  502. if (@available(iOS 11, *)) {
  503. UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
  504. }
  505. imagePickerController.modalPresentationStyle = 0;
  506. [self presentViewController:imagePickerController animated:YES completion:nil];
  507. */
  508. TZImagePickerController *imagePC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
  509. imagePC.preferredLanguage = [lagType isEqual:ZH_CN] ? @"zh-Hans":@"en";
  510. imagePC.modalPresentationStyle = 0;
  511. imagePC.showSelectBtn = NO;
  512. imagePC.allowPickingOriginalPhoto = NO;
  513. imagePC.oKButtonTitleColorNormal = Pink_Cor;
  514. imagePC.allowTakePicture = NO;
  515. imagePC.allowTakeVideo = NO;
  516. imagePC.allowPickingVideo = NO;
  517. imagePC.allowPickingMultipleVideo = NO;
  518. imagePC.modalPresentationStyle = 0;
  519. imagePC.allowCrop = YES;
  520. imagePC.cropRect = CGRectMake(0, (_window_height-_window_width)/2, _window_width, _window_width);
  521. [[[YBBaseAppDelegate sharedAppDelegate] topViewController]presentViewController:imagePC animated:YES completion:nil];
  522. }
  523. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto{
  524. UIImage* image = photos[0];
  525. [backWallArr insertObject:image atIndex:backWallArr.count-1];
  526. [self addZZView];
  527. }
  528. -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
  529. if (@available(iOS 11, *)) {
  530. UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  531. }
  532. NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
  533. if ([type isEqualToString:@"public.image"]) {
  534. //先把图片转成NSData
  535. UIImage* image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
  536. [backWallArr insertObject:image atIndex:backWallArr.count-1];
  537. [self addZZView];
  538. [picker dismissViewControllerAnimated:YES completion:^{
  539. [UIApplication sharedApplication].statusBarHidden=NO;
  540. }];
  541. }
  542. }
  543. -(void)textViewDidChange:(UITextView *)textView
  544. {
  545. NSString *toBeString = textView.text;
  546. NSString *lang = [[[UITextInputMode activeInputModes]firstObject] primaryLanguage]; // 键盘输入模式
  547. if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写
  548. UITextRange *selectedRange = [textView markedTextRange];//获取高亮部分
  549. UITextPosition *position = [textView positionFromPosition:selectedRange.start offset:0];
  550. //没有高亮选择的字,则对已输入的文字进行字数统计和限制
  551. if (!position) {
  552. //签名tf
  553. if (textView == _authText) {
  554. if (toBeString.length > 50) {
  555. textView.text = [toBeString substringToIndex:50];
  556. _authNumLb.text = [NSString stringWithFormat:@"%lu/50",textView.text.length];
  557. }else{
  558. //signature_num.text = [NSString stringWithFormat:@"%lu/20",(20-toBeString.length)];
  559. _authNumLb.text = [NSString stringWithFormat:@"%lu/50",toBeString.length];
  560. }
  561. }
  562. }else{
  563. //有高亮选择的字符串,则暂不对文字进行统计和限制
  564. }
  565. }else{
  566. // 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况
  567. if (textView == _authText) {
  568. if (toBeString.length > 50) {
  569. textView.text = [toBeString substringToIndex:50];
  570. _authNumLb.text = [NSString stringWithFormat:@"%lu/50",textView.text.length];
  571. }else{
  572. _authNumLb.text = [NSString stringWithFormat:@"%lu/50",toBeString.length];
  573. }
  574. }
  575. }
  576. }
  577. @end