猎豆优选

LDCollectionTicketController.m 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //
  2. // LDCollectionTicketController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/24.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDCollectionTicketController.h"
  9. #import "LDCollectionTicketCell.h"
  10. #import "LDDateHeaderView.h"
  11. #import "LDCollectionModel.h"
  12. #import "LDSimilarGoodsController.h"
  13. #import "LDLoginViewController.h"
  14. @interface LDCollectionTicketController ()<UITableViewDelegate,UITableViewDataSource>
  15. @property (nonatomic, strong) UITableView *tableView;
  16. @property (nonatomic, strong) NSMutableArray *nearbyArr; // 即将过期的数组
  17. @property (nonatomic, strong) NSMutableArray *allDataArr;
  18. @end
  19. @implementation LDCollectionTicketController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. [self configTableView];
  23. }
  24. - (void)viewWillAppear:(BOOL)animated {
  25. [super viewWillAppear:animated];
  26. [self configNoDataView];
  27. [self loadData];
  28. }
  29. - (void)configTableView {
  30. self.view.backgroundColor = [UIColor whiteColor];
  31. [self.view addSubview:self.tableView];
  32. }
  33. - (void)configNoDataView {
  34. self.tableView.showNoDataView = YES;
  35. if (![AccountTool isLogin]) {
  36. self.tableView.defaultNoDataText = @"未登录,点击登录";
  37. kWeak(self);
  38. self.tableView.defaultNoDataViewDidClickBlock = ^(UIView *view) {
  39. kStrong(self);
  40. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  41. login.modalPresentationStyle = UIModalPresentationFullScreen;
  42. [self presentViewController:login animated:YES completion:nil];
  43. };
  44. }else {
  45. self.tableView.defaultNoDataText = @"暂无收藏数据,点击刷新";
  46. kWeak(self);
  47. self.tableView.defaultNoDataViewDidClickBlock = ^(UIView *view) {
  48. kStrong(self);
  49. [self loadData];
  50. };
  51. }
  52. }
  53. - (void)loadData {
  54. if (![AccountTool isLogin]) {
  55. return;
  56. }
  57. [LDHttp post:MyCollectCollectTicket params:nil success:^(id json) {
  58. [self.allDataArr removeAllObjects];
  59. NSArray *detailList = json[@"goods_detail"];
  60. for (NSArray *arr in detailList) {
  61. NSMutableArray *items = (NSMutableArray *)[NSArray yy_modelArrayWithClass:[LDCollectionModel class] json:arr];
  62. [self.allDataArr addObject:items];
  63. }
  64. self.nearbyArr = (NSMutableArray *)[NSArray yy_modelArrayWithClass:[LDCollectionModel class] json:json[@"nearly_outdate"]];
  65. if (self.nearbyArr.count != 0) {
  66. [self.allDataArr insertObject:self.nearbyArr atIndex:0];
  67. }
  68. [self.tableView reloadData];
  69. } failure:^(NSError *error) {
  70. }];
  71. }
  72. /**
  73. 移除收藏
  74. */
  75. - (void)deleteCollectionGoodAtIndexPath:(NSIndexPath *)indexPath {
  76. LDCollectionModel *model = self.allDataArr[indexPath.section][indexPath.row];
  77. NSDictionary *para = @{@"goods_id":model.goods_id};
  78. [LDHttp post:DelCollectionTickets params:para success:^(id json) {
  79. // 删除模型
  80. NSMutableArray *mArr = self.allDataArr[indexPath.section];
  81. [mArr removeObjectAtIndex:indexPath.row];
  82. [self.allDataArr replaceObjectAtIndex:indexPath.section withObject:mArr];
  83. [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  84. } failure:^(NSError *error) {
  85. }];
  86. }
  87. #pragma mark ------------------------
  88. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  89. {
  90. [self deleteCollectionGoodAtIndexPath:indexPath];
  91. }
  92. /**
  93. * 修改Delete按钮文字为“删除”
  94. */
  95. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  96. {
  97. return @"删除";
  98. }
  99. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  100. NSArray *arr = self.allDataArr[section];
  101. return arr.count;
  102. }
  103. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  104. return self.allDataArr.count;
  105. }
  106. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  107. return 40;
  108. }
  109. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  110. LDCollectionTicketCell *cell = [LDCollectionTicketCell cellWithTableView:tableView];
  111. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  112. LDCollectionModel *model = self.allDataArr[indexPath.section][indexPath.row];
  113. cell.model = model;
  114. cell.similarClick = ^{
  115. //找相似点击
  116. LDSimilarGoodsController *similar = [[LDSimilarGoodsController alloc] init];
  117. similar.goods_id = model.goods_id;
  118. [self.navigationController pushViewController:similar animated:YES];
  119. };
  120. return cell;
  121. }
  122. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  123. return 100;
  124. }
  125. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  126. LDDateHeaderView *header = [[LDDateHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
  127. LDCollectionModel *model = [self.allDataArr[section] firstObject];
  128. [header setDateWith:model.collect_time];
  129. return header;
  130. }
  131. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  132. LDCollectionModel *model = self.allDataArr[indexPath.section][indexPath.row];
  133. // if ([model.is_outdate boolValue]) {
  134. // //找相似
  135. // LDSimilarGoodsController *similar = [[LDSimilarGoodsController alloc] init];
  136. // similar.goods_id = model.goods_id;
  137. // [self.navigationController pushViewController:similar animated:YES];
  138. // }else {
  139. // LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  140. // detail.goods_id = model.goods_id;
  141. // [self.navigationController pushViewController:detail animated:YES];
  142. // }
  143. LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  144. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id
  145. is_coupon:model.is_coupon
  146. coupon_price:model.coupon_price
  147. price:model.price
  148. discount_price:model.discount_price
  149. commission_rate:model.commission_rate
  150. coupon_start_time:model.coupon_start_time
  151. coupon_end_time:model.coupon_end_time
  152. coupon_id:model.coupon_id];
  153. detail.requestModel = requestModel;
  154. [self.navigationController pushViewController:detail animated:YES];
  155. }
  156. #pragma mark ===================== layezer ==============
  157. - (UITableView *)tableView {
  158. if (!_tableView) {
  159. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-TabbarHeight) style:UITableViewStylePlain];
  160. _tableView.estimatedSectionHeaderHeight = 0;
  161. _tableView.estimatedSectionFooterHeight = 0;
  162. _tableView.sectionFooterHeight = 0;
  163. _tableView.sectionHeaderHeight = 0;
  164. _tableView.delegate = self;
  165. _tableView.dataSource = self;
  166. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  167. _tableView.backgroundColor = [UIColor yhGrayColor];
  168. _tableView.bounces = YES;
  169. _tableView.showsVerticalScrollIndicator = NO;
  170. // _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  171. }
  172. return _tableView;
  173. }
  174. - (NSMutableArray *)allDataArr {
  175. if (!_allDataArr) {
  176. _allDataArr = [NSMutableArray array];
  177. }
  178. return _allDataArr;
  179. }
  180. - (void)didReceiveMemoryWarning {
  181. [super didReceiveMemoryWarning];
  182. // Dispose of any resources that can be recreated.
  183. }
  184. /*
  185. #pragma mark - Navigation
  186. // In a storyboard-based application, you will often want to do a little preparation before navigation
  187. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  188. // Get the new view controller using [segue destinationViewController].
  189. // Pass the selected object to the new view controller.
  190. }
  191. */
  192. @end