《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRCommunityLeftController.m 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. //
  2. // DRCommunityLeftController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRCommunityLeftController.h"
  9. #import "DRCommunityCell.h"
  10. #import "UITableView+SDAutoTableViewCellHeight.h"
  11. #import "DRCommunityModel.h"
  12. #import "DRCommunityDetailModel.h"
  13. #import "DRShareGoodsModel.h"
  14. #import "DRShareGoodsView.h"
  15. #import "DRGoodDetailViewController.h"
  16. #import "DRLoginViewController.h"
  17. #import "DRPopShareGoodView.h"
  18. #import "DRCommunityTopModel.h"
  19. #import "DRCommunityShareCell.h"
  20. #import "DRGoodDetailModel.h"
  21. #import "DRShareImgPopView.h"
  22. #import "DRCommunityRightController.h"
  23. #import "DRCommunityCell.h"
  24. #import "UITableView+SDAutoTableViewCellHeight.h"
  25. #import "DRCommunityModel.h"
  26. #import "DRCommunityDetailModel.h"
  27. #import "DRShareGetFriendsModel.h"
  28. #import "DRShareGetFriendsView.h"
  29. #import "DRLoginViewController.h"
  30. #import "DRCommunityRightCell.h"
  31. #import "DRCommunityRightModel.h"
  32. #import "DRGoodDetailViewController.h"
  33. #import "shareView.h"
  34. #import "DRShareGoodsTempModel.h"
  35. #import "DRShareGoodsModel.h"
  36. #import <SDWebImageDownloader.h>
  37. #import "DRPopShareGoodView.h"
  38. #import "DRShareManager.h"
  39. #import "HYUMShareManager.h"
  40. #import "WXApi.h"
  41. #import "DRShareImgPopView.h"
  42. #import "CCAlertShowView.h"
  43. #import "DRGoodDetailModel.h"
  44. #import "DRLinkFansController.h"
  45. #import "AccountTool.h"
  46. @interface DRCommunityLeftController ()
  47. <
  48. UICollectionViewDelegate,
  49. UICollectionViewDataSource,
  50. UICollectionViewDelegateFlowLayout,
  51. UITableViewDelegate,
  52. UITableViewDataSource,
  53. YHCommunityDelegate,
  54. PhotoContainerViewDelegate
  55. >
  56. {
  57. ActivityIndicatorView *_indicatorView;
  58. }
  59. @property (nonatomic, strong) UITableView *tableView;
  60. @property (nonatomic, strong) NSMutableArray *dataArr;//分享前十
  61. @property(nonatomic,strong)NSMutableArray *recommendListArray;//优选推荐
  62. //@property (nonatomic,strong ) UIView *backgroudView;
  63. @property(nonatomic,strong)UICollectionView *collections;
  64. @property (nonatomic ) NSInteger page;
  65. @end
  66. @implementation DRCommunityLeftController
  67. - (void)viewDidLoad {
  68. [super viewDidLoad];
  69. [self initHUD];
  70. self.page=1;
  71. [self configTableView];
  72. }
  73. - (void)initHUD {
  74. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  75. _indicatorView = indicatorView;
  76. [_indicatorView startAnimating];
  77. }
  78. - (void)configTableView {
  79. self.view.backgroundColor = [UIColor backgroudColor];
  80. [self.view addSubview:self.tableView];
  81. // [[UIApplication sharedApplication].keyWindow addSubview:self.backgroudView];
  82. }
  83. - (void)requestData {
  84. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/todayHotGoodsList",BaseURL];
  85. NSDictionary *dic=@{
  86. @"page":@(self.page)
  87. };
  88. [DRHttp post:url params:dic success:^(id json) {
  89. [_indicatorView stopAnimating];
  90. [self.dataArr removeAllObjects];
  91. if ([self.tableView.mj_header isRefreshing]) {
  92. [self.recommendListArray removeAllObjects];
  93. }
  94. NSArray *arr=[NSArray yy_modelArrayWithClass:[DRCommunityDetailModel class] json:json[@"recommendList"]];
  95. NSArray *dataA =[NSArray yy_modelArrayWithClass:[DRCommunityDetailModel class] json:json[@"top10"]];
  96. [self.dataArr addObjectsFromArray:dataA];
  97. [self.recommendListArray addObjectsFromArray:arr];
  98. if (self.dataArr.count != 0) {
  99. [self addTableViewHeader];
  100. [self.collections reloadData];
  101. }
  102. [self setNoDataView:arr];
  103. [self.tableView reloadData];
  104. [self.tableView.mj_header endRefreshing];
  105. } failure:^(NSError *error) {
  106. [self.tableView.mj_header endRefreshing];
  107. [self.tableView.mj_footer endRefreshing];
  108. [_indicatorView stopAnimating];
  109. }];
  110. }
  111. - (void)setNoDataView:(NSArray *)array {
  112. self.tableView.showNoDataView = YES;
  113. self.tableView.defaultNoDataText = @"暂无数据";
  114. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  115. if (array.count > 0) {
  116. [self.tableView.mj_footer endRefreshing];
  117. }else {
  118. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  119. }
  120. }
  121. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  122. return self.dataArr.count;
  123. }
  124. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  125. DRCommunityShareCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
  126. if (!cell ) {
  127. cell = [[DRCommunityShareCell alloc] init];
  128. }
  129. cell.model=self.dataArr[indexPath.row];
  130. switch (indexPath.row) {
  131. case 0:
  132. cell.tipeImg.image =[UIImage imageNamed:@"comm_one"];
  133. break;
  134. case 1:
  135. cell.tipeImg.image =[UIImage imageNamed:@"comm_two"];
  136. break;
  137. case 2:
  138. cell.tipeImg.image =[UIImage imageNamed:@"comm_three"];
  139. break;
  140. default:
  141. cell.tipeImg.image =[UIImage imageNamed:@""];
  142. break;
  143. }
  144. cell.backgroundColor = [UIColor yellowColor];
  145. return cell;
  146. }
  147. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  148. {
  149. DRCommunityDetailModel *model=self.dataArr[indexPath.row];
  150. [self otherOPByModel:model isTop:YES];
  151. [MobClick event:FaddishTopItemClick];
  152. }
  153. #pragma mark ============ UITableView Delegate && DataSource ==========
  154. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  155. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  156. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  157. }
  158. }
  159. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  160. {
  161. return FITSIZE(10);
  162. }
  163. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  164. return 1;
  165. }
  166. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  167. {
  168. return self.recommendListArray.count;
  169. }
  170. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  171. DRCommunityDetailModel *model = self.recommendListArray[indexPath.section];
  172. DRCommunityCell *cell = [DRCommunityCell cellWithTableView:tableView];
  173. cell.model = model;
  174. cell.picContainerView.delegate=self;
  175. cell.delegate=self;
  176. cell.layer.cornerRadius=5;
  177. cell.layer.masksToBounds=YES;
  178. cell.shareClick = ^{
  179. if (![AccountTool isLogin]) {
  180. DRLoginViewController *login = [[DRLoginViewController alloc] init];
  181. [self presentViewController:login animated:YES completion:nil];
  182. }else{
  183. [self showShareView:model];
  184. }
  185. };
  186. return cell;
  187. }
  188. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  189. DRCommunityDetailModel *model=self.recommendListArray[indexPath.section];
  190. if (model.texts.length ==0) {
  191. return FITSIZE(155);
  192. }
  193. return FITSIZE(270);
  194. }
  195. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  196. DRCommunityDetailModel *model=self.recommendListArray[indexPath.section];
  197. [self otherOPByModel:model isTop:NO];
  198. [MobClick event:FaddishNormalItemClick];
  199. }
  200. #pragma mark -代理 PhotoContainerViewDelegate
  201. - (void)otherOPByModel:(DRCommunityDetailModel *)model isTop:(BOOL)isTop{
  202. DREventModel *eventModel;
  203. if (isTop) {
  204. eventModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:@"0" source:TodayFaddishTopAction];
  205. }else {
  206. eventModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:@"0" source:TodayFaddishAction];
  207. }
  208. DRGoodDetailViewController *detailVC = [[DRGoodDetailViewController alloc] init];
  209. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithCommunityDetailModel:model];
  210. detailVC.requestModel = requestModel;
  211. detailVC.eventModel = eventModel;
  212. [self.navigationController pushViewController:detailVC animated:YES];
  213. [MobClick event:ComunityGoodClick label:@"今日爆款"];
  214. }
  215. - (void)showShareView:(DRCommunityDetailModel *)model {
  216. DRGoodDetailModel *detailModel = [[DRGoodDetailModel alloc] init];
  217. [detailModel changeDetailModelWithComunityModel:model];
  218. DRShareImgPopView *shareView = [[DRShareImgPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) goodModel:detailModel];
  219. CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:shareView backgroundDismissEnable:YES];
  220. shareView.closeAction = ^{
  221. [showView dismiss];
  222. };
  223. shareView.shareResult = ^(id result, NSError *error) {
  224. if (!error) {
  225. [self shareSuccManagerWithModel:model];
  226. }else {
  227. [MBProgressHUD showMessage:@"分享失败"];
  228. }
  229. };
  230. showView.backgroundView.backgroundColor = [UIColor clearColor];
  231. [showView show];
  232. }
  233. - (void)shareSuccManagerWithModel:(DRCommunityDetailModel *)model {
  234. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/shareCount",BaseURL];
  235. NSDictionary *para = @{@"goods_id":model.goods_id};
  236. [DRHttp post:url params:para success:^(id json) {
  237. [MBProgressHUD showMessage:@"分享成功"];
  238. } failure:^(NSError *error) {
  239. }];
  240. }
  241. #pragma mark -代理 YHCommunityDelegate
  242. -(void)oneTouchShareWithModel:(DRCommunityModel *)model{
  243. // NSArray *arr=model.detail;
  244. [MobClick event:OneKeyShareRecommend label:@"优选商品"];
  245. if([AccountTool isLogin]){
  246. // UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  247. // pasteboard.string=model.note;
  248. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/oneKeySharing",BaseURL];
  249. NSDictionary *dic=@{@"id":model.Id};
  250. [SVProgressHUD showWithStatus:@"生成分享中"];
  251. [DRHttp post:url params:dic success:^(id json) {
  252. NSArray *arr=[NSArray yy_modelArrayWithClass:[DRCommunityDetailModel class] json:json[@"data"]];
  253. NSDictionary *userInfo = json[@"userinfo"];
  254. if (arr.count>0) {
  255. __block NSInteger count=0;
  256. NSMutableArray *imgArr=[NSMutableArray array];
  257. __block NSInteger max=(arr.count<9?arr.count:9);
  258. // self.backgroudView.hidden=NO;
  259. for (int i=0;i<max;i++) {
  260. DRCommunityDetailModel *model=arr[i];
  261. NSLog(@"model.img--%@",model.img);
  262. DRShareGoodsModel *goodsModel=[[DRShareGoodsModel alloc]init];
  263. goodsModel.mainImageUrl=model.img;
  264. goodsModel.commission_price = model.commission_price;
  265. if([model.shop_type integerValue]==0){
  266. goodsModel.shareGoodsFromType=YHShareGoodsFromTypeTaoBao;
  267. }else if([model.shop_type integerValue]==1){
  268. goodsModel.shareGoodsFromType=YHShareGoodsFromTypeTianMao;
  269. }else{
  270. goodsModel.shareGoodsFromType=YHShareGoodsFromTypeOriginal;
  271. }
  272. goodsModel.title=model.title;
  273. goodsModel.ticketAfterPrice=model.discount_price;
  274. goodsModel.ticketPrice=model.coupon_price;
  275. goodsModel.originalPrice=model.price;
  276. goodsModel.QRcodeImageUrl=model.url;
  277. if ([model.is_coupon integerValue]==0) {//进入折扣
  278. goodsModel.shareGoodsPurchaseType=YHShareGoodsPurchaseTypePrice;
  279. }
  280. DRShareGoodsView *view1=[[DRShareGoodsView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];
  281. __weak __typeof(view1) weakView1 = view1;
  282. view1.imgSuccBlock = ^{
  283. count++;
  284. [imgArr addObject: [weakView1 changeToImage]];
  285. if (count==max) {
  286. count=0;
  287. [SVProgressHUD dismiss];
  288. // self.backgroudView.hidden=YES;
  289. UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:imgArr applicationActivities:nil];
  290. [self presentViewController:activityVC animated:YES completion:nil];
  291. }
  292. };
  293. view1.model=goodsModel;
  294. view1.userInfo = userInfo;
  295. }
  296. }else{
  297. [SVProgressHUD dismiss];
  298. [MBProgressHUD showMessage:@"没有商品可以分享"];
  299. }
  300. } failure:^(NSError *error) {
  301. [SVProgressHUD dismiss];
  302. [MBProgressHUD showMessage:@"加载失败,请稍后再试"];
  303. }];
  304. }else{
  305. DRLoginViewController *login = [[DRLoginViewController alloc] init];
  306. login.loginSucc = ^{
  307. [self requestData];
  308. };
  309. [self.navigationController presentViewController:login animated:YES completion:nil];
  310. }
  311. }
  312. #pragma mark ------- layzer ---------
  313. -(UICollectionView *)collections
  314. {
  315. if (!_collections) {
  316. CGRect collectionViewFrame= CGRectMake(0, FITSIZE(10), [UIScreen mainScreen].bounds.size.width-FITSIZE(20), FITSIZE(182));
  317. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  318. // 设置UICollectionView为横向滚动
  319. flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  320. // 每一行cell之间的间距
  321. flowLayout.minimumLineSpacing = FITSIZE(10);
  322. // 每一列cell之间的间距
  323. // flowLayout.minimumInteritemSpacing = 10;
  324. // 设置第一个cell和最后一个cell,与父控件之间的间距
  325. flowLayout.sectionInset = UIEdgeInsetsMake(FITSIZE(40), FITSIZE(10), 0, FITSIZE(10));
  326. flowLayout.itemSize = CGSizeMake(FITSIZE(106), FITSIZE(140));// 该行代码就算不写,item也会有默认尺寸
  327. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:flowLayout];
  328. collectionView.backgroundColor = [UIColor whiteColor];
  329. collectionView.dataSource = self;
  330. collectionView.delegate = self;
  331. _collections = collectionView;
  332. _collections.showsVerticalScrollIndicator=NO;
  333. _collections.showsHorizontalScrollIndicator=NO;
  334. self.collections.hidden=YES;
  335. _collections.layer.cornerRadius=5;
  336. _collections.layer.masksToBounds=YES;
  337. [self.collections registerClass:[DRCommunityShareCell class] forCellWithReuseIdentifier:@"cellId"];
  338. }
  339. return _collections;
  340. }
  341. - (UITableView *)tableView {
  342. if (!_tableView) {
  343. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(FITSIZE(10), 0, SCREEN_WIDTH-FITSIZE(20), ChildTableViewHeight+40) style:UITableViewStyleGrouped];
  344. _tableView.estimatedSectionHeaderHeight = 0;
  345. _tableView.estimatedSectionFooterHeight = 0;
  346. _tableView.sectionFooterHeight = 0;
  347. _tableView.sectionHeaderHeight = 0;
  348. _tableView.estimatedRowHeight = 0;
  349. _tableView.delegate = self;
  350. _tableView.dataSource = self;
  351. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  352. _tableView.backgroundColor = [UIColor clearColor];
  353. _tableView.bounces = YES;
  354. _tableView.showsVerticalScrollIndicator = NO;
  355. _tableView.separatorColor = [UIColor lineColor];
  356. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  357. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  358. self.page = 1;
  359. [_tableView.mj_footer resetNoMoreData];
  360. [self requestData];
  361. }];
  362. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  363. _page++;
  364. [self requestData];
  365. }];
  366. _tableView.mj_footer = footer;
  367. [_tableView.mj_header beginRefreshing];
  368. }
  369. return _tableView;
  370. }
  371. #pragma mark-添加区头
  372. -(void)addTableViewHeader
  373. {
  374. UIView *bakck =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-FITSIZE(20), FITSIZE(200))];
  375. [bakck addSubview:self.collections];
  376. UIImageView *imgV =[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(10), FITSIZE(20), FITSIZE(20), FITSIZE(20))];
  377. imgV.image=[UIImage imageNamed:@"paihang"];
  378. [bakck addSubview:imgV];
  379. self.collections.hidden=NO;
  380. UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(40), FITSIZE(10), FITSIZE(85), FITSIZE(40))];
  381. label.text=@"分享排行榜";
  382. label.textColor=[UIColor homeRedColor];
  383. [bakck addSubview:label];
  384. label.font =[UIFont systemFontOfSize:FITSIZE(15)];
  385. UILabel *tiplabel =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(130), FITSIZE(10), FITSIZE(120), FITSIZE(40))];
  386. tiplabel.text=@"那些值得分享的好物";
  387. tiplabel.textColor=[UIColor YHColorWithHex:0x9B9B9B];
  388. [bakck addSubview:tiplabel];
  389. tiplabel.font =[UIFont systemFontOfSize:FITSIZE(13)];
  390. self.tableView.tableHeaderView =bakck;
  391. }
  392. - (NSMutableArray *)dataArr {
  393. if (!_dataArr) {
  394. _dataArr = [NSMutableArray array];
  395. }
  396. return _dataArr;
  397. }
  398. -(NSMutableArray *)recommendListArray
  399. {
  400. if (!_recommendListArray) {
  401. _recommendListArray =[NSMutableArray array];
  402. }
  403. return _recommendListArray;
  404. }
  405. //-(UIView *)backgroudView{
  406. // if (!_backgroudView) {
  407. // _backgroudView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  408. // _backgroudView.backgroundColor=[[UIColor grayColor] colorWithAlphaComponent:0.2];
  409. // _backgroudView.hidden=YES;
  410. // }
  411. // return _backgroudView;
  412. //}
  413. @end