123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- //
- // LDShopDetailViewController.m
- // YouHuiProject
- //
- // Created by xiaoxi on 2018/1/29.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDShopDetailViewController.h"
- #import "LDGoodDetailModel.h"
- #import "LDCollectionView.h"
- #import "LDGoodCollectionCell.h"
- #import "LDGoodDetailRequestViewModel.h"
- static NSString *const cellID = @"LDGoodCollectionCell";
- static NSString *const collectionViewHeader = @"collectionViewHeader";
- static NSInteger page = 1;
- @interface LDShopDetailViewController () <UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, strong) UIImageView *shopImageView;
- @property (nonatomic, strong) UILabel *shopTitleLabel;
- @property (nonatomic, strong) CALayer *lineLayer;
- @property (nonatomic, strong) UIButton *goodIntro;
- @property (nonatomic, strong) UIButton *shopService;
- @property (nonatomic, strong) UIButton *postService;
- @property (nonatomic, strong) NSMutableArray *goodsArr;
- @end
- @implementation LDShopDetailViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self initNavBar];
- [self initSubviews];
- [self request];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- - (void)initNavBar {
- [self.navigationBar setBackButtonWithTarget:self selector:@selector(backAction)];
- [self.navigationBar setNavTitle:@"商家店铺"];
- [self.navigationBar setShowNavigationBarBottomLine:YES];
- }
- - (void)backAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)initSubviews {
- [self.view addSubview:self.collectionView];
- }
- - (void)setGoodModel:(LDGoodDetailModel *)goodModel {
- _goodModel = goodModel;
-
- [self.shopImageView yy_setImageWithURL:[NSURL URLWithString:goodModel.shop_pict_url] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
- self.shopTitleLabel.text = goodModel.shop_title;
- [self.goodIntro setTitle:[NSString stringWithFormat:@"宝贝描述:%@", goodModel.item_score] forState:UIControlStateNormal];
- [self.shopService setTitle:[NSString stringWithFormat:@"卖家服务:%@", goodModel.service_score] forState:UIControlStateNormal];
- [self.postService setTitle:[NSString stringWithFormat:@"物流服务:%@", goodModel.delivery_score] forState:UIControlStateNormal];
- }
- #pragma mark - request
- - (void)request {
- [LDGoodDetailRequestViewModel requestShopGoodParamSellerId:self.goodModel.sellerId Page:page success:^(NSArray *array) {
- if (array.count > 0) {
- [self.goodsArr addObjectsFromArray:array];
- [self.collectionView reloadData];
- }
-
- [self noMoreDataWithArray:array];
-
- [self.collectionView.mj_header endRefreshing];
- [self.collectionView.mj_footer endRefreshing];
- } failure:^(NSError *error) {
- [self.collectionView.mj_header endRefreshing];
- [self.collectionView.mj_footer endRefreshing];
- }];
- }
- - (void)noMoreDataWithArray:(NSArray *)array {
- if (array.count <= 0) {
- MJRefreshBackNormalFooter *foot = (MJRefreshBackNormalFooter *)self.collectionView.mj_footer;
- [foot setTitle:@"到底啦" forState:MJRefreshStateIdle];
- }
- }
- #pragma mark - collectionView
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.goodsArr.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- LDGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
- cell.backgroundColor = [UIColor whiteColor];
- cell.backgroundView.backgroundColor = [UIColor whiteColor];
- cell.contentView.backgroundColor = [UIColor whiteColor];
- LDChildGoodModel *model = self.goodsArr[indexPath.item];
- cell.model = model;
- return cell;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
- UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader forIndexPath:indexPath];
- view.backgroundColor = [UIColor whiteColor];
-
- [view.layer addSublayer:self.lineLayer];
-
- for (NSInteger i=0; i<3; i++) {
- CALayer *layer = [CALayer layer];
- layer.frame = CGRectMake(kScreenWidth/3*i, FITSIZE(105)+FITSIZE(40)/2-FITSIZE(5)/2, 1, FITSIZE(5));
- layer.backgroundColor = [UIColor YHColorWithHex:0x999999].CGColor;
- [view.layer addSublayer:layer];
- }
-
- [view addSubview:self.shopImageView];
- [view addSubview:self.shopTitleLabel];
- [view addSubview:self.goodIntro];
- [view addSubview:self.shopService];
- [view addSubview:self.postService];
-
- [self.shopImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(view).offset(FITSIZE(20));
- make.top.equalTo(view).offset(FITSIZE(22));
- make.size.mas_equalTo(CGSizeMake(FITSIZE(60), FITSIZE(60)));
- }];
-
- [self.shopTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.shopImageView.mas_right).offset(FITSIZE(14));
- make.centerY.equalTo(self.shopImageView);
- }];
-
- [self.goodIntro mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(view);
- make.top.equalTo(view).offset(FITSIZE(105));
- make.width.mas_equalTo(kScreenWidth/3);
- make.bottom.equalTo(view);
- }];
-
- [self.shopService mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.goodIntro.mas_right);
- make.top.equalTo(self.goodIntro);
- make.width.equalTo(self.goodIntro);
- make.bottom.equalTo(self.goodIntro);
- }];
-
- [self.postService mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.shopService.mas_right);
- make.top.equalTo(self.shopService);
- make.width.equalTo(self.shopService);
- make.bottom.equalTo(self.shopService);
- }];
-
- return view;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
- return CGSizeMake(kScreenWidth, FITSIZE(145));
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- LDChildGoodModel *model = self.goodsArr[indexPath.item];
- //详情
- LDGoodDetailViewController *detailVC = [[LDGoodDetailViewController alloc] init];
- DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
- detailVC.requestModel = requestModel;
-
- LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:merchantShopAction];
- detailVC.eventModel = evevtModel;
-
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- #pragma mark - lazy
- - (UICollectionView *)collectionView {
- if (!_collectionView) {
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
- flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
- flowLayout.itemSize = CGSizeMake(FITSIZE(184.9), FITSIZE(287));
- flowLayout.minimumLineSpacing = FITSIZE(5);
- flowLayout.minimumInteritemSpacing = FITSIZE(5);
-
- _collectionView = [[LDCollectionView alloc] initWithFrame:CGRectMake(0, NavBarHeight, kScreenWidth, kScreenHeight-NavBarHeight) collectionViewLayout:flowLayout];
- _collectionView.delegate = self;
- _collectionView.dataSource = self;
- [_collectionView registerClass:[LDGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
- [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeader];
- if (@available(iOS 11.0, *)) {
- _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- kWeak(self);
- _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [self.goodsArr removeAllObjects];
- page = 1;
- [selfWeak request];
- }];
- _collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- page ++;
- [selfWeak request];
- }];
-
- }
- return _collectionView;
- }
- - (CALayer *)lineLayer {
- if (!_lineLayer) {
- _lineLayer = [CALayer layer];
- _lineLayer.frame = CGRectMake(0, FITSIZE(100), kScreenWidth, FITSIZE(5));
- _lineLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
- }
- return _lineLayer;
- }
- - (UIImageView *)shopImageView {
- if (!_shopImageView) {
- _shopImageView = [[UIImageView alloc] init];
- _shopImageView.backgroundColor = [UIColor clearColor];
- _shopImageView.layer.borderColor = [UIColor YHColorWithHex:0xdddddd].CGColor;
- _shopImageView.layer.borderWidth = 0.5f;
- }
- return _shopImageView;
- }
- - (UILabel *)shopTitleLabel {
- if (!_shopTitleLabel) {
- _shopTitleLabel = [[UILabel alloc] init];
- _shopTitleLabel.backgroundColor = [UIColor clearColor];
- _shopTitleLabel.textColor = [UIColor YHColorWithHex:0x222222];
- _shopTitleLabel.font = [UIFont systemFontOfSize:FITSIZE(14)];
- }
- return _shopTitleLabel;
- }
- - (UIButton *)goodIntro {
- if (!_goodIntro) {
- _goodIntro = [UIButton buttonWithType:UIButtonTypeCustom];
- _goodIntro.backgroundColor = [UIColor clearColor];
- [_goodIntro setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
- _goodIntro.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
- }
- return _goodIntro;
- }
- - (UIButton *)shopService {
- if (!_shopService) {
- _shopService = [UIButton buttonWithType:UIButtonTypeCustom];
- _shopService.backgroundColor = [UIColor clearColor];
- [_shopService setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
- _shopService.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
- }
- return _shopService;
- }
- - (UIButton *)postService {
- if (!_postService) {
- _postService = [UIButton buttonWithType:UIButtonTypeCustom];
- _postService.backgroundColor = [UIColor clearColor];
- [_postService setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
- _postService.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
- }
- return _postService;
- }
- - (NSMutableArray *)goodsArr {
- if (!_goodsArr) {
- _goodsArr = [NSMutableArray array];
- }
- return _goodsArr;
- }
- @end
|