猎豆优选

LDMyTicketViewController.m 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // LDMyTicketViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/25.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDMyTicketViewController.h"
  9. #import "LDMyTicketModel.h"
  10. #import "LDMyTicketCell.h"
  11. #import "LDSimilarGoodsController.h"
  12. @interface LDMyTicketViewController ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, strong) UITableView *tableView;
  14. @property (nonatomic, strong) NSMutableArray *dataArr;
  15. @end
  16. @implementation LDMyTicketViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self configNavigationBar];
  20. [self loadData];
  21. }
  22. - (void)configNavigationBar {
  23. self.view.backgroundColor = [UIColor whiteColor];
  24. [self.navigationBar setNavTitle:@"已领优惠券"];
  25. self.navigationBar.showNavigationBarBottomLine = YES;
  26. [self.view addSubview:self.tableView];
  27. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  28. [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  29. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  30. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  31. self.tableView.showNoDataView = YES;
  32. self.tableView.defaultNoDataText = @"暂无数据,点击刷新";
  33. kWeak(self);
  34. self.tableView.defaultNoDataViewDidClickBlock = ^(UIView *view) {
  35. kStrong(self);
  36. [self loadData];
  37. };
  38. }
  39. - (void)backAction {
  40. [self.navigationController popViewControllerAnimated:YES];
  41. }
  42. - (void)loadData {
  43. if (![AccountTool isLogin]) {
  44. return;
  45. }
  46. [LDHttp post:MyReceiveTickets params:nil success:^(id json) {
  47. self.dataArr = (NSMutableArray *)[NSArray yy_modelArrayWithClass:[LDMyTicketModel class] json:json];
  48. [self.tableView reloadData];
  49. } failure:^(NSError *error) {
  50. }];
  51. }
  52. /**
  53. 移除收藏
  54. */
  55. - (void)deleteCollectionGoodAtIndexPath:(NSIndexPath *)indexPath {
  56. LDMyTicketModel *model = self.dataArr[indexPath.row];
  57. NSDictionary *para = @{@"goods_id":model.goods_id};
  58. [LDHttp post:MyDelReceiveTickets params:para success:^(id json) {
  59. // 删除模型
  60. [self.dataArr removeObjectAtIndex:indexPath.row];
  61. [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  62. } failure:^(NSError *error) {
  63. }];
  64. }
  65. #pragma mark ------------------------
  66. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  67. {
  68. [self deleteCollectionGoodAtIndexPath:indexPath];
  69. }
  70. /**
  71. * 修改Delete按钮文字为“删除”
  72. */
  73. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  74. {
  75. return @"删除";
  76. }
  77. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  78. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  79. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 10)];
  80. }
  81. }
  82. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  83. return self.dataArr.count;
  84. }
  85. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  86. return 100;
  87. }
  88. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  89. return 0.1;
  90. }
  91. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  92. LDMyTicketModel *model = self.dataArr[indexPath.row];
  93. LDMyTicketCell *cell = [LDMyTicketCell cellWithTableView:tableView];
  94. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  95. cell.model = model;
  96. cell.saimarClick = ^{
  97. //找相似
  98. LDSimilarGoodsController *similar = [[LDSimilarGoodsController alloc] init];
  99. similar.goods_id = model.goods_id;
  100. [self.navigationController pushViewController:similar animated:YES];
  101. };
  102. return cell;
  103. }
  104. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  105. LDMyTicketModel *model = self.dataArr[indexPath.row];
  106. LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  107. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id
  108. is_coupon:model.is_coupon
  109. coupon_price:model.coupon_price
  110. price:model.price
  111. discount_price:model.discount_price
  112. commission_rate:model.commission_rate
  113. coupon_start_time:model.coupon_start_time
  114. coupon_end_time:model.coupon_end_time
  115. coupon_id:model.coupon_id];
  116. detail.requestModel = requestModel;
  117. [self.navigationController pushViewController:detail animated:YES];
  118. }
  119. - (UITableView *)tableView {
  120. if (!_tableView) {
  121. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStylePlain];
  122. _tableView.estimatedSectionHeaderHeight = 0;
  123. _tableView.estimatedSectionFooterHeight = 0;
  124. _tableView.sectionFooterHeight = 0;
  125. _tableView.sectionHeaderHeight = 0;
  126. _tableView.delegate = self;
  127. _tableView.dataSource = self;
  128. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  129. _tableView.backgroundColor = [UIColor yhGrayColor];
  130. _tableView.bounces = YES;
  131. _tableView.showsVerticalScrollIndicator = NO;
  132. [_tableView setSeparatorColor:[UIColor YHColorWithHex:0xdddddd]];
  133. }
  134. return _tableView;
  135. }
  136. - (void)didReceiveMemoryWarning {
  137. [super didReceiveMemoryWarning];
  138. // Dispose of any resources that can be recreated.
  139. }
  140. /*
  141. #pragma mark - Navigation
  142. // In a storyboard-based application, you will often want to do a little preparation before navigation
  143. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  144. // Get the new view controller using [segue destinationViewController].
  145. // Pass the selected object to the new view controller.
  146. }
  147. */
  148. @end