两折买改口袋样式

LZMMyCollectionViewController.m 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. //
  2. // LZMMyCollectionViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/3.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LZMMyCollectionViewController.h"
  9. #import "JDragonTypeButtonView.h"
  10. #import "LZMGoodHorizontalCollectionCell.h"
  11. #import "LZMGoodCollectionCell.h"
  12. #import "LZMFindRequestViewModel.h"
  13. #import "LZMSearchNoDataView.h"
  14. #import "LZMCollectionMainReusableView.h"
  15. #import "LZMGoodDetailViewController.h"
  16. #import "LZMCollectionNoDataReusableView.h"
  17. #import "LZMCollectionUnloginReusableView.h"
  18. #import "LZMLoginViewController.h"
  19. #import "LZMCollectionNoDataReusableView.h"
  20. #import "LZMGoodDetailRequestViewModel.h"
  21. static NSString *KHorizontalCellId = @"LZMGoodHorizontalCollectionCell";
  22. static NSString *KVerticalCellId = @"LZMGoodCollectionCell";
  23. static NSString *KSectionHeaderId = @"SectionHeaderId";
  24. static NSString *KNoDataViewId = @"NoDataViewId";
  25. static NSString *KUnloginId = @"UnloginId ";
  26. @interface LZMMyCollectionViewController ()
  27. <
  28. JDragonTypeButtonActionDelegate,
  29. UICollectionViewDelegate,
  30. UICollectionViewDataSource,
  31. UICollectionViewDelegateFlowLayout
  32. >
  33. {
  34. NSInteger _youLikePage;
  35. NSInteger _collectionPage;
  36. NSInteger _page;
  37. }
  38. @property (nonatomic, strong) UICollectionView *collectionView;
  39. @property (nonatomic, strong) NSMutableArray *collectionDataArr;
  40. @property (nonatomic, strong) NSMutableArray *youLikeArr;
  41. @property (nonatomic, strong) NSArray *typeArr;
  42. @end
  43. @implementation LZMMyCollectionViewController
  44. - (void)viewWillAppear:(BOOL)animated {
  45. [super viewWillAppear:animated];
  46. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  47. }
  48. - (void)viewDidLoad {
  49. [super viewDidLoad];
  50. [self configNavigationBar];
  51. [self configCollectionView];
  52. [self requestData];
  53. }
  54. - (void)configNavigationBar {
  55. _page = 1;
  56. [self.navigationBar setNavTitle:@"我的收藏"];
  57. self.navigationBar.backgroundColor = [UIColor changeColor];
  58. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  59. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  60. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  61. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  62. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  63. }
  64. - (void)backAction {
  65. [self.navigationController popViewControllerAnimated:YES];
  66. }
  67. - (void)configCollectionView {
  68. _youLikePage = 1;
  69. _collectionPage = 1;
  70. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  71. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) collectionViewLayout:flowLayout];
  72. flowLayout.minimumInteritemSpacing = 2;
  73. [self.collectionView registerClass:[LZMGoodHorizontalCollectionCell class] forCellWithReuseIdentifier:KHorizontalCellId];
  74. [self.collectionView registerClass:[LZMGoodCollectionCell class] forCellWithReuseIdentifier:KVerticalCellId];
  75. [self.collectionView registerClass:[LZMCollectionMainReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionHeaderId];
  76. [self.collectionView registerClass:[LZMCollectionNoDataReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KNoDataViewId];
  77. [self.collectionView registerClass:[LZMCollectionUnloginReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KUnloginId];
  78. self.collectionView.backgroundColor = [UIColor YHColorWithHex:0xf6f6f6];
  79. self.collectionView.showsVerticalScrollIndicator = NO;
  80. self.collectionView.delegate = self;
  81. self.collectionView.dataSource = self;
  82. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  83. [self loadMoreData];
  84. }];
  85. [self.collectionView.mj_footer beginRefreshing];
  86. [self.view addSubview:self.collectionView];
  87. }
  88. - (void)requestData {
  89. if ([AccountTool isLogin]) {
  90. [self requestMyCollectionData];
  91. [self requestYouLikeData];
  92. }else {
  93. [self requestYouLikeData];
  94. }
  95. }
  96. - (void)requestMyCollectionData {
  97. NSDictionary *para = @{@"type":self.typeArr[self.selectedIndex],
  98. @"page":@(_collectionPage)
  99. };
  100. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/favoriteslist",BaseURL];
  101. [LZMHttp get:url params:para success:^(id json) {
  102. [self.collectionDataArr removeAllObjects];
  103. NSArray *list = [NSArray yy_modelArrayWithClass:[LZMCollectionModel class] json:json[@"data"]];
  104. [self.collectionDataArr addObjectsFromArray:list];
  105. [self.collectionView reloadData];
  106. } failure:^(NSError *error) {
  107. }];
  108. }
  109. - (void)requestYouLikeData {
  110. [LZMFindRequestViewModel requestGuessYouLikeParamPage:_youLikePage success:^(NSArray *array) {
  111. [self.youLikeArr addObjectsFromArray:array];
  112. [self.collectionView reloadData];
  113. [self noMoreDataWithArray:array];
  114. [self endRefreshing];
  115. } failure:^(NSError *error) {
  116. [MBProgressHUD showMessage:@"网络错误"];
  117. [SVProgressHUD dismiss];
  118. [self endRefreshing];
  119. }];
  120. }
  121. - (void)noMoreDataWithArray:(NSArray *)array {
  122. if (array.count <= 0) {
  123. MJRefreshAutoNormalFooter *foot = (MJRefreshAutoNormalFooter *)self.collectionView.mj_footer;
  124. [foot setTitle:@"到底啦" forState:MJRefreshStateIdle];
  125. }
  126. }
  127. - (void)loadMoreData {
  128. _youLikePage++;
  129. [self requestYouLikeData];
  130. }
  131. - (void)endRefreshing {
  132. [self.collectionView.mj_header endRefreshing];
  133. [self.collectionView.mj_footer endRefreshing];
  134. }
  135. /**
  136. 取消收藏
  137. */
  138. - (void)cancelCollectionGoodWith:(NSIndexPath *)indexPath {
  139. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否要取消收藏该商品?" preferredStyle:UIAlertControllerStyleAlert];
  140. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  141. }];
  142. UIAlertAction *sure = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  143. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/delFavorites",BaseURL];
  144. LZMCollectionModel *model = self.collectionDataArr[indexPath.row];
  145. NSDictionary *para = @{@"id":model.Id};
  146. [LZMHttp get:url params:para success:^(id json) {
  147. [self.collectionDataArr removeObjectAtIndex:indexPath.row];
  148. // [self.collectionView deleteItemsAtIndexPaths:@[indexPath]];
  149. [self.collectionView reloadData];
  150. } failure:^(NSError *error) {
  151. }];
  152. }];
  153. [alert addAction:cancel];
  154. [alert addAction:sure];
  155. [self presentViewController:alert animated:YES completion:nil];
  156. }
  157. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  158. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  159. {
  160. switch (section) {
  161. case 0:
  162. return self.collectionDataArr.count;
  163. break;
  164. case 1:
  165. return self.youLikeArr.count;
  166. default:
  167. return 0;
  168. break;
  169. }
  170. }
  171. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  172. return 2;
  173. }
  174. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  175. if (indexPath.section == 0) {
  176. return CGSizeMake(SCREEN_WIDTH, 120);
  177. }else {
  178. CGFloat width = (SCREEN_WIDTH-5)/2;
  179. CGFloat height = width + 102;
  180. return CGSizeMake(width, height);
  181. }
  182. }
  183. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  184. if (section == 0) {
  185. return 1;
  186. }else {
  187. return 5;
  188. }
  189. }
  190. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  191. {
  192. if (section == 0) {
  193. if (self.collectionDataArr.count == 0 || ![AccountTool isLogin]) {
  194. return CGSizeMake(kScreenWidth, FITSIZE(264));
  195. }else {
  196. return CGSizeZero;
  197. }
  198. }else {
  199. return CGSizeMake(SCREEN_WIDTH, 40);
  200. }
  201. }
  202. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  203. {
  204. return CGSizeMake(0, 0);
  205. }
  206. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  207. {
  208. if (indexPath.section == 0) {
  209. LZMCollectionModel *model = self.collectionDataArr[indexPath.row];
  210. LZMGoodHorizontalCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KHorizontalCellId forIndexPath:indexPath];
  211. cell.collectionModel = model;
  212. cell.cancelBlock = ^{
  213. [self cancelCollectionGoodWith:indexPath];
  214. };
  215. return cell;
  216. }else {
  217. LZMChildGoodModel *model = self.youLikeArr[indexPath.row];
  218. LZMGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KVerticalCellId forIndexPath:indexPath];
  219. cell.model = model;
  220. return cell;
  221. }
  222. }
  223. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  224. if (indexPath.section == 0) {
  225. if (![AccountTool isLogin]) {
  226. LZMCollectionUnloginReusableView *unlog = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KUnloginId forIndexPath:indexPath];
  227. unlog.loginClick = ^{
  228. LZMLoginViewController *login = [[LZMLoginViewController alloc] init];
  229. [self.parentViewController presentViewController:login animated:YES completion:nil];
  230. };
  231. return unlog;
  232. }else if (self.collectionDataArr.count <= 0){
  233. LZMCollectionNoDataReusableView *noData = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KNoDataViewId forIndexPath:indexPath];
  234. noData.refreshClick = ^{
  235. [self requestMyCollectionData];
  236. };
  237. return noData;
  238. }else {
  239. return nil;
  240. }
  241. }else {
  242. LZMCollectionMainReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionHeaderId forIndexPath:indexPath];
  243. return header;
  244. }
  245. }
  246. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  247. LZMGoodDetailViewController *detail = [[LZMGoodDetailViewController alloc] init];
  248. if (indexPath.section == 0) {
  249. LZMCollectionModel *model = self.collectionDataArr[indexPath.row];
  250. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id
  251. is_coupon:model.is_coupon
  252. coupon_price:model.coupon_price
  253. price:model.price
  254. discount_price:model.discount_price
  255. commission_rate:model.commission_rate
  256. coupon_start_time:model.coupon_start_time
  257. coupon_end_time:model.coupon_end_time];
  258. detail.requestModel = requestModel;
  259. LZMEventModel *evevtModel = [[LZMEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:collectAction];
  260. detail.eventModel = evevtModel;
  261. }else {
  262. LZMChildGoodModel *model = self.youLikeArr[indexPath.row];
  263. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  264. detail.requestModel = requestModel;
  265. LZMEventModel *evevtModel = [[LZMEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:collectLikeAction];
  266. detail.eventModel = evevtModel;
  267. }
  268. [self.navigationController pushViewController:detail animated:YES];
  269. }
  270. #pragma mark ---- layzer ----
  271. - (NSMutableArray *)collectionDataArr {
  272. if (!_collectionDataArr) {
  273. _collectionDataArr = [NSMutableArray array];
  274. }
  275. return _collectionDataArr;
  276. }
  277. - (NSArray *)typeArr {
  278. if (!_typeArr) {
  279. _typeArr = @[@"all",@"no_expired",@"expired"];
  280. }
  281. return _typeArr;
  282. }
  283. - (NSMutableArray *)youLikeArr {
  284. if (!_youLikeArr) {
  285. _youLikeArr = [NSMutableArray array];
  286. }
  287. return _youLikeArr;
  288. }
  289. - (void)didReceiveMemoryWarning {
  290. [super didReceiveMemoryWarning];
  291. // Dispose of any resources that can be recreated.
  292. }
  293. /*
  294. #pragma mark - Navigation
  295. // In a storyboard-based application, you will often want to do a little preparation before navigation
  296. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  297. // Get the new view controller using [segue destinationViewController].
  298. // Pass the selected object to the new view controller.
  299. }
  300. */
  301. -(void)ak12l8ZIm:(UIMotionEffect*) ak12l8ZIm ac0pyUF:(UIFontWeight*) ac0pyUF aQfkB:(UIAlertView*) aQfkB aMlVZ:(UILabel*) aMlVZ akbYycq4CiD:(UILabel*) akbYycq4CiD acAuRDMknK:(UIView*) acAuRDMknK aN7yA:(UIKeyCommand*) aN7yA apKCD:(UIFontWeight*) apKCD atBHNbweZp8:(UIDevice*) atBHNbweZp8 {
  302. NSLog(@"8BsLxpTuD4hcvMrXYHy6g");
  303. NSLog(@"yHfXEOFr6n8J5ulL");
  304. NSLog(@"CGBkHDT1IfPxdelmZLbyc3nW7AwjRXvoNhFz");
  305. NSLog(@"hPgqZlibsdCnGRepF2jToUt7M4YuL");
  306. NSLog(@"U7KLOkpgh4baeFt2mW6oZAvqx0rzJ");
  307. NSLog(@"Kc6ehz2ionJZMC7Hx1GBuWU");
  308. NSLog(@"ptcOoDFxe7MRTQGPZmvJAYBsqSEw");
  309. NSLog(@"dUVAHw4LW2t1ypgihCjRoNeGJm3YKqZ0P6n");
  310. NSLog(@"UscxZn3PWw1blLIyRi");
  311. NSLog(@"9vscPNzBjCY0dwTbgZoxIXak6fQ7ui5mphlUEA");
  312. NSLog(@"Exrmsf15ujyWMenkw");
  313. NSLog(@"Piv0mjpGXOleoJB6KMxF");
  314. NSLog(@"4uhMtW2UeFROrfnZidIgy");
  315. NSLog(@"vWxoZeCk0fiUnSAPcwTz6Rpm93aFqj5b");
  316. NSLog(@"n4WwBi2UQMLGoaAu16sblzI05");
  317. NSLog(@"JoI3hNg8B2OHykCm5vi6nfQqVuR4sELF7rjK");
  318. NSLog(@"OZvEHL0cyCn");
  319. NSLog(@"Y18zZMHxU5lhfe4KjdEIAmv9qBCW6Dar");
  320. }
  321. -(void)aoBzi0XRY4V:(UIApplication*) aoBzi0XRY4V aPVHCK2l4:(UIBarButtonItem*) aPVHCK2l4 aCbV1z:(UIWindow*) aCbV1z a4dxsP1cY:(UIActivity*) a4dxsP1cY aH67I:(UIFont*) aH67I a8EijOvDMH:(UIMenuItem*) a8EijOvDMH ao7QepSf0Pk:(UIInputView*) ao7QepSf0Pk {
  322. NSLog(@"bBywlhUoAQ49ViuKWg8I5TGfrCMLpFRxtScJeD");
  323. NSLog(@"FtZV5HPkh7L4nI");
  324. NSLog(@"CKEfq8k6xGBplZ3FoSuhm29Y4dy");
  325. NSLog(@"a9A0wZlQyz6TiX8ShYBPMf3moOtVHqK");
  326. NSLog(@"sVxQ82WKgwoyRlPJqtpF9fhr");
  327. NSLog(@"ng9KF8iLdTbu6xwGMPYjmEJyc4VHOkDB");
  328. NSLog(@"CKdBZm9PfXcOAksxz1W5gyY");
  329. NSLog(@"btiNcvkGI4RDEVdS3uMZhH9mJ");
  330. NSLog(@"SkTXGgJ9qpNA0ZLVthbYUCvFaQDux32nfelKRycw");
  331. NSLog(@"kdBZrCzetiof");
  332. NSLog(@"pakYuQwWxfGr");
  333. NSLog(@"1ac3PKLEpz9Mdf6eqlogsXxQ4");
  334. NSLog(@"sJnfEHg1wLB9jFYld2");
  335. }
  336. -(void)aQ3keh6mt:(UIApplication*) aQ3keh6mt aRPdxHqZolW:(UIInputView*) aRPdxHqZolW aP3GXmbZuK:(UIMotionEffect*) aP3GXmbZuK a94j5rA:(UIInputView*) a94j5rA aVNR7Z0t:(UIAlertView*) aVNR7Z0t aahn9fB:(UIEdgeInsets*) aahn9fB aUvCLX3YPH:(UICollectionView*) aUvCLX3YPH ay4iZVwd:(UIScreen*) ay4iZVwd aoiNk7:(UIDevice*) aoiNk7 aKB9X4j7D:(UICollectionView*) aKB9X4j7D aem1Rf:(UIVisualEffectView*) aem1Rf arlX3sJ9OL:(UIMotionEffect*) arlX3sJ9OL aPHS7Vn:(UIBarButtonItem*) aPHS7Vn aIGFro1tL:(UIMenuItem*) aIGFro1tL agJT0:(UIColor*) agJT0 aoUzFkx:(UIVisualEffectView*) aoUzFkx aXarg8:(UIEdgeInsets*) aXarg8 aQExd:(UIKeyCommand*) aQExd {
  337. NSLog(@"Pc56tTr4GoXeOZ0B97MqdsylHfzmijQaxIJLgE");
  338. NSLog(@"TI6yO8moGiEFMsUwbc5fPgX9je2qxCadV4S");
  339. NSLog(@"UuJL5KkixaWbzTB4s2A9YqN1OF");
  340. NSLog(@"7wFCUgsfpKGJ");
  341. NSLog(@"pziSmC2WEKUF");
  342. NSLog(@"Kmp6uZBSkG3c5x8eLJFn4l1H7EsC2zbDOjgNP");
  343. NSLog(@"rILc5h0EdbNAPaOMR6xKpWqBzJfujYivXkgs2");
  344. NSLog(@"JoxmK1MCN7GdnqsOZbHpPSIi9");
  345. NSLog(@"fzFu4OMv3cr9hWxolNTwR6");
  346. NSLog(@"4Gn5FpTmtofSyeJqrLMBzs69");
  347. NSLog(@"yLeRjC0PAtoEkWVFIxbZcg");
  348. NSLog(@"SlbkytM8OR");
  349. NSLog(@"NzR2XhgsGU6xVmybjDSLrYcin7a1El5Hk3AOQ");
  350. NSLog(@"t8uh1RHrBX7E");
  351. NSLog(@"AP1SDmR8zEegkp04");
  352. }
  353. @end