JXMyBaseInFovc.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. //
  2. // JXMyBaseInFovc.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/5/29.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXMyBaseInFovc.h"
  9. #import "JXQRCodeViewController.h"
  10. #import "JXImageScrollVC.h"
  11. #import "DMScaleTransition.h"
  12. #import "JXTelAreaListVC.h"
  13. #import "RITLPhotosViewController.h"
  14. #import "JXselectSexView.h"
  15. #import "JXCameraVC.h"
  16. #import "STAlertView.h"
  17. #import "selectProvinceVC.h"
  18. @interface JXMyBaseInFovc ()<RITLPhotosViewControllerDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate,JXActionSheetVCDelegate,JXCameraVCDelegate,UITextFieldDelegate>
  19. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewH;
  20. @property (weak, nonatomic) IBOutlet UIView *updateheadIMG;
  21. @property (weak, nonatomic) IBOutlet UIImageView *IconIMG;
  22. @property (weak, nonatomic) IBOutlet UITextField *nickName;
  23. @property (weak, nonatomic) IBOutlet UILabel *sexL;
  24. @property (weak, nonatomic) IBOutlet UILabel *addrL;
  25. @property (weak, nonatomic) IBOutlet UIView *qQCodeView;
  26. @property (weak, nonatomic) IBOutlet UIView *addressView;
  27. @property (weak, nonatomic) IBOutlet UIView *sexView;
  28. @property (weak, nonatomic) IBOutlet UIButton *compleBtn;
  29. @property (nonatomic,copy) NSString *recordUrlIcon;
  30. @property (nonatomic,assign) int cityStr;
  31. @property (nonatomic,assign) int proViStr;
  32. @property (nonatomic,assign) int areaStr;
  33. @property (nonatomic,strong) JXselectSexView *selectSexView;
  34. @property (nonatomic,assign) NSInteger sexInt;
  35. @end
  36. @implementation JXMyBaseInFovc
  37. -(instancetype)init{
  38. if (self=[super init]) {
  39. [g_notify addObserver:self selector:@selector(newRequest:) name:kXMPPNewRequestNotifaction object:nil];
  40. }
  41. return self;
  42. }
  43. #pragma mark - 发送原图
  44. // - (void)photosViewController:(UIViewController *)viewController images:(NSArray<UIImage *> *)images infos:(NSArray<NSDictionary *> *)infos {
  45. //
  46. // self.IconIMG.image = images.firstObject;
  47. //
  48. // // [g_server uploadHeadImage:_user.userId image:self.IconIMG.image toView:self];
  49. //
  50. // }
  51. // #pragma mark - 发送缩略图
  52. // - (void)photosViewController:(UIViewController *)viewController thumbnailImages:(NSArray *)thumbnailImages infos:(NSArray<NSDictionary *> *)infos {
  53. // self.IconIMG.image = thumbnailImages.firstObject;
  54. // // [g_server uploadHeadImage:_user.userId image:self.IconIMG.image toView:self];
  55. // }
  56. - (void)actionSheet:(JXActionSheetVC *)actionSheet didButtonWithIndex:(NSInteger)index {
  57. if (index == 0) {
  58. UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
  59. ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  60. ipc.delegate = self;
  61. ipc.allowsEditing = YES;
  62. //选择图片模式
  63. ipc.modalPresentationStyle = UIModalPresentationCurrentContext;
  64. // [g_window addSubview:ipc.view];
  65. if (IS_PAD) {
  66. UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:ipc];
  67. [pop presentPopoverFromRect:CGRectMake((self.view.frame.size.width - 320) / 2, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  68. }else {
  69. [self presentViewController:ipc animated:YES completion:nil];
  70. }
  71. }else {
  72. JXCameraVC *vc = [JXCameraVC alloc];
  73. vc.cameraDelegate = self;
  74. vc.isPhoto = YES;
  75. vc = [vc init];
  76. [self presentViewController:vc animated:YES completion:nil];
  77. }
  78. }
  79. - (void)cameraVC:(JXCameraVC *)vc didFinishWithImage:(UIImage *)image {
  80. //_image = [ImageResize image:image fillSize:CGSizeMake(640, 640)];
  81. // [_image retain];
  82. // 照相
  83. [g_server uploadHeadImage:g_server.myself.userId image:image toView:self];
  84. self.IconIMG.image = image;
  85. }
  86. -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  87. {
  88. [picker dismissViewControllerAnimated:YES completion:nil];
  89. }
  90. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  91. {
  92. //_image = [ImageResize image:[info objectForKey:@"UIImagePickerControllerEditedImage"] fillSize:CGSizeMake(640, 640)];
  93. UIImage *imgV = [info objectForKey:@"UIImagePickerControllerEditedImage"];
  94. self.IconIMG.image=imgV;
  95. [g_server uploadHeadImage:g_server.myself.userId image:imgV toView:self];
  96. [picker dismissViewControllerAnimated:YES completion:nil];
  97. }
  98. -(void)onHeadImage{
  99. JXActionSheetVC *actionVC = [[JXActionSheetVC alloc] initWithImages:@[] names:@[Localized(@"JX_ChoosePhoto"),Localized(@"JX_TakePhoto")]];
  100. actionVC.delegate = self;
  101. [self presentViewController:actionVC animated:NO completion:nil];
  102. UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
  103. ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  104. ipc.delegate = self;
  105. ipc.allowsEditing = YES;
  106. ipc.modalPresentationStyle = UIModalPresentationFullScreen;
  107. // [g_window addSubview:ipc.view];
  108. if (IS_PAD) {
  109. UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:ipc];
  110. [pop presentPopoverFromRect:CGRectMake((self.view.frame.size.width - 320) / 2, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  111. }else {
  112. [self presentViewController:ipc animated:YES completion:nil];
  113. }
  114. // RITLPhotosViewController *photoController = RITLPhotosViewController.photosViewController;
  115. // photoController.configuration.maxCount = 1;//最大的选择数目
  116. // photoController.configuration.containVideo = NO;//选择类型,目前只选择图片不选择视频
  117. //
  118. // photoController.photo_delegate = self;
  119. // photoController.thumbnailSize = CGSizeMake(320, 320);//缩略图的尺寸
  120. // // photoController.defaultIdentifers = self.saveAssetIds;//记录已经选择过的资源
  121. //
  122. // [self presentViewController:photoController animated:true completion:^{}];
  123. }
  124. - (void)viewDidLoad {
  125. [super viewDidLoad];
  126. // Do any additional setup after loading the view from its nib.
  127. UILabel *tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT>=812?88:64, JX_SCREEN_WIDTH, 30)];
  128. tipLabel.text=@"请使用中文昵称";
  129. tipLabel.textAlignment=NSTextAlignmentCenter;
  130. tipLabel.font=[UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
  131. [self.view addSubview:tipLabel];
  132. self.topViewH.constant=JX_SCREEN_HEIGHT>=812?88+30:64+30;
  133. [self defineNavBar:@"个人信息" andRinghtBtnImg:@""];
  134. self.IconIMG.layer.cornerRadius=22;
  135. self.IconIMG.layer.masksToBounds=YES;
  136. self.compleBtn.layer.cornerRadius=5;
  137. self.compleBtn.layer.masksToBounds=YES;
  138. _selectSexView=[[JXselectSexView alloc]init];
  139. _selectSexView.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.7];
  140. _selectSexView.frame=[UIScreen mainScreen].bounds;
  141. [[UIApplication sharedApplication].keyWindow addSubview:_selectSexView];
  142. _selectSexView.hidden=YES;
  143. _nickName.delegate=self;
  144. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFiledEditChanged:)name:UITextFieldTextDidChangeNotification object:_nickName];
  145. __weak typeof(self) weakSelf=self;
  146. _selectSexView.selectBtnBlock = ^(UIButton *sender) {
  147. weakSelf.selectSexView.hidden=YES;
  148. weakSelf.sexInt=sender.tag;
  149. if (sender.tag == 0) {// 女
  150. weakSelf.sexL.text = @"男";
  151. }else {// 男
  152. weakSelf.sexL.text = @"女";
  153. }
  154. };
  155. self.nickName.text=self.user.userNickname;
  156. if ([_user.sex intValue] == 0) {// 女
  157. _sexL.text = @"女";
  158. }else {// 男
  159. _sexL.text = @"男";
  160. }
  161. //self.addrL.text=[NSString stringWithFormat:@"%@",self.user.cityId];
  162. //self.addrL.text=[NSString stringWithFormat:@"%@%@%@",_user,g_server.myself.provinceId,g_server.myself.cityId];
  163. NSString* city = [g_constant getAddressForNumber:_user.provinceId cityId:_user.cityId areaId:_user.areaId];
  164. _addrL.text = [NSString stringWithFormat:@"%@",city.length > 0 ? city : @"--"];
  165. [g_server getHeadImageLarge:self.user.userId userName:self.user.userNickname imageView:self.IconIMG];
  166. // http://47.57.16.13:8092/user/update?language=zh&access_token=b78dad1a039d4329b7f4bac634613fdf&salt=1591627301966&secret=l2qBmMzO557VWSh62nJiNA%3D%3D
  167. [self.compleBtn addTarget:self action:@selector(compleBtnClick) forControlEvents:UIControlEventTouchUpInside];
  168. [self.updateheadIMG addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onHeadImage)]];
  169. [self.sexView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sexViewView)]];
  170. [self.qQCodeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(qQCodeViewClick)]];
  171. [self.addressView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addressViewClick)]];
  172. [g_server getUser:self.userId toView:self];
  173. }
  174. //=====================================start ============
  175. - (BOOL)textFieldShouldReturn:(UITextField *)textField{
  176. [textField resignFirstResponder];
  177. //过滤非汉字字符
  178. textField.text = [self filterCharactor:textField.text withRegex:@"[^\u4e00-\u9fa5]"];
  179. if (textField.text.length >= 24) {
  180. textField.text = [textField.text substringToIndex:24];
  181. }
  182. return NO;
  183. }
  184. - (void)textFiledEditChanged:(id)notification{
  185. UITextRange *selectedRange = _nickName.markedTextRange;
  186. UITextPosition *position = [_nickName positionFromPosition:selectedRange.start offset:0];
  187. if (!position) { //// 没有高亮选择的字
  188. //过滤非汉字字符
  189. _nickName.text = [self filterCharactor:_nickName.text withRegex:@"[^\u4e00-\u9fa5]"];
  190. if (_nickName.text.length >= 24) {
  191. _nickName.text = [_nickName.text substringToIndex:24];
  192. }
  193. }else { //有高亮文字
  194. //do nothing
  195. }
  196. }
  197. //根据正则,过滤特殊字符
  198. - (NSString *)filterCharactor:(NSString *)string withRegex:(NSString *)regexStr{
  199. NSString *searchText = string;
  200. NSError *error = NULL;
  201. NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionCaseInsensitive error:&error];
  202. NSString *result = [regex stringByReplacingMatchesInString:searchText options:NSMatchingReportCompletion range:NSMakeRange(0, searchText.length) withTemplate:@""];
  203. return result;
  204. }
  205. //=====================================end=============
  206. //- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
  207. // if(textField == _birthday){
  208. //
  209. // return NO;
  210. // }else{
  211. //
  212. // return YES;
  213. // }
  214. //}
  215. /**地区选择*/
  216. - (void)addressViewClick{
  217. selectProvinceVC *vc = [[selectProvinceVC alloc] init];
  218. vc.delegate = self;
  219. vc.didSelect = @selector(onSelCity:);
  220. vc.showCity = YES;
  221. vc.showArea = NO;
  222. vc.parentId = 1;
  223. vc = [vc init];
  224. // [g_window addSubview:vc.view];
  225. [g_navigation pushViewController:vc animated:YES];
  226. }
  227. -(void)onSelCity:(selectProvinceVC*)sender{
  228. // resume.cityId = sender.cityId;
  229. // resume.provinceId = sender.provinceId;
  230. // resume.areaId = sender.areaId;
  231. // resume.countryId = 1;
  232. // _city.text = sender.selValue;
  233. _proViStr = sender.provinceId;
  234. _areaStr = sender.areaId;
  235. _cityStr =sender.cityId;
  236. _addrL.text= [NSString stringWithFormat:@"%@",sender.selValue];
  237. }
  238. - (void)didSelectTelArea:(NSDictionary *)areaCode{
  239. _addrL.text= [NSString stringWithFormat:@"%@",areaCode[@"prefix"]];
  240. }
  241. - (void)sexViewView{
  242. _selectSexView.hidden=NO;
  243. }
  244. /**完成 */
  245. - (void)compleBtnClick{
  246. JXUserObject *user=[[JXUserObject alloc]init];
  247. user.userNickname = _nickName.text.length>0?_nickName.text:self.user.userNickname;
  248. user.sex = [NSNumber numberWithBool:_sexInt];
  249. user.cityId= @(_cityStr);;
  250. user.provinceId= @(_proViStr);;
  251. user.areaId= @(_areaStr);;
  252. user.countryId=@(1);
  253. // [g_server delHeadImage:self.user.userId];
  254. //URL v /user/update?sex=1&nickname=t%E5%91%83%E5%91%83%E5%91%83&language=zh&access_token=c4892f40d8c54e7887b59bf1a6c97190&salt=1594274614096&secret=vq9AvT%2BoEkmQnVlh2g0p2A%3D%3D HTTP/1.1
  255. //[g_server getHeadImageLarge:self.user.userId userName:self.user.userNickname imageView:_IconIMG];
  256. // 更新用户信息
  257. //[user updateUserNickname];
  258. [g_server updateUser:user toView:self];
  259. }
  260. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  261. if( [aDownload.action isEqualToString:act_UserGet] ){
  262. JXUserObject* user = [[JXUserObject alloc]init];
  263. [user getDataFromDict:dict];
  264. [user insertFriend];
  265. [user updateUserNickname];
  266. [user updateRemarkName];
  267. [user updateTelephone];
  268. [self setUserInfo:user];
  269. }if( [aDownload.action isEqualToString:act_UploadHeadImage] ){
  270. JXUserObject* user = [[JXUserObject alloc]init];
  271. _recordUrlIcon=dict[@"data"][@"TUrl"];
  272. }if( [aDownload.action isEqualToString:act_UserUpdate] ){
  273. [g_notify postNotificationName:@"updateUserHeadIMG" object:nil];
  274. [g_navigation dismissViewController:self animated:NO];
  275. }
  276. }
  277. - (void)newRequest:(NSNotification *)notif {
  278. [g_server getUser:self.user.userId toView:self];
  279. }
  280. - (void) setUserInfo:(JXUserObject *)user {
  281. if (self.user.content) {
  282. user.content = self.user.content;
  283. }
  284. [g_server delHeadImage:self.user.userId];
  285. [g_server getHeadImageLarge:self.user.userId userName:self.user.userNickname imageView:_IconIMG];
  286. // 更新用户信息
  287. [user updateUserNickname];
  288. }
  289. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  290. return show_error;
  291. }
  292. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  293. return show_error;
  294. }
  295. -(void) didServerConnectStart:(JXConnection*)aDownload{
  296. if( [aDownload.action isEqualToString:act_UserGet] ){
  297. return;
  298. }
  299. }
  300. - (void)qQCodeViewClick{
  301. JXQRCodeViewController * qrVC = [[JXQRCodeViewController alloc] init];
  302. qrVC.type = QRUserType;
  303. qrVC.userId = _user.userId;
  304. qrVC.account = _user.account;
  305. qrVC.nickName = _user.userNickname;
  306. qrVC.sex = _user.sex;
  307. // [g_window addSubview:qrVC.view];
  308. [g_navigation pushViewController:qrVC animated:YES];
  309. }
  310. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  311. [self.view endEditing:YES];
  312. }
  313. @end