ASCategoryViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #import "ASCategoriesViewModel.h"
  11. @interface ASCategoryViewController ()
  12. @property (nonatomic, strong) ASCategoriesViewModel *vm;
  13. @property (nonatomic, strong) KWSearchMainTypeTableView *leftTableV;
  14. @property (nonatomic, strong) KWSearchSubTypeTableView *rightTableV;
  15. @property (nonatomic, strong) UIView *bottomV;
  16. @end
  17. @implementation ASCategoryViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.vm = [ASCategoriesViewModel new];
  21. [self loadSubVs];
  22. [self getData];
  23. }
  24. - (void)getData {
  25. __weak typeof(self) weakSelf = self;
  26. [self.vm getAllCateGories:@"" com:^(BOOL isSuc, NSString * _Nonnull msg) {
  27. NSArray<KWMainTypeModel *> *tempArr = weakSelf.vm.totalDatas;
  28. weakSelf.leftTableV.arr = tempArr;
  29. NSInteger cusSelect = 0;
  30. for (int i=0; i<tempArr.count; i++) {
  31. KWMainTypeModel *temp = tempArr[i];
  32. if (temp.children_data.count > 0) {
  33. cusSelect = i;
  34. break;
  35. }
  36. }
  37. if (tempArr.count > cusSelect) {
  38. weakSelf.rightTableV.arr = tempArr[cusSelect].children_data;
  39. }
  40. weakSelf.leftTableV.selectIndex = cusSelect;
  41. [weakSelf.leftTableV reloadData];
  42. [weakSelf.rightTableV reloadData];
  43. if (!isSuc) {
  44. [weakSelf.view makeToast:msg];
  45. }
  46. }];
  47. }
  48. - (void)loadSubVs {
  49. self.statusBgV.backgroundColor = _E0FFF5;
  50. self.customNavBar.backgroundColor = _E0FFF5;
  51. self.titleStr = @"Category";
  52. [self.view addSubview:self.bottomV];
  53. [self.bottomV addSubview:self.leftTableV];
  54. [self.bottomV addSubview:self.rightTableV];
  55. [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.equalTo(self.customNavBar.mas_bottom).offset(10);
  57. make.left.right.equalTo(self.view);
  58. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  59. }];
  60. [self.leftTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.width.equalTo(@130);
  62. make.left.top.bottom.equalTo(self.bottomV);
  63. }];
  64. [self.rightTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.bottom.right.equalTo(self.bottomV);
  66. make.left.equalTo(self.leftTableV.mas_right);
  67. }];
  68. }
  69. // MARK: - actions
  70. - (void)toResult:(NSString *)key type:(NSString *)type keyWord:(NSString *)word {
  71. NSDictionary *para = @{
  72. @"type":type, //String
  73. @"title":key,//String
  74. @"searchKey":word,//String
  75. };
  76. UIViewController *vc = [CTMediator.sharedInstance getProductListVc:para];
  77. [self.navigationController pushViewController:vc animated:true];
  78. }
  79. // MARK: - subvs
  80. - (KWSearchMainTypeTableView *)leftTableV {
  81. if (!_leftTableV) {
  82. KWSearchMainTypeTableView *leftTab = [[KWSearchMainTypeTableView alloc] initWithFrame:CGRectMake(0, 10, 180, self.view.bounds.size.height) style:UITableViewStylePlain];
  83. leftTab.backgroundColor = _F8F8F8;
  84. @weakify(self);
  85. _leftTableV = leftTab;
  86. leftTab.callBack = ^{
  87. NSInteger selectIndex = weak_self.leftTableV.selectIndex;
  88. if (selectIndex >= weak_self.leftTableV.arr.count) {
  89. weak_self.rightTableV.arr = weak_self.leftTableV.moneyType.children_data;
  90. [weak_self.rightTableV reloadData];
  91. return;
  92. }
  93. KWMainTypeModel *m = weak_self.leftTableV.arr[selectIndex];
  94. if (m.children_data.count == 0) {
  95. [self toResult:m.title type:m.Id keyWord:@""];
  96. } else {
  97. weak_self.rightTableV.arr = m.children_data;
  98. [weak_self.rightTableV reloadData];
  99. }
  100. };
  101. }
  102. return _leftTableV;
  103. }
  104. - (KWSearchSubTypeTableView *)rightTableV {
  105. if(!_rightTableV) {
  106. KWSearchSubTypeTableView *tab = [[KWSearchSubTypeTableView alloc] initWithFrame:CGRectMake(0, 10, 180, self.view.bounds.size.height) style:UITableViewStylePlain];
  107. tab.backgroundColor = _F8F8F8;
  108. _rightTableV = tab;
  109. @weakify(self);
  110. [_rightTableV setCallBack:^(NSIndexPath * _Nonnull indexP) {
  111. KWSearchSubTypeModel *m = weak_self.rightTableV.arr[indexP.section].children_data[indexP.item];
  112. [weak_self toResult:m.title type:m.Id keyWord:@""];
  113. }];
  114. [_rightTableV setCallBackSection:^(NSInteger index) {
  115. KWSubTypeSectionModel *m = weak_self.rightTableV.arr[index];
  116. if (m.isMoneyType) {
  117. [ASCurrencyManager.shared setSelectCurrency:m.title];
  118. [weak_self.rightTableV reloadData];
  119. return;
  120. }
  121. [weak_self toResult:m.title type:m.Id keyWord:@""];
  122. }];
  123. }
  124. return _rightTableV;
  125. }
  126. -(UIView *)bottomV {
  127. if (!_bottomV) {
  128. UIView *v = [[UIView alloc] init];
  129. v.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
  130. _bottomV = v;
  131. }
  132. return _bottomV;
  133. }
  134. @end