XYSkillCertificationApplyViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. //
  2. // XYSkillCertificationApplyViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/10/26.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYSkillCertificationApplyViewController.h"
  9. #import "XYSkillCertificationApplyPhaseView.h"
  10. #import "XYSkillCertificationApplyOnePhaseView.h"
  11. #import "XYCertificationSkillModel.h"
  12. #import "XYSkillCertificationApplyViewModel.h"
  13. #import "XYSkillVertificationApplyIntroduceView.h"
  14. #import "XYSkillCertificationApplyTwoPhaseView.h"
  15. #import "XYSkillCertificationApplyThreePhaseView.h"
  16. #import "XYSearchFamilyViewController.h"
  17. #import "XYFamilyModel.h"
  18. #import "XYCertificationSkillsMainViewController.h"
  19. #import "XYCertificationSkillsSelectedViewController.h"
  20. @interface XYSkillCertificationApplyViewController ()<XYSkillCertificationApplyOnePhaseViewDelegate, TZImagePickerControllerDelegate, XYSkillCertificationApplyTwoPhaseViewDelegate, XYSkillCertificationApplyThreePhaseViewDelegate, XYSearchFamilyViewControllerDelegate>
  21. @property (nonatomic, strong) XYSkillCertificationApplyViewModel *viewModel;
  22. @property (nonatomic, strong) XYSkillCertificationApplyPhaseView *phaseView;
  23. @property (nonatomic, strong) XYSkillCertificationApplyOnePhaseView *onePhaseView;
  24. @property (nonatomic, strong) XYSkillCertificationApplyTwoPhaseView *twoPhaseView;
  25. @property (nonatomic, strong) XYSkillCertificationApplyThreePhaseView *threePhaseView;
  26. @end
  27. @implementation XYSkillCertificationApplyViewController
  28. - (void)dealloc {
  29. if (_twoPhaseView) {
  30. [_twoPhaseView clear];
  31. }
  32. }
  33. - (instancetype)init
  34. {
  35. self = [super init];
  36. if (self) {
  37. self.prefersNavigationBarBottomLineHidden = NO;
  38. self.keyboardEnable = NO;
  39. self.shouldAutoToolbarEnable = NO;
  40. }
  41. return self;
  42. }
  43. - (void)viewDidLoad {
  44. [super viewDidLoad];
  45. // Do any additional setup after loading the view.
  46. [self setupUI];
  47. // 设置默认值
  48. [self setupDefaultlue];
  49. }
  50. - (void)setupDefaultlue {
  51. if (StringIsNotEmpty(self.skillId)) {
  52. // 有默认技能
  53. for (XYCertificationSkillModel *model in ApplicationDelegate.appConfigModel.skills) {
  54. if ([model.skillId isEqualToString:self.skillId]) {
  55. // 设置默认技能
  56. self.viewModel.skillId = model.skillId;
  57. self.viewModel.skillName = model.skillName;
  58. // if (model.skillTags.count > 0) {
  59. // // 设置默认技能的标签
  60. // if (StringIsNotEmpty(self.tagId)) {
  61. // for (XYCertificationSkillTagModel *tagModel in model.skillTags) {
  62. // if ([tagModel.tagId isEqualToString:self.tagId]) {
  63. // self.viewModel.skillTagId = tagModel.tagId;
  64. // self.viewModel.skillTagName = tagModel.tagName;
  65. // }
  66. // }
  67. // }else {
  68. // XYCertificationSkillTagModel *tagModel = [model.skillTags firstObject];
  69. // self.viewModel.skillTagId = tagModel.tagId;
  70. // self.viewModel.skillTagName = tagModel.tagName;
  71. // }
  72. // }
  73. [self.onePhaseView setupViewModel:self.viewModel];
  74. break;
  75. }
  76. }
  77. }
  78. }
  79. - (void)bindViewModel {
  80. self.viewModel = XYSkillCertificationApplyViewModel.new;
  81. }
  82. - (void)requestRemoteData {
  83. [self.viewModel loadData:^(id _Nullable responseModel) {
  84. if (StringIsNotEmpty(self.viewModel.familyId)) {
  85. self.threePhaseView.familyIdButton.enabled = NO;
  86. [self.threePhaseView setupFamilyName:self.viewModel.familyName];
  87. }
  88. } failure:^(ZYLNetworkError * _Nullable error) {
  89. }];
  90. }
  91. #pragma mark — UI
  92. - (void)setupUI {
  93. self.title = kLocalizedString(@"技能申请");
  94. [self.view addSubview:self.phaseView];
  95. [self.view addSubview:self.onePhaseView];
  96. [self.view addSubview:self.twoPhaseView];
  97. [self.view addSubview:self.threePhaseView];
  98. }
  99. #pragma mark — XYSkillCertificationApplyOnePhaseViewDelegate
  100. - (void)onePhaseViewSelectedSkillAction {
  101. NSMutableArray *tempTitle = [NSMutableArray array];
  102. for (XYCertificationSkillModel *model in ApplicationDelegate.appConfigModel.skills) {
  103. [tempTitle addObject:model.skillName];
  104. }
  105. BasePickerViewController *skillPicker = [[BasePickerViewController alloc] initWithTitle:kLocalizedString(@"选择服务技能") dataArray:tempTitle target:self sureBlock:^(NSInteger index, id _Nonnull info) {
  106. XYCertificationSkillModel *model = ApplicationDelegate.appConfigModel.skills[index];
  107. self.viewModel.skillId = model.skillId;
  108. self.viewModel.skillName = model.skillName;
  109. // 选择默认标签
  110. // if (model.skillTags.count > 0) {
  111. // XYCertificationSkillTagModel *tagModel = [model.skillTags firstObject];
  112. // self.viewModel.skillTagId = tagModel.tagId;
  113. // self.viewModel.skillTagName = tagModel.tagName;
  114. // }
  115. self.viewModel.skillTagId = @"";
  116. self.viewModel.skillTagName = @"";
  117. [self.onePhaseView setupNextStatus:NO];
  118. [self.onePhaseView setupViewModel:self.viewModel];
  119. }];
  120. [skillPicker showWithController:self];
  121. }
  122. - (void)onePhaseViewSelectedTagAction {
  123. if (StringIsEmpty(self.viewModel.skillId)) {
  124. [SVProgressHUD showInfoWithStatus:kLocalizedString(@"请先选择服务技能")];
  125. return;
  126. }
  127. NSMutableArray *tempTagTitle = [NSMutableArray array];
  128. for (XYCertificationSkillModel *model in ApplicationDelegate.appConfigModel.skills) {
  129. if ([model.skillId isEqualToString:self.viewModel.skillId]) {
  130. for (XYCertificationSkillTagModel *tagModel in model.skillTags) {
  131. [tempTagTitle addObject:tagModel.tagName];
  132. }
  133. break;
  134. }
  135. }
  136. if (tempTagTitle.count == 0) {
  137. [SVProgressHUD showInfoWithStatus:kLocalizedString(@"没有标签")];
  138. return;
  139. }
  140. BasePickerViewController *skillPicker = [[BasePickerViewController alloc] initWithTitle:kLocalizedString(@"选择服务技能") dataArray:tempTagTitle target:self sureBlock:^(NSInteger index, id _Nonnull info) {
  141. for (XYCertificationSkillModel *model in ApplicationDelegate.appConfigModel.skills) {
  142. if ([model.skillId isEqualToString:self.viewModel.skillId]) {
  143. if (model.skillTags.count > 0) {
  144. XYCertificationSkillTagModel *tagModel = model.skillTags[index];
  145. self.viewModel.skillTagId = tagModel.tagId;
  146. self.viewModel.skillTagName = tagModel.tagName;
  147. }
  148. if (StringIsNotEmpty(self.viewModel.skillTagId)) {
  149. [self.onePhaseView setupNextStatus:YES];
  150. }else {
  151. [self.onePhaseView setupNextStatus:NO];
  152. }
  153. [self.onePhaseView setupViewModel:self.viewModel];
  154. break;
  155. }
  156. }
  157. }];
  158. [skillPicker showWithController:self];
  159. }
  160. - (void)onePhaseViewSelectedIntroduceAction {
  161. XYSkillVertificationApplyIntroduceView *introduceView = [[XYSkillVertificationApplyIntroduceView alloc] initWithTitle:kLocalizedString(@"输入技能介绍") content:self.viewModel.skillIntro actionBlock:^(NSString * _Nonnull content) {
  162. self.viewModel.skillIntro = content;
  163. [self.onePhaseView setupViewModel:self.viewModel];
  164. }];
  165. [introduceView showWithView:self.view];
  166. }
  167. - (void)onePhaseViewSelectedImageAction {
  168. // 为空则直接添加
  169. TZImagePickerController *picker = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
  170. picker.allowTakeVideo = NO;
  171. picker.allowPickingVideo = NO;
  172. picker.allowCrop = YES;
  173. CGFloat height = SCREEN_WIDTH/16*9;
  174. picker.cropRect = CGRectMake(0, (SCREEN_HEIGHT - height)/2, SCREEN_WIDTH, height);
  175. [self presentViewController:picker animated:YES completion:nil];
  176. }
  177. - (void)onePhaseViewNextAction {
  178. if (self.viewModel.skillImage && StringIsEmpty(self.viewModel.skillImageUrl)) {
  179. // 上传图片
  180. [self uploadHeadImage:self.viewModel.skillImage];
  181. }else {
  182. [self.phaseView setupPhaseStatusNo:2];
  183. self.onePhaseView.hidden = YES;
  184. self.twoPhaseView.hidden = NO;
  185. }
  186. }
  187. #pragma mark -TZImagePickerControllerDelegate 添加图片回调
  188. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos {
  189. if (photos.count == 0) {
  190. return;
  191. }
  192. self.viewModel.skillImage = [photos firstObject];
  193. self.viewModel.skillImageUrl = @"";
  194. [self.onePhaseView setupViewModel:self.viewModel];
  195. }
  196. #pragma mark — XYSkillCertificationApplyTwoPhaseViewDelegate
  197. - (void)twoPhaseViewDeleteVoiceAction {
  198. [self.viewModel deleteTempVoiceFile];
  199. }
  200. - (void)twoPhaseViewNextAction {
  201. if (StringIsEmpty(self.viewModel.voiceUrl)) {
  202. // 为空则需要上传语音文件
  203. [self uploadVoiceFile];
  204. }else {
  205. [self.phaseView setupPhaseStatusNo:3];
  206. self.twoPhaseView.hidden = YES;
  207. self.threePhaseView.hidden = NO;
  208. }
  209. }
  210. #pragma mark — XYSkillCertificationApplyThreePhaseViewDelegate
  211. - (void)threePhaseViewSelectedFamilyAction {
  212. if (StringIsEmpty(self.viewModel.familyId)) {
  213. // 选择家族
  214. XYSearchFamilyViewController *controller = XYSearchFamilyViewController.new;
  215. controller.delegate = self;
  216. [self.navigationController pushViewController:controller animated:YES];
  217. }
  218. }
  219. - (void)threePhaseViewSubmitAction {
  220. CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"提交审核") message:[NSString stringWithFormat:kLocalizedString(@"您申请的家族为【%@】,确认提交吗?"),self.viewModel.familyName] sure:kLocalizedString(@"确认") cancel:kLocalizedString(@"再想想") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
  221. if ([title isEqualToString:kLocalizedString(@"确认")]) {
  222. [self submitCertificationSkillInfo];
  223. }
  224. }];
  225. [al show];
  226. }
  227. - (void)submitCertificationSkillInfo {
  228. WeakSelf
  229. [self.viewModel addSkillAudit:^(id _Nullable responseModel) {
  230. [SVProgressHUD showSuccessWithStatus:kLocalizedString(@"已提交")];
  231. [weakSelf removeControllerWithClass:XYCertificationSkillsSelectedViewController.class];
  232. [weakSelf removeControllerWithClass:XYCertificationSkillsMainViewController.class];
  233. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  234. [weakSelf.navigationController pushViewController:XYCertificationSkillsMainViewController.new animated:YES];
  235. });
  236. } failure:^(ZYLNetworkError * _Nullable error) {
  237. [SVProgressHUD showInfoWithStatus:error.domain];
  238. }];
  239. }
  240. #pragma mark — XYSearchFamilyViewControllerDelegate
  241. - (void)didSelectedFamilyFinishModel:(XYFamilyModel *)model {
  242. if (StringIsNotEmpty(model.familyId)) {
  243. self.viewModel.familyId = [model.familyId copy];
  244. self.viewModel.familyName = [model.familyName copy];
  245. self.viewModel.familyNo = [model.familyNo copy];
  246. [self.threePhaseView setupFamilyName:self.viewModel.familyName];
  247. }
  248. }
  249. - (void)uploadHeadImage:(UIImage *)image {
  250. // 上传图片
  251. [SVProgressHUD showWithStatus:kLocalizedString(@"上传中...")];
  252. [[UploadManager new] getSkillImagePhotoUploadConfigSuccessHandler:^(ZYLResponseModel *responseModel) {
  253. if (responseModel.codeState) {
  254. NSDictionary *dict = responseModel.result[@"data"];
  255. [[UploadManager new] dispatchUploadImage:image info:nil uploadParameter:dict withProgress:^(NSString *key, float percent) {
  256. } success:^(id index, NSDictionary *resp) {
  257. self.viewModel.skillImageUrl = resp[@"url"];
  258. [self onePhaseViewNextAction];
  259. [SVProgressHUD dismiss];
  260. } failure:^(id index, NSError *error) {
  261. [SVProgressHUD showInfoWithStatus:error.domain];
  262. }];
  263. }else {
  264. [SVProgressHUD showInfoWithStatus:responseModel.message];
  265. }
  266. } failureHandler:^(ZYLNetworkError *error) {
  267. [SVProgressHUD showInfoWithStatus:error.domain];
  268. }];
  269. }
  270. - (void)uploadVoiceFile {
  271. NSData *voiceData = [NSData dataWithContentsOfFile:self.viewModel.voicePath];
  272. if (!voiceData) {
  273. [SVProgressHUD showInfoWithStatus:kLocalizedString(@"语音文件损坏,请重新录入")];
  274. return;
  275. }
  276. // 上传语音
  277. [SVProgressHUD showWithStatus:kLocalizedString(@"上传中...")];
  278. [[UploadManager new] getSkillVoiceUploadConfigSuccessHandler:^(ZYLResponseModel *responseModel) {
  279. if (responseModel.codeState) {
  280. NSDictionary *dict = responseModel.result[@"data"];
  281. [[UploadManager new] dispatchUploadVideo:voiceData info:nil uploadParameter:dict withProgress:nil success:^(id index, NSDictionary *resp) {
  282. self.viewModel.voiceUrl = resp[@"url"];
  283. [self twoPhaseViewNextAction];
  284. [SVProgressHUD dismiss];
  285. } failure:^(id index, NSError *error) {
  286. [SVProgressHUD showInfoWithStatus:error.domain];
  287. }];
  288. }else {
  289. [SVProgressHUD showInfoWithStatus:responseModel.message];
  290. }
  291. } failureHandler:^(ZYLNetworkError *error) {
  292. [SVProgressHUD showInfoWithStatus:error.domain];
  293. }];
  294. }
  295. #pragma mark — Getter
  296. - (XYSkillCertificationApplyPhaseView *)phaseView {
  297. if (!_phaseView) {
  298. _phaseView = [[XYSkillCertificationApplyPhaseView alloc] initWithFrame:CGRectMake(0, NAVGATION_HEIGHT, SCREEN_WIDTH, 100.0f)];
  299. _phaseView.titles = @[@"技能认证", @"资料填写", @"家族签约"];
  300. [_phaseView setupPhaseStatusNo:1];
  301. }
  302. return _phaseView;
  303. }
  304. - (XYSkillCertificationApplyOnePhaseView *)onePhaseView {
  305. if (!_onePhaseView) {
  306. _onePhaseView = [[XYSkillCertificationApplyOnePhaseView alloc] initWithFrame:CGRectMake(0, self.phaseView.f_top + 10.0f, SCREEN_WIDTH, SCREEN_HEIGHT - self.phaseView.f_top - 10.0f)];
  307. _onePhaseView.delegate = self;
  308. }
  309. return _onePhaseView;
  310. }
  311. - (XYSkillCertificationApplyTwoPhaseView *)twoPhaseView {
  312. if (!_twoPhaseView) {
  313. _twoPhaseView = [[XYSkillCertificationApplyTwoPhaseView alloc] initWithFrame:CGRectMake(0, self.phaseView.f_top + 10.0f, SCREEN_WIDTH, SCREEN_HEIGHT - self.phaseView.f_top - 10.0f)];
  314. _twoPhaseView.delegate = self;
  315. _twoPhaseView.hidden = YES;
  316. [_twoPhaseView setupVoicePath:self.viewModel.voicePath];
  317. }
  318. return _twoPhaseView;
  319. }
  320. - (XYSkillCertificationApplyThreePhaseView *)threePhaseView {
  321. if (!_threePhaseView) {
  322. _threePhaseView = [[XYSkillCertificationApplyThreePhaseView alloc] initWithFrame:CGRectMake(0, self.phaseView.f_top + 10.0f, SCREEN_WIDTH, SCREEN_HEIGHT - self.phaseView.f_top - 10.0f)];
  323. _threePhaseView.delegate = self;
  324. _threePhaseView.hidden = YES;
  325. }
  326. return _threePhaseView;
  327. }
  328. /*
  329. #pragma mark - Navigation
  330. // In a storyboard-based application, you will often want to do a little preparation before navigation
  331. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  332. // Get the new view controller using [segue destinationViewController].
  333. // Pass the selected object to the new view controller.
  334. }
  335. */
  336. @end