123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- //
- // UserSettingViewController.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/5/27.
- //
- #import "UserSettingViewController.h"
- #import "UseBodyView.h"
- #import "AppDelegate.h"
- #import "CustomNavViewController.h"
- #import "JPUSHService.h"
- #import "KSBaseWKWebViewController.h"
- #import "ModifyNameViewController.h"
- #import "PasswordCheckViewController.h"
- #import "ModifyPhoneCheckController.h"
- #import "KSMediaManager.h"
- #import "UserAuthViewController.h"
- #import "UserInfoManager.h"
- #import "InstrumentChooseViewController.h"
- #import "UserInfo.h"
- #import <KSFullDatePicker.h>
- #import "UserInfoManager.h"
- #import <RSKImageCropper/RSKImageCropper.h>
- #import <KSSmallChoosePicker.h>
- #import <UIImageView+DisplayImage.h>
- @interface UserSettingViewController ()<RSKImageCropViewControllerDelegate>
- @property (nonatomic, strong) UseBodyView *bodyView;
- @property (nonatomic, strong) NSString *userSex;
- @property (nonatomic, strong) KSMediaManager *mediaManager;
- @property (nonatomic, strong) UserInfo *mineInfo;
- @property (nonatomic, strong) NSString *birthday;
- @property (nonatomic, assign) NSInteger lastChooseIndex;
- @property (nonatomic, strong) UIImage *preDisplayImage;
- @end
- @implementation UserSettingViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"设置"];
- [self configUI];
- [self requestUserMessage];
- [self requestSubjectInfo];
- }
- - (void)requestSubjectInfo {
- [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- UserInfo *studentInfo = [[UserInfo alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
- [self refreshStudentSubject:studentInfo.subjectName];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)refreshStudentSubject:(NSString *)subjectName {
- if ([NSString isEmptyString:subjectName]) {
- subjectName = @"请选择乐器";
- }
- self.bodyView.subjectLabel.text = subjectName;
- }
- - (void)requestUserMessage {
-
- [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
- self.mineInfo = userInfo;
- [self configMessage];
- }];
- }
- - (void)configMessage {
- if (![NSString isEmptyString:self.mineInfo.heardUrl]) {
- [self.bodyView.userAvatal displayImageWithUrl:[NSURL URLWithString:[self.mineInfo.heardUrl getUrlEndcodeString]] placeholder:self.preDisplayImage defaultImage:[UIImage imageNamed:STUDENT_AVATAR] callback:^(UIImage * _Nonnull image) {
- self.preDisplayImage = image;
- }];
- }
- else {
- [self.bodyView.userAvatal setImage:[UIImage imageNamed:STUDENT_AVATAR]];
- self.preDisplayImage = [UIImage imageNamed:STUDENT_AVATAR];
- }
- self.bodyView.nickNameLabel.text = [NSString returnNoNullStringWithString:self.mineInfo.username];
- NSString *userSex = @"";
- if (self.mineInfo.gender == 1) {
- userSex = @"男";
- self.userSex = @"1";
- self.lastChooseIndex = 1;
- }
- else {
- userSex = @"女";
- self.userSex = @"0";
- self.lastChooseIndex = 2;
- }
- self.bodyView.genderLabel.text = userSex;
- self.bodyView.phoneLabel.text = [NSString returnNoNullStringWithString:self.mineInfo.phone];
- NSString *authStatus = @"";
- if (USER_MANAGER.hasAuth) {
- authStatus = @"已认证";
- }
- else {
- authStatus = @"未认证";
- }
- self.bodyView.authStatusLabel.text = authStatus;
-
- if ([NSString isEmptyString:self.mineInfo.birthdate]) {
- self.bodyView.birthdayLabel.text = @"未设置";
- }
- else {
- self.bodyView.birthdayLabel.text = [[self.mineInfo.birthdate componentsSeparatedByString:@" "] firstObject];
- }
- }
- - (void)configUI {
- [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.view.mas_top);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
- }];
- self.bodyView = [UseBodyView shareInstance];
- CGFloat height = [self.bodyView getViewHeight];
- CGFloat viewHeight = height > KPortraitHeight - kNaviBarHeight - iPhoneXSafeBottomMargin ? height : KPortraitHeight - kNaviBarHeight - iPhoneXSafeBottomMargin;
- [self.scrollView addSubview:self.bodyView];
- [self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.right.left.mas_equalTo(self.view);
- make.height.mas_equalTo(viewHeight);
- }];
- [self.scrollView setContentSize:CGSizeMake(kScreenWidth, viewHeight)];
- KSWeakSelf(weakSelf);
- [self.bodyView userSettingAction:^(USERSETTING type) {
- [weakSelf operationAction:type];
- }];
- }
- - (void)operationAction:(USERSETTING)type {
- switch (type) {
- case USERSETTING_AVATAL: // 头像
- {
- [self chooseImage];
- }
- break;
- case USERSETTING_NAME:
- {
- ModifyNameViewController *nameCtrl = [[ModifyNameViewController alloc] init];
- nameCtrl.preNickName = self.mineInfo.username;
- MJWeakSelf;
- [nameCtrl successCallback:^{
- [weakSelf requestUserMessage];
- }];
- [self.navigationController pushViewController:nameCtrl animated:YES];
- }
- break;
- case USERSETTING_SEX:
- {
- [self showModifySexAlert];
- }
- break;
- case USERSETTING_PHONE:
- {
- ModifyPhoneCheckController *checkCtrl = [[ModifyPhoneCheckController alloc] init];
- [self.navigationController pushViewController:checkCtrl animated:YES];
- }
- break;
- case USERSETTING_PWD:
- {
- PasswordCheckViewController *modifyVC = [[PasswordCheckViewController alloc] init];
- [self.navigationController pushViewController:modifyVC animated:YES];
- }
- break;
- case USERSETTING_BIRTHDAY:
- {
- [self chooseBirthDay];
- }
- break;
- case USERSETTING_SUBJECT:
- {
- [self showInstrumentView];
- }
- break;
- case USERSETTING_VEFI:
- {
- if (USER_MANAGER.hasAuth == NO) {
- UserAuthViewController *ctrl = [[UserAuthViewController alloc] init];
- MJWeakSelf;
- [ctrl sureCallback:^{
- [weakSelf requestUserMessage];
- }];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- break;
- case USERSETTING_LOGOUT:
- {
- [self logoutAction];
- }
- break;
- default:
- break;
- }
- }
- - (void)showInstrumentView {
- InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
- MJWeakSelf;
- [ctrl chooseCallback:^{
- [weakSelf requestSubjectInfo];
- }];
- [self.navigationController pushViewController:ctrl animated:YES];
-
- }
- - (void)chooseBirthDay {
- NSDate *data = [NSDate date];
-
- if (![NSString isEmptyString:self.mineInfo.birthdate]) {
- NSString *birthday = self.mineInfo.birthdate;
- NSDateFormatter *formatter = [NSObject getDateformatter];
- [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- NSDate *birthdate = [formatter dateFromString:birthday];
- if (birthdate) {
- data = birthdate;
- }
- }
- MJWeakSelf;
- KSFullDatePicker *datePicker = [[KSFullDatePicker alloc] initWithTitle:@"" date:data pickMode:KSDATEPICKER_MODE_DAY sureButtonColor:CLIENT_THEMECOLOR selectDateBlock:^(NSString *date) {
- [weakSelf.bodyView.birthdayLabel setText:date];
- weakSelf.birthday = date;
- [weakSelf modifyUserMessage:nil gender:self.userSex birthday:date];
- } cancleBlock:^{
-
- }];
- [datePicker show];
- }
- - (void)chooseImage {
- // 调用相册
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = MEDIATYPE_PHOTO;
- self.mediaManager.maxPhotoNumber = 1;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.needCropImage = NO;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
- UIImage *sendImg = [imageArray lastObject];
- // 跳转到裁剪功能
- RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:sendImg cropMode:RSKImageCropModeSquare];
- imageCropVC.avoidEmptySpaceAroundImage = YES;
- imageCropVC.rotationEnabled = YES;
- imageCropVC.delegate = weakSelf;
- CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:imageCropVC];
- navCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
- [weakSelf.navigationController presentViewController:navCtrl animated:YES completion:nil];
- }];
- [self.mediaManager pushImagePickerController];
- }
- - (void)updateWithUserLogo:(UIImage *)image {
- NSData *imgData = [UIImage turnsImaegDataByImage:image];
- NSString *fileName = @"image";
- [UPLOAD_MANAGER configWithfilePath:@"/user/"];
- [UPLOAD_MANAGER uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- NSString *avatarUrl = [fileUrlArray lastObject];
- [self modifyUserMessage:avatarUrl gender:nil birthday:nil];
- } faliure:^(NSError * _Nullable error, NSString *descMessaeg) {
- if (![NSString isEmptyString:descMessaeg]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
- }
- }];
- }
- - (void)modifyUserMessage:(NSString *)imgUrl gender:(NSString *)gender birthday:(NSString *)birthday {
- NSString *userName = nil;
- [LOADING_MANAGER showCustomLoading:@"加载中..."];
- [KSNetworkingManager modifyUserMessage:KS_POST avatal:imgUrl gender:gender username:userName birthdate:birthday success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeCustomLoading];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"修改成功"];
- [self requestUserMessage];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeCustomLoading];
- }];
- }
- - (void)showModifySexAlert {
- KSSmallChoosePicker *picker = [[KSSmallChoosePicker alloc] initWithTitle:@"修改性别" sourceData:@[@"男",@"女"] lastChoose:self.lastChooseIndex chooseColor:CLIENT_THEMECOLOR chooseReturnWithBlock:^(NSString * _Nonnull returnValue, NSInteger chooseIndex) {
- self.bodyView.genderLabel.text = returnValue;
- self.lastChooseIndex = chooseIndex;
- if (chooseIndex == 1) {
- self.userSex = @"1";
- }
- else {
- self.userSex = @"0";
- }
- [self modifyUserSex];
- } cancel:^{
-
- }];
- [picker showPicker];
- }
- - (void)modifyUserSex {
- // 更新性别
- [self modifyUserMessage:nil gender:self.userSex birthday:nil];
- }
- - (void)logoutAction {
-
- [KSNetworkingManager logoutRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- [self clearSource];
- } faliure:^(NSError * _Nonnull error) {
- [self clearSource];
- }];
- }
- - (void)clearUMCount {
- [USER_MANAGER sendUMEvent:@"klx_logout"];
- [USER_MANAGER stopCountUMEvent];
- }
- - (void)clearSource {
- [APPLOGIN_MANAGER logoutActionWithMsg:@""];
- }
- #pragma mark --- RSKImageCropViewControllerDelegate
- /**
- 通知 delegate 取消裁剪图像。
- */
- - (void)imageCropViewControllerDidCancelCrop:(RSKImageCropViewController *)controller {
- self.zh_statusBarHidden = NO;
- [controller.navigationController dismissViewControllerAnimated:YES completion:nil];
- }
- /**
- 通知 delegate 原始图像已经被裁剪。此外,还提供了一个裁剪矩形和用于生成图像的旋转角度。
- */
- - (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect rotationAngle:(CGFloat)rotationAngle {
- self.zh_statusBarHidden = NO;
- // croppedImage
- [self updateWithUserLogo:croppedImage];
- [controller.navigationController dismissViewControllerAnimated:YES completion:nil];
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|