// // ASCategoryViewController.m // Asteria // // Created by iOS on 2023/7/10. // #import "ASCategoryViewController.h" #import "KWSearchMainTypeTableView.h" #import "KWSearchSubTypeTableView.h" #import "ASCategoriesViewModel.h" @interface ASCategoryViewController () @property (nonatomic, strong) ASCategoriesViewModel *vm; @property (nonatomic, strong) KWSearchMainTypeTableView *leftTableV; @property (nonatomic, strong) KWSearchSubTypeTableView *rightTableV; @property (nonatomic, strong) UIView *bottomV; @end @implementation ASCategoryViewController - (void)viewDidLoad { [super viewDidLoad]; self.vm = [ASCategoriesViewModel new]; [self loadSubVs]; [self getData]; } - (void)getData { __weak typeof(self) weakSelf = self; [self.vm getAllCateGories:@"" com:^(BOOL isSuc, NSString * _Nonnull msg) { NSArray *tempArr = weakSelf.vm.totalDatas; weakSelf.leftTableV.arr = tempArr; NSInteger cusSelect = 0; for (int i=0; i 0) { cusSelect = i; break; } } if (tempArr.count > cusSelect) { weakSelf.rightTableV.arr = tempArr[cusSelect].children_data; } weakSelf.leftTableV.selectIndex = cusSelect; [weakSelf.leftTableV reloadData]; [weakSelf.rightTableV reloadData]; if (!isSuc) { [weakSelf.view makeToast:msg]; } }]; } - (void)loadSubVs { self.statusBgV.backgroundColor = _E0FFF5; self.customNavBar.backgroundColor = _E0FFF5; self.titleStr = @"Category"; [self.view addSubview:self.bottomV]; [self.bottomV addSubview:self.leftTableV]; [self.bottomV addSubview:self.rightTableV]; [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.customNavBar.mas_bottom).offset(10); make.left.right.equalTo(self.view); make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom); }]; [self.leftTableV mas_makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(@130); make.left.top.bottom.equalTo(self.bottomV); }]; [self.rightTableV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.right.equalTo(self.bottomV); make.left.equalTo(self.leftTableV.mas_right); }]; } // MARK: - actions - (void)toResult:(NSString *)key type:(NSString *)type keyWord:(NSString *)word { NSDictionary *para = @{ @"type":type, //String @"title":key,//String @"searchKey":word,//String }; UIViewController *vc = [CTMediator.sharedInstance getProductListVc:para]; [self.navigationController pushViewController:vc animated:true]; } // MARK: - subvs - (KWSearchMainTypeTableView *)leftTableV { if (!_leftTableV) { KWSearchMainTypeTableView *leftTab = [[KWSearchMainTypeTableView alloc] initWithFrame:CGRectMake(0, 10, 180, self.view.bounds.size.height) style:UITableViewStylePlain]; leftTab.backgroundColor = _F8F8F8; @weakify(self); _leftTableV = leftTab; leftTab.callBack = ^{ NSInteger selectIndex = weak_self.leftTableV.selectIndex; if (selectIndex >= weak_self.leftTableV.arr.count) { weak_self.rightTableV.arr = weak_self.leftTableV.moneyType.children_data; [weak_self.rightTableV reloadData]; return; } KWMainTypeModel *m = weak_self.leftTableV.arr[selectIndex]; if (m.children_data.count == 0) { [self toResult:m.title type:m.Id keyWord:@""]; } else { weak_self.rightTableV.arr = m.children_data; [weak_self.rightTableV reloadData]; } }; } return _leftTableV; } - (KWSearchSubTypeTableView *)rightTableV { if(!_rightTableV) { KWSearchSubTypeTableView *tab = [[KWSearchSubTypeTableView alloc] initWithFrame:CGRectMake(0, 10, 180, self.view.bounds.size.height) style:UITableViewStylePlain]; tab.backgroundColor = _F8F8F8; _rightTableV = tab; @weakify(self); [_rightTableV setCallBack:^(NSIndexPath * _Nonnull indexP) { KWSearchSubTypeModel *m = weak_self.rightTableV.arr[indexP.section].children_data[indexP.item]; [weak_self toResult:m.title type:m.Id keyWord:@""]; }]; [_rightTableV setCallBackSection:^(NSInteger index) { KWSubTypeSectionModel *m = weak_self.rightTableV.arr[index]; if (m.isMoneyType) { [ASCurrencyManager.shared setSelectCurrency:m.title]; [weak_self.rightTableV reloadData]; return; } [weak_self toResult:m.title type:m.Id keyWord:@""]; }]; } return _rightTableV; } -(UIView *)bottomV { if (!_bottomV) { UIView *v = [[UIView alloc] init]; v.backgroundColor = [UIColor colorWithHexString:@"#ffffff"]; _bottomV = v; } return _bottomV; } @end