PlatformGoodsVC.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // PlatformGoodsVC.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/12/1.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "PlatformGoodsVC.h"
  9. #import "PlatformListCell.h"
  10. #import "OutsideGoodsDetailVC.h"
  11. #import "CommodityDetailVC.h"
  12. @interface PlatformGoodsVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
  13. {
  14. int page;
  15. }
  16. @property(nonatomic,strong)UICollectionView *collectionView;
  17. @property(nonatomic,strong)NSMutableArray *goodsArray;
  18. @end
  19. @implementation PlatformGoodsVC
  20. -(void)initData{
  21. self.goodsArray = [NSMutableArray array];
  22. page = 1;
  23. }
  24. -(void)pullInternet{
  25. NSDictionary *signdic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken], @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]]};
  26. NSString *sign = [PublicObj sortString:signdic];
  27. NSDictionary *dic = @{
  28. @"uid":[Config getOwnID],
  29. @"token":[Config getOwnToken],
  30. @"time":[NSNumber numberWithLong: (long)[[NSDate date] timeIntervalSince1970]],
  31. @"sign":sign,
  32. @"p":@(page)
  33. };
  34. [YBNetworking postWithUrl:@"Seller.getPlatformGoodsLists" Dic:dic Suc:^(int code, id info, NSString *msg) {
  35. [_collectionView.mj_header endRefreshing];
  36. [_collectionView.mj_footer endRefreshing];
  37. if (code == 0) {
  38. NSArray *infos = info;
  39. if (page == 1) {
  40. [self.goodsArray removeAllObjects];
  41. }
  42. [self.goodsArray addObjectsFromArray:infos];
  43. if (self.goodsArray.count < 1) {
  44. [PublicView showImgNoData:_collectionView name:@"shop_无数据" text:YZMsg(@"你还没有相关商品")];
  45. [self.collectionView reloadData];
  46. return ;
  47. }else{
  48. [PublicView hiddenImgNoData:_collectionView];
  49. }
  50. [self.collectionView reloadData];
  51. }
  52. } Fail:^(id fail) {
  53. [_collectionView.mj_header endRefreshing];
  54. [_collectionView.mj_footer endRefreshing];
  55. }];
  56. }
  57. - (UIStatusBarStyle)preferredStatusBarStyle {
  58. if (@available(iOS 13.0,*)) {
  59. return UIStatusBarStyleDarkContent;
  60. }
  61. return UIStatusBarStyleDefault;
  62. }
  63. - (void)viewDidLoad {
  64. [super viewDidLoad];
  65. self.subNavi.backgroundColor = UIColor.whiteColor;
  66. self.titleL.textColor = UIColor.blackColor;
  67. [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
  68. self.naviLine.hidden = NO;
  69. self.naviLine.backgroundColor = RGB(245, 245, 245);
  70. self.titleL.text = YZMsg(@"平台商品");
  71. [self initData];
  72. [self createCollectionView];
  73. }
  74. -(void)createCollectionView{
  75. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
  76. flow.scrollDirection = UICollectionViewScrollDirectionVertical;
  77. flow.itemSize = CGSizeMake((_window_width-21)/2, (_window_width-21)/2 + 90);
  78. flow.minimumLineSpacing = 7;
  79. flow.minimumInteritemSpacing = 7;
  80. flow.sectionInset = UIEdgeInsetsMake(7, 7, 7, 7);
  81. _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight, _window_width, _window_height-64-statusbarHeight) collectionViewLayout:flow];
  82. _collectionView.backgroundColor = RGB_COLOR(@"#f5f5f5", 1);
  83. _collectionView.delegate = self;
  84. _collectionView.dataSource = self;
  85. [_collectionView registerNib:[UINib nibWithNibName:@"PlatformListCell" bundle:nil] forCellWithReuseIdentifier:@"PlatformListCeLL"];
  86. [self.view addSubview:_collectionView];
  87. _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  88. _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  89. page = 1;
  90. [self pullInternet];
  91. }];
  92. _collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  93. page ++;
  94. [self pullInternet];
  95. }];
  96. [self pullInternet];
  97. }
  98. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  99. return self.goodsArray.count;
  100. }
  101. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  102. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  103. NSDictionary *subDic = self.goodsArray[indexPath.row];
  104. [PublicObj checkGoodsExistenceWithID:minstr([subDic valueForKey:@"id"]) Existence:^(int code, NSString *msg) {
  105. if (code == 0 ) {
  106. CommodityDetailVC *detail = [[CommodityDetailVC alloc]init];
  107. detail.goodsID = minstr([subDic valueForKey:@"id"]);
  108. detail.liveUid = @"0";
  109. [[YBBaseAppDelegate sharedAppDelegate] pushViewController:detail animated:YES];
  110. }else{
  111. [MBProgressHUD showError:msg];
  112. }
  113. }];
  114. }
  115. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  116. PlatformListCell *cell = (PlatformListCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"PlatformListCeLL" forIndexPath:indexPath];
  117. cell.dataDic = self.goodsArray[indexPath.row];
  118. cell.reloadEvent = ^(NSDictionary *dic, NSString *statuStr) {
  119. for (int i = 0; i < self.goodsArray.count; i ++) {
  120. NSMutableDictionary *onedic = [NSMutableDictionary dictionaryWithDictionary:self.goodsArray[i]];
  121. if ([[onedic valueForKey:@"id"] isEqual:[dic valueForKey:@"id"]]) {
  122. NSDictionary *replayDic = @{@"isadd":statuStr};
  123. [onedic addEntriesFromDictionary:replayDic];
  124. [self.goodsArray replaceObjectAtIndex:i withObject:onedic];
  125. }
  126. }
  127. };
  128. return cell;
  129. }
  130. @end