INSSettingViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. //
  2. // INSSettingViewController.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2023/9/11.
  6. //
  7. #import "INSSettingViewController.h"
  8. #import "SettingBottomView.h"
  9. #import "INSSettingBodyView.h"
  10. #import "ModifyNameViewController.h"
  11. #import "KSFullDatePicker.h"
  12. #import <RSKImageCropper/RSKImageCropper.h>
  13. #import "KSMediaManager.h"
  14. #import "AccountDeleteViewController.h"
  15. #import "ModifyPhoneCheckController.h"
  16. #import "ModifyViewController.h"
  17. #import "InstrumentChooseViewController.h"
  18. #import "UserAuthViewController.h"
  19. #import "UserInfoManager.h"
  20. #import "AccountDeleteViewController.h"
  21. #import "KSSmallChoosePicker.h"
  22. @interface INSSettingViewController ()<RSKImageCropViewControllerDelegate>
  23. @property (nonatomic, strong) INSSettingBodyView *bodyView;
  24. @property (nonatomic, strong) SettingBottomView *bottomView;
  25. @property (nonatomic, strong) NSString *userSex;
  26. @property (nonatomic, strong) NSString *birthday;
  27. @property (nonatomic, strong) KSMediaManager *mediaManager;
  28. @property (nonatomic, strong) UserInfo *mineInfo;
  29. @property (nonatomic, assign) NSInteger lastChooseIndex;
  30. @end
  31. @implementation INSSettingViewController
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // Do any additional setup after loading the view.
  35. [self allocTitle:@"设置"];
  36. [self configUI];
  37. [self requestUserMessage];
  38. }
  39. - (void)requestUserMessage {
  40. [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
  41. self.mineInfo = userInfo;
  42. [self refreshView:userInfo];
  43. }];
  44. }
  45. - (void)configUI {
  46. [self.scrollView addSubview:self.bodyView];
  47. CGFloat bodyHeight = [self.bodyView getViewHeight];
  48. [self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.right.mas_equalTo(self.view);
  50. make.top.mas_equalTo(self.scrollView.mas_top);
  51. make.height.mas_equalTo(bodyHeight);
  52. }];
  53. [self.scrollView addSubview:self.bottomView];
  54. CGFloat bottomHeight = [SettingBottomView getViewHeight];
  55. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.right.mas_equalTo(self.view);
  57. make.top.mas_equalTo(self.bodyView.mas_bottom).offset(58);
  58. make.height.mas_equalTo(bottomHeight);
  59. make.bottom.mas_equalTo(self.scrollView.mas_bottom);
  60. }];
  61. }
  62. - (void)refreshView:(UserInfo *)info {
  63. if (info.gender == 1) {
  64. self.lastChooseIndex = 1;
  65. }
  66. else {
  67. self.lastChooseIndex = 2;
  68. }
  69. [self.bodyView configUserWithUserInfo:info];
  70. }
  71. - (void)settingAction:(INSETTINGTYPE)type {
  72. switch (type) {
  73. case INSETTINGTYPE_AVATAR:
  74. {
  75. [self chooseImage];
  76. }
  77. break;
  78. case INSETTINGTYPE_NAME:
  79. {
  80. ModifyNameViewController *nameCtrl = [[ModifyNameViewController alloc] init];
  81. nameCtrl.preNickName = self.mineInfo.username;
  82. MJWeakSelf;
  83. [nameCtrl successCallback:^{
  84. [weakSelf requestUserMessage];
  85. }];
  86. [self.navigationController pushViewController:nameCtrl animated:YES];
  87. }
  88. break;
  89. case INSETTINGTYPE_SEX:
  90. {
  91. [self showModifySexAlert];
  92. }
  93. break;
  94. case INSETTINGTYPE_SUBJECT: // 9月18同步机构学员不可修改声部
  95. {
  96. // [self showInstrumentView];
  97. }
  98. break;
  99. case INSETTINGTYPE_BIRTHDAY:
  100. {
  101. [self chooseBirthDay];
  102. }
  103. break;
  104. case INSETTINGTYPE_PHONE:
  105. {
  106. ModifyPhoneCheckController *checkCtrl = [[ModifyPhoneCheckController alloc] init];
  107. [self.navigationController pushViewController:checkCtrl animated:YES];
  108. }
  109. break;
  110. case INSETTINGTYPE_PWD:
  111. {
  112. ModifyViewController *modifyVC = [[ModifyViewController alloc] init];
  113. [self.navigationController pushViewController:modifyVC animated:YES];
  114. }
  115. break;
  116. case INSETTINGTYPE_LOGOFF:
  117. {
  118. AccountDeleteViewController *deleteVC = [[AccountDeleteViewController alloc] init];
  119. [self.navigationController pushViewController:deleteVC animated:YES];
  120. }
  121. break;
  122. default:
  123. break;
  124. }
  125. }
  126. - (void)showInstrumentView {
  127. InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
  128. MJWeakSelf;
  129. [ctrl chooseCallback:^{
  130. [weakSelf requestUserMessage];
  131. }];
  132. [self.navigationController pushViewController:ctrl animated:YES];
  133. }
  134. - (void)chooseBirthDay {
  135. MJWeakSelf;
  136. KSFullDatePicker *datePicker = [[KSFullDatePicker alloc] initWithTitle:@"" date:[NSDate date] pickMode:KSDATEPICKER_MODE_DAY selectDateBlock:^(NSString *date) {
  137. [weakSelf.bodyView.birthdayLabel setText:date];
  138. weakSelf.birthday = date;
  139. [weakSelf modifyUserMessage:nil gender:self.userSex birthday:date];
  140. } cancleBlock:^{
  141. }];
  142. [datePicker show];
  143. }
  144. - (void)chooseImage {
  145. // 调用相册
  146. self.mediaManager = [[KSMediaManager alloc] init];
  147. self.mediaManager.mediaType = MEDIATYPE_PHOTO;
  148. self.mediaManager.maxPhotoNumber = 1;
  149. self.mediaManager.baseCtrl = self;
  150. self.mediaManager.needCropImage = NO;
  151. MJWeakSelf;
  152. [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
  153. UIImage *sendImg = [imageArray lastObject];
  154. // 跳转到裁剪功能
  155. RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:sendImg cropMode:RSKImageCropModeSquare];
  156. imageCropVC.avoidEmptySpaceAroundImage = YES;
  157. imageCropVC.rotationEnabled = YES;
  158. imageCropVC.delegate = weakSelf;
  159. CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:imageCropVC];
  160. navCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
  161. [weakSelf.navigationController presentViewController:navCtrl animated:YES completion:nil];
  162. }];
  163. [self.mediaManager pushImagePickerController];
  164. }
  165. - (void)updateWithUserLogo:(UIImage *)image {
  166. NSData *imgData = [UIImage turnsImaegDataByImage:image];
  167. NSString *fileName = @"image";
  168. [[KSUploadManager shareInstance] configBucketName:@"daya"];
  169. [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
  170. NSString *avatarUrl = [fileUrlArray lastObject];
  171. [self modifyUserMessage:avatarUrl gender:nil birthday:nil];
  172. } faliure:^(NSError * _Nullable error, NSString *descMessaeg) {
  173. if ([NSString isEmptyString:descMessaeg]) {
  174. [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
  175. }
  176. }];
  177. }
  178. - (void)modifyUserMessage:(NSString *)imgUrl gender:(NSString *)gender birthday:(NSString *)birthday {
  179. NSString *userName = nil;
  180. [LOADING_MANAGER showHUD];
  181. [KSNetworkingManager modifyUserMessage:KS_POST avatal:imgUrl gender:gender username:userName birthdate:birthday success:^(NSDictionary * _Nonnull dic) {
  182. [LOADING_MANAGER removeHUD];
  183. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  184. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"修改成功"];
  185. [self requestUserMessage];
  186. }
  187. else {
  188. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  189. }
  190. } faliure:^(NSError * _Nonnull error) {
  191. [LOADING_MANAGER removeHUD];
  192. }];
  193. }
  194. - (void)showModifySexAlert {
  195. KSSmallChoosePicker *picker = [[KSSmallChoosePicker alloc] initWithTitle:@"修改性别" sourceData:@[@"男",@"女"] lastChoose:self.lastChooseIndex chooseReturnWithBlock:^(NSString * _Nonnull returnValue, NSInteger chooseIndex) {
  196. self.bodyView.userSex.text = returnValue;
  197. self.lastChooseIndex = chooseIndex;
  198. if (chooseIndex == 1) {
  199. self.userSex = @"1";
  200. }
  201. else {
  202. self.userSex = @"0";
  203. }
  204. [self modifyUserSex];
  205. } cancel:^{
  206. }];
  207. [picker showPicker];
  208. }
  209. - (void)modifyUserSex {
  210. // 更新性别
  211. [self modifyUserMessage:nil gender:self.userSex birthday:nil];
  212. }
  213. - (void)logoutAction {
  214. [KSNetworkingManager logoutRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  215. [self clearSource];
  216. } faliure:^(NSError * _Nonnull error) {
  217. [self clearSource];
  218. }];
  219. }
  220. - (void)clearSource {
  221. [APPLOGIN_MANAGER logoutAction];
  222. }
  223. #pragma mark ----- lazying
  224. - (INSSettingBodyView *)bodyView {
  225. if (!_bodyView) {
  226. _bodyView = [INSSettingBodyView shareInstance];
  227. MJWeakSelf;
  228. [_bodyView settingCallback:^(INSETTINGTYPE type) {
  229. [weakSelf settingAction:type];
  230. }];
  231. }
  232. return _bodyView;
  233. }
  234. - (SettingBottomView *)bottomView {
  235. if (!_bottomView) {
  236. _bottomView = [SettingBottomView shareInstance];
  237. MJWeakSelf;
  238. [_bottomView bottomActionCallback:^{
  239. [weakSelf logoutAction];
  240. }];
  241. }
  242. return _bottomView;
  243. }
  244. #pragma mark --- RSKImageCropViewControllerDelegate
  245. /**
  246. 通知 delegate 取消裁剪图像。
  247. */
  248. - (void)imageCropViewControllerDidCancelCrop:(RSKImageCropViewController *)controller {
  249. [controller.navigationController dismissViewControllerAnimated:YES completion:nil];
  250. }
  251. /**
  252. 通知 delegate 原始图像已经被裁剪。此外,还提供了一个裁剪矩形和用于生成图像的旋转角度。
  253. */
  254. - (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect rotationAngle:(CGFloat)rotationAngle {
  255. // croppedImage
  256. [self updateWithUserLogo:croppedImage];
  257. [controller.navigationController dismissViewControllerAnimated:YES completion:nil];
  258. }
  259. /*
  260. #pragma mark - Navigation
  261. // In a storyboard-based application, you will often want to do a little preparation before navigation
  262. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  263. // Get the new view controller using [segue destinationViewController].
  264. // Pass the selected object to the new view controller.
  265. }
  266. */
  267. @end