ASCategoryViewController.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. weakSelf.rightTableV.arr = tempArr.firstObject.children_data;
  30. [weakSelf.leftTableV reloadData];
  31. [weakSelf.rightTableV reloadData];
  32. if (!isSuc) {
  33. [weakSelf.view makeToast:msg];
  34. }
  35. }];
  36. }
  37. - (void)loadSubVs {
  38. self.statusBgV.backgroundColor = _E0FFF5;
  39. self.customNavBar.backgroundColor = _E0FFF5;
  40. self.titleStr = @"Category";
  41. [self.view addSubview:self.bottomV];
  42. [self.bottomV addSubview:self.leftTableV];
  43. [self.bottomV addSubview:self.rightTableV];
  44. [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.equalTo(self.customNavBar.mas_bottom).offset(10);
  46. make.left.right.equalTo(self.view);
  47. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  48. }];
  49. [self.leftTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.width.equalTo(@130);
  51. make.left.top.bottom.equalTo(self.bottomV);
  52. }];
  53. [self.rightTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.bottom.right.equalTo(self.bottomV);
  55. make.left.equalTo(self.leftTableV.mas_right);
  56. }];
  57. }
  58. // MARK: - actions
  59. - (void)toResult:(NSString *)key type:(NSString *)type keyWord:(NSString *)word {
  60. NSDictionary *para = @{
  61. @"type":type, //String
  62. @"title":key,//String
  63. @"searchKey":word,//String
  64. };
  65. UIViewController *vc = [CTMediator.sharedInstance getProductListVc:para];
  66. [self.navigationController pushViewController:vc animated:true];
  67. }
  68. // MARK: - subvs
  69. - (KWSearchMainTypeTableView *)leftTableV {
  70. if (!_leftTableV) {
  71. KWSearchMainTypeTableView *leftTab = [[KWSearchMainTypeTableView alloc] initWithFrame:CGRectMake(0, 10, 180, self.view.bounds.size.height) style:UITableViewStylePlain];
  72. leftTab.backgroundColor = _F8F8F8;
  73. @weakify(self);
  74. _leftTableV = leftTab;
  75. leftTab.callBack = ^{
  76. NSInteger selectIndex = weak_self.leftTableV.selectIndex;
  77. if (selectIndex >= weak_self.leftTableV.arr.count) {
  78. weak_self.rightTableV.arr = weak_self.leftTableV.moneyType.children_data;
  79. [weak_self.rightTableV reloadData];
  80. return;
  81. }
  82. KWMainTypeModel *m = weak_self.leftTableV.arr[selectIndex];
  83. if (m.children_data.count == 0) {
  84. [self toResult:m.title type:m.Id keyWord:@""];
  85. } else {
  86. weak_self.rightTableV.arr = m.children_data;
  87. [weak_self.rightTableV reloadData];
  88. }
  89. };
  90. }
  91. return _leftTableV;
  92. }
  93. - (KWSearchSubTypeTableView *)rightTableV {
  94. if(!_rightTableV) {
  95. KWSearchSubTypeTableView *tab = [[KWSearchSubTypeTableView alloc] initWithFrame:CGRectMake(0, 10, 180, self.view.bounds.size.height) style:UITableViewStylePlain];
  96. tab.backgroundColor = _F8F8F8;
  97. _rightTableV = tab;
  98. @weakify(self);
  99. [_rightTableV setCallBack:^(NSIndexPath * _Nonnull indexP) {
  100. KWSearchSubTypeModel *m = weak_self.rightTableV.arr[indexP.section].children_data[indexP.item];
  101. [weak_self toResult:m.title type:m.Id keyWord:@""];
  102. }];
  103. [_rightTableV setCallBackSection:^(NSInteger index) {
  104. KWSubTypeSectionModel *m = weak_self.rightTableV.arr[index];
  105. if (m.isMoneyType) {
  106. [ASCurrencyManager.shared setSelectCurrency:m.title];
  107. [weak_self.rightTableV reloadData];
  108. return;
  109. }
  110. [weak_self toResult:m.title type:m.Id keyWord:@""];
  111. }];
  112. }
  113. return _rightTableV;
  114. }
  115. -(UIView *)bottomV {
  116. if (!_bottomV) {
  117. UIView *v = [[UIView alloc] init];
  118. v.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
  119. _bottomV = v;
  120. }
  121. return _bottomV;
  122. }
  123. @end