ASCategoryViewController.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // ASCategoryViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/7/10.
  6. //
  7. #import "ASCategoryViewController.h"
  8. #import "KWSearchMainTypeTableView.h"
  9. #import "KWSearchSubTypeTableView.h"
  10. @interface ASCategoryViewController ()
  11. @property (nonatomic, strong) KWSearchMainTypeTableView *leftTableV;
  12. @property (nonatomic, strong) KWSearchSubTypeTableView *rightTableV;
  13. @property (nonatomic, strong) UIView *bottomV;
  14. @property (nonatomic, strong) UIButton *cusBackBt;
  15. @end
  16. @implementation ASCategoryViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self loadSubVs];
  20. }
  21. - (void)loadSubVs {
  22. self.statusBgV.backgroundColor = _E0FFF5;
  23. self.customNavBar.backgroundColor = _E0FFF5;
  24. self.titleStr = @"Category";
  25. [self.customNavBar addSubview:self.cusBackBt];
  26. [self.cusBackBt mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.trailing.equalTo(self.customNavBar).offset(-10);
  28. make.centerY.equalTo(self.customNavBar);
  29. make.width.height.equalTo(@44);
  30. }];
  31. [self.view addSubview:self.bottomV];
  32. [self.bottomV addSubview:self.leftTableV];
  33. [self.bottomV addSubview:self.rightTableV];
  34. [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.top.equalTo(self.customNavBar.mas_bottom).offset(10);
  36. make.left.right.equalTo(self.view);
  37. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  38. }];
  39. [self.leftTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.width.equalTo(@130);
  41. make.left.top.bottom.equalTo(self.bottomV);
  42. }];
  43. [self.rightTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.bottom.right.equalTo(self.bottomV);
  45. make.left.equalTo(self.leftTableV.mas_right);
  46. }];
  47. }
  48. // MARK: - actions
  49. - (void)toResult:(NSString *)key type:(NSString *)type keyWord:(NSString *)word {
  50. NSDictionary *para = @{
  51. @"type":type, //String
  52. @"title":key,//String
  53. @"searchKey":word,//String
  54. };
  55. UIViewController *vc = [CTMediator.sharedInstance getProductListVc:para];
  56. [self.navigationController pushViewController:vc animated:true];
  57. }
  58. - (void)backAction {
  59. [self dismissViewControllerAnimated:true completion:nil];
  60. }
  61. // MARK: - subvs
  62. - (KWSearchMainTypeTableView *)leftTableV {
  63. if (!_leftTableV) {
  64. KWSearchMainTypeTableView *leftTab = [[KWSearchMainTypeTableView alloc] initWithFrame:CGRectMake(0, 10, 180, self.view.bounds.size.height) style:UITableViewStylePlain];
  65. @weakify(self);
  66. _leftTableV = leftTab;
  67. leftTab.callBack = ^{
  68. NSInteger selectIndex = weak_self.leftTableV.selectIndex;
  69. if (selectIndex >= weak_self.leftTableV.arr.count) {
  70. weak_self.rightTableV.arr = weak_self.leftTableV.moneyType.children;
  71. [weak_self.rightTableV reloadData];
  72. return;
  73. }
  74. KWMainTypeModel *m = weak_self.leftTableV.arr[selectIndex];
  75. if (m.children.count == 0) {
  76. [self toResult:m.title type:m.Id keyWord:@""];
  77. } else {
  78. weak_self.rightTableV.arr = m.children;
  79. [weak_self.rightTableV reloadData];
  80. }
  81. };
  82. }
  83. return _leftTableV;
  84. }
  85. - (KWSearchSubTypeTableView *)rightTableV {
  86. if(!_rightTableV) {
  87. KWSearchSubTypeTableView *tab = [[KWSearchSubTypeTableView alloc] initWithFrame:CGRectMake(0, 10, 180, self.view.bounds.size.height) style:UITableViewStylePlain];
  88. _rightTableV = tab;
  89. @weakify(self);
  90. [_rightTableV setCallBack:^(NSIndexPath * _Nonnull indexP) {
  91. KWSearchSubTypeModel *m = weak_self.rightTableV.arr[indexP.section].children[indexP.item];
  92. [weak_self toResult:m.title type:m.Id keyWord:@""];
  93. }];
  94. [_rightTableV setCallBackSection:^(NSInteger index) {
  95. KWSubTypeSectionModel *m = weak_self.rightTableV.arr[index];
  96. if (m.isMoneyType) {
  97. [MBProgressHUD showHUDAddedTo:weak_self.view animated:true];
  98. // [weak_self.vm switchCurrencie:m callback:^(BOOL flag) {
  99. //
  100. // if (flag) {
  101. // [[NSNotificationCenter defaultCenter] postNotificationName:MoneyTypeChanged object:nil];
  102. // [weak_self.vm reqCurrenciesList:^{
  103. // [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  104. // weak_self.leftTableV.moneyType = weak_self.vm.moneyType;
  105. // weak_self.rightTableV.arr = weak_self.vm.moneyType.children;
  106. // [weak_self.rightTableV reloadData];
  107. // }];
  108. // } else {
  109. // [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  110. // }
  111. // }];
  112. return;
  113. }
  114. [weak_self toResult:m.title type:m.Id keyWord:@""];
  115. }];
  116. }
  117. return _rightTableV;
  118. }
  119. - (UIButton *)cusBackBt {
  120. if (!_cusBackBt) {
  121. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  122. [bt setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
  123. [bt addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  124. _cusBackBt = bt;
  125. }
  126. return _cusBackBt;
  127. }
  128. -(UIView *)bottomV {
  129. if (!_bottomV) {
  130. UIView *v = [[UIView alloc] init];
  131. v.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
  132. _bottomV = v;
  133. }
  134. return _bottomV;
  135. }
  136. @end