新UI马甲包

HCMyTicketViewController.m 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //
  2. // HCMyTicketViewController.m
  3. // hc
  4. //
  5. // Created by hc on 2018/1/25.
  6. // Copyright © 2018年 hc. All rights reserved.
  7. //
  8. #import "HCMyTicketViewController.h"
  9. #import "HCMyTicketModel.h"
  10. #import "HCMyTicketCell.h"
  11. #import "HCGoodDetailViewController.h"
  12. #import "HCSimilarGoodsController.h"
  13. @interface HCMyTicketViewController ()<UITableViewDelegate,UITableViewDataSource>
  14. @property (nonatomic, strong) UITableView *tableView;
  15. @property (nonatomic, strong) NSMutableArray *dataArr;
  16. @end
  17. @implementation HCMyTicketViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self configNavigationBar];
  21. [self loadData];
  22. }
  23. - (void)configNavigationBar {
  24. self.view.backgroundColor = [UIColor whiteColor];
  25. [self.navigationBar setNavTitle:@"已领优惠券"];
  26. self.navigationBar.showNavigationBarBottomLine = YES;
  27. [self.view addSubview:self.tableView];
  28. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  29. [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  30. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  31. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  32. self.tableView.showNoDataView = YES;
  33. self.tableView.defaultNoDataText = @"暂无数据,点击刷新";
  34. kWeak(self);
  35. self.tableView.defaultNoDataViewDidClickBlock = ^(UIView *view) {
  36. kStrong(self);
  37. [self loadData];
  38. };
  39. }
  40. - (void)backAction {
  41. [self.navigationController popViewControllerAnimated:YES];
  42. }
  43. - (void)loadData {
  44. if (![AccountTool isLogin]) {
  45. return;
  46. }
  47. [HCHttp post:MyReceiveTickets params:nil success:^(id json) {
  48. self.dataArr = (NSMutableArray *)[NSArray yy_modelArrayWithClass:[HCMyTicketModel class] json:json];
  49. [self.tableView reloadData];
  50. } failure:^(NSError *error) {
  51. }];
  52. }
  53. /**
  54. 移除收藏
  55. */
  56. - (void)deleteCollectionGoodAtIndexPath:(NSIndexPath *)indexPath {
  57. HCMyTicketModel *model = self.dataArr[indexPath.row];
  58. NSDictionary *para = @{@"goods_id":model.goods_id};
  59. [HCHttp post:MyDelReceiveTickets params:para success:^(id json) {
  60. // 删除模型
  61. [self.dataArr removeObjectAtIndex:indexPath.row];
  62. [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  63. } failure:^(NSError *error) {
  64. }];
  65. }
  66. #pragma mark ------------------------
  67. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  68. {
  69. [self deleteCollectionGoodAtIndexPath:indexPath];
  70. }
  71. /**
  72. * 修改Delete按钮文字为“删除”
  73. */
  74. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  75. {
  76. return @"删除";
  77. }
  78. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  79. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  80. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 10)];
  81. }
  82. }
  83. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  84. return self.dataArr.count;
  85. }
  86. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  87. return 100;
  88. }
  89. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  90. return 0.1;
  91. }
  92. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  93. HCMyTicketModel *model = self.dataArr[indexPath.row];
  94. HCMyTicketCell *cell = [HCMyTicketCell cellWithTableView:tableView];
  95. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  96. cell.model = model;
  97. cell.saimarClick = ^{
  98. //找相似
  99. HCSimilarGoodsController *similar = [[HCSimilarGoodsController alloc] init];
  100. similar.goods_id = model.goods_id;
  101. [self.navigationController pushViewController:similar animated:YES];
  102. };
  103. return cell;
  104. }
  105. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  106. HCMyTicketModel *model = self.dataArr[indexPath.row];
  107. HCGoodDetailViewController *detail = [[HCGoodDetailViewController alloc] init];
  108. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id
  109. is_coupon:model.is_coupon
  110. coupon_price:model.coupon_price
  111. price:model.price
  112. discount_price:model.discount_price
  113. commission_rate:model.commission_rate
  114. coupon_start_time:model.coupon_start_time
  115. coupon_end_time:model.coupon_end_time];
  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