猎豆优选

LDCommunityRightController.m 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. //
  2. // LDCommunityLeftController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDCommunityRightController.h"
  9. #import "LDCommunityCell.h"
  10. #import "UITableView+SDAutoTableViewCellHeight.h"
  11. #import "LDCommunityModel.h"
  12. #import "LDCommunityDetailModel.h"
  13. #import "LDShareGetFriendsModel.h"
  14. #import "LDShareGetFriendsView.h"
  15. #import "LDLoginViewController.h"
  16. #import "LDCommunityRightCell.h"
  17. #import "LDCommunityRightModel.h"
  18. #import "shareView.h"
  19. #import "LDShareGoodsTempModel.h"
  20. #import "LDShareGoodsModel.h"
  21. #import <SDWebImageDownloader.h>
  22. #import "LDPopShareGoodView.h"
  23. #import "LDShareManager.h"
  24. #import "HYUMShareManager.h"
  25. #import "WXApi.h"
  26. #import "LDShareImgPopView.h"
  27. #import "CCAlertShowView.h"
  28. #import "LDGoodDetailModel.h"
  29. @interface LDCommunityRightController ()
  30. <
  31. UITableViewDelegate,
  32. UITableViewDataSource,
  33. YHCommunityDelegate
  34. >
  35. {
  36. __block BOOL _imgSuccFlag;
  37. }
  38. @property (nonatomic, strong) UITableView *tableView;
  39. @property (nonatomic, strong) NSMutableArray *dataArr;
  40. @property (nonatomic ) NSInteger page;
  41. @property(nonatomic,strong)UIView *backShareView;
  42. @property (nonatomic,strong ) UIView *backgroudView;
  43. @property(nonatomic,strong) shareView *shareView;
  44. @property(nonatomic,strong)LDShareGoodsModel *model;
  45. @property (nonatomic, strong) LDPopShareGoodView *shareGoodView;
  46. @property (nonatomic, assign) BOOL imgSuccFlag;
  47. @property (nonatomic, strong) LDCommunityRightModel *rightModel;
  48. @end
  49. @implementation LDCommunityRightController
  50. - (void)viewDidLoad {
  51. [super viewDidLoad];
  52. self.page=1;
  53. [self configTableView];
  54. }
  55. - (void)configTableView {
  56. self.view.backgroundColor = [UIColor yhGrayColor];
  57. [self.view addSubview:self.tableView];
  58. [[UIApplication sharedApplication].keyWindow addSubview:self.backgroudView];
  59. [[UIApplication sharedApplication].keyWindow addSubview:self.backShareView];
  60. [[UIApplication sharedApplication].keyWindow addSubview:self.shareView];
  61. }
  62. - (void)requestData {
  63. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/editorRecommendation",BaseURL];
  64. NSDictionary *dic=@{
  65. @"page":@(self.page)
  66. };
  67. [LDHttp post:url params:dic success:^(id json) {
  68. if ([self.tableView.mj_header isRefreshing]) {
  69. [self.dataArr removeAllObjects];
  70. }
  71. NSArray *arr=[NSArray yy_modelArrayWithClass:[LDCommunityRightModel class] json:json[@"data"]];
  72. [self setNoDataView:arr];
  73. [self.dataArr addObjectsFromArray:arr];
  74. [self.tableView reloadData];
  75. } failure:^(NSError *error) {
  76. [self.tableView.mj_header endRefreshing];
  77. [self.tableView.mj_footer endRefreshing];
  78. }];
  79. }
  80. - (void)setNoDataView:(NSArray *)array {
  81. if (array.count > 0) {
  82. [self.tableView.mj_header endRefreshing];
  83. [self.tableView.mj_footer endRefreshing];
  84. }else {
  85. [self.tableView.mj_header endRefreshing];
  86. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  87. }
  88. self.tableView.showNoDataView = YES;
  89. self.tableView.defaultNoDataText = @"暂无数据";
  90. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  91. }
  92. #pragma mark ============ UITableView Delegate && DataSource ==========
  93. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  94. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  95. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  96. }
  97. }
  98. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  99. return 0.1;
  100. }
  101. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  102. return self.dataArr.count;
  103. }
  104. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  105. LDCommunityRightModel *model = self.dataArr[indexPath.row];
  106. LDCommunityRightCell *cell = [LDCommunityRightCell cellWithTableView:tableView];
  107. cell.model = model;
  108. cell.shareClick = ^{
  109. // [self loadShareData:model];
  110. [self showShareView:model];
  111. };
  112. return cell;
  113. }
  114. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  115. // return [self cellHeightForIndexPath:indexPath cellContentViewWidth:SCREEN_WIDTH tableView:tableView];
  116. return Fitsize(177);
  117. }
  118. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  119. LDCommunityRightModel *model = self.dataArr[indexPath.row];
  120. 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.start_time coupon_end_time:model.end_time coupon_id:model.coupon_id];
  121. LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  122. detail.requestModel = requestModel;
  123. [self.navigationController pushViewController:detail animated:YES];
  124. [MobClick event:ComunityGoodClick label:@"小编推荐"];
  125. }
  126. - (void)showShareView:(LDCommunityRightModel *)model {
  127. self.rightModel = model;
  128. LDGoodDetailModel *detailModel = [[LDGoodDetailModel alloc] init];
  129. [detailModel changeDetailModelWithComunityRightModel:model];
  130. LDShareImgPopView *shareView = [[LDShareImgPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) goodModel:detailModel];
  131. CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:shareView backgroundDismissEnable:YES];
  132. shareView.closeAction = ^{
  133. [showView dismiss];
  134. };
  135. shareView.shareResult = ^(id result, NSError *error) {
  136. if (!error) {
  137. [self shareSuccManager];
  138. }else {
  139. [MBProgressHUD showMessage:@"分享失败"];
  140. }
  141. };
  142. showView.backgroundView.backgroundColor = [UIColor clearColor];
  143. [showView show];
  144. }
  145. //- (void)loadShareData:(LDCommunityRightModel *)model {
  146. //
  147. // self.rightModel = model;
  148. //
  149. // NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/shareCommonGoods",BaseURL];
  150. // NSString *coupon_start_time = [model.is_coupon boolValue] ? model.start_time : @"";
  151. // NSString *coupon_end_time = [model.is_coupon boolValue] ? model.end_time : @"";
  152. // if (!coupon_start_time) coupon_start_time = @"";
  153. // if (!coupon_end_time) coupon_end_time = @"";
  154. // NSDictionary *dic=@{
  155. // @"goods_id":model.goods_id,
  156. // @"is_coupon":model.is_coupon,
  157. // @"coupon_price":model.coupon_price,
  158. // @"price":model.price,
  159. // @"discount_price":model.discount_price,
  160. // @"commission_rate":model.commission_rate,
  161. // @"coupon_end_time":coupon_end_time,
  162. // @"coupon_start_time":coupon_start_time
  163. // };
  164. //
  165. // [LDHttp post:url params:dic success:^(id json) {
  166. // LDShareGoodsTempModel *tmpModel=[LDShareGoodsTempModel yy_modelWithJSON:json[@"data"]];
  167. // LDShareGoodsModel *shreModel = [LDShareGoodsModel createShareGoodsModelByShareGoodsTempModel:tmpModel];
  168. // shreModel.commissionPrice = model.commission_price;//佣金价格
  169. // shreModel.commission_rate = model.commission_rate;
  170. // shreModel.discount_price = model.discount_price;
  171. // shreModel.userinfo = tmpModel.userinfo;
  172. //
  173. // LDPopShareGoodView *shareGoodView = [[LDPopShareGoodView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, Fitsize(254), Fitsize(455))];
  174. // self.shareGoodView = shareGoodView;
  175. // shareGoodView.backgroundColor = [UIColor whiteColor];
  176. // shareGoodView.imgSuccBlock = ^{
  177. // _imgSuccFlag = YES;
  178. // };
  179. // shareGoodView.model = shreModel;
  180. // [self.view addSubview:shareGoodView];
  181. //
  182. // } failure:^(NSError *error) {
  183. //
  184. // }];
  185. //
  186. // //分享图片
  187. // self.backShareView.hidden = NO;
  188. // [UIView animateWithDuration:0.2f animations:^{
  189. // self.shareView.frame=CGRectMake(0, SCREEN_HEIGHT-200-SafeBottomHeight, SCREEN_WIDTH, 200+SafeBottomHeight);
  190. // }];
  191. //
  192. //}
  193. #pragma mark -代理 YHCommunityDelegate
  194. //-(void)oneTouchShareWithModel:(LDCommunityModel *)model{
  195. //// NSArray *arr=model.detail;
  196. //// /api/v2/adzoneCreate/secretOneSharing
  197. // [MobClick event:OneKeyShareCheats label:@"优选素材"];
  198. // if([AccountTool isLogin]){
  199. // UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  200. // pasteboard.string=model.note;
  201. // NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/secretOneSharing",BaseURL];
  202. // NSDictionary *dic=@{@"id":model.Id};
  203. // [LDHttp post:url params:dic success:^(id json) {
  204. // NSArray *arr=[NSArray yy_modelArrayWithClass:[LDCommunityDetailModel class] json:json[@"data"]];
  205. // NSDictionary *userinfo = json[@"userinfo"];
  206. // if (arr.count>0) {
  207. // __block NSInteger count=0;
  208. // NSMutableArray *imgArr=[NSMutableArray array];
  209. // __block NSInteger max=(arr.count<9?arr.count:9);
  210. // self.backgroudView.hidden=NO;
  211. // [SVProgressHUD showWithStatus:@"生成分享中"];
  212. // for (int i=0;i<max;i++) {
  213. // LDCommunityDetailModel *model=arr[i];
  214. // LDShareGetFriendsModel *friendModel=[[LDShareGetFriendsModel alloc]init];
  215. // friendModel.getFriendCode=@"";
  216. // friendModel.QRcodeUrl=model.url;
  217. // friendModel.imgUrl=model.img;
  218. // LDShareGetFriendsView *view1=[[LDShareGetFriendsView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  219. // view1.model=friendModel;
  220. // view1.userinfo = userinfo;
  221. // __weak __typeof(view1) weakView1 = view1;
  222. // view1.imgSuccBlock = ^{
  223. // count++;
  224. // [imgArr addObject: [weakView1 changeToImage]];
  225. // if (count==max) {
  226. // count=0;
  227. // [SVProgressHUD dismiss];
  228. // self.backgroudView.hidden=YES;
  229. // UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:imgArr applicationActivities:nil];
  230. // [self presentViewController:activityVC animated:YES completion:nil];
  231. // }
  232. // };
  233. //
  234. // }
  235. // }else{
  236. //
  237. // [SVProgressHUD dismiss];
  238. // [MBProgressHUD showMessage:@"没有商品可以分享"];
  239. // }
  240. // } failure:^(NSError *error) {
  241. //
  242. // }];
  243. //
  244. //
  245. //
  246. //
  247. // }else{
  248. // LDLoginViewController *login = [[LDLoginViewController alloc] init];
  249. // login.loginSucc = ^{
  250. // self.page=0;
  251. // [self requestData];
  252. // };
  253. // [self.navigationController presentViewController:login animated:YES completion:nil];
  254. // }
  255. //}
  256. - (void)shareSuccManager {
  257. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/shareCount",BaseURL];
  258. NSDictionary *para = @{@"goods_id":self.rightModel.goods_id};
  259. [LDHttp post:url params:para success:^(id json) {
  260. [MBProgressHUD showMessage:@"分享成功"];
  261. } failure:^(NSError *error) {
  262. }];
  263. }
  264. -(void)doTapChange{
  265. self.backShareView.hidden=YES;
  266. [UIView animateWithDuration:0.2f animations:^{
  267. self.shareView.frame=CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 200+SafeBottomHeight);
  268. } completion:^(BOOL finished) {
  269. }];
  270. }
  271. #pragma mark ------- layzer ---------
  272. - (UITableView *)tableView {
  273. if (!_tableView) {
  274. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 1, SCREEN_WIDTH, ChildTableViewHeight) style:UITableViewStyleGrouped];
  275. _tableView.estimatedSectionHeaderHeight = 0;
  276. _tableView.estimatedSectionFooterHeight = 0;
  277. _tableView.sectionFooterHeight = 0;
  278. _tableView.sectionHeaderHeight = 0;
  279. _tableView.estimatedRowHeight = 0;
  280. _tableView.delegate = self;
  281. _tableView.dataSource = self;
  282. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  283. _tableView.backgroundColor = [UIColor backgroudColor];
  284. _tableView.bounces = YES;
  285. _tableView.showsVerticalScrollIndicator = NO;
  286. _tableView.separatorColor = [UIColor lineColor];
  287. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  288. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  289. self.page = 1;
  290. [_tableView.mj_footer resetNoMoreData];
  291. [self requestData];
  292. }];
  293. MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  294. _page++;
  295. [self requestData];
  296. }];
  297. _tableView.mj_footer = footer;
  298. [_tableView.mj_header beginRefreshing];
  299. }
  300. return _tableView;
  301. }
  302. - (NSMutableArray *)dataArr {
  303. if (!_dataArr) {
  304. _dataArr = [NSMutableArray array];
  305. }
  306. return _dataArr;
  307. }
  308. -(UIView *)backgroudView{
  309. if (!_backgroudView) {
  310. _backgroudView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  311. _backgroudView.backgroundColor=[[UIColor grayColor] colorWithAlphaComponent:0.2];
  312. _backgroudView.hidden=YES;
  313. }
  314. return _backgroudView;
  315. }
  316. -(UIView *)shareView{
  317. if (!_shareView) {
  318. _shareView=[[[NSBundle mainBundle] loadNibNamed:@"shareView" owner:self options:nil] lastObject];
  319. _shareView.frame=CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH,SCREEN_HEIGHT);
  320. [_shareView.cancelButton addTarget:self action:@selector(doTapChange) forControlEvents:UIControlEventTouchUpInside];
  321. WeakSelf(weakSelf)
  322. _shareView.shareToFriend = ^{
  323. if (weakSelf.imgSuccFlag) {
  324. [weakSelf doTapChange];
  325. _imgSuccFlag = NO;
  326. [LDShareManager shareImageWithplatformType:UMSocialPlatformType_WechatSession withImg:[weakSelf.shareGoodView changeToImage] complete:^(id result, NSError *error) {
  327. if (!error) {
  328. [weakSelf shareSuccManager];
  329. }else {
  330. [MBProgressHUD showMessage:@"分享失败"];
  331. }
  332. }];
  333. }else {
  334. [MBProgressHUD showMessage:@"海报生成中,请稍后再试"];
  335. }
  336. };
  337. _shareView.shareToSession = ^{
  338. if (weakSelf.imgSuccFlag) {
  339. [weakSelf doTapChange];
  340. _imgSuccFlag = NO;
  341. [LDShareManager shareImageWithplatformType:UMSocialPlatformType_WechatTimeLine withImg:[weakSelf.shareGoodView changeToImage] complete:^(id result, NSError *error) {
  342. if (!error) {
  343. [weakSelf shareSuccManager];
  344. }else {
  345. [MBProgressHUD showMessage:@"分享失败"];
  346. }
  347. }];
  348. }else {
  349. [MBProgressHUD showMessage:@"海报生成中,请稍后再试"];
  350. }
  351. };
  352. // _shareView.shareButtonTwoBlock=^(void){
  353. // __strong typeof(self) strongSelf=weakSelf;
  354. // [strongSelf doTapChange];
  355. // };
  356. // _shareView.shareButtonOneBlock=^(void){
  357. // __strong typeof(self) strongSelf=weakSelf;
  358. // [strongSelf doTapChange];
  359. // };
  360. }
  361. return _shareView;
  362. }
  363. -(UIView *)backShareView{
  364. if (!_backShareView) {
  365. _backShareView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  366. _backShareView.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.3f];
  367. _backShareView.hidden=YES;
  368. UITapGestureRecognizer *r5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doTapChange)];
  369. r5.numberOfTapsRequired = 1;
  370. [_backShareView addGestureRecognizer:r5];
  371. }
  372. return _backShareView;
  373. }
  374. @end