猎豆优选

LDShopDetailViewController.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. //
  2. // LDShopDetailViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/29.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDShopDetailViewController.h"
  9. #import "LDGoodDetailModel.h"
  10. #import "LDCollectionView.h"
  11. #import "LDGoodCollectionCell.h"
  12. #import "LDGoodDetailRequestViewModel.h"
  13. static NSString *const cellID = @"LDGoodCollectionCell";
  14. static NSString *const collectionViewHeader = @"collectionViewHeader";
  15. static NSInteger page = 1;
  16. @interface LDShopDetailViewController () <UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  17. @property (nonatomic, strong) UICollectionView *collectionView;
  18. @property (nonatomic, strong) UIImageView *shopImageView;
  19. @property (nonatomic, strong) UILabel *shopTitleLabel;
  20. @property (nonatomic, strong) CALayer *lineLayer;
  21. @property (nonatomic, strong) UIButton *goodIntro;
  22. @property (nonatomic, strong) UIButton *shopService;
  23. @property (nonatomic, strong) UIButton *postService;
  24. @property (nonatomic, strong) NSMutableArray *goodsArr;
  25. @end
  26. @implementation LDShopDetailViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. [self initNavBar];
  30. [self initSubviews];
  31. [self request];
  32. }
  33. - (void)didReceiveMemoryWarning {
  34. [super didReceiveMemoryWarning];
  35. }
  36. - (void)initNavBar {
  37. [self.navigationBar setBackButtonWithTarget:self selector:@selector(backAction)];
  38. [self.navigationBar setNavTitle:@"商家店铺"];
  39. [self.navigationBar setShowNavigationBarBottomLine:YES];
  40. }
  41. - (void)backAction {
  42. [self.navigationController popViewControllerAnimated:YES];
  43. }
  44. - (void)initSubviews {
  45. [self.view addSubview:self.collectionView];
  46. }
  47. - (void)setGoodModel:(LDGoodDetailModel *)goodModel {
  48. _goodModel = goodModel;
  49. [self.shopImageView yy_setImageWithURL:[NSURL URLWithString:goodModel.shop_pict_url] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
  50. self.shopTitleLabel.text = goodModel.shop_title;
  51. [self.goodIntro setTitle:[NSString stringWithFormat:@"宝贝描述:%@", goodModel.item_score] forState:UIControlStateNormal];
  52. [self.shopService setTitle:[NSString stringWithFormat:@"卖家服务:%@", goodModel.service_score] forState:UIControlStateNormal];
  53. [self.postService setTitle:[NSString stringWithFormat:@"物流服务:%@", goodModel.delivery_score] forState:UIControlStateNormal];
  54. }
  55. #pragma mark - request
  56. - (void)request {
  57. [LDGoodDetailRequestViewModel requestShopGoodParamSellerId:self.goodModel.sellerId Page:page success:^(NSArray *array) {
  58. if (array.count > 0) {
  59. [self.goodsArr addObjectsFromArray:array];
  60. [self.collectionView reloadData];
  61. }
  62. [self noMoreDataWithArray:array];
  63. [self.collectionView.mj_header endRefreshing];
  64. [self.collectionView.mj_footer endRefreshing];
  65. } failure:^(NSError *error) {
  66. [self.collectionView.mj_header endRefreshing];
  67. [self.collectionView.mj_footer endRefreshing];
  68. }];
  69. }
  70. - (void)noMoreDataWithArray:(NSArray *)array {
  71. if (array.count <= 0) {
  72. MJRefreshBackNormalFooter *foot = (MJRefreshBackNormalFooter *)self.collectionView.mj_footer;
  73. [foot setTitle:@"到底啦" forState:MJRefreshStateIdle];
  74. }
  75. }
  76. #pragma mark - collectionView
  77. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  78. return 1;
  79. }
  80. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  81. return self.goodsArr.count;
  82. }
  83. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  84. LDGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  85. cell.backgroundColor = [UIColor whiteColor];
  86. cell.backgroundView.backgroundColor = [UIColor whiteColor];
  87. cell.contentView.backgroundColor = [UIColor whiteColor];
  88. LDChildGoodModel *model = self.goodsArr[indexPath.item];
  89. cell.model = model;
  90. return cell;
  91. }
  92. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  93. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader forIndexPath:indexPath];
  94. view.backgroundColor = [UIColor whiteColor];
  95. [view.layer addSublayer:self.lineLayer];
  96. for (NSInteger i=0; i<3; i++) {
  97. CALayer *layer = [CALayer layer];
  98. layer.frame = CGRectMake(kScreenWidth/3*i, FITSIZE(105)+FITSIZE(40)/2-FITSIZE(5)/2, 1, FITSIZE(5));
  99. layer.backgroundColor = [UIColor YHColorWithHex:0x999999].CGColor;
  100. [view.layer addSublayer:layer];
  101. }
  102. [view addSubview:self.shopImageView];
  103. [view addSubview:self.shopTitleLabel];
  104. [view addSubview:self.goodIntro];
  105. [view addSubview:self.shopService];
  106. [view addSubview:self.postService];
  107. [self.shopImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.left.equalTo(view).offset(FITSIZE(20));
  109. make.top.equalTo(view).offset(FITSIZE(22));
  110. make.size.mas_equalTo(CGSizeMake(FITSIZE(60), FITSIZE(60)));
  111. }];
  112. [self.shopTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.equalTo(self.shopImageView.mas_right).offset(FITSIZE(14));
  114. make.centerY.equalTo(self.shopImageView);
  115. }];
  116. [self.goodIntro mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.left.equalTo(view);
  118. make.top.equalTo(view).offset(FITSIZE(105));
  119. make.width.mas_equalTo(kScreenWidth/3);
  120. make.bottom.equalTo(view);
  121. }];
  122. [self.shopService mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.left.equalTo(self.goodIntro.mas_right);
  124. make.top.equalTo(self.goodIntro);
  125. make.width.equalTo(self.goodIntro);
  126. make.bottom.equalTo(self.goodIntro);
  127. }];
  128. [self.postService mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.left.equalTo(self.shopService.mas_right);
  130. make.top.equalTo(self.shopService);
  131. make.width.equalTo(self.shopService);
  132. make.bottom.equalTo(self.shopService);
  133. }];
  134. return view;
  135. }
  136. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  137. return CGSizeMake(kScreenWidth, FITSIZE(145));
  138. }
  139. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  140. LDChildGoodModel *model = self.goodsArr[indexPath.item];
  141. //详情
  142. LDGoodDetailViewController *detailVC = [[LDGoodDetailViewController alloc] init];
  143. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  144. detailVC.requestModel = requestModel;
  145. LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:merchantShopAction];
  146. detailVC.eventModel = evevtModel;
  147. [self.navigationController pushViewController:detailVC animated:YES];
  148. }
  149. #pragma mark - lazy
  150. - (UICollectionView *)collectionView {
  151. if (!_collectionView) {
  152. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  153. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  154. flowLayout.itemSize = CGSizeMake(FITSIZE(184.9), FITSIZE(287));
  155. flowLayout.minimumLineSpacing = FITSIZE(5);
  156. flowLayout.minimumInteritemSpacing = FITSIZE(5);
  157. _collectionView = [[LDCollectionView alloc] initWithFrame:CGRectMake(0, NavBarHeight, kScreenWidth, kScreenHeight-NavBarHeight) collectionViewLayout:flowLayout];
  158. _collectionView.delegate = self;
  159. _collectionView.dataSource = self;
  160. [_collectionView registerClass:[LDGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  161. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader];
  162. if (@available(iOS 11.0, *)) {
  163. _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  164. }
  165. kWeak(self);
  166. _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  167. [self.goodsArr removeAllObjects];
  168. page = 1;
  169. [selfWeak request];
  170. }];
  171. _collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  172. page ++;
  173. [selfWeak request];
  174. }];
  175. }
  176. return _collectionView;
  177. }
  178. - (CALayer *)lineLayer {
  179. if (!_lineLayer) {
  180. _lineLayer = [CALayer layer];
  181. _lineLayer.frame = CGRectMake(0, FITSIZE(100), kScreenWidth, FITSIZE(5));
  182. _lineLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
  183. }
  184. return _lineLayer;
  185. }
  186. - (UIImageView *)shopImageView {
  187. if (!_shopImageView) {
  188. _shopImageView = [[UIImageView alloc] init];
  189. _shopImageView.backgroundColor = [UIColor clearColor];
  190. _shopImageView.layer.borderColor = [UIColor YHColorWithHex:0xdddddd].CGColor;
  191. _shopImageView.layer.borderWidth = 0.5f;
  192. }
  193. return _shopImageView;
  194. }
  195. - (UILabel *)shopTitleLabel {
  196. if (!_shopTitleLabel) {
  197. _shopTitleLabel = [[UILabel alloc] init];
  198. _shopTitleLabel.backgroundColor = [UIColor clearColor];
  199. _shopTitleLabel.textColor = [UIColor YHColorWithHex:0x222222];
  200. _shopTitleLabel.font = [UIFont systemFontOfSize:FITSIZE(14)];
  201. }
  202. return _shopTitleLabel;
  203. }
  204. - (UIButton *)goodIntro {
  205. if (!_goodIntro) {
  206. _goodIntro = [UIButton buttonWithType:UIButtonTypeCustom];
  207. _goodIntro.backgroundColor = [UIColor clearColor];
  208. [_goodIntro setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
  209. _goodIntro.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  210. }
  211. return _goodIntro;
  212. }
  213. - (UIButton *)shopService {
  214. if (!_shopService) {
  215. _shopService = [UIButton buttonWithType:UIButtonTypeCustom];
  216. _shopService.backgroundColor = [UIColor clearColor];
  217. [_shopService setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
  218. _shopService.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  219. }
  220. return _shopService;
  221. }
  222. - (UIButton *)postService {
  223. if (!_postService) {
  224. _postService = [UIButton buttonWithType:UIButtonTypeCustom];
  225. _postService.backgroundColor = [UIColor clearColor];
  226. [_postService setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
  227. _postService.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  228. }
  229. return _postService;
  230. }
  231. - (NSMutableArray *)goodsArr {
  232. if (!_goodsArr) {
  233. _goodsArr = [NSMutableArray array];
  234. }
  235. return _goodsArr;
  236. }
  237. @end