123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- //
- // LDTimeLineSeconeListVc.m
- // YouHuiProject
- //
- // Created by liuxueli on 2019/1/18.
- // Copyright © 2019 kuxuan. All rights reserved.
- //
- #import "LDTimeLineSeconeListVc.h"
- #import "LDTimeLineTableCell.h"
- #import "UIView+SDAutoLayout.h"
- #import "UITableView+SDAutoTableViewCellHeight.h"
- #import "LDShareGoodViewController.h"
- #import "LDTimeLineChannelModel.h"
- #import "LDTimeLineTopView.h"
- #import "LDShareRequestViewModel.h"
- #import "LDShareRequestViewModel.h"
- #import "LDLoginViewController.h"
- #import "LDTimeLineRecomCell.h"
- #import "LDTimeLineShareView.h"
- #import "LDShareManager.h"
- #import <AssetsLibrary/AssetsLibrary.h>
- #import <AssetsLibrary/AssetsLibrary.h>
- #import <Photos/Photos.h>
- #import "LDTimeLineSeconeListVc.h"
- #import <AlibabaAuthSDK/ALBBSDK.h>
- #import <AlibabaAuthSDK/ALBBSession.h>
- #import "LDTaobaoWebAuthorController.h"
- @interface LDTimeLineSeconeListVc ()<UITableViewDelegate,UITableViewDataSource,TimeLineShareViewDelegate>
- {
- NSInteger _page;
- ActivityIndicatorView *_indicatorView;
- }
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @property (nonatomic, assign) NSInteger page;
- @end
- @implementation LDTimeLineSeconeListVc
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self configTableView];
- [self configNavigationBar];
- [self requestData];
-
- }
- - (void)configNavigationBar{
- [self.navigationBar setNavTitle:self.model.title];
- self.view.backgroundColor = [UIColor whiteColor];
- self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
- self.navigationBar.backgroundColor = [UIColor changeColor];
- self.navigationBar.showNavigationBarBottomLine = YES;
- UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
- [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
- [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- [self.navigationBar setCustomLeftButtons:@[leftBtn]];
- [self.navigationBar setShowNavigationBarBottomLine:YES];
- }
- -(void)backAction
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)requestData {
- [self loadTimelineData];
-
- }
- #pragma mark ============ UITableView Delegate && DataSource ==========
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
- cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
- }
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 0.1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.dataArr.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- LDTimeLineModel *model = self.dataArr[indexPath.row];
- switch ([model.type integerValue]) {
- case 1:
- {
- LDTimeLineTableCell *cell = [LDTimeLineTableCell cellWithTableView:tableView];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.shareClickBlock = ^{
- [self shareWithModel:model indexPath:indexPath];
- [MobClick event:OptimizingCircleShareClick];
- };
- cell.tapBlock = ^{
- DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithLDTimeLineModel:model];
- LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
- detail.requestModel = requestModel;
- [self.navigationController pushViewController:detail animated:YES];
- [MobClick event:OptimizingCircleListClick];
- };
- cell.model = model;
- return cell;
- }
- break;
- case 2:
- {
- LDTimeLineRecomCell *cell = [LDTimeLineRecomCell cellWithTableView:tableView];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.model = model;
- cell.shareClickBlock = ^{
- [self showShareView:model indexPath:indexPath];
- [MobClick event:OptimizingCircleShareClick label:model.img];
- };
- return cell;
- }
-
- break;
- default:
- {
- LDTimeLineTableCell *cell = [LDTimeLineTableCell cellWithTableView:tableView];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.shareClickBlock = ^{
- [self shareWithModel:model indexPath:indexPath];
- };
- cell.model = model;
- return cell;
- }
- break;
- }
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- LDTimeLineModel *model = self.dataArr[indexPath.row];
- switch ([model.type integerValue]) {
- case 1:
- return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[LDTimeLineTableCell class] contentViewWidth:SCREEN_WIDTH];
- break;
- case 2:
- return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[LDTimeLineRecomCell class] contentViewWidth:SCREEN_WIDTH];
- break;
- default:
- return 0;
- break;
- }
-
-
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
-
-
- }
- - (void)loadTimelineData {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/labelJumpList",BaseURL];
- NSDictionary *para = @{@"page":@(_page),@"label_id":self.model.Id};
- [LDHttp post:url params:para success:^(id json) {
- NSArray *list = [NSArray yy_modelArrayWithClass:[LDTimeLineModel class] json:json];
- if (list.count == 0 && _page == 1) {
- [self setUpNoDataView];
- [self.tableView.mj_footer setHidden:YES];
- [self.tableView.mj_header endRefreshing];
- }else{
-
- if ([self.tableView.mj_header isRefreshing]) {
- [self.dataArr removeAllObjects];
- }
-
- [self.dataArr addObjectsFromArray:list];
- [self.tableView.mj_header endRefreshing];
- if (list.count == 0) {
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }else {
- [self.tableView.mj_footer endRefreshing];
- }
-
- }
- [self.tableView reloadData];
- [_indicatorView stopAnimating];
- } failure:^(NSError *error) {
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- [_indicatorView stopAnimating];
- }];
- }
- - (void)setUpNoDataView {
- self.tableView.showNoDataView = YES;
- self.tableView.noDataImageOffsetY = -70;
- self.tableView.defaultNoDataText = @"还没有信息~";
- self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
- }
- #pragma ----private
- - (void)shareWithModel:(LDTimeLineModel *)model indexPath:(NSIndexPath *)indexPath{
- if (![AccountTool isLogin]) {
- LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
- login.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:login animated:YES completion:nil];
- return;
- }
-
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/relationAuth/isAuthOrNo",BaseURL];
- [LDHttp post:url params:nil success:^(id json) {
-
- NSNumber *flag = json[@"flag"];
- if (flag.boolValue) {
- //已授权 直接分享
- DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id is_coupon:model.is_coupon coupon_price:model.coupon_price price:model.price discount_price:model.discount_price commission_rate:model.commission_rate coupon_start_time:model.coupon_start_time coupon_end_time:model.coupon_end_time
- coupon_id:model.coupon_id];
- [LoadingView show];
- [LDShareRequestViewModel requestGoodDetailParamGoods_id:requestModel success:^(LDShareInfoModel * _Nonnull infoModel, NSDictionary * _Nonnull dic) {
- [LoadingView dismiss];
- LDShareGoodViewController *shareVc = [[LDShareGoodViewController alloc] init];
- shareVc.goodModel = infoModel;
- shareVc.shareResult = ^{
- [self shareRequest:model indexPath:indexPath];
- };
- [self.navigationController pushViewController:shareVc animated:YES];
-
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
- }else {
- //未授权 去授权
- [LDTaobaoAuthorTool taobaoAuthorManager:json[@"auth_url"] type:@"1" currentVc:self];
- }
-
-
- } failure:^(NSError *error) {
-
- }];
-
- }
- - (void)shareRequest:(LDTimeLineModel *)model indexPath:(NSIndexPath *)indexPath {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/youXuanShareUser",BaseURL];
- NSDictionary *para = @{@"goods_id":model.goods_id,@"type":model.type};
- [LDHttp post:url params:para success:^(id json) {
- NSNumber *flag = json[@"flag"];
- if (flag.boolValue) {
- NSMutableArray *arr = [NSMutableArray array];
- [arr addObjectsFromArray:model.shareUser];
- NSString *nick = [AccountTool account].nickname;
- if (nick.length == 0) {
- nick = @"我";
- }
- if ([arr containsObject:nick]) {
- [arr removeObject:nick];
- }
- [arr addObject:nick];
- model.shareUser = arr;
- [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)showShareView:(LDTimeLineModel *)model indexPath:(NSIndexPath *)indexPath{
- LDTimeLineShareView *shareView = [[LDTimeLineShareView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- shareView.delegate = self;
- shareView.model = model;
- shareView.indexPath = indexPath;
- UIWindow *window = [UIApplication sharedApplication].keyWindow;
- [shareView showInView:window];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [LoadingView dismiss];
-
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
- }
- - (void)configTableView {
- _page = 1;
- [self.view addSubview:self.tableView];
-
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
-
- ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-TabbarHeight)];
- _indicatorView = indicatorView;
- }
- #pragma mark ------- layzer ---------
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStyleGrouped];
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.sectionFooterHeight = 0;
- _tableView.sectionHeaderHeight = 0;
- _tableView.estimatedRowHeight = 0;
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- _tableView.backgroundColor = [UIColor whiteColor];
- _tableView.bounces = YES;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.separatorColor = [UIColor lineColor];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
- _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- self.page = 1;
- [_tableView.mj_footer resetNoMoreData];
- [self requestData];
- }];
- MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- _page++;
- [self loadTimelineData];
- }];
- _tableView.mj_footer = footer;
- }
- return _tableView;
- }
- - (NSMutableArray *)dataArr {
- if (!_dataArr) {
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- @end
|