YOUPAILCWriteMesVC.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. //
  2. // YOUPAILCWriteMesVC.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/8/3.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILCWriteMesVC.h"
  9. #import "YOUPAILCWriteMesCell.h"
  10. #import "UIViewController+TFPresent.h"
  11. #import "YOUPAILCUpdateCityVC.h"
  12. #import "PGDatePickManager.h"
  13. #import "YOUPAILZWriteMesModel.h"
  14. #import "YOUPAILZWriteMesFemaleModel.h"
  15. #import "YOUPAISelectSexView.h"
  16. #import "IQKeyboardManager.h"
  17. #import "YYKit.h"
  18. @interface YOUPAILCWriteMesVC ()<UITableViewDelegate,UITableViewDataSource,TZImagePickerControllerDelegate,PGDatePickerDelegate,UITextFieldDelegate>
  19. /* tableView */
  20. @property (strong, nonatomic) UITableView *youpaiptableView;
  21. /* inputNickField */
  22. @property (strong, nonatomic) UITextField *youpaipinputNickField;
  23. /* iconImageView */
  24. @property (strong, nonatomic) UIImageView *youpaipiconImageView;
  25. @property(nonatomic,strong)YOUPAILCUserModel* youpaipuserModel;
  26. /* finishBtn */
  27. @property (strong, nonatomic) UIButton *youpaipfinishBtn;
  28. /* */
  29. @property (strong, nonatomic) UIImage *youpaipiconImage;
  30. /* 图片url */
  31. @property (copy, nonatomic) NSString *youpaipimageUrl;
  32. /* 男 */
  33. @property (strong, nonatomic) YOUPAILZWriteMesModel *youpaipmaleModel;
  34. /* 女 */
  35. @property (strong, nonatomic) YOUPAILZWriteMesFemaleModel *youpaipfemaleModel;
  36. /* key */
  37. @property (copy, nonatomic) NSString *youpaipkeyStr;
  38. @property(strong, nonatomic)YOUPAISelectSexView *youpaipselectSex;
  39. @end
  40. @implementation YOUPAILCWriteMesVC
  41. -(void)viewWillAppear:(BOOL)animated{
  42. [super viewWillAppear:animated];
  43. [UMengRecordTool umengEnterViewWithName:NSStringFromClass(self.class)];
  44. }
  45. -(void)viewWillDisappear:(BOOL)animated{
  46. [super viewWillDisappear:animated];
  47. [UMengRecordTool umengOutViewWithName:NSStringFromClass(self.class)];
  48. }
  49. - (void)viewDidLoad {
  50. [super viewDidLoad];
  51. [UMengRecordTool umengEventCountWithId:EnterRegistration];
  52. self.view.backgroundColor = LCWhiteColor;
  53. self.youpaipuserModel = [LCSaveModel getUserModel];
  54. // 默认男生
  55. if (self.youpaipgender>0){
  56. self.youpaipuserModel.youpaipuserinfo.youpaipgender = self.youpaipgender;
  57. }
  58. // else{
  59. // self.youpaipuserModel.youpaipuserinfo.youpaipgender = 2;
  60. // }
  61. if(self.youpaipinviteCodeStr == nil)
  62. {
  63. self.youpaipinviteCodeStr = @"";
  64. }
  65. [self youpaiptableView];
  66. [self youpaiftableViewHeaderView];
  67. [self youpaifgetNicknameAndIconData];
  68. }
  69. -(YOUPAISelectSexView *)youpaipselectSex{
  70. if(_youpaipselectSex == nil){
  71. _youpaipselectSex = [YOUPAISelectSexView new];
  72. @weakify(self);
  73. // 选择男用户
  74. [_youpaipselectSex.youpaipmanBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  75. @strongify(self);
  76. self.youpaipuserModel.youpaipuserinfo.youpaipgender = 2;
  77. self.youpaipgender = 2; // 2 == 男
  78. [self youpaifrandomBtnClick]; // 随机昵称
  79. // [self youpaifrandomSelectIcon];
  80. }];
  81. // 选择女用户
  82. [_youpaipselectSex.youpaipwomanBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  83. @strongify(self);
  84. self.youpaipuserModel.youpaipuserinfo.youpaipgender = 1;
  85. self.youpaipgender = 1; // 1 == 女
  86. [self youpaifrandomBtnClick]; // 随机昵称
  87. // [self youpaifrandomSelectIcon];
  88. }];
  89. }
  90. return _youpaipselectSex;
  91. }
  92. //完成资料
  93. -(void)youpaiffinishBtnClick{
  94. if (self.youpaipuserModel.youpaipuserinfo.youpaipgender == 0){
  95. [ZCHUDHelper showTitle:@"请选择性别"];
  96. return;
  97. }
  98. UIAlertController *systemAlert = [UIAlertController alertControllerWithTitle:nil message:@"性别确定后,将无法修改,如性别不符将导致部分功能不能正常使用" preferredStyle:UIAlertControllerStyleAlert];
  99. UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  100. NSMutableDictionary *dict = [NSMutableDictionary new];
  101. [dict setObject:@(self.youpaipuserModel.youpaipuserinfo.youpaipgender) forKey:@"gender"];
  102. [dict setObject:self.youpaipuserModel.youpaipuserinfo.youpaipbirthday forKey:@"birthday"];
  103. [dict setObject:[LCTools getCityIDWithCityName:self.youpaipuserModel.youpaipuserinfo.youpaipcity] forKey:@"cityId"];
  104. //
  105. [dict setObject:[LCTools getbindData]?[LCTools getbindData]:@"" forKey:@"bindData"];
  106. [dict setObject:[LCTools getchannelCode]?[LCTools getchannelCode]:@"" forKey:@"channelCode"];
  107. [dict setObject:[LCTools getbindData]?[LCTools getbindData]:@"" forKey:@"invite_code"];
  108. [dict setObject:self.youpaipimageUrl forKey:@"avatar"];
  109. [dict setObject:self.youpaipimageUrl forKey:@"albums"];
  110. [dict setObject:self.youpaipinputNickField.text forKey:@"nickname"];
  111. [dict setObject:self.youpaipkeyStr forKey:@"key"];
  112. [dict setObject:@(25) forKey:@"age"];
  113. [LCHttpHelper requestWithURLString:UpdateUserMsgNew parameters:dict needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  114. NSDictionary* dict = (NSDictionary*)responseObject;
  115. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  116. if (code==0) {//成功
  117. [UMengRecordTool umengEventCountWithId:CompleteRegistration];
  118. YOUPAILCUserModel* userModel = [YOUPAILCUserModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  119. [LCSaveModel saveUserModel:userModel];
  120. [MobClick profileSignInWithPUID:userModel.youpaipuserinfo.youpaipuser_id];
  121. // YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  122. if (self.isFinishMsg) {
  123. userModel.youpaipuserinfo.youpaipgender = self.youpaipuserModel.youpaipuserinfo.youpaipgender;
  124. userModel.youpaipuserinfo.youpaipbirthday = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  125. userModel.youpaipuserinfo.youpaipcity = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  126. [LCSaveModel saveUserModel:userModel];
  127. [LCSaveData saveLoginMark:YES];
  128. [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
  129. [LCTools changeRootToTabbar];
  130. }else{
  131. if(userModel.youpaipuserinfo.youpaipmobile!=nil&&userModel.youpaipuserinfo.youpaipmobile.length>9)
  132. {
  133. userModel.youpaipuserinfo.youpaipgender = self.youpaipuserModel.youpaipuserinfo.youpaipgender;
  134. userModel.youpaipuserinfo.youpaipbirthday = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  135. userModel.youpaipuserinfo.youpaipcity = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  136. [LCSaveModel saveUserModel:userModel];
  137. // [LCSaveData saveLoginMark:YES];
  138. [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
  139. // [LCTools changeRootToTabbar];
  140. }
  141. else
  142. {
  143. //不做强制绑定
  144. /*
  145. userModel.userinfo.gender = self.userModel.userinfo.gender;
  146. userModel.userinfo.birthday = self.userModel.userinfo.birthday;
  147. userModel.userinfo.city = self.userModel.userinfo.city;
  148. [LCSaveModel saveUserModel:userModel];
  149. YOUPAILCBindPhoneAccountVC *bind = [[YOUPAILCBindPhoneAccountVC alloc]init];
  150. bind.inLogin = YES;
  151. [self.navigationController pushViewController:bind animated:YES];
  152. */
  153. userModel.youpaipuserinfo.youpaipgender = self.youpaipuserModel.youpaipuserinfo.youpaipgender;
  154. userModel.youpaipuserinfo.youpaipbirthday = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  155. userModel.youpaipuserinfo.youpaipcity = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  156. [LCSaveModel saveUserModel:userModel];
  157. // [LCSaveData saveLoginMark:YES];
  158. [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
  159. // [LCTools changeRootToTabbar];
  160. }
  161. }
  162. }
  163. } failure:^(NSError *error) {
  164. }];
  165. }];
  166. UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
  167. [systemAlert addAction:action2];
  168. [systemAlert addAction:action1];
  169. [self presentViewController:systemAlert animated:YES completion:nil];
  170. }
  171. - (void)youpaifupdateStartBtnStatu{
  172. if (![self.youpaipuserModel.youpaipuserinfo.youpaipnickname isEqualToString:@""] && self.youpaipuserModel.youpaipuserinfo.youpaipgender != 0 &&
  173. ![self.youpaipuserModel.youpaipuserinfo.youpaipcity isEqualToString:@""]&&
  174. self.youpaipimageUrl.length >0 &&
  175. ![self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@"0000-00-00"]&&self.youpaipimageUrl) {
  176. [self.youpaipfinishBtn setAlpha:1];
  177. self.youpaipfinishBtn.userInteractionEnabled = YES;
  178. }else{
  179. [self.youpaipfinishBtn setAlpha:0.45];
  180. self.youpaipfinishBtn.userInteractionEnabled = NO;
  181. }
  182. [self.youpaipselectSex.youpaipmanBtn setSelected:self.youpaipuserModel.youpaipuserinfo.youpaipgender==2];
  183. [self.youpaipselectSex.youpaipwomanBtn setSelected:self.youpaipuserModel.youpaipuserinfo.youpaipgender==1];
  184. self.youpaipselectSex.youpaipmanBtn.backgroundColor = (self.youpaipuserModel.youpaipuserinfo.youpaipgender==2)? LZ1DBEF9Color:LZF5F4F7Color;
  185. self.youpaipselectSex.youpaipwomanBtn.backgroundColor = (self.youpaipuserModel.youpaipuserinfo.youpaipgender==1)? LZ1DBEF9Color:LZF5F4F7Color;
  186. [self.youpaiptableView reloadData];
  187. }
  188. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  189. if (indexPath.row==1){
  190. PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
  191. datePickManager.isShadeBackground = true;
  192. datePickManager.cancelButtonFont = LCFont(15);
  193. datePickManager.confirmButtonFont = LCFont(15);
  194. datePickManager.cancelButtonTextColor = HexColorFromRGB(0x9F9DA5);
  195. datePickManager.confirmButtonTextColor = LZ273145Color;
  196. datePickManager.headerViewBackgroundColor = LCWhiteColor;
  197. datePickManager.headerHeight = 50;
  198. PGDatePicker *datePicker = datePickManager.datePicker;
  199. datePicker.backgroundColor = LCWhiteColor;
  200. datePicker.rowHeight = 35;
  201. datePicker.middleTextColor = LZ273145Color;
  202. datePicker.textColorOfSelectedRow = LZ273145Color;
  203. datePicker.textColorOfOtherRow = [LZ273145Color colorWithAlphaComponent:0.2f];
  204. datePicker.textFontOfSelectedRow = LCFont(17);
  205. datePicker.textFontOfOtherRow = LCFont(17);
  206. datePicker.lineBackgroundColor = [UIColor clearColor];
  207. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  208. NSDate* currentDate = [NSDate date];
  209. [dateFormatter setDateFormat:@"yyyy"];
  210. NSString* currentYear=[dateFormatter stringFromDate:currentDate] ;
  211. [dateFormatter setDateFormat:@"MM"];
  212. NSString* currentMonth=[dateFormatter stringFromDate:currentDate];
  213. [dateFormatter setDateFormat:@"dd"];
  214. NSString* currentDay=[dateFormatter stringFromDate:currentDate] ;
  215. NSString* maxDateStr = [NSString stringWithFormat:@"%zd-%@-%@",[currentYear integerValue]-18,currentMonth,currentDay];
  216. NSString* minDateStr = [NSString stringWithFormat:@"%zd-%@-%@",[currentYear integerValue]-50,currentMonth,currentDay];
  217. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  218. NSString* defaultDateStr;
  219. if ([self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@""]) {
  220. defaultDateStr = @"1999-03-15";
  221. }else{
  222. defaultDateStr = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  223. }
  224. NSDate *date = [dateFormatter dateFromString:defaultDateStr];//上次设置的日期
  225. [datePicker setDate:date];
  226. datePicker.maximumDate = [dateFormatter dateFromString:maxDateStr];
  227. datePicker.minimumDate = [dateFormatter dateFromString:minDateStr];
  228. datePicker.delegate = self;
  229. datePicker.datePickerType = PGDatePickerTypeLine;
  230. datePicker.isHiddenMiddleText = false;
  231. datePicker.datePickerMode = PGDatePickerModeDate;
  232. [self presentViewController:datePickManager animated:false completion:nil];
  233. }else if (indexPath.row==2){
  234. YOUPAILCUpdateCityVC* cityVC = [[YOUPAILCUpdateCityVC alloc]init];
  235. cityVC.youpaipcityName = @"";
  236. cityVC.youpaipblock = ^(NSString *cityName) {
  237. self.youpaipuserModel.youpaipuserinfo.youpaipcity = cityName;
  238. [self youpaifupdateStartBtnStatu];
  239. };
  240. [self.navigationController pushViewController:cityVC animated:YES];
  241. }
  242. }
  243. - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents{
  244. NSLog(@"dateComponents = %@", dateComponents);
  245. NSInteger year=[dateComponents year];
  246. NSInteger month=[dateComponents month];
  247. NSInteger day=[dateComponents day];
  248. NSString* birthday = [NSString stringWithFormat:@"%ld-%ld-%ld",year,month,day];
  249. self.youpaipuserModel.youpaipuserinfo.youpaipbirthday = birthday;
  250. [self youpaifupdateStartBtnStatu];
  251. }
  252. -(void)textFieldDidEndEditing:(UITextField *)textField{
  253. [IQKeyboardManager sharedManager].enable = NO;
  254. if (self.youpaipinputNickField == textField) {
  255. self.youpaipuserModel.youpaipuserinfo.youpaipnickname = textField.text;
  256. [self youpaifupdateStartBtnStatu];
  257. }
  258. }
  259. -(void)textFieldDidBeginEditing:(UITextField *)textField{
  260. [IQKeyboardManager sharedManager].enable = YES;
  261. }
  262. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  263. [self.youpaipinputNickField resignFirstResponder];//取消第一响应者
  264. return YES;
  265. }
  266. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  267. return 69;
  268. }
  269. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  270. return 3;
  271. }
  272. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  273. YOUPAILCWriteMesCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YOUPAILCWriteMesCell"];
  274. cell = [[YOUPAILCWriteMesCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YOUPAILCWriteMesCell"];
  275. cell.backgroundColor = LCWhiteColor;
  276. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  277. switch (indexPath.row) {
  278. case 0:
  279. {
  280. cell.youpaiptitleLabel.text = @"昵称";
  281. cell.youpaiparrowImageView.hidden = YES;
  282. cell.youpaiphintLabel.hidden = YES;
  283. UITextField *inputNickField = [UITextField new];
  284. self.youpaipinputNickField =inputNickField;
  285. [cell addSubview:inputNickField];
  286. [inputNickField mas_makeConstraints:^(MASConstraintMaker *make) {
  287. make.left.mas_equalTo(cell.youpaiptitleLabel.mas_right).offset(12);
  288. make.centerY.mas_equalTo(0);
  289. make.width.mas_equalTo(183);
  290. }];
  291. inputNickField.tintColor = LZD3D1D7Color;
  292. inputNickField.returnKeyType = UIReturnKeyDone;
  293. inputNickField.textColor = LZ273145Color;
  294. inputNickField.delegate = self;
  295. inputNickField.userInteractionEnabled = NO;
  296. if (self.youpaipgender != 0) {
  297. inputNickField.text = self.youpaipuserModel.youpaipuserinfo.youpaipnickname;
  298. }
  299. NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc]initWithString:@"请输入昵称"];
  300. [attrStr addAttribute:NSFontAttributeName value:LCFont(15) range:NSMakeRange(0, attrStr.length)];
  301. [attrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xCFCFCF) range:NSMakeRange(0, attrStr.length)];
  302. inputNickField.attributedPlaceholder = attrStr;
  303. inputNickField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
  304. //色子
  305. UIButton *randomBtn = [UIButton new];
  306. [cell.contentView addSubview:randomBtn];
  307. [randomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  308. make.right.mas_equalTo(-24);
  309. make.centerY.mas_equalTo(inputNickField);
  310. make.size.mas_equalTo(CGSizeMake(40, 40));
  311. }];
  312. [randomBtn setImage:[UIImage imageNamed:@"icon_ random_nickname"] forState:UIControlStateNormal];
  313. [randomBtn addTarget:self action:@selector(youpaifrandomBtnClick) forControlEvents:UIControlEventTouchUpInside];
  314. }
  315. break;
  316. case 1:
  317. {
  318. cell.youpaiptitleLabel.text = @"生日";
  319. if ([self.youpaipuserModel.youpaipuserinfo.youpaipbirthday isEqualToString:@"0000-00-00"]) {
  320. cell.youpaiphintLabel.text = @"请选择生日";
  321. cell.youpaiphintLabel.textColor = HexColorFromRGB(0x6C6B70);
  322. }else{
  323. cell.youpaiphintLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipbirthday;
  324. cell.youpaiphintLabel.textColor = LZ273145Color;
  325. }
  326. }
  327. break;
  328. case 2:
  329. {
  330. cell.youpaiptitleLabel.text = @"城市";
  331. if ([self.youpaipuserModel.youpaipuserinfo.youpaipcity isEqualToString:@""]) {
  332. [[LCLocationManager shareInstance]getLocationCity:^(NSString *city) {
  333. if (![city isEqualToString:@""]) {
  334. for (NSString* dictCity in [[LCSaveData getCityDict] allValues]) {
  335. if ([city containsString:dictCity]) {
  336. self.youpaipuserModel.youpaipuserinfo.youpaipcity = dictCity;
  337. cell.youpaiphintLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  338. cell.youpaiphintLabel.textColor = LZ273145Color;
  339. [self youpaifupdateStartBtnStatu];
  340. }
  341. }
  342. }else{
  343. cell.youpaiphintLabel.text = @"请选择城市";
  344. cell.youpaiphintLabel.textColor = HexColorFromRGB(0x6C6B70);
  345. }
  346. }];
  347. }else{
  348. cell.youpaiphintLabel.text = self.youpaipuserModel.youpaipuserinfo.youpaipcity;
  349. cell.youpaiphintLabel.textColor = LZ273145Color;
  350. }
  351. }
  352. break;
  353. default:
  354. break;
  355. }
  356. return cell;
  357. }
  358. #pragma mark-随机生成昵称和头像事件
  359. //1女2男
  360. -(void)youpaifrandomBtnClick{
  361. if (self.youpaipgender == 0){
  362. return;
  363. }
  364. if (self.youpaipgender == 1) {
  365. NSMutableArray *randomArray = [[NSMutableArray alloc] init];
  366. int r = arc4random() % [self.youpaipfemaleModel.youpaipnickname count];
  367. [randomArray addObject:[self.youpaipfemaleModel.youpaipnickname objectAtIndex:r]];
  368. WNickname *nameModel = randomArray.firstObject;
  369. self.youpaipinputNickField.text = nameModel.youpaipname;
  370. self.youpaipkeyStr = nameModel.youpaipkey;
  371. YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  372. userModel.youpaipuserinfo.youpaipnickname = nameModel.youpaipname;
  373. }else{
  374. NSMutableArray *randomArray = [[NSMutableArray alloc] init];
  375. int r = arc4random() % [self.youpaipmaleModel.youpaipnickname count];
  376. [randomArray addObject:[self.youpaipmaleModel.youpaipnickname objectAtIndex:r]];
  377. Nickname *nameModel = randomArray.firstObject;
  378. self.youpaipinputNickField.text = nameModel.youpaipname;
  379. self.youpaipkeyStr = nameModel.youpaipkey;
  380. YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  381. userModel.youpaipuserinfo.youpaipnickname = nameModel.youpaipname;
  382. }
  383. self.youpaipuserModel.youpaipuserinfo.youpaipnickname = self.youpaipinputNickField.text;
  384. [self.youpaiptableView reloadData];
  385. [self youpaifupdateStartBtnStatu];
  386. }
  387. -(void)youpaifrandomSelectIcon{
  388. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self];
  389. [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVc];
  390. imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮
  391. imagePickerVc.allowPickingVideo = NO;//是否允许选择视频
  392. imagePickerVc.allowPickingImage = YES;//是否允许选择照片
  393. imagePickerVc.allowPickingOriginalPhoto = NO;//是否选择原图
  394. imagePickerVc.showSelectedIndex = YES; //显示图片序号
  395. imagePickerVc.allowCrop = NO;//是否允许裁剪
  396. // // 裁剪框的尺寸
  397. // imagePickerVc.cropRect = CGRectMake(0, KScreenHeight/2-(KScreenWidth/3.0*4)/2, KScreenWidth,KScreenWidth/3.0*4);
  398. // 4. 照片排列按修改时间升序
  399. imagePickerVc.sortAscendingByModificationDate = YES;//按时间倒序排列图片
  400. // You can get the photos by block, the same as by delegate.
  401. // 你可以通过block或者代理,来得到用户选择的照片.
  402. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  403. [ZCHUDHelper showWithStatus:@"上传中..."];
  404. // [LCCommonHttp uploadImages:photos type:@"album" succress:^(NSArray *imageArray) {
  405. // [ZCHUDHelper dismiss];
  406. // for (NSDictionary* dict in imageArray) {
  407. // if ([[dict objectForKey:@"type"] isEqualToString:@"album"]) {
  408. // NSString* str = [dict objectForKey:@"url"];
  409. // [self.userModel.userinfo.album_list addObject:str];
  410. // [self.collectionView reloadData];
  411. // [self setupHeaderView];
  412. // }
  413. // }
  414. // }];
  415. // NSMutableArray *images = [NSMutableArray array];
  416. // for (UIImage *image in photos) {
  417. // NSData *data = UIImageJPEGRepresentation(image, 0.2f);
  418. // [images addObject:[UIImage imageWithData:data]];
  419. // }
  420. // 1通过,0待审核,2,未通过
  421. UIImage *image = [photos firstObject];
  422. [LCCommonHttp uploadWithImages:photos Type:@"album" successBlock:^(NSArray<NSString *> *ossImagePaths) {
  423. [ZCHUDHelper dismiss];
  424. NSString *uploadHead = ossImagePaths.firstObject;
  425. [self.youpaipiconImageView setImage:image];
  426. self.youpaipimageUrl = uploadHead;
  427. }];
  428. }];
  429. [self presentViewController:imagePickerVc animated:YES completion:nil];
  430. // if (self.youpaipgender == 0){
  431. // return;
  432. // }
  433. // if (self.youpaipgender == 1) { //
  434. // NSMutableArray *randomArray = [[NSMutableArray alloc] init];
  435. //
  436. //
  437. // int r = arc4random() % [self.youpaipfemaleModel.youpaipavatar count];
  438. // [randomArray addObject:[self.youpaipfemaleModel.youpaipavatar objectAtIndex:r]];
  439. //
  440. // [self.youpaipiconImageView sd_setImageWithURL:[LCTools getImageUrlWithAddress:randomArray.firstObject] placeholderImage:nil];
  441. // self.youpaipimageUrl = randomArray.firstObject;
  442. // }else{
  443. // NSMutableArray *randomArray = [[NSMutableArray alloc] init];
  444. //
  445. //
  446. // int r = arc4random() % [self.youpaipmaleModel.youpaipavatar count];
  447. // [randomArray addObject:[self.youpaipmaleModel.youpaipavatar objectAtIndex:r]];
  448. //
  449. // [self.youpaipiconImageView sd_setImageWithURL:[LCTools getImageUrlWithAddress:randomArray.firstObject] placeholderImage:nil];
  450. // self.youpaipimageUrl = randomArray.firstObject;
  451. // }
  452. // [self youpaifupdateStartBtnStatu];
  453. }
  454. //懒加载tableView
  455. -(UITableView*)youpaiptableView{
  456. if(!_youpaiptableView)
  457. {
  458. _youpaiptableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
  459. _youpaiptableView.delegate = self;
  460. _youpaiptableView.dataSource = self;
  461. if (@available(iOS 15.0, *)) {
  462. _youpaiptableView.sectionHeaderTopPadding = 0;
  463. }
  464. [self.view addSubview:_youpaiptableView ];
  465. [_youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) {
  466. make.top.mas_equalTo(NavBarHeight);
  467. make.left.mas_offset(0);
  468. make.right.mas_offset(0);
  469. make.bottom.mas_offset(0);
  470. }];
  471. // _tableView.scrollEnabled = NO;
  472. _youpaiptableView.backgroundColor = LCWhiteColor;
  473. [_youpaiptableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  474. UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 68+56+SafeHeight)];
  475. _youpaiptableView.tableFooterView = footView;
  476. UIButton *finishBtn = [UIButton new];
  477. self.youpaipfinishBtn =finishBtn;
  478. [footView addSubview:finishBtn];
  479. [finishBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  480. make.top.mas_equalTo(50);
  481. make.left.mas_equalTo(ScaleSize(27));
  482. make.right.mas_equalTo(-ScaleSize(27));
  483. make.height.mas_equalTo(56);
  484. }];
  485. finishBtn.userInteractionEnabled = NO;
  486. finishBtn.layer.cornerRadius = 56/2;
  487. finishBtn.layer.masksToBounds = YES;
  488. // [finishBtn setBackgroundColor:HexColorFromRGB(0x2A2935)];
  489. [finishBtn layoutIfNeeded];
  490. [finishBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth-54, 56) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:1] forState:UIControlStateNormal];
  491. finishBtn.titleLabel.font = [UIFont systemFontOfSize:17];
  492. finishBtn.adjustsImageWhenHighlighted = NO;
  493. [finishBtn setTitle:@"开始交友" forState:UIControlStateNormal];
  494. [finishBtn setTitleColor:HexColorFromRGB(0xffffff) forState:UIControlStateNormal];
  495. [finishBtn addTarget:self action:@selector(youpaiffinishBtnClick) forControlEvents:UIControlEventTouchUpInside];
  496. }
  497. return _youpaiptableView;
  498. }
  499. -(void)youpaiftableViewHeaderView{
  500. UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 365)];
  501. self.youpaiptableView.tableHeaderView = headerView;
  502. UILabel *titleLabel = [UILabel new];
  503. [headerView addSubview:titleLabel];
  504. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  505. make.top.mas_equalTo(40);
  506. make.left.mas_equalTo(27);
  507. }];
  508. titleLabel.font = LCBoldFont(27);
  509. titleLabel.textColor = LZ273145Color;
  510. titleLabel.text = @"让大家都认识你~";
  511. //头像
  512. UIImageView *iconImageView = [UIImageView new];
  513. self.youpaipiconImageView= iconImageView;
  514. [headerView addSubview:iconImageView];
  515. [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  516. make.centerX.mas_equalTo(0);
  517. make.top.mas_equalTo(titleLabel.mas_bottom).offset(35);
  518. make.size.mas_equalTo(CGSizeMake(124, 124));
  519. }];
  520. iconImageView.userInteractionEnabled = YES;
  521. iconImageView.contentMode = UIViewContentModeScaleAspectFill;
  522. iconImageView.clipsToBounds = YES;
  523. iconImageView.layer.cornerRadius = 124/2;
  524. iconImageView.layer.masksToBounds = YES;
  525. iconImageView.image = [UIImage imageNamed:@"vqu_images_finish_msg_n"];
  526. UITapGestureRecognizer *iconTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifopenAlbum)];
  527. [iconImageView addGestureRecognizer:iconTap];
  528. //图标
  529. UIImageView *iconImageView1 = [UIImageView new];
  530. [headerView addSubview:iconImageView1];
  531. [iconImageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  532. make.right.mas_equalTo(iconImageView.mas_right).offset(-9);
  533. make.bottom.mas_equalTo(iconImageView.mas_bottom).offset(-9);
  534. make.size.mas_equalTo(CGSizeMake(24, 24));
  535. }];
  536. iconImageView1.image = [UIImage imageNamed:@"icon_ random_header"];
  537. iconImageView1.userInteractionEnabled = YES;
  538. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifrandomSelectIcon)];
  539. [iconImageView addGestureRecognizer:tap];
  540. UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifrandomSelectIcon)];
  541. [iconImageView1 addGestureRecognizer:tap1];
  542. [headerView addSubview:self.youpaipselectSex];
  543. [_youpaipselectSex mas_makeConstraints:^(MASConstraintMaker *make) {
  544. make.left.right.mas_equalTo(0);
  545. make.bottom.mas_equalTo(0).offset(-20);
  546. make.height.mas_equalTo(75);
  547. }];
  548. }
  549. - (void)youpaifopenAlbum{
  550. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self];
  551. [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVc];
  552. imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮
  553. imagePickerVc.allowPickingVideo = NO;//是否允许选择视频
  554. imagePickerVc.allowPickingImage = YES;//是否允许选择照片
  555. imagePickerVc.allowPickingOriginalPhoto = NO;//是否选择原图
  556. imagePickerVc.showSelectedIndex = YES; //显示图片序号
  557. imagePickerVc.allowCrop = NO;//是否允许裁剪
  558. // // 裁剪框的尺寸
  559. // imagePickerVc.cropRect = CGRectMake(0, KScreenHeight/2-(KScreenWidth/3.0*4)/2, KScreenWidth,KScreenWidth/3.0*4);
  560. // 4. 照片排列按修改时间升序
  561. imagePickerVc.sortAscendingByModificationDate = YES;//按时间倒序排列图片
  562. // You can get the photos by block, the same as by delegate.
  563. // 你可以通过block或者代理,来得到用户选择的照片.
  564. __weak __typeof(self)wself = self;
  565. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  566. [ZCHUDHelper showWithStatus:@"上传中..."];
  567. // 1通过,0待审核,2,未通过
  568. [LCCommonHttp uploadWithImages:photos Type:@"album" successBlock:^(NSArray<NSString *> *ossImagePaths) {
  569. [ZCHUDHelper dismiss];
  570. wself.youpaipimageUrl = ossImagePaths.firstObject;
  571. wself.youpaipiconImageView.image = photos[0];
  572. wself.youpaipiconImage = photos[0];
  573. [wself youpaifupdateStartBtnStatu];
  574. }];
  575. }];
  576. [self presentViewController:imagePickerVc animated:YES completion:nil];
  577. }
  578. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
  579. NSLog(@"%@",photos[0]);
  580. }
  581. #pragma mark-获取昵称和头像数据
  582. -(void)youpaifgetNicknameAndIconData{
  583. @weakify(self);
  584. [LCHttpHelper requestWithURLString:Getnickname parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  585. @strongify(self);
  586. NSDictionary* dict = (NSDictionary*)responseObject;
  587. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  588. if (code==0) {//成功
  589. NSDictionary *male = dict[@"data"][@"male"];
  590. NSDictionary *female = dict[@"data"][@"female"];
  591. self.youpaipmaleModel = [YOUPAILZWriteMesModel mj_objectWithKeyValues:male];
  592. self.youpaipfemaleModel = [YOUPAILZWriteMesFemaleModel mj_objectWithKeyValues:female];
  593. [self youpaifrandomBtnClick];
  594. // [self youpaifrandomSelectIcon];
  595. }
  596. } failure:^(NSError *error) {
  597. }];
  598. }
  599. @end