dkahgld

ProductViewController.m 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. //
  2. // ProductViewController.m
  3. // ZBProject
  4. //
  5. // Created by 学丽 on 2019/3/26.
  6. // Copyright © 2019 ZB. All rights reserved.
  7. //
  8. #import "ProductViewController.h"
  9. #import "ZBProductListCell.h"
  10. #import "UIView+BABadgeView.h"
  11. @interface ProductViewController ()<LPPageVCDelegate,LPPageVCDataSource>
  12. {
  13. UIButton *messageBtn;
  14. }
  15. @property(nonatomic,strong)UIImageView *bgImageView;
  16. @property (nonatomic, strong) NSMutableArray *titleArr;
  17. @property (nonatomic, strong) NSMutableArray *vcArray;
  18. @property (nonatomic, strong) NSMutableArray *modelArray;
  19. @property (nonatomic, strong) NSMutableArray*classArray;
  20. @end
  21. @implementation ProductViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollDirectorNoti:) name:@"scrollDirectorNoti" object:nil];
  25. [self initNav];
  26. [self configSegmentDelegate];
  27. [self getDataClass];
  28. }
  29. #pragma mark---获取顶部分类
  30. -(void)getDataClass
  31. {
  32. if (![AccountTool isLogin]) {
  33. return;
  34. }
  35. [LoadingView showInView:self.view];
  36. [ZBHTTP post:[NSString stringWithFormat:@"%@api/goods/listTopBar",BASEURL] params:nil success:^(id _Nonnull json) {
  37. [LoadingView dismiss];
  38. NSLog(@"%@",json);
  39. NSArray *array =[NSArray yy_modelArrayWithClass:[ClassModel class] json:json[@"list"]];
  40. [self.classArray addObjectsFromArray:array];
  41. for (ClassModel *models in self.classArray) {
  42. [self.titleArr addObject:models.name];
  43. ZBProductListViewController *vc=[[ZBProductListViewController alloc]init];
  44. vc.model=models;
  45. [self.vcArray addObject:vc];
  46. }
  47. [self reloadData];
  48. } failure:^(NSError * _Nonnull error) {
  49. [LoadingView dismiss];
  50. }];
  51. }
  52. - (void)configSegmentDelegate {
  53. self.normalTextColor = [UIColor whiteColor];
  54. self.higlightTextColor = [UIColor whiteColor];
  55. self.lineBackground = [UIColor whiteColor];
  56. self.segmentStyle = LPPageVCSegmentStyleLineHighlight;
  57. self.delegate = self;
  58. self.dataSource = self;
  59. }
  60. #pragma mark ======================= LPPageVC Delegate & DataSource =======================
  61. - (UIViewController *)pageVC:(LPPageVC *)pageVC viewControllerAtIndex:(NSInteger)index{
  62. return self.vcArray[index];
  63. }
  64. - (NSString *)pageVC:(LPPageVC *)pageVC titleAtIndex:(NSInteger)index{
  65. return self.titleArr[index];
  66. }
  67. - (NSInteger)numberOfContentForPageVC:(LPPageVC *)pageVC {
  68. return self.titleArr.count;
  69. }
  70. - (void)pageVC:(LPPageVC *)pageVC didClickEditMode:(LPPageVCEditMode)mode {
  71. }
  72. - (void)pageVC:(LPPageVC *)pageVC didChangeToIndex:(NSInteger)toIndex fromIndex:(NSInteger)fromIndex {
  73. NSInteger index = toIndex;
  74. if (toIndex<0 || toIndex >self.classArray.count-1) {
  75. index = 0;
  76. }
  77. ClassModel *models =self.classArray[index];
  78. [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:models.backimg] placeholderImage:nil];
  79. }
  80. -(void)changeHeadInfo
  81. {
  82. ZBUserInfoViewController *setV =[[ZBUserInfoViewController alloc]init];
  83. [self.navigationController pushViewController:setV animated:YES];
  84. }
  85. #pragma mark -- 左边控制器页面push方法
  86. -(void)leftSliderClickWithRow:(NSNotification *)noti{
  87. NSIndexPath *indexPaht =[noti object];
  88. NSInteger row =indexPaht.row;
  89. if (row == 0 ) {//收藏夹
  90. ZBCollectionVC *collV =[[ZBCollectionVC alloc]init];
  91. [self.navigationController pushViewController:collV animated:YES];
  92. return;
  93. }else if (row == 1) {//客服小蜜
  94. ZBAdWebViewController *adWeb = [[ZBAdWebViewController alloc] init];
  95. adWeb.url =jiaochengUrl;
  96. [self.navigationController pushViewController:adWeb animated:YES];
  97. return;
  98. }
  99. //过审.没有快手
  100. if (![PublicFunction canOpenURL:kwaiUrl]) {
  101. ZBSetViewController *setv=[[ZBSetViewController alloc]init];
  102. [self.navigationController pushViewController:setv animated:YES];
  103. }else{
  104. if (row == 2){//招商合作
  105. ZBWebViewController *web = [[ZBWebViewController alloc] init];
  106. web.url = CooperationURl;
  107. [self.navigationController pushViewController:web animated:YES];
  108. }else if (row == 3) {//PId
  109. ZBPIdViewController *pidV =[[ZBPIdViewController alloc]init];
  110. [self.navigationController pushViewController:pidV animated:YES];
  111. }else if (row == 4){//设置
  112. ZBSetViewController *setv=[[ZBSetViewController alloc]init];
  113. [self.navigationController pushViewController:setv animated:YES];
  114. }
  115. }
  116. }
  117. #pragma mark -- 移除通知
  118. -(void)dealloc{
  119. [[NSNotificationCenter defaultCenter]removeObserver:self];
  120. }
  121. -(void)initNav
  122. {
  123. self.backView.hidden=NO;
  124. self.navBar.navTitleLabel.font=[UIFont systemFontOfSize:18];
  125. //接收通知
  126. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(leftSliderClickWithRow:) name:@"product" object:nil];
  127. //接收通知
  128. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeHeadInfo) name:@"producthead" object:nil];
  129. self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, KStatusBarHeight+NavBarHeight+95)];
  130. self.bgImageView.contentMode = UIViewContentModeScaleAspectFill;
  131. self.bgImageView.backgroundColor = [UIColor baseColor];
  132. [self.view addSubview:self.bgImageView];
  133. [self.view sendSubviewToBack:self.bgImageView];
  134. self.navBar.backgroundColor=[UIColor clearColor];
  135. self.backView.backgroundColor=[UIColor clearColor];
  136. UIButton *searchBtn =[[UIButton alloc]initWithFrame:CGRectMake(60, KStatusBarHeight+7, SCREEN_WIDTH-75, 31)];
  137. searchBtn.backgroundColor=[UIColor whiteColor];
  138. searchBtn.adjustsImageWhenHighlighted=NO;
  139. [searchBtn setTitleColor:[UIColor YHColorWithHex:0x999999] forState:UIControlStateNormal];
  140. searchBtn.titleLabel.font=[UIFont systemFontOfSize:14];
  141. searchBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
  142. searchBtn.imageEdgeInsets=UIEdgeInsetsMake(0, 10, 0, 0);
  143. searchBtn.titleEdgeInsets=UIEdgeInsetsMake(0, 15, 0, 0);
  144. searchBtn.layer.cornerRadius=15.5;
  145. searchBtn.layer.masksToBounds=YES;
  146. [searchBtn setTitle:@"搜索你想要的商品" forState:UIControlStateNormal];
  147. [searchBtn setImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateNormal];
  148. [searchBtn addTarget:self action:@selector(searchClickBtn) forControlEvents:UIControlEventTouchUpInside];
  149. [self.navBar addSubview:searchBtn];
  150. }
  151. //- (void)scrollDirectorNoti:(NSNotification *)noti{
  152. //
  153. // NSDictionary *info = noti.userInfo;
  154. // //获取到拖拽的速度 >0 向下拖动 <0 向上拖动
  155. // CGFloat director =[info[@"director"] floatValue];
  156. // if (director<0) {
  157. // self.backView.hidden=YES;
  158. // }else{
  159. // self.backView.hidden=NO;
  160. // }
  161. //
  162. // CGFloat offY = [info[@"offY"] floatValue];
  163. // CGFloat standard = NavBarHeight-KStatusBarHeight;//渐变的距离
  164. // self.navBar.alpha -= offY/standard;
  165. // if (self.navBar.alpha > 1) {
  166. // self.navBar.alpha = 1;
  167. // }
  168. // if (self.navBar.alpha < 0) {
  169. // self.navBar.alpha = 0;
  170. // }
  171. //
  172. // if ((self.navBar.y-offY) <= (-standard)) {
  173. // self.navBar.y = -standard;
  174. // return;
  175. // }
  176. // if (self.navBar.y-offY > 0) {
  177. // self.navBar.y = 0;
  178. // return;
  179. // }
  180. //
  181. // self.navBar.y -= offY;
  182. // [_segmentScrollView layoutIfNeeded];
  183. //
  184. //}
  185. -(void)viewWillAppear:(BOOL)animated
  186. {
  187. [super viewWillAppear:animated];
  188. self.navBar.hidden=NO;
  189. [PublicFunction saveAccountWithPush:@"product"];
  190. [PublicFunction saveAccountChangeInfoWithPush:@"producthead"];
  191. self.backView.hidden=NO;
  192. if ([AccountTool isLogin]) {
  193. AccountModel *infomodels =[AccountTool account];
  194. NSLog(@"%@",infomodels.img);
  195. [self.headImgV sd_setImageWithURL:[NSURL URLWithString:infomodels.img]];
  196. }
  197. [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
  198. self.tabBarController.tabBar.hidden=NO;
  199. }
  200. - (NSMutableArray *)titleArr {
  201. if (!_titleArr) {
  202. _titleArr = [NSMutableArray array];
  203. }
  204. return _titleArr;
  205. }
  206. - (NSMutableArray *)vcArray {
  207. if (!_vcArray) {
  208. _vcArray = [NSMutableArray array];
  209. }
  210. return _vcArray;
  211. }
  212. -(NSMutableArray *)classArray
  213. {
  214. if (!_classArray) {
  215. _classArray=[NSMutableArray array];
  216. }
  217. return _classArray;
  218. }
  219. -(NSMutableArray *)modelArray
  220. {
  221. if (!_modelArray) {
  222. _modelArray=[NSMutableArray array];
  223. }
  224. return _modelArray;
  225. }
  226. #pragma mark-----教程
  227. -(void)rightBtnClickBtn
  228. {
  229. ZBAdWebViewController *adWeb = [[ZBAdWebViewController alloc] init];
  230. adWeb.url =jiaochengUrl;
  231. [self.navigationController pushViewController:adWeb animated:YES];
  232. }
  233. #pragma mark---搜索
  234. -(void)searchClickBtn
  235. {
  236. ZBSearchViewController *searchViewController=[[ZBSearchViewController alloc]init];
  237. [self.navigationController pushViewController:searchViewController animated:NO];
  238. }
  239. @end