天天省钱快报

KBShopDetailViewController.m 11KB

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