ASBaseViewController.m 15 KB

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