123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- //
- // XYSkillCertificationApplyViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/10/26.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYSkillCertificationApplyViewController.h"
- #import "XYSkillCertificationApplyPhaseView.h"
- #import "XYSkillCertificationApplyOnePhaseView.h"
- #import "XYCertificationSkillModel.h"
- #import "XYSkillCertificationApplyViewModel.h"
- #import "XYSkillVertificationApplyIntroduceView.h"
- #import "XYSkillCertificationApplyTwoPhaseView.h"
- #import "XYSkillCertificationApplyThreePhaseView.h"
- #import "XYSearchFamilyViewController.h"
- #import "XYFamilyModel.h"
- #import "XYCertificationSkillsMainViewController.h"
- #import "XYCertificationSkillsSelectedViewController.h"
- @interface XYSkillCertificationApplyViewController ()<XYSkillCertificationApplyOnePhaseViewDelegate, TZImagePickerControllerDelegate, XYSkillCertificationApplyTwoPhaseViewDelegate, XYSkillCertificationApplyThreePhaseViewDelegate, XYSearchFamilyViewControllerDelegate>
- @property (nonatomic, strong) XYSkillCertificationApplyViewModel *viewModel;
- @property (nonatomic, strong) XYSkillCertificationApplyPhaseView *phaseView;
- @property (nonatomic, strong) XYSkillCertificationApplyOnePhaseView *onePhaseView;
- @property (nonatomic, strong) XYSkillCertificationApplyTwoPhaseView *twoPhaseView;
- @property (nonatomic, strong) XYSkillCertificationApplyThreePhaseView *threePhaseView;
- @end
- @implementation XYSkillCertificationApplyViewController
- - (void)dealloc {
-
- if (_twoPhaseView) {
- [_twoPhaseView clear];
- }
- }
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.prefersNavigationBarBottomLineHidden = NO;
- self.keyboardEnable = NO;
- self.shouldAutoToolbarEnable = NO;
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self setupUI];
-
- // 设置默认值
- [self setupDefaultlue];
- }
- - (void)setupDefaultlue {
- if (StringIsNotEmpty(self.skillId)) {
- // 有默认技能
- for (XYCertificationSkillModel *model in ApplicationDelegate.appConfigModel.skills) {
- if ([model.skillId isEqualToString:self.skillId]) {
- // 设置默认技能
- self.viewModel.skillId = model.skillId;
- self.viewModel.skillName = model.skillName;
- // if (model.skillTags.count > 0) {
- // // 设置默认技能的标签
- // if (StringIsNotEmpty(self.tagId)) {
- // for (XYCertificationSkillTagModel *tagModel in model.skillTags) {
- // if ([tagModel.tagId isEqualToString:self.tagId]) {
- // self.viewModel.skillTagId = tagModel.tagId;
- // self.viewModel.skillTagName = tagModel.tagName;
- // }
- // }
- // }else {
- // XYCertificationSkillTagModel *tagModel = [model.skillTags firstObject];
- // self.viewModel.skillTagId = tagModel.tagId;
- // self.viewModel.skillTagName = tagModel.tagName;
- // }
- // }
- [self.onePhaseView setupViewModel:self.viewModel];
- break;
- }
- }
- }
- }
- - (void)bindViewModel {
- self.viewModel = XYSkillCertificationApplyViewModel.new;
- }
- - (void)requestRemoteData {
- [self.viewModel loadData:^(id _Nullable responseModel) {
- if (StringIsNotEmpty(self.viewModel.familyId)) {
- self.threePhaseView.familyIdButton.enabled = NO;
- [self.threePhaseView setupFamilyName:self.viewModel.familyName];
- }
- } failure:^(ZYLNetworkError * _Nullable error) {
-
- }];
- }
- #pragma mark — UI
- - (void)setupUI {
- self.title = kLocalizedString(@"技能申请");
-
- [self.view addSubview:self.phaseView];
- [self.view addSubview:self.onePhaseView];
- [self.view addSubview:self.twoPhaseView];
- [self.view addSubview:self.threePhaseView];
- }
- #pragma mark — XYSkillCertificationApplyOnePhaseViewDelegate
- - (void)onePhaseViewSelectedSkillAction {
-
- NSMutableArray *tempTitle = [NSMutableArray array];
- for (XYCertificationSkillModel *model in ApplicationDelegate.appConfigModel.skills) {
- [tempTitle addObject:model.skillName];
- }
-
- BasePickerViewController *skillPicker = [[BasePickerViewController alloc] initWithTitle:kLocalizedString(@"选择服务技能") dataArray:tempTitle target:self sureBlock:^(NSInteger index, id _Nonnull info) {
- XYCertificationSkillModel *model = ApplicationDelegate.appConfigModel.skills[index];
- self.viewModel.skillId = model.skillId;
- self.viewModel.skillName = model.skillName;
-
- // 选择默认标签
- // if (model.skillTags.count > 0) {
- // XYCertificationSkillTagModel *tagModel = [model.skillTags firstObject];
- // self.viewModel.skillTagId = tagModel.tagId;
- // self.viewModel.skillTagName = tagModel.tagName;
- // }
- self.viewModel.skillTagId = @"";
- self.viewModel.skillTagName = @"";
- [self.onePhaseView setupNextStatus:NO];
- [self.onePhaseView setupViewModel:self.viewModel];
- }];
- [skillPicker showWithController:self];
- }
- - (void)onePhaseViewSelectedTagAction {
- if (StringIsEmpty(self.viewModel.skillId)) {
- [SVProgressHUD showInfoWithStatus:kLocalizedString(@"请先选择服务技能")];
- return;
- }
- NSMutableArray *tempTagTitle = [NSMutableArray array];
- for (XYCertificationSkillModel *model in ApplicationDelegate.appConfigModel.skills) {
- if ([model.skillId isEqualToString:self.viewModel.skillId]) {
- for (XYCertificationSkillTagModel *tagModel in model.skillTags) {
- [tempTagTitle addObject:tagModel.tagName];
- }
- break;
- }
- }
- if (tempTagTitle.count == 0) {
- [SVProgressHUD showInfoWithStatus:kLocalizedString(@"没有标签")];
- return;
- }
- BasePickerViewController *skillPicker = [[BasePickerViewController alloc] initWithTitle:kLocalizedString(@"选择服务技能") dataArray:tempTagTitle target:self sureBlock:^(NSInteger index, id _Nonnull info) {
- for (XYCertificationSkillModel *model in ApplicationDelegate.appConfigModel.skills) {
- if ([model.skillId isEqualToString:self.viewModel.skillId]) {
- if (model.skillTags.count > 0) {
- XYCertificationSkillTagModel *tagModel = model.skillTags[index];
- self.viewModel.skillTagId = tagModel.tagId;
- self.viewModel.skillTagName = tagModel.tagName;
- }
- if (StringIsNotEmpty(self.viewModel.skillTagId)) {
- [self.onePhaseView setupNextStatus:YES];
- }else {
- [self.onePhaseView setupNextStatus:NO];
- }
- [self.onePhaseView setupViewModel:self.viewModel];
- break;
- }
- }
- }];
- [skillPicker showWithController:self];
- }
- - (void)onePhaseViewSelectedIntroduceAction {
- XYSkillVertificationApplyIntroduceView *introduceView = [[XYSkillVertificationApplyIntroduceView alloc] initWithTitle:kLocalizedString(@"输入技能介绍") content:self.viewModel.skillIntro actionBlock:^(NSString * _Nonnull content) {
- self.viewModel.skillIntro = content;
-
- [self.onePhaseView setupViewModel:self.viewModel];
- }];
- [introduceView showWithView:self.view];
- }
- - (void)onePhaseViewSelectedImageAction {
- // 为空则直接添加
- TZImagePickerController *picker = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
- picker.allowTakeVideo = NO;
- picker.allowPickingVideo = NO;
- picker.allowCrop = YES;
- CGFloat height = SCREEN_WIDTH/16*9;
- picker.cropRect = CGRectMake(0, (SCREEN_HEIGHT - height)/2, SCREEN_WIDTH, height);
- [self presentViewController:picker animated:YES completion:nil];
- }
- - (void)onePhaseViewNextAction {
- if (self.viewModel.skillImage && StringIsEmpty(self.viewModel.skillImageUrl)) {
- // 上传图片
- [self uploadHeadImage:self.viewModel.skillImage];
- }else {
- [self.phaseView setupPhaseStatusNo:2];
- self.onePhaseView.hidden = YES;
- self.twoPhaseView.hidden = NO;
- }
- }
- #pragma mark -TZImagePickerControllerDelegate 添加图片回调
- - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos {
- if (photos.count == 0) {
- return;
- }
- self.viewModel.skillImage = [photos firstObject];
- self.viewModel.skillImageUrl = @"";
- [self.onePhaseView setupViewModel:self.viewModel];
- }
- #pragma mark — XYSkillCertificationApplyTwoPhaseViewDelegate
- - (void)twoPhaseViewDeleteVoiceAction {
- [self.viewModel deleteTempVoiceFile];
- }
- - (void)twoPhaseViewNextAction {
- if (StringIsEmpty(self.viewModel.voiceUrl)) {
- // 为空则需要上传语音文件
- [self uploadVoiceFile];
- }else {
- [self.phaseView setupPhaseStatusNo:3];
- self.twoPhaseView.hidden = YES;
- self.threePhaseView.hidden = NO;
- }
- }
- #pragma mark — XYSkillCertificationApplyThreePhaseViewDelegate
- - (void)threePhaseViewSelectedFamilyAction {
- if (StringIsEmpty(self.viewModel.familyId)) {
- // 选择家族
- XYSearchFamilyViewController *controller = XYSearchFamilyViewController.new;
- controller.delegate = self;
- [self.navigationController pushViewController:controller animated:YES];
- }
- }
- - (void)threePhaseViewSubmitAction {
- CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"提交审核") message:[NSString stringWithFormat:kLocalizedString(@"您申请的家族为【%@】,确认提交吗?"),self.viewModel.familyName] sure:kLocalizedString(@"确认") cancel:kLocalizedString(@"再想想") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
- if ([title isEqualToString:kLocalizedString(@"确认")]) {
- [self submitCertificationSkillInfo];
- }
- }];
- [al show];
- }
- - (void)submitCertificationSkillInfo {
- WeakSelf
- [self.viewModel addSkillAudit:^(id _Nullable responseModel) {
-
- [SVProgressHUD showSuccessWithStatus:kLocalizedString(@"已提交")];
- [weakSelf removeControllerWithClass:XYCertificationSkillsSelectedViewController.class];
- [weakSelf removeControllerWithClass:XYCertificationSkillsMainViewController.class];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-
- [weakSelf.navigationController pushViewController:XYCertificationSkillsMainViewController.new animated:YES];
- });
- } failure:^(ZYLNetworkError * _Nullable error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- #pragma mark — XYSearchFamilyViewControllerDelegate
- - (void)didSelectedFamilyFinishModel:(XYFamilyModel *)model {
- if (StringIsNotEmpty(model.familyId)) {
- self.viewModel.familyId = [model.familyId copy];
- self.viewModel.familyName = [model.familyName copy];
- self.viewModel.familyNo = [model.familyNo copy];
- [self.threePhaseView setupFamilyName:self.viewModel.familyName];
- }
- }
- - (void)uploadHeadImage:(UIImage *)image {
- // 上传图片
- [SVProgressHUD showWithStatus:kLocalizedString(@"上传中...")];
- [[UploadManager new] getSkillImagePhotoUploadConfigSuccessHandler:^(ZYLResponseModel *responseModel) {
- if (responseModel.codeState) {
- NSDictionary *dict = responseModel.result[@"data"];
- [[UploadManager new] dispatchUploadImage:image info:nil uploadParameter:dict withProgress:^(NSString *key, float percent) {
- } success:^(id index, NSDictionary *resp) {
- self.viewModel.skillImageUrl = resp[@"url"];
- [self onePhaseViewNextAction];
- [SVProgressHUD dismiss];
- } failure:^(id index, NSError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }else {
- [SVProgressHUD showInfoWithStatus:responseModel.message];
- }
- } failureHandler:^(ZYLNetworkError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- - (void)uploadVoiceFile {
-
- NSData *voiceData = [NSData dataWithContentsOfFile:self.viewModel.voicePath];
- if (!voiceData) {
- [SVProgressHUD showInfoWithStatus:kLocalizedString(@"语音文件损坏,请重新录入")];
- return;
- }
-
- // 上传语音
- [SVProgressHUD showWithStatus:kLocalizedString(@"上传中...")];
- [[UploadManager new] getSkillVoiceUploadConfigSuccessHandler:^(ZYLResponseModel *responseModel) {
- if (responseModel.codeState) {
- NSDictionary *dict = responseModel.result[@"data"];
- [[UploadManager new] dispatchUploadVideo:voiceData info:nil uploadParameter:dict withProgress:nil success:^(id index, NSDictionary *resp) {
- self.viewModel.voiceUrl = resp[@"url"];
- [self twoPhaseViewNextAction];
- [SVProgressHUD dismiss];
- } failure:^(id index, NSError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }else {
- [SVProgressHUD showInfoWithStatus:responseModel.message];
- }
- } failureHandler:^(ZYLNetworkError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- #pragma mark — Getter
- - (XYSkillCertificationApplyPhaseView *)phaseView {
- if (!_phaseView) {
- _phaseView = [[XYSkillCertificationApplyPhaseView alloc] initWithFrame:CGRectMake(0, NAVGATION_HEIGHT, SCREEN_WIDTH, 100.0f)];
- _phaseView.titles = @[@"技能认证", @"资料填写", @"家族签约"];
- [_phaseView setupPhaseStatusNo:1];
- }
- return _phaseView;
- }
- - (XYSkillCertificationApplyOnePhaseView *)onePhaseView {
- if (!_onePhaseView) {
- _onePhaseView = [[XYSkillCertificationApplyOnePhaseView alloc] initWithFrame:CGRectMake(0, self.phaseView.f_top + 10.0f, SCREEN_WIDTH, SCREEN_HEIGHT - self.phaseView.f_top - 10.0f)];
- _onePhaseView.delegate = self;
- }
- return _onePhaseView;
- }
- - (XYSkillCertificationApplyTwoPhaseView *)twoPhaseView {
- if (!_twoPhaseView) {
- _twoPhaseView = [[XYSkillCertificationApplyTwoPhaseView alloc] initWithFrame:CGRectMake(0, self.phaseView.f_top + 10.0f, SCREEN_WIDTH, SCREEN_HEIGHT - self.phaseView.f_top - 10.0f)];
- _twoPhaseView.delegate = self;
- _twoPhaseView.hidden = YES;
- [_twoPhaseView setupVoicePath:self.viewModel.voicePath];
- }
- return _twoPhaseView;
- }
- - (XYSkillCertificationApplyThreePhaseView *)threePhaseView {
- if (!_threePhaseView) {
- _threePhaseView = [[XYSkillCertificationApplyThreePhaseView alloc] initWithFrame:CGRectMake(0, self.phaseView.f_top + 10.0f, SCREEN_WIDTH, SCREEN_HEIGHT - self.phaseView.f_top - 10.0f)];
- _threePhaseView.delegate = self;
- _threePhaseView.hidden = YES;
- }
- return _threePhaseView;
- }
- /*
- #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
|