RedEnvelopeController.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // RedEnvelopeController.m
  3. // model
  4. //
  5. // Created by JuYi on 2018/7/17.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. // 红包界面
  8. #import "RedEnvelopeController.h"
  9. #import "MyOrderCell.h"
  10. #import "ModelTitleView.h" // 选择按钮
  11. @interface RedEnvelopeController ()<UITableViewDelegate, UITableViewDataSource>
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, strong) NSMutableArray *oneArr;
  14. @property (nonatomic, strong) NSMutableArray *twoArr;
  15. @property (nonatomic, assign) NSInteger selectIndex; //1是未领取,2是已领取
  16. @end
  17. @implementation RedEnvelopeController
  18. - (NSMutableArray *)oneArr {
  19. if (!_oneArr) {
  20. _oneArr = [NSMutableArray arrayWithCapacity:0];
  21. }
  22. return _oneArr;
  23. }
  24. - (NSMutableArray *)twoArr {
  25. if (!_twoArr) {
  26. _twoArr = [NSMutableArray arrayWithCapacity:0];
  27. }
  28. return _twoArr;
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. // Do any additional setup after loading the view.
  33. self.selectIndex = 1;
  34. //设置导航条
  35. [self creatNavBar];
  36. //设置子试图
  37. [self creatSubViews];
  38. [self getDataFromNetworking];
  39. }
  40. - (void)didReceiveMemoryWarning {
  41. [super didReceiveMemoryWarning];
  42. // Dispose of any resources that can be recreated.
  43. }
  44. - (void)creatNavBar {
  45. self.title = @"我的红包";
  46. //
  47. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  48. btn.frame = CGRectMake(0, 0, 40, 40);
  49. [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
  50. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); // backBtn2
  51. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  52. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  53. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  54. // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
  55. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  56. }
  57. - (void)backClick {
  58. [self.navigationController popViewControllerAnimated:YES];
  59. }
  60. #pragma mark -- 网络请求
  61. - (void)getDataFromNetworking {
  62. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  63. // [ModelUser user].pk
  64. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"1",@"MemberPk", nil];
  65. [YanCNetWorkManager requestPostWithURLStr:Url_getreceiveredlist(PublicUrl) parameters:dic finish:^(id dataDic) {
  66. [MBProgressHUD hideHUDForView:self.view animated:YES];
  67. NSString *issuccess = dataDic[@"msg"];
  68. if ([issuccess isEqualToString:@"success"]) {
  69. NSArray *dataArr = dataDic[@"data"];
  70. if (dataArr.count > 0) {
  71. for (NSDictionary *dic in dataArr) {
  72. if ([dic[@"rstate"] isEqualToString:@"1"]) {
  73. [self.oneArr addObject:dic];
  74. } else {
  75. [self.twoArr addObject:dic];
  76. }
  77. }
  78. [self.tableView reloadData];
  79. }
  80. } else {
  81. [MBProgressHUD showInfo:@"请求失败!"];
  82. }
  83. } enError:^(NSError *error) {
  84. [MBProgressHUD hideHUDForView:self.view animated:YES];
  85. }];
  86. }
  87. /*
  88. {
  89. coin = "99.99";
  90. memberpk = 1;
  91. modelpk = 1;
  92. pk = 3;
  93. rdate = "2018-07-09 14:53:36";
  94. rstate = 2;
  95. },
  96. */
  97. - (void)creatSubViews {
  98. ModelTitleView *titlesView = [[ModelTitleView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
  99. titlesView.titleArr = @[@"未领取", @"已领取"];
  100. __weak typeof (self) weakself = self;
  101. titlesView.ModelTitleViewBlock = ^(NSInteger tag) {
  102. NSLog(@"tag %ld", tag);
  103. weakself.selectIndex = tag + 1;
  104. [weakself.tableView reloadData];
  105. };
  106. [self.view addSubview:titlesView];
  107. //
  108. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titlesView.frame), ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
  109. self.tableView.backgroundColor = [UIColor whiteColor];
  110. self.tableView.delegate = self;
  111. self.tableView.dataSource = self;
  112. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  113. [self.view addSubview:self.tableView];
  114. }
  115. #pragma mark -- UITableViewDelegate, UITableViewDataSource
  116. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  117. if (self.selectIndex == 1) {
  118. return _oneArr.count;
  119. } else {
  120. return _twoArr.count;
  121. }
  122. }
  123. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  124. return 1;
  125. }
  126. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  127. static NSString *cellid = @"cellid";
  128. MyOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
  129. if (!cell) {
  130. cell = [[MyOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
  131. }
  132. if (self.selectIndex == 1) {
  133. [cell setMyOrderCellValueWithDic:_oneArr[indexPath.section] titleStr:@"redEnvelope"];
  134. } else {
  135. [cell setMyOrderCellValueWithDic:_twoArr[indexPath.section] titleStr:@"redEnvelope"];
  136. }
  137. return cell;
  138. }
  139. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  140. return 80;
  141. }
  142. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  143. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.01)];
  144. footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  145. return footerView;
  146. }
  147. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  148. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
  149. headerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  150. return headerView;
  151. }
  152. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  153. return 0.01;
  154. }
  155. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  156. if (section == 0) {
  157. return 0.01;
  158. } else {
  159. return 10;
  160. }
  161. }
  162. @end