ASBaseViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. QMUITabBarViewController *tabVC = (QMUITabBarViewController *)((AppDelegate *)UIApplication.sharedApplication.delegate).window.rootViewController;
  113. tabVC.selectedIndex = 0;
  114. UITabBar *tabbar = tabVC.tabBar;
  115. if (tabbar.items.count > 2) {
  116. UITabBarItem *temp = tabbar.items[2];
  117. temp.qmui_badgeInteger = 0;
  118. }
  119. UIViewController *loginC = [[CTMediator sharedInstance] Login_LoginC:@{}];
  120. QMUINavigationController *uikitNavController = [[QMUINavigationController alloc] initWithRootViewController:loginC];
  121. uikitNavController.navigationBar.hidden = YES;
  122. uikitNavController.modalPresentationStyle = UIModalPresentationFullScreen;
  123. [tabVC presentViewController:uikitNavController animated:YES completion:nil];
  124. }
  125. - (void)toOrderListVc {
  126. ASOrderListViewController *orderC = [[ASOrderListViewController alloc]init];
  127. [self.navigationController pushViewController:orderC animated:true];
  128. }
  129. - (void)toLoginVC {
  130. UIViewController *loginC = [[CTMediator sharedInstance] Login_LoginC:@{}];
  131. QMUINavigationController *uikitNavController = [[QMUINavigationController alloc] initWithRootViewController:loginC];
  132. uikitNavController.navigationBar.hidden = YES;
  133. uikitNavController.modalPresentationStyle = UIModalPresentationFullScreen;
  134. [self presentViewController:uikitNavController animated:YES completion:nil];
  135. }
  136. - (void)setTitleStr:(NSString *)titleStr {
  137. _titleStr = titleStr;
  138. self.nav_titleLB.text = _titleStr;
  139. }
  140. - (void)hiddenEmpty {
  141. self.emptyV.hidden = true;
  142. }
  143. - (void)setEmptyTip:(NSString *)tipStr {
  144. self.emptylb.text = tipStr;
  145. }
  146. - (void)showEmptyV:(UIView *)v {
  147. if (self.emptyV.superview == v) {
  148. self.emptyV.hidden = false;
  149. [self.emptyV.superview bringSubviewToFront:self.emptyV];
  150. return;
  151. }
  152. if (v == nil) {
  153. [self.view addSubview:self.emptyV];
  154. [self.emptyV mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.top.equalTo(self.customNavBar.mas_bottom);
  156. make.leading.trailing.bottom.equalTo(self.view);
  157. }];
  158. } else {
  159. [v addSubview:self.emptyV];
  160. [self.emptyV mas_remakeConstraints:^(MASConstraintMaker *make) {
  161. make.edges.equalTo(v);
  162. make.width.height.equalTo(v);
  163. }];
  164. }
  165. self.emptyV.hidden = false;
  166. [self.emptyV.superview bringSubviewToFront:self.emptyV];
  167. dispatch_async(dispatch_get_main_queue(), ^{
  168. [UIView viewAddHorColorBg:self.emptyV colorArr:@[
  169. (id)_E0FFF5.CGColor,
  170. (id)Col_FFF.CGColor
  171. ] startP:CGPointMake(0.5, 0.25) endP:CGPointMake(0.5, 1)];
  172. [self.emptyV bringSubviewToFront:self.emptylb];
  173. });
  174. }
  175. - (void)viewDidLoad {
  176. [super viewDidLoad];
  177. [self addBaseNav];
  178. self.navigationController.navigationBar.hidden = true;
  179. self.customNavBar.backgroundColor = Col_FFF;
  180. self.view.backgroundColor = _F8F8F8;
  181. }
  182. - (void)viewWillAppear:(BOOL)animated {
  183. [super viewWillAppear:animated];
  184. dispatch_async(dispatch_get_main_queue(), ^{
  185. self.tabBarController.tabBar.hidden = self.navigationController.viewControllers.count > 1;
  186. });
  187. }
  188. - (void)viewWillDisappear:(BOOL)animated {
  189. [super viewWillAppear:animated];
  190. }
  191. - (void)setNavRightSearch:(btnClickBlock)nav_searchAction {
  192. self.nav_searchBlock = nav_searchAction;
  193. [self.customNavBar addSubview:self.searchNavBt];
  194. [self.searchNavBt mas_makeConstraints:^(MASConstraintMaker *make) {
  195. make.width.height.equalTo(@44);
  196. make.trailing.equalTo(self.customNavBar).offset(-10);
  197. make.centerY.equalTo(self.customNavBar);
  198. }];
  199. }
  200. - (void)ucHomeStyle:(btnClickBlock)tapSearch {
  201. self.tapSearchBlock = tapSearch;
  202. [self.customNavBar addSubview:self.leftImgV];
  203. [self.customNavBar addSubview:self.searchTf];
  204. [self.customNavBar addSubview:self.tfBt];
  205. [self.leftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  206. make.leading.equalTo(self.customNavBar).offset(20);
  207. make.width.equalTo(@140);
  208. make.height.equalTo(@43.5);
  209. make.centerY.equalTo(self.customNavBar);
  210. }];
  211. [self.searchTf mas_makeConstraints:^(MASConstraintMaker *make) {
  212. make.leading.equalTo(self.leftImgV.mas_trailing).offset(20);
  213. make.height.equalTo(@36);
  214. make.centerY.equalTo(self.leftImgV);
  215. make.trailing.equalTo(self.customNavBar).offset(-10);
  216. }];
  217. [self.tfBt mas_makeConstraints:^(MASConstraintMaker *make) {
  218. make.edges.equalTo(self.searchTf);
  219. }];
  220. }
  221. - (void)addBaseNav {
  222. [self.view addSubview:self.statusBgV];
  223. [self.view addSubview:self.customNavBar];
  224. [self.customNavBar addSubview:self.nav_bottomLineV];
  225. self.statusBgV.frame = CGRectMake(0, 0, KScreenWidth, kStatusBarH);
  226. self.customNavBar.frame = CGRectMake(0, kStatusBarH, KScreenWidth, kCustomNavBarH);
  227. self.nav_bottomLineV.frame = CGRectMake(0, kCustomNavBarH-1, KScreenWidth, 1);
  228. [self.customNavBar addSubview:self.backBt];
  229. [self.customNavBar addSubview:self.nav_titleLB];
  230. [self.backBt mas_makeConstraints:^(MASConstraintMaker *make) {
  231. make.leading.equalTo(self.customNavBar).offset(10);
  232. make.centerY.equalTo(self.customNavBar);
  233. make.width.height.equalTo(@44);
  234. }];
  235. [self.nav_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
  236. make.center.equalTo(self.customNavBar);
  237. make.width.equalTo(self.customNavBar).offset(-120);
  238. make.height.equalTo(@40);
  239. }];
  240. self.backBt.hidden = true;
  241. if (self.navigationController.viewControllers.count > 1) {
  242. self.backBt.hidden = false;
  243. }
  244. [self.emptyV addSubview:self.emptylb];
  245. [self.emptylb mas_makeConstraints:^(MASConstraintMaker *make) {
  246. make.leading.equalTo(self.emptyV).offset(30);
  247. make.trailing.equalTo(self.emptyV).offset(-30);
  248. make.centerY.equalTo(self.emptyV).offset(-30);
  249. make.top.greaterThanOrEqualTo(self.emptyV).offset(20);
  250. }];
  251. }
  252. // MARK: - actions
  253. - (void)searchBtAction {
  254. UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}];
  255. [self presentViewController:vc animated:true completion:nil];
  256. if (self.tapSearchBlock) {
  257. self.tapSearchBlock();
  258. }
  259. }
  260. // MARK: - subVs
  261. - (UIView *)emptyV {
  262. if (!_emptyV) {
  263. UIView *v = [UIView baseV];
  264. v.backgroundColor = Col_FFF;
  265. v.hidden = true;
  266. _emptyV = v;
  267. }
  268. return _emptyV;
  269. }
  270. - (UILabel *)emptylb {
  271. if (!_emptylb) {
  272. UILabel *lb = [UILabel baseLb];
  273. lb.font = [UIFont fontWithName:Rob_Medium size:72];
  274. lb.textAlignment = NSTextAlignmentCenter;
  275. lb.numberOfLines = 0;
  276. lb.text = @"No Data";
  277. lb.textColor = _043632;
  278. _emptylb = lb;
  279. }
  280. return _emptylb;
  281. }
  282. - (UIView *)statusBgV {
  283. if (!_statusBgV) {
  284. UIView *v = [UIView baseV];
  285. v.backgroundColor = _32CFB0;
  286. _statusBgV = v;
  287. }
  288. return _statusBgV;
  289. }
  290. - (UIView *)customNavBar {
  291. if (!_customNavBar) {
  292. UIView *v = [UIView baseV];
  293. v.backgroundColor = _32CFB0;
  294. _customNavBar = v;
  295. }
  296. return _customNavBar;
  297. }
  298. - (UIView *)nav_bottomLineV {
  299. if (!_nav_bottomLineV) {
  300. UIView *v = [UIView baseV];
  301. v.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.05];
  302. _nav_bottomLineV = v;
  303. }
  304. return _nav_bottomLineV;
  305. }
  306. - (UIImageView *)leftImgV {
  307. if (!_leftImgV) {
  308. UIImageView *v = [UIImageView baseImgV];
  309. v.image = [UIImage imageNamed:@"nav_icon"];
  310. _leftImgV = v;
  311. }
  312. return _leftImgV;
  313. }
  314. - (UITextField *)searchTf {
  315. if (!_searchTf) {
  316. UITextField *tf = [[UITextField alloc] init];
  317. tf.borderStyle = UITextBorderStyleNone;
  318. UIView *leftV = [[UIView alloc] init];
  319. leftV.backgroundColor = UIColor.clearColor;
  320. UIImageView *imgV = [UIImageView baseImgV];
  321. imgV.backgroundColor = UIColor.clearColor;
  322. imgV.image = [UIImage imageNamed:@"nav_search"];
  323. leftV.frame = CGRectMake(0, 0, 44, 36);
  324. imgV.frame = CGRectMake(10, 6, 24, 24);
  325. [leftV addSubview:imgV];
  326. tf.leftView = leftV;
  327. tf.leftViewMode = UITextFieldViewModeAlways;
  328. tf.backgroundColor = _F5F5F5;
  329. tf.layer.cornerRadius = 5;
  330. tf.layer.masksToBounds = true;
  331. _searchTf = tf;
  332. }
  333. return _searchTf;
  334. }
  335. - (UIButton *)tfBt {
  336. if (!_tfBt) {
  337. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  338. [bt addTarget:self action:@selector(searchBtAction) forControlEvents:UIControlEventTouchUpInside];
  339. _tfBt = bt;
  340. }
  341. return _tfBt;
  342. }
  343. - (UIButton *)backBt {
  344. if (!_backBt) {
  345. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  346. [bt setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
  347. [bt addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  348. _backBt = bt;
  349. }
  350. return _backBt;
  351. }
  352. - (UILabel *)nav_titleLB {
  353. if (!_nav_titleLB) {
  354. UILabel *lb = [[UILabel alloc] init];
  355. lb.font = [UIFont fontWithName:Rob_Regular size:20];
  356. lb.textAlignment = NSTextAlignmentCenter;
  357. lb.textColor = Col_000;
  358. _nav_titleLB = lb;
  359. }
  360. return _nav_titleLB;
  361. }
  362. - (void)backAction {
  363. [self.navigationController popViewControllerAnimated:true];
  364. }
  365. - (UIButton *)searchNavBt {
  366. if (!_searchNavBt) {
  367. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  368. [bt setImage:[UIImage imageNamed:@"nav_search"] forState:UIControlStateNormal];
  369. [bt addTarget:self action:@selector(search_navAction) forControlEvents:UIControlEventTouchUpInside];
  370. _searchNavBt = bt;
  371. }
  372. return _searchNavBt;
  373. }
  374. // MARK: - actions
  375. - (void)search_navAction {
  376. UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}];
  377. [self presentViewController:vc animated:true completion:nil];
  378. if (self.nav_searchBlock) {
  379. self.nav_searchBlock();
  380. }
  381. }
  382. @end