ASBaseViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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)viewWillDisappear:(BOOL)animated {
  192. [super viewWillAppear:animated];
  193. }
  194. - (void)setNavRightSearch:(btnClickBlock)nav_searchAction {
  195. self.nav_searchBlock = nav_searchAction;
  196. [self.customNavBar addSubview:self.searchNavBt];
  197. [self.searchNavBt mas_makeConstraints:^(MASConstraintMaker *make) {
  198. make.width.height.equalTo(@44);
  199. make.trailing.equalTo(self.customNavBar).offset(-10);
  200. make.centerY.equalTo(self.customNavBar);
  201. }];
  202. }
  203. - (void)ucHomeStyle:(btnClickBlock)tapSearch {
  204. self.tapSearchBlock = tapSearch;
  205. [self.customNavBar addSubview:self.leftImgV];
  206. [self.customNavBar addSubview:self.searchTf];
  207. [self.customNavBar addSubview:self.tfBt];
  208. [self.leftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  209. make.leading.equalTo(self.customNavBar).offset(20);
  210. make.width.equalTo(@140);
  211. make.height.equalTo(@43.5);
  212. make.centerY.equalTo(self.customNavBar);
  213. }];
  214. [self.searchTf mas_makeConstraints:^(MASConstraintMaker *make) {
  215. make.leading.equalTo(self.leftImgV.mas_trailing).offset(20);
  216. make.height.equalTo(@36);
  217. make.centerY.equalTo(self.leftImgV);
  218. make.trailing.equalTo(self.customNavBar).offset(-10);
  219. }];
  220. [self.tfBt mas_makeConstraints:^(MASConstraintMaker *make) {
  221. make.edges.equalTo(self.searchTf);
  222. }];
  223. }
  224. - (void)addBaseNav {
  225. [self.view addSubview:self.statusBgV];
  226. [self.view addSubview:self.customNavBar];
  227. [self.customNavBar addSubview:self.nav_bottomLineV];
  228. self.statusBgV.frame = CGRectMake(0, 0, KScreenWidth, kStatusBarH);
  229. self.customNavBar.frame = CGRectMake(0, kStatusBarH, KScreenWidth, kCustomNavBarH);
  230. self.nav_bottomLineV.frame = CGRectMake(0, kCustomNavBarH-1, KScreenWidth, 1);
  231. [self.customNavBar addSubview:self.backBt];
  232. [self.customNavBar addSubview:self.nav_titleLB];
  233. [self.backBt mas_makeConstraints:^(MASConstraintMaker *make) {
  234. make.leading.equalTo(self.customNavBar).offset(10);
  235. make.centerY.equalTo(self.customNavBar);
  236. make.width.height.equalTo(@44);
  237. }];
  238. [self.nav_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
  239. make.center.equalTo(self.customNavBar);
  240. make.width.equalTo(self.customNavBar).offset(-120);
  241. make.height.equalTo(@40);
  242. }];
  243. self.backBt.hidden = true;
  244. if (self.navigationController.viewControllers.count > 1) {
  245. self.backBt.hidden = false;
  246. }
  247. [self.emptyV addSubview:self.emptylb];
  248. [self.emptylb mas_makeConstraints:^(MASConstraintMaker *make) {
  249. make.leading.equalTo(self.emptyV).offset(30);
  250. make.trailing.equalTo(self.emptyV).offset(-30);
  251. make.centerY.equalTo(self.emptyV).offset(-30);
  252. make.top.greaterThanOrEqualTo(self.emptyV).offset(20);
  253. }];
  254. }
  255. // MARK: - actions
  256. - (void)searchBtAction {
  257. UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}];
  258. [self presentViewController:vc animated:true completion:nil];
  259. if (self.tapSearchBlock) {
  260. self.tapSearchBlock();
  261. }
  262. }
  263. // MARK: - subVs
  264. - (UIView *)emptyV {
  265. if (!_emptyV) {
  266. UIView *v = [UIView baseV];
  267. v.backgroundColor = Col_FFF;
  268. v.hidden = true;
  269. _emptyV = v;
  270. }
  271. return _emptyV;
  272. }
  273. - (UILabel *)emptylb {
  274. if (!_emptylb) {
  275. UILabel *lb = [UILabel baseLb];
  276. lb.font = [UIFont fontWithName:Rob_Medium size:72];
  277. lb.textAlignment = NSTextAlignmentCenter;
  278. lb.numberOfLines = 0;
  279. lb.text = @"No Data";
  280. lb.textColor = _043632;
  281. _emptylb = lb;
  282. }
  283. return _emptylb;
  284. }
  285. - (UIView *)statusBgV {
  286. if (!_statusBgV) {
  287. UIView *v = [UIView baseV];
  288. v.backgroundColor = _32CFB0;
  289. _statusBgV = v;
  290. }
  291. return _statusBgV;
  292. }
  293. - (UIView *)customNavBar {
  294. if (!_customNavBar) {
  295. UIView *v = [UIView baseV];
  296. v.backgroundColor = _32CFB0;
  297. _customNavBar = v;
  298. }
  299. return _customNavBar;
  300. }
  301. - (UIView *)nav_bottomLineV {
  302. if (!_nav_bottomLineV) {
  303. UIView *v = [UIView baseV];
  304. v.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.05];
  305. _nav_bottomLineV = v;
  306. }
  307. return _nav_bottomLineV;
  308. }
  309. - (UIImageView *)leftImgV {
  310. if (!_leftImgV) {
  311. UIImageView *v = [UIImageView baseImgV];
  312. v.image = [UIImage imageNamed:@"nav_icon"];
  313. v.userInteractionEnabled = true;
  314. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(logo_navAction)];
  315. [v addGestureRecognizer:tap];
  316. _leftImgV = v;
  317. }
  318. return _leftImgV;
  319. }
  320. - (UITextField *)searchTf {
  321. if (!_searchTf) {
  322. UITextField *tf = [[UITextField alloc] init];
  323. tf.borderStyle = UITextBorderStyleNone;
  324. UIView *leftV = [[UIView alloc] init];
  325. leftV.backgroundColor = UIColor.clearColor;
  326. UIImageView *imgV = [UIImageView baseImgV];
  327. imgV.backgroundColor = UIColor.clearColor;
  328. imgV.image = [UIImage imageNamed:@"nav_search"];
  329. leftV.frame = CGRectMake(0, 0, 44, 36);
  330. imgV.frame = CGRectMake(10, 6, 24, 24);
  331. [leftV addSubview:imgV];
  332. tf.leftView = leftV;
  333. tf.leftViewMode = UITextFieldViewModeAlways;
  334. tf.backgroundColor = _F5F5F5;
  335. tf.layer.cornerRadius = 5;
  336. tf.layer.masksToBounds = true;
  337. _searchTf = tf;
  338. }
  339. return _searchTf;
  340. }
  341. - (UIButton *)tfBt {
  342. if (!_tfBt) {
  343. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  344. [bt addTarget:self action:@selector(searchBtAction) forControlEvents:UIControlEventTouchUpInside];
  345. _tfBt = bt;
  346. }
  347. return _tfBt;
  348. }
  349. - (UIButton *)backBt {
  350. if (!_backBt) {
  351. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  352. [bt setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
  353. [bt addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  354. _backBt = bt;
  355. }
  356. return _backBt;
  357. }
  358. - (UILabel *)nav_titleLB {
  359. if (!_nav_titleLB) {
  360. UILabel *lb = [[UILabel alloc] init];
  361. lb.font = [UIFont fontWithName:Rob_Regular size:20];
  362. lb.textAlignment = NSTextAlignmentCenter;
  363. lb.textColor = Col_000;
  364. _nav_titleLB = lb;
  365. }
  366. return _nav_titleLB;
  367. }
  368. - (void)backAction {
  369. [self.navigationController popViewControllerAnimated:true];
  370. }
  371. - (UIButton *)searchNavBt {
  372. if (!_searchNavBt) {
  373. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  374. [bt setImage:[UIImage imageNamed:@"nav_search"] forState:UIControlStateNormal];
  375. [bt addTarget:self action:@selector(search_navAction) forControlEvents:UIControlEventTouchUpInside];
  376. _searchNavBt = bt;
  377. }
  378. return _searchNavBt;
  379. }
  380. // MARK: - actions
  381. - (void)search_navAction {
  382. UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}];
  383. [self presentViewController:vc animated:true completion:nil];
  384. if (self.nav_searchBlock) {
  385. self.nav_searchBlock();
  386. }
  387. }
  388. // MARK: - actions
  389. - (void)logo_navAction {
  390. if (self.nav_logoBlock) {
  391. self.nav_logoBlock();
  392. }
  393. }
  394. @end