ASBaseViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. //
  2. // ASBaseViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/4/24.
  6. //
  7. #import "ASBaseViewController.h"
  8. #import "AppDelegate.h"
  9. #import "GoodsInformationM.h"
  10. @interface ASBaseViewController ()
  11. @property (nonatomic, strong) UIImageView *leftImgV;
  12. @property (nonatomic, strong) UITextField *searchTf;
  13. @property (nonatomic, strong) UIButton *tfBt;
  14. @property (nonatomic, copy) btnClickBlock tapSearchBlock;
  15. @property (nonatomic, strong) UIButton *backBt;
  16. @property (nonatomic, strong) UIButton *searchNavBt;
  17. @property (nonatomic, copy) btnClickBlock nav_searchBlock;
  18. @property (nonatomic, strong) UIView *emptyV;
  19. @property (nonatomic, strong) UILabel *emptylb;
  20. @end
  21. @implementation ASBaseViewController
  22. /// 跳转类型 0 web 1商品详情 2商品列表 3koc 4:注册页
  23. - (void)jumpWithModel:(ASJumpModel *)model {
  24. if (model.type.intValue == 1) {
  25. [self goto_WKM_GoodsDetailsC:model.link];
  26. return;
  27. }
  28. if (model.type.intValue == 2) {
  29. NSString *typeId = model.link;
  30. [self pushToProductList:model.title typeid:typeId];
  31. return;
  32. }
  33. if (model.type.intValue == 4) {
  34. [self toLoginVC];
  35. return;
  36. }
  37. // if (model.type.intValue == 3) {
  38. // if (![self checkLogin:true]) {
  39. // return;
  40. // }
  41. // __weak typeof(self) weak_self = self;
  42. // [MBProgressHUD showHUDAddedTo:self.view animated:true];
  43. // [[KWBalanceInfoManager shareInstance] updateApplyStatus:^(BOOL flag) {
  44. // [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  45. // if (![KWBalanceInfoManager shareInstance].isApply) {
  46. // KWBrandAMBViewController *vc = [KWBrandAMBViewController new];
  47. // [weak_self.navigationController pushViewController:vc animated:true];
  48. // } else {
  49. // APKocTotalViewController *vc = [[APKocTotalViewController alloc] init];
  50. // [weak_self.navigationController pushViewController:vc animated:true];
  51. // }
  52. // }];
  53. // return;
  54. // }
  55. if ([model.link.lowercaseString hasPrefix:@"http"]) {
  56. [self toWebVC:model.link name:model.title];
  57. }
  58. }
  59. - (void)toWebVC:(NSString *)urlStr name:(NSString *)name {
  60. [Fuction_Tool push_BaseWebUrl:urlStr webTitle:name];
  61. }
  62. -(void)pushToProductList:(NSString *)name typeid:(NSString *)typeId {
  63. if (typeId == nil || [typeId isEqualToString:@""]) {
  64. return;
  65. }
  66. if (name == nil || [name isEqualToString:@""]) {
  67. name = @"Products";
  68. }
  69. UIViewController *vc = [CTMediator.sharedInstance getProductListVc:@{
  70. @"type":typeId, //String
  71. @"title":name,//String
  72. }];
  73. [self.navigationController pushViewController:vc animated:true];
  74. }
  75. -(void)goto_WKM_GoodsDetailsC:(NSString *)entity_id {
  76. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":entity_id}];
  77. [self.navigationController pushViewController:viewController animated:YES];
  78. }
  79. -(void)action_GoodsSizeC:(NSString *)entity_id {
  80. if (!ASUserInfoManager.shared.isLogin) {
  81. [self toLoginVC];
  82. return;
  83. }
  84. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  85. [params setObject:entity_id forKey:@"productId"];
  86. [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
  87. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  88. __weak typeof(self) weakSelf = self;
  89. [ASNetTools.shared getWithPath:getProdectDetail param:params success:^(id _Nonnull json) {
  90. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  91. GoodsInformationM *model = [GoodsInformationM mj_objectWithKeyValues:json];
  92. if (model == nil || model.Id == nil || model.Id.isEmpty) {
  93. return;
  94. }
  95. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsSizeC:@{@"model":model}];
  96. viewController.modalPresentationStyle = UIModalPresentationFullScreen;
  97. [weakSelf presentViewController:viewController animated:YES completion:nil];
  98. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  99. [self.view makeToast:msg];
  100. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  101. }];
  102. }
  103. - (void)toHomeVc {
  104. if (self.navigationController != nil) {
  105. [self.navigationController popToRootViewControllerAnimated:false];
  106. }
  107. QMUITabBarViewController *tabVC = (QMUITabBarViewController *)((AppDelegate *)UIApplication.sharedApplication.delegate).window.rootViewController;
  108. tabVC.selectedIndex = 0;
  109. }
  110. - (void)popAndToLogin {
  111. QMUITabBarViewController *tabVC = (QMUITabBarViewController *)((AppDelegate *)UIApplication.sharedApplication.delegate).window.rootViewController;
  112. tabVC.selectedIndex = 0;
  113. UITabBar *tabbar = tabVC.tabBar;
  114. if (tabbar.items.count > 2) {
  115. UITabBarItem *temp = tabbar.items[2];
  116. temp.qmui_badgeInteger = 0;
  117. }
  118. UIViewController *loginC = [[CTMediator sharedInstance] Login_LoginC:@{}];
  119. QMUINavigationController *uikitNavController = [[QMUINavigationController alloc] initWithRootViewController:loginC];
  120. uikitNavController.navigationBar.hidden = YES;
  121. uikitNavController.modalPresentationStyle = UIModalPresentationFullScreen;
  122. [tabVC presentViewController:uikitNavController animated:YES completion:nil];
  123. }
  124. - (void)toLoginVC {
  125. UIViewController *loginC = [[CTMediator sharedInstance] Login_LoginC:@{}];
  126. QMUINavigationController *uikitNavController = [[QMUINavigationController alloc] initWithRootViewController:loginC];
  127. uikitNavController.navigationBar.hidden = YES;
  128. uikitNavController.modalPresentationStyle = UIModalPresentationFullScreen;
  129. [self presentViewController:uikitNavController animated:YES completion:nil];
  130. }
  131. - (void)setTitleStr:(NSString *)titleStr {
  132. _titleStr = titleStr;
  133. self.nav_titleLB.text = _titleStr;
  134. }
  135. - (void)hiddenEmpty {
  136. self.emptyV.hidden = true;
  137. }
  138. - (void)setEmptyTip:(NSString *)tipStr {
  139. self.emptylb.text = tipStr;
  140. }
  141. - (void)showEmptyV:(UIView *)v {
  142. if (self.emptyV.superview == v) {
  143. self.emptyV.hidden = false;
  144. [self.emptyV.superview bringSubviewToFront:self.emptyV];
  145. return;
  146. }
  147. if (v == nil) {
  148. [self.view addSubview:self.emptyV];
  149. [self.emptyV mas_makeConstraints:^(MASConstraintMaker *make) {
  150. make.top.equalTo(self.customNavBar.mas_bottom);
  151. make.leading.trailing.bottom.equalTo(self.view);
  152. }];
  153. } else {
  154. [v addSubview:self.emptyV];
  155. [self.emptyV mas_remakeConstraints:^(MASConstraintMaker *make) {
  156. make.edges.equalTo(v);
  157. make.width.height.equalTo(v);
  158. }];
  159. }
  160. self.emptyV.hidden = false;
  161. [self.emptyV.superview bringSubviewToFront:self.emptyV];
  162. dispatch_async(dispatch_get_main_queue(), ^{
  163. [UIView viewAddHorColorBg:self.emptyV colorArr:@[
  164. (id)_E0FFF5.CGColor,
  165. (id)Col_FFF.CGColor
  166. ] startP:CGPointMake(0.5, 0.25) endP:CGPointMake(0.5, 1)];
  167. [self.emptyV bringSubviewToFront:self.emptylb];
  168. });
  169. }
  170. - (void)viewDidLoad {
  171. [super viewDidLoad];
  172. [self addBaseNav];
  173. self.navigationController.navigationBar.hidden = true;
  174. self.customNavBar.backgroundColor = Col_FFF;
  175. self.view.backgroundColor = _F8F8F8;
  176. }
  177. - (void)viewWillAppear:(BOOL)animated {
  178. [super viewWillAppear:animated];
  179. dispatch_async(dispatch_get_main_queue(), ^{
  180. self.tabBarController.tabBar.hidden = self.navigationController.viewControllers.count > 1;
  181. });
  182. }
  183. - (void)viewWillDisappear:(BOOL)animated {
  184. [super viewWillAppear:animated];
  185. }
  186. - (void)setNavRightSearch:(btnClickBlock)nav_searchAction {
  187. self.nav_searchBlock = nav_searchAction;
  188. [self.customNavBar addSubview:self.searchNavBt];
  189. [self.searchNavBt mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.width.height.equalTo(@44);
  191. make.trailing.equalTo(self.customNavBar).offset(-10);
  192. make.centerY.equalTo(self.customNavBar);
  193. }];
  194. }
  195. - (void)ucHomeStyle:(btnClickBlock)tapSearch {
  196. self.tapSearchBlock = tapSearch;
  197. [self.customNavBar addSubview:self.leftImgV];
  198. [self.customNavBar addSubview:self.searchTf];
  199. [self.customNavBar addSubview:self.tfBt];
  200. [self.leftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  201. make.leading.equalTo(self.customNavBar).offset(20);
  202. make.width.equalTo(@140);
  203. make.height.equalTo(@43.5);
  204. make.centerY.equalTo(self.customNavBar);
  205. }];
  206. [self.searchTf mas_makeConstraints:^(MASConstraintMaker *make) {
  207. make.leading.equalTo(self.leftImgV.mas_trailing).offset(20);
  208. make.height.equalTo(@36);
  209. make.centerY.equalTo(self.leftImgV);
  210. make.trailing.equalTo(self.customNavBar).offset(-10);
  211. }];
  212. [self.tfBt mas_makeConstraints:^(MASConstraintMaker *make) {
  213. make.edges.equalTo(self.searchTf);
  214. }];
  215. }
  216. - (void)addBaseNav {
  217. [self.view addSubview:self.statusBgV];
  218. [self.view addSubview:self.customNavBar];
  219. [self.customNavBar addSubview:self.nav_bottomLineV];
  220. self.statusBgV.frame = CGRectMake(0, 0, KScreenWidth, kStatusBarH);
  221. self.customNavBar.frame = CGRectMake(0, kStatusBarH, KScreenWidth, kCustomNavBarH);
  222. self.nav_bottomLineV.frame = CGRectMake(0, kCustomNavBarH-1, KScreenWidth, 1);
  223. [self.customNavBar addSubview:self.backBt];
  224. [self.customNavBar addSubview:self.nav_titleLB];
  225. [self.backBt mas_makeConstraints:^(MASConstraintMaker *make) {
  226. make.leading.equalTo(self.customNavBar).offset(10);
  227. make.centerY.equalTo(self.customNavBar);
  228. make.width.height.equalTo(@44);
  229. }];
  230. [self.nav_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
  231. make.center.equalTo(self.customNavBar);
  232. make.width.equalTo(self.customNavBar).offset(-120);
  233. make.height.equalTo(@40);
  234. }];
  235. self.backBt.hidden = true;
  236. if (self.navigationController.viewControllers.count > 1) {
  237. self.backBt.hidden = false;
  238. }
  239. [self.emptyV addSubview:self.emptylb];
  240. [self.emptylb mas_makeConstraints:^(MASConstraintMaker *make) {
  241. make.leading.equalTo(self.emptyV).offset(30);
  242. make.trailing.equalTo(self.emptyV).offset(-30);
  243. make.centerY.equalTo(self.emptyV).offset(-30);
  244. make.top.greaterThanOrEqualTo(self.emptyV).offset(20);
  245. }];
  246. }
  247. // MARK: - actions
  248. - (void)searchBtAction {
  249. UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}];
  250. [self presentViewController:vc animated:true completion:nil];
  251. if (self.tapSearchBlock) {
  252. self.tapSearchBlock();
  253. }
  254. }
  255. // MARK: - subVs
  256. - (UIView *)emptyV {
  257. if (!_emptyV) {
  258. UIView *v = [UIView baseV];
  259. v.backgroundColor = Col_FFF;
  260. v.hidden = true;
  261. _emptyV = v;
  262. }
  263. return _emptyV;
  264. }
  265. - (UILabel *)emptylb {
  266. if (!_emptylb) {
  267. UILabel *lb = [UILabel baseLb];
  268. lb.font = [UIFont fontWithName:Rob_Medium size:72];
  269. lb.textAlignment = NSTextAlignmentCenter;
  270. lb.numberOfLines = 0;
  271. lb.text = @"No Data";
  272. lb.textColor = _043632;
  273. _emptylb = lb;
  274. }
  275. return _emptylb;
  276. }
  277. - (UIView *)statusBgV {
  278. if (!_statusBgV) {
  279. UIView *v = [UIView baseV];
  280. v.backgroundColor = _32CFB0;
  281. _statusBgV = v;
  282. }
  283. return _statusBgV;
  284. }
  285. - (UIView *)customNavBar {
  286. if (!_customNavBar) {
  287. UIView *v = [UIView baseV];
  288. v.backgroundColor = _32CFB0;
  289. _customNavBar = v;
  290. }
  291. return _customNavBar;
  292. }
  293. - (UIView *)nav_bottomLineV {
  294. if (!_nav_bottomLineV) {
  295. UIView *v = [UIView baseV];
  296. v.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.05];
  297. _nav_bottomLineV = v;
  298. }
  299. return _nav_bottomLineV;
  300. }
  301. - (UIImageView *)leftImgV {
  302. if (!_leftImgV) {
  303. UIImageView *v = [UIImageView baseImgV];
  304. v.image = [UIImage imageNamed:@"nav_icon"];
  305. _leftImgV = v;
  306. }
  307. return _leftImgV;
  308. }
  309. - (UITextField *)searchTf {
  310. if (!_searchTf) {
  311. UITextField *tf = [[UITextField alloc] init];
  312. tf.borderStyle = UITextBorderStyleNone;
  313. UIView *leftV = [[UIView alloc] init];
  314. leftV.backgroundColor = UIColor.clearColor;
  315. UIImageView *imgV = [UIImageView baseImgV];
  316. imgV.backgroundColor = UIColor.clearColor;
  317. imgV.image = [UIImage imageNamed:@"nav_search"];
  318. leftV.frame = CGRectMake(0, 0, 44, 36);
  319. imgV.frame = CGRectMake(10, 6, 24, 24);
  320. [leftV addSubview:imgV];
  321. tf.leftView = leftV;
  322. tf.leftViewMode = UITextFieldViewModeAlways;
  323. tf.backgroundColor = _F5F5F5;
  324. tf.layer.cornerRadius = 5;
  325. tf.layer.masksToBounds = true;
  326. _searchTf = tf;
  327. }
  328. return _searchTf;
  329. }
  330. - (UIButton *)tfBt {
  331. if (!_tfBt) {
  332. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  333. [bt addTarget:self action:@selector(searchBtAction) forControlEvents:UIControlEventTouchUpInside];
  334. _tfBt = bt;
  335. }
  336. return _tfBt;
  337. }
  338. - (UIButton *)backBt {
  339. if (!_backBt) {
  340. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  341. [bt setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
  342. [bt addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  343. _backBt = bt;
  344. }
  345. return _backBt;
  346. }
  347. - (UILabel *)nav_titleLB {
  348. if (!_nav_titleLB) {
  349. UILabel *lb = [[UILabel alloc] init];
  350. lb.font = [UIFont fontWithName:Rob_Regular size:20];
  351. lb.textAlignment = NSTextAlignmentCenter;
  352. lb.textColor = Col_000;
  353. _nav_titleLB = lb;
  354. }
  355. return _nav_titleLB;
  356. }
  357. - (void)backAction {
  358. [self.navigationController popViewControllerAnimated:true];
  359. }
  360. - (UIButton *)searchNavBt {
  361. if (!_searchNavBt) {
  362. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  363. [bt setImage:[UIImage imageNamed:@"nav_search"] forState:UIControlStateNormal];
  364. [bt addTarget:self action:@selector(search_navAction) forControlEvents:UIControlEventTouchUpInside];
  365. _searchNavBt = bt;
  366. }
  367. return _searchNavBt;
  368. }
  369. // MARK: - actions
  370. - (void)search_navAction {
  371. UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}];
  372. [self presentViewController:vc animated:true completion:nil];
  373. if (self.nav_searchBlock) {
  374. self.nav_searchBlock();
  375. }
  376. }
  377. @end