猎豆优选

LDTimeLineSeconeListVc.m 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. //
  2. // LDTimeLineSeconeListVc.m
  3. // YouHuiProject
  4. //
  5. // Created by liuxueli on 2019/1/18.
  6. // Copyright © 2019 kuxuan. All rights reserved.
  7. //
  8. #import "LDTimeLineSeconeListVc.h"
  9. #import "LDTimeLineTableCell.h"
  10. #import "UIView+SDAutoLayout.h"
  11. #import "UITableView+SDAutoTableViewCellHeight.h"
  12. #import "LDShareGoodViewController.h"
  13. #import "LDTimeLineChannelModel.h"
  14. #import "LDTimeLineTopView.h"
  15. #import "LDShareRequestViewModel.h"
  16. #import "LDShareRequestViewModel.h"
  17. #import "LDLoginViewController.h"
  18. #import "LDTimeLineRecomCell.h"
  19. #import "LDTimeLineShareView.h"
  20. #import "LDShareManager.h"
  21. #import <AssetsLibrary/AssetsLibrary.h>
  22. #import <AssetsLibrary/AssetsLibrary.h>
  23. #import <Photos/Photos.h>
  24. #import "LDTimeLineSeconeListVc.h"
  25. #import <AlibabaAuthSDK/ALBBSDK.h>
  26. #import <AlibabaAuthSDK/ALBBSession.h>
  27. #import "LDTaobaoWebAuthorController.h"
  28. @interface LDTimeLineSeconeListVc ()<UITableViewDelegate,UITableViewDataSource,TimeLineShareViewDelegate>
  29. {
  30. NSInteger _page;
  31. ActivityIndicatorView *_indicatorView;
  32. }
  33. @property (nonatomic, strong) UITableView *tableView;
  34. @property (nonatomic, strong) NSMutableArray *dataArr;
  35. @property (nonatomic, assign) NSInteger page;
  36. @end
  37. @implementation LDTimeLineSeconeListVc
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. [self configTableView];
  41. [self configNavigationBar];
  42. [self requestData];
  43. }
  44. - (void)configNavigationBar{
  45. [self.navigationBar setNavTitle:self.model.title];
  46. self.view.backgroundColor = [UIColor whiteColor];
  47. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  48. self.navigationBar.backgroundColor = [UIColor changeColor];
  49. self.navigationBar.showNavigationBarBottomLine = YES;
  50. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  51. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  52. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  53. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  54. [self.navigationBar setShowNavigationBarBottomLine:YES];
  55. }
  56. -(void)backAction
  57. {
  58. [self.navigationController popViewControllerAnimated:YES];
  59. }
  60. - (void)requestData {
  61. [self loadTimelineData];
  62. }
  63. #pragma mark ============ UITableView Delegate && DataSource ==========
  64. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  65. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  66. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  67. }
  68. }
  69. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  70. return 0.1;
  71. }
  72. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  73. return self.dataArr.count;
  74. }
  75. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  76. LDTimeLineModel *model = self.dataArr[indexPath.row];
  77. switch ([model.type integerValue]) {
  78. case 1:
  79. {
  80. LDTimeLineTableCell *cell = [LDTimeLineTableCell cellWithTableView:tableView];
  81. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  82. cell.shareClickBlock = ^{
  83. [self shareWithModel:model indexPath:indexPath];
  84. [MobClick event:OptimizingCircleShareClick];
  85. };
  86. cell.tapBlock = ^{
  87. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithLDTimeLineModel:model];
  88. LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  89. detail.requestModel = requestModel;
  90. [self.navigationController pushViewController:detail animated:YES];
  91. [MobClick event:OptimizingCircleListClick];
  92. };
  93. cell.model = model;
  94. return cell;
  95. }
  96. break;
  97. case 2:
  98. {
  99. LDTimeLineRecomCell *cell = [LDTimeLineRecomCell cellWithTableView:tableView];
  100. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  101. cell.model = model;
  102. cell.shareClickBlock = ^{
  103. [self showShareView:model indexPath:indexPath];
  104. [MobClick event:OptimizingCircleShareClick label:model.img];
  105. };
  106. return cell;
  107. }
  108. break;
  109. default:
  110. {
  111. LDTimeLineTableCell *cell = [LDTimeLineTableCell cellWithTableView:tableView];
  112. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  113. cell.shareClickBlock = ^{
  114. [self shareWithModel:model indexPath:indexPath];
  115. };
  116. cell.model = model;
  117. return cell;
  118. }
  119. break;
  120. }
  121. }
  122. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  123. LDTimeLineModel *model = self.dataArr[indexPath.row];
  124. switch ([model.type integerValue]) {
  125. case 1:
  126. return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[LDTimeLineTableCell class] contentViewWidth:SCREEN_WIDTH];
  127. break;
  128. case 2:
  129. return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[LDTimeLineRecomCell class] contentViewWidth:SCREEN_WIDTH];
  130. break;
  131. default:
  132. return 0;
  133. break;
  134. }
  135. }
  136. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  137. }
  138. - (void)loadTimelineData {
  139. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/labelJumpList",BaseURL];
  140. NSDictionary *para = @{@"page":@(_page),@"label_id":self.model.Id};
  141. [LDHttp post:url params:para success:^(id json) {
  142. NSArray *list = [NSArray yy_modelArrayWithClass:[LDTimeLineModel class] json:json];
  143. if (list.count == 0 && _page == 1) {
  144. [self setUpNoDataView];
  145. [self.tableView.mj_footer setHidden:YES];
  146. [self.tableView.mj_header endRefreshing];
  147. }else{
  148. if ([self.tableView.mj_header isRefreshing]) {
  149. [self.dataArr removeAllObjects];
  150. }
  151. [self.dataArr addObjectsFromArray:list];
  152. [self.tableView.mj_header endRefreshing];
  153. if (list.count == 0) {
  154. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  155. }else {
  156. [self.tableView.mj_footer endRefreshing];
  157. }
  158. }
  159. [self.tableView reloadData];
  160. [_indicatorView stopAnimating];
  161. } failure:^(NSError *error) {
  162. [self.tableView.mj_header endRefreshing];
  163. [self.tableView.mj_footer endRefreshing];
  164. [_indicatorView stopAnimating];
  165. }];
  166. }
  167. - (void)setUpNoDataView {
  168. self.tableView.showNoDataView = YES;
  169. self.tableView.noDataImageOffsetY = -70;
  170. self.tableView.defaultNoDataText = @"还没有信息~";
  171. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  172. }
  173. #pragma ----private
  174. - (void)shareWithModel:(LDTimeLineModel *)model indexPath:(NSIndexPath *)indexPath{
  175. if (![AccountTool isLogin]) {
  176. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  177. login.modalPresentationStyle = UIModalPresentationFullScreen;
  178. [self presentViewController:login animated:YES completion:nil];
  179. return;
  180. }
  181. NSString *url = [NSString stringWithFormat:@"%@/api/v2/relationAuth/isAuthOrNo",BaseURL];
  182. [LDHttp post:url params:nil success:^(id json) {
  183. NSNumber *flag = json[@"flag"];
  184. if (flag.boolValue) {
  185. //已授权 直接分享
  186. 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
  187. coupon_id:model.coupon_id];
  188. [LoadingView show];
  189. [LDShareRequestViewModel requestGoodDetailParamGoods_id:requestModel success:^(LDShareInfoModel * _Nonnull infoModel, NSDictionary * _Nonnull dic) {
  190. [LoadingView dismiss];
  191. LDShareGoodViewController *shareVc = [[LDShareGoodViewController alloc] init];
  192. shareVc.goodModel = infoModel;
  193. shareVc.shareResult = ^{
  194. [self shareRequest:model indexPath:indexPath];
  195. };
  196. [self.navigationController pushViewController:shareVc animated:YES];
  197. } failure:^(NSError * _Nonnull error) {
  198. [LoadingView dismiss];
  199. }];
  200. }else {
  201. //未授权 去授权
  202. [LDTaobaoAuthorTool taobaoAuthorManager:json[@"auth_url"] type:@"1" currentVc:self];
  203. }
  204. } failure:^(NSError *error) {
  205. }];
  206. }
  207. - (void)shareRequest:(LDTimeLineModel *)model indexPath:(NSIndexPath *)indexPath {
  208. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/youXuanShareUser",BaseURL];
  209. NSDictionary *para = @{@"goods_id":model.goods_id,@"type":model.type};
  210. [LDHttp post:url params:para success:^(id json) {
  211. NSNumber *flag = json[@"flag"];
  212. if (flag.boolValue) {
  213. NSMutableArray *arr = [NSMutableArray array];
  214. [arr addObjectsFromArray:model.shareUser];
  215. NSString *nick = [AccountTool account].nickname;
  216. if (nick.length == 0) {
  217. nick = @"我";
  218. }
  219. if ([arr containsObject:nick]) {
  220. [arr removeObject:nick];
  221. }
  222. [arr addObject:nick];
  223. model.shareUser = arr;
  224. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  225. }
  226. } failure:^(NSError *error) {
  227. }];
  228. }
  229. - (void)showShareView:(LDTimeLineModel *)model indexPath:(NSIndexPath *)indexPath{
  230. LDTimeLineShareView *shareView = [[LDTimeLineShareView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  231. shareView.delegate = self;
  232. shareView.model = model;
  233. shareView.indexPath = indexPath;
  234. UIWindow *window = [UIApplication sharedApplication].keyWindow;
  235. [shareView showInView:window];
  236. }
  237. - (void)viewWillDisappear:(BOOL)animated {
  238. [super viewWillDisappear:animated];
  239. [LoadingView dismiss];
  240. }
  241. - (void)viewDidAppear:(BOOL)animated {
  242. [super viewDidAppear:animated];
  243. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  244. }
  245. - (void)configTableView {
  246. _page = 1;
  247. [self.view addSubview:self.tableView];
  248. if (@available(iOS 11.0, *)) {
  249. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  250. } else {
  251. self.automaticallyAdjustsScrollViewInsets = NO;
  252. }
  253. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-TabbarHeight)];
  254. _indicatorView = indicatorView;
  255. }
  256. #pragma mark ------- layzer ---------
  257. - (UITableView *)tableView {
  258. if (!_tableView) {
  259. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStyleGrouped];
  260. _tableView.estimatedSectionHeaderHeight = 0;
  261. _tableView.estimatedSectionFooterHeight = 0;
  262. _tableView.sectionFooterHeight = 0;
  263. _tableView.sectionHeaderHeight = 0;
  264. _tableView.estimatedRowHeight = 0;
  265. _tableView.delegate = self;
  266. _tableView.dataSource = self;
  267. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  268. _tableView.backgroundColor = [UIColor whiteColor];
  269. _tableView.bounces = YES;
  270. _tableView.showsVerticalScrollIndicator = NO;
  271. _tableView.separatorColor = [UIColor lineColor];
  272. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  273. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  274. self.page = 1;
  275. [_tableView.mj_footer resetNoMoreData];
  276. [self requestData];
  277. }];
  278. MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  279. _page++;
  280. [self loadTimelineData];
  281. }];
  282. _tableView.mj_footer = footer;
  283. }
  284. return _tableView;
  285. }
  286. - (NSMutableArray *)dataArr {
  287. if (!_dataArr) {
  288. _dataArr = [NSMutableArray array];
  289. }
  290. return _dataArr;
  291. }
  292. @end