ASCategoryViewController.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. @end
  15. @implementation ASCategoryViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self loadSubVs];
  19. NSMutableArray<KWMainTypeModel *> *tempArr = [NSMutableArray array];
  20. for (int i = 0; i<8; i++) {
  21. [tempArr addObject:[KWMainTypeModel demoData]];
  22. }
  23. NSMutableArray *subArr = [[NSMutableArray alloc] init];
  24. for (NSString *dic in @[@"AUD",@"CAD",@"EUR",@"GBP",@"USD",@"ZAR"]) {
  25. NSString *name = dic;
  26. NSString *short_name = dic;
  27. NSNumber *status =[NSNumber numberWithBool:[dic isEqualToString:@"USD"]];
  28. KWSubTypeSectionModel *m = [[KWSubTypeSectionModel alloc] init];
  29. m.Id = short_name;
  30. m.title = name;
  31. m.isOpen = status.boolValue;
  32. m.isMoneyType = true;
  33. m.children = [[NSMutableArray alloc] init];
  34. [subArr addObject:m];
  35. }
  36. KWMainTypeModel *model = [KWMainTypeModel new];
  37. model.title = @"CURRENCY";
  38. model.isMoneyType = true;
  39. model.children = subArr;
  40. [tempArr addObject:model];
  41. _leftTableV.arr = tempArr;
  42. _rightTableV.arr = tempArr.firstObject.children;
  43. [_leftTableV reloadData];
  44. [_rightTableV reloadData];
  45. }
  46. - (void)loadSubVs {
  47. self.statusBgV.backgroundColor = _E0FFF5;
  48. self.customNavBar.backgroundColor = _E0FFF5;
  49. self.titleStr = @"Category";
  50. [self.view addSubview:self.bottomV];
  51. [self.bottomV addSubview:self.leftTableV];
  52. [self.bottomV addSubview:self.rightTableV];
  53. [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.equalTo(self.customNavBar.mas_bottom).offset(10);
  55. make.left.right.equalTo(self.view);
  56. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  57. }];
  58. [self.leftTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.width.equalTo(@130);
  60. make.left.top.bottom.equalTo(self.bottomV);
  61. }];
  62. [self.rightTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.top.bottom.right.equalTo(self.bottomV);
  64. make.left.equalTo(self.leftTableV.mas_right);
  65. }];
  66. }
  67. // MARK: - actions
  68. - (void)toResult:(NSString *)key type:(NSString *)type keyWord:(NSString *)word {
  69. NSDictionary *para = @{
  70. @"type":type, //String
  71. @"title":key,//String
  72. @"searchKey":word,//String
  73. };
  74. UIViewController *vc = [CTMediator.sharedInstance getProductListVc:para];
  75. [self.navigationController pushViewController:vc animated:true];
  76. }
  77. // MARK: - subvs
  78. - (KWSearchMainTypeTableView *)leftTableV {
  79. if (!_leftTableV) {
  80. KWSearchMainTypeTableView *leftTab = [[KWSearchMainTypeTableView alloc] initWithFrame:CGRectMake(0, 10, 180, self.view.bounds.size.height) style:UITableViewStylePlain];
  81. leftTab.backgroundColor = _F8F8F8;
  82. @weakify(self);
  83. _leftTableV = leftTab;
  84. leftTab.callBack = ^{
  85. NSInteger selectIndex = weak_self.leftTableV.selectIndex;
  86. if (selectIndex >= weak_self.leftTableV.arr.count) {
  87. weak_self.rightTableV.arr = weak_self.leftTableV.moneyType.children;
  88. [weak_self.rightTableV reloadData];
  89. return;
  90. }
  91. KWMainTypeModel *m = weak_self.leftTableV.arr[selectIndex];
  92. if (m.children.count == 0) {
  93. [self toResult:m.title type:m.Id keyWord:@""];
  94. } else {
  95. weak_self.rightTableV.arr = m.children;
  96. [weak_self.rightTableV reloadData];
  97. }
  98. };
  99. }
  100. return _leftTableV;
  101. }
  102. - (KWSearchSubTypeTableView *)rightTableV {
  103. if(!_rightTableV) {
  104. KWSearchSubTypeTableView *tab = [[KWSearchSubTypeTableView alloc] initWithFrame:CGRectMake(0, 10, 180, self.view.bounds.size.height) style:UITableViewStylePlain];
  105. tab.backgroundColor = _F8F8F8;
  106. _rightTableV = tab;
  107. @weakify(self);
  108. [_rightTableV setCallBack:^(NSIndexPath * _Nonnull indexP) {
  109. KWSearchSubTypeModel *m = weak_self.rightTableV.arr[indexP.section].children[indexP.item];
  110. [weak_self toResult:m.title type:m.Id keyWord:@""];
  111. }];
  112. [_rightTableV setCallBackSection:^(NSInteger index) {
  113. KWSubTypeSectionModel *m = weak_self.rightTableV.arr[index];
  114. if (m.isMoneyType) {
  115. [MBProgressHUD showHUDAddedTo:weak_self.view animated:true];
  116. // [weak_self.vm switchCurrencie:m callback:^(BOOL flag) {
  117. //
  118. // if (flag) {
  119. // [[NSNotificationCenter defaultCenter] postNotificationName:MoneyTypeChanged object:nil];
  120. // [weak_self.vm reqCurrenciesList:^{
  121. // [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  122. // weak_self.leftTableV.moneyType = weak_self.vm.moneyType;
  123. // weak_self.rightTableV.arr = weak_self.vm.moneyType.children;
  124. // [weak_self.rightTableV reloadData];
  125. // }];
  126. // } else {
  127. // [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  128. // }
  129. // }];
  130. return;
  131. }
  132. [weak_self toResult:m.title type:m.Id keyWord:@""];
  133. }];
  134. }
  135. return _rightTableV;
  136. }
  137. -(UIView *)bottomV {
  138. if (!_bottomV) {
  139. UIView *v = [[UIView alloc] init];
  140. v.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
  141. _bottomV = v;
  142. }
  143. return _bottomV;
  144. }
  145. @end