ASBaseViewController.m 14 KB

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