MerchantEnrollViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. //
  2. // MerchantEnrollViewController.m
  3. // BuguLive
  4. //
  5. // Created by qitewei on 2025/8/11.
  6. // Copyright © 2025 xfg. All rights reserved.
  7. //
  8. #import "MerchantEnrollViewController.h"
  9. #import "MerchantEnrollGuideView.h"
  10. #import "MerchantEnrollCheckListView.h"
  11. #import "MerchantStoreInfoView.h"
  12. #import "MerchantBusinessLicenseView.h"
  13. #import "MerchantLegalInfoView.h"
  14. #import "MerchantBankInfoView.h"
  15. #import "MerchantAdminSetupView.h"
  16. #import "MerchantPaymentView.h"
  17. #import "MerchantEnrollResultView.h"
  18. #import "NavigationBarView.h"
  19. #import "MerchantBaseEnrollContentView.h"
  20. #import "UIButton+Layout.h"
  21. @interface MerchantEnrollViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate, MerchantEnrollContentViewDelegate>
  22. @property (nonatomic, assign) MerchantEnrollStep currentStep;
  23. @property (nonatomic, strong) NavigationBarView *navBar;
  24. @property (nonatomic, strong) UIImageView *bgImageView;
  25. @property (nonatomic, strong) UILabel *titleLabel;
  26. @property (nonatomic, strong) UIStackView *stepsStackView;
  27. @property (nonatomic, strong) UIView *step1View;
  28. @property (nonatomic, strong) UIView *step2View;
  29. @property (nonatomic, strong) UIView *step3View;
  30. @property (nonatomic, strong) UIImageView *line1ImageView;
  31. @property (nonatomic, strong) UIImageView *line2ImageView;
  32. @property (nonatomic, strong) NSMutableArray<UIButton *> *buttons;
  33. @property (nonatomic, strong) JXCategoryTitleView *categoryView;
  34. @property (nonatomic, strong) JXCategoryListContainerView *containerView;
  35. @property (nonatomic, copy) NSArray *list;
  36. @property (nonatomic, strong, nullable) MerchantEnrollGuideView *guideView;
  37. @property (nonatomic, strong, nullable) MerchantEnrollCheckListView *checkListView;
  38. @property (nonatomic, strong, nullable) MerchantEnrollResultView *resultView;
  39. @end
  40. @implementation MerchantEnrollViewController
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. self.view.backgroundColor = [UIColor whiteColor];
  44. [IQKeyboardManager sharedManager].enable = YES;
  45. [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
  46. [self setupNavigationBar];
  47. [self setupStepsUI];
  48. [self showCurrentStep];
  49. }
  50. - (void)viewWillAppear:(BOOL)animated {
  51. [super viewWillAppear:animated];
  52. self.navigationController.navigationBar.hidden = YES;
  53. }
  54. - (void)viewWillDisappear:(BOOL)animated {
  55. [super viewWillDisappear:animated];
  56. self.navigationController.navigationBar.hidden = NO;
  57. }
  58. #pragma mark - UI Setup
  59. - (void)setupNavigationBar {
  60. self.title = ASLocalizedString(@"商家入驻");
  61. [self.view addSubview:self.bgImageView];
  62. [self.view addSubview:self.navBar];
  63. self.navBar.titleLabel.text = self.title;
  64. [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.right.top.mas_offset(0);
  66. make.height.mas_equalTo(self.bgImageView.height);
  67. }];
  68. [self.navBar mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.top.right.left.mas_offset(0);
  70. make.height.mas_equalTo(self.navBar.height);
  71. }];
  72. }
  73. #pragma mark - Steps UI Setup
  74. - (void)setupStepsUI {
  75. [self.view addSubview:self.categoryView];
  76. [self.view addSubview:self.stepsStackView];
  77. [self.view addSubview:self.containerView];
  78. // 创建步骤视图
  79. [self.stepsStackView addArrangedSubview:self.step1View];
  80. [self.stepsStackView addArrangedSubview:self.step2View];
  81. [self.stepsStackView addArrangedSubview:self.step3View];
  82. [self.view addSubview:self.line1ImageView];
  83. [self.view addSubview:self.line2ImageView];
  84. // 设置步骤1(选中状态)
  85. [self setupStepView:self.step1View withNumber:@"1" title:ASLocalizedString(@"提交材料") isSelected:YES];
  86. // 设置步骤2(未选中状态)
  87. [self setupStepView:self.step2View withNumber:@"2" title:ASLocalizedString(@"平台审核") isSelected:NO];
  88. // 设置步骤3(未选中状态)
  89. [self setupStepView:self.step3View withNumber:@"3" title:ASLocalizedString(@"完成入驻") isSelected:NO];
  90. [self.stepsStackView mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.top.equalTo(self.navBar.mas_bottom).offset(kRealValue(20));
  92. make.centerX.mas_offset(0);
  93. make.left.right.mas_offset(0);
  94. make.height.mas_equalTo(kRealValue(80));
  95. }];
  96. [self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.edges.mas_equalTo(self.stepsStackView);
  98. }];
  99. [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.left.right.bottom.mas_offset(0);
  101. make.top.equalTo(self.stepsStackView.mas_bottom);
  102. }];
  103. [self.line1ImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.size.mas_equalTo(CGSizeMake(kRealValue(70), kRealValue(8)));
  105. make.left.mas_offset(kRealValue(90));
  106. make.centerY.equalTo(self.stepsStackView).mas_offset(-kRealValue(20));
  107. }];
  108. [self.line2ImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  109. make.size.mas_equalTo(CGSizeMake(kRealValue(70), kRealValue(8)));
  110. make.right.mas_offset(kRealValue(-90));
  111. make.centerY.equalTo(self.line1ImageView);
  112. }];
  113. }
  114. - (void)setupStepView:(UIView *)stepView withNumber:(NSString *)number title:(NSString *)title isSelected:(BOOL)isSelected {
  115. NSString *imageName = [NSString stringWithFormat:@"store_step_%@", number];
  116. NSString *selImageName = [NSString stringWithFormat:@"store_step_%@_sel", number];
  117. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  118. [button setTitle:title forState:UIControlStateNormal];
  119. button.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
  120. [button setTitleColor:[UIColor colorWithHexString:@"#777777"] forState:UIControlStateNormal];
  121. [button setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
  122. [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
  123. [button setImage:[UIImage imageNamed:selImageName] forState:UIControlStateSelected];
  124. button.selected = isSelected;
  125. [button layoutImageTopSpace:3];
  126. // 添加视图
  127. [stepView addSubview:button];
  128. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.edges.mas_offset(0);
  130. }];
  131. button.tag = [number integerValue];
  132. [self.buttons addObject:button];
  133. }
  134. - (void)showCurrentStep {
  135. if (self.guideView) {
  136. [self.guideView removeFromSuperview];
  137. self.guideView = nil;
  138. }
  139. if (self.checkListView) {
  140. [self.checkListView removeFromSuperview];
  141. self.guideView = nil;
  142. }
  143. if (self.currentStep <= MerchantEnrollStepCheckList) {
  144. self.stepsStackView.hidden = YES;
  145. self.containerView.hidden = YES;
  146. self.line1ImageView.hidden = YES;
  147. self.line2ImageView.hidden = YES;
  148. MerchantBaseEnrollContentView *contentView;
  149. switch (self.currentStep) {
  150. case MerchantEnrollStepGuide:
  151. self.guideView = [[MerchantEnrollGuideView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-self.bgImageView.height+kRealValue(60))];
  152. contentView = self.guideView;
  153. break;
  154. case MerchantEnrollStepCheckList:
  155. self.checkListView = [[MerchantEnrollCheckListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-self.bgImageView.height+kRealValue(100))];
  156. contentView = self.checkListView;
  157. break;
  158. default:
  159. break;
  160. }
  161. if (contentView) {
  162. contentView.currentStep = self.currentStep;
  163. contentView.delegate = self;
  164. [self.view addSubview:contentView];
  165. [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  166. make.size.mas_equalTo(contentView.size);
  167. make.bottom.inset(0);
  168. make.centerX.mas_offset(0);
  169. }];
  170. }
  171. } else {
  172. self.line1ImageView.hidden = NO;
  173. self.line2ImageView.hidden = NO;
  174. if (self.buttons.count > 1) {
  175. UIButton *second = self.buttons[1];
  176. second.selected = self.currentStep >= MerchantEnrollStepWatingForReview;
  177. }
  178. NSString *name = self.currentStep >= MerchantEnrollStepWatingForReview ? @"store_line_blue" : @"store_line_gray(1)";
  179. self.line2ImageView.image = [UIImage imageNamed:name];
  180. UIButton *last = self.buttons.lastObject;
  181. last.selected = self.currentStep >= MerchantEnrollStepComplete;
  182. if (self.currentStep > MerchantEnrollStepCheckList && self.currentStep < MerchantEnrollStepWatingForReview) {
  183. self.stepsStackView.hidden = NO;
  184. self.containerView.hidden = NO;
  185. [self.categoryView selectItemAtIndex:self.currentStep-2];
  186. } else {
  187. self.stepsStackView.hidden = NO;
  188. self.containerView.hidden = YES;
  189. switch (self.currentStep) {
  190. case MerchantEnrollStepWatingForReview:
  191. [self showEnrollResult:MerchantEnrollResultPending];
  192. break;
  193. case MerchantEnrollStepReviewFail:
  194. [self showEnrollResult:MerchantEnrollResultFailed];
  195. break;
  196. case MerchantEnrollStepComplete:
  197. [self showEnrollResult:MerchantEnrollResultSuccess];
  198. break;
  199. default:
  200. break;
  201. }
  202. }
  203. }
  204. }
  205. - (void)backButtonClicked:(UIButton *)sender {
  206. [self.navigationController popViewControllerAnimated:YES];
  207. }
  208. - (void)helpButtonClicked:(UIButton *)sender {
  209. // TODO: 显示帮助页面
  210. NSLog(@"Help button clicked");
  211. }
  212. - (void)showEnrollResult:(MerchantEnrollResultType)resultType {
  213. if (_resultView) {
  214. [_resultView removeFromSuperview];
  215. _resultView = nil;
  216. }
  217. // 添加结果页面
  218. MerchantEnrollResultView *resultView = [[MerchantEnrollResultView alloc]
  219. initWithResultType:resultType
  220. frame:CGRectMake(0, 0, SCREEN_WIDTH-24, SCREEN_HEIGHT-self.bgImageView.height+kRealValue(16))];
  221. [self.view addSubview:resultView];
  222. resultView.delegate = self;
  223. _resultView = resultView;
  224. [resultView mas_makeConstraints:^(MASConstraintMaker *make) {
  225. make.size.mas_equalTo(resultView.size);
  226. make.bottom.inset(0);
  227. make.centerX.mas_offset(0);
  228. }];
  229. }
  230. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  231. }
  232. - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
  233. MerchantBaseEnrollContentView *contentView;
  234. MerchantEnrollStep step = index + 2;
  235. CGFloat height = SCREEN_HEIGHT-self.bgImageView.height+kRealValue(16);
  236. CGFloat width = SCREEN_WIDTH;
  237. CGRect frame = CGRectMake(0, 0, width, height);
  238. switch (step) {
  239. case MerchantEnrollStepStoreInfo:
  240. contentView = [[MerchantStoreInfoView alloc] initWithFrame:frame];
  241. break;
  242. case MerchantEnrollStepBusinessLicense:
  243. contentView = [[MerchantBusinessLicenseView alloc] initWithFrame:frame];
  244. break;
  245. case MerchantEnrollStepLegalInfo:
  246. contentView = [[MerchantLegalInfoView alloc] initWithFrame:frame];
  247. break;
  248. case MerchantEnrollStepBank:
  249. contentView = [[MerchantBankInfoView alloc] initWithFrame:frame];
  250. break;
  251. case MerchantEnrollStepSetAdmin:
  252. contentView = [[MerchantAdminSetupView alloc] initWithFrame:frame];
  253. break;
  254. case MerchantEnrollStepPay:
  255. contentView = [[MerchantPaymentView alloc] initWithFrame:frame];
  256. break;
  257. default:
  258. break;
  259. }
  260. contentView.delegate = self;
  261. contentView.currentStep = step;
  262. return contentView;
  263. }
  264. - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
  265. return self.list.count;
  266. }
  267. #pragma mark - MerchantEnrollContentViewDelegate
  268. - (void)onMerchantEnrollGotoNextButtonClick {
  269. self.currentStep++;
  270. [self showCurrentStep];
  271. }
  272. - (void)onMerchantEnrollResultNextButtonClick:(MerchantEnrollResultType)type {
  273. switch (type) {
  274. case MerchantEnrollResultPending:
  275. [self.navigationController popViewControllerAnimated:YES];
  276. break;
  277. case MerchantEnrollResultFailed:
  278. self.currentStep = MerchantEnrollStepStoreInfo;
  279. [self showCurrentStep];
  280. break;
  281. case MerchantEnrollResultSuccess:
  282. [self.navigationController popViewControllerAnimated:YES];
  283. break;
  284. }
  285. }
  286. - (NavigationBarView *)navBar {
  287. if (!_navBar) {
  288. _navBar = [[NavigationBarView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, STATUS_BAR_HEIGHT+44)];
  289. _navBar.backgroundColor = UIColor.clearColor;
  290. _navBar.contentView.backgroundColor = UIColor.clearColor;
  291. WeakSelf
  292. [_navBar setOnBackButtonkAction:^{
  293. [weakSelf.navigationController popViewControllerAnimated:YES];
  294. }];
  295. [_navBar setOnRightButtonkAction:^{
  296. }];
  297. }
  298. return _navBar;
  299. }
  300. - (UIImageView *)bgImageView {
  301. if (!_bgImageView) {
  302. _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kRealValue(200))];
  303. _bgImageView.contentMode = UIViewContentModeScaleAspectFill;
  304. _bgImageView.image = [UIImage imageNamed:@"store_header_bg"];
  305. }
  306. return _bgImageView;
  307. }
  308. - (UIStackView *)stepsStackView {
  309. if (!_stepsStackView) {
  310. UIStackView *stackView = [[UIStackView alloc] init];
  311. stackView.axis = UILayoutConstraintAxisHorizontal;
  312. stackView.distribution = UIStackViewDistributionFill;
  313. stackView.alignment = UIStackViewAlignmentCenter;
  314. stackView.spacing = 0;
  315. _stepsStackView = stackView;
  316. }
  317. return _stepsStackView;
  318. }
  319. - (UIView *)step1View {
  320. if (!_step1View) {
  321. _step1View = [[UIView alloc] init];
  322. }
  323. return _step1View;
  324. }
  325. - (UIView *)step2View {
  326. if (!_step2View) {
  327. _step2View = [[UIView alloc] init];
  328. }
  329. return _step2View;
  330. }
  331. - (UIView *)step3View {
  332. if (!_step3View) {
  333. _step3View = [[UIView alloc] init];
  334. }
  335. return _step3View;
  336. }
  337. - (UIImageView *)line1ImageView {
  338. if (!_line1ImageView) {
  339. _line1ImageView = [[UIImageView alloc] init];
  340. _line1ImageView.image = [UIImage imageNamed:@"store_line_blue"];
  341. _line1ImageView.contentMode = UIViewContentModeScaleAspectFit;
  342. }
  343. return _line1ImageView;
  344. }
  345. - (UIImageView *)line2ImageView {
  346. if (!_line2ImageView) {
  347. _line2ImageView = [[UIImageView alloc] init];
  348. _line2ImageView.image = [UIImage imageNamed:@"store_line_gray(1)"];
  349. _line2ImageView.contentMode = UIViewContentModeScaleAspectFit;
  350. }
  351. return _line2ImageView;
  352. }
  353. - (JXCategoryTitleView *)categoryView {
  354. if (!_categoryView) {
  355. NSMutableArray *array = [NSMutableArray array];
  356. for (NSNumber *num in self.list) {
  357. [array addObject:[NSString stringWithFormat:@"%ld", [num integerValue]]];
  358. }
  359. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectZero];
  360. _categoryView.delegate = self;
  361. _categoryView.titles = array;
  362. _categoryView.listContainer = self.containerView;
  363. _categoryView.hidden = YES;
  364. }
  365. return _categoryView;
  366. }
  367. - (JXCategoryListContainerView *)containerView {
  368. if (!_containerView) {
  369. _containerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_CollectionView delegate:self];
  370. }
  371. return _containerView;
  372. }
  373. - (NSArray *)list {
  374. if (!_list) {
  375. _list = @[
  376. @(MerchantEnrollStepStoreInfo),
  377. @(MerchantEnrollStepBusinessLicense),
  378. @(MerchantEnrollStepLegalInfo),
  379. @(MerchantEnrollStepBank),
  380. @(MerchantEnrollStepSetAdmin),
  381. @(MerchantEnrollStepPay)
  382. ];
  383. }
  384. return _list;
  385. }
  386. - (NSMutableArray<UIButton *> *)buttons {
  387. if (!_buttons) {
  388. _buttons = [NSMutableArray array];
  389. }
  390. return _buttons;
  391. }
  392. @end