JXRedPacketListVC.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //
  2. // JXRedPacketListVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/6/5.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXRedPacketListVC.h"
  9. #import "JXRecordTBCell.h"
  10. @interface JXRedPacketListVC ()
  11. @property (nonatomic, strong) UIButton *getBtn;
  12. @property (nonatomic, strong) UIButton *sendBtn;
  13. @property (nonatomic, strong) NSMutableArray *array;
  14. @property (nonatomic, assign) int selIndex;
  15. @end
  16. @implementation JXRedPacketListVC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view.
  20. _array = [NSMutableArray array];
  21. self.isShowFooterPull = YES;
  22. self.isShowHeaderPull = YES;
  23. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 150)];
  24. headView.backgroundColor = HEXCOLOR(0xFD7070);
  25. [self.view addSubview:headView];
  26. self.tableView.frame = CGRectMake(0, CGRectGetMaxY(headView.frame), JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT - CGRectGetMaxY(headView.frame));
  27. UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 46, 46, 46)];
  28. [closeBtn setBackgroundImage:[[UIImage imageNamed:@"title_back_black_big"] imageWithTintColor:[UIColor whiteColor]] forState:UIControlStateNormal];
  29. [closeBtn addTarget:self action:@selector(closeBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  30. [headView addSubview:closeBtn];
  31. UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(60, JX_SCREEN_TOP -15- 17, JX_SCREEN_WIDTH-60*2, 20)];
  32. title.textAlignment = NSTextAlignmentCenter;
  33. title.text = Localized(@"JX_RedPacketRecord");
  34. title.textColor = [UIColor whiteColor];
  35. title.font = [UIFont systemFontOfSize:18.0];
  36. [headView addSubview:title];
  37. _getBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, headView.frame.size.height - 37, headView.frame.size.width / 2, 30)];
  38. [_getBtn setTitle:Localized(@"PACKETS_RECEIVED") forState:UIControlStateNormal];
  39. [_getBtn setTitleColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5] forState:UIControlStateNormal];
  40. [_getBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  41. _getBtn.selected = YES;
  42. _getBtn.tag = 1000;
  43. _getBtn.titleLabel.font = [UIFont systemFontOfSize:16.0];
  44. [_getBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
  45. [headView addSubview:_getBtn];
  46. _sendBtn = [[UIButton alloc] initWithFrame:CGRectMake(headView.frame.size.width / 2, headView.frame.size.height - 37, headView.frame.size.width / 2, 30)];
  47. [_sendBtn setTitle:Localized(@"ENVELOPES_ISSUED") forState:UIControlStateNormal];
  48. [_sendBtn setTitleColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5] forState:UIControlStateNormal];
  49. [_sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  50. _sendBtn.selected = NO;
  51. _sendBtn.tag = 1001;
  52. _sendBtn.titleLabel.font = [UIFont systemFontOfSize:16.0];
  53. [_sendBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
  54. [headView addSubview:_sendBtn];
  55. _selIndex = 0;
  56. _page = 0;
  57. [self getServerData];
  58. }
  59. - (void)closeBtnAction:(UIButton *)btn {
  60. [self actionQuit];
  61. }
  62. - (void)btnAction:(UIButton *)btn {
  63. if (_selIndex == 0 && btn.tag == 1000) {
  64. return;
  65. }
  66. if (_selIndex == 1 && btn.tag == 1001) {
  67. return;
  68. }
  69. _getBtn.selected = !_getBtn.selected;
  70. _sendBtn.selected = !_sendBtn.selected;
  71. _page = 0;
  72. if (btn.tag == 1000) {
  73. _selIndex = 0;
  74. }else {
  75. _selIndex = 1;
  76. }
  77. [self getServerData];
  78. }
  79. - (void)scrollToPageUp {
  80. _page = 0;
  81. [self getServerData];
  82. }
  83. - (void)scrollToPageDown {
  84. _page ++;
  85. [self getServerData];
  86. }
  87. - (void) getServerData {
  88. if (_selIndex == 0) {
  89. [g_server redPacketGetRedReceiveListIndex:_page toView:self];
  90. }else {
  91. [g_server redPacketGetSendRedPacketListIndex:_page toView:self];
  92. }
  93. }
  94. #pragma mark --------------------TableView-------------------------
  95. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  96. return 1;
  97. }
  98. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  99. return [_array count];
  100. }
  101. -(JXRecordTBCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  102. //领取过红包的用户,使用JXRPacketListCell展示
  103. NSString * cellName = @"JXRecordTBCell";
  104. JXRecordTBCell * cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  105. if(cell==nil){
  106. cell = [[NSBundle mainBundle] loadNibNamed:@"JXRecordTBCell" owner:self options:nil][0];
  107. }
  108. NSDictionary *dict = _array[indexPath.row];
  109. //用户名
  110. cell.titleLabel.text = dict[@"sendName"];
  111. if(_selIndex == 1) {
  112. NSString *str;
  113. int type = [dict[@"type"] intValue];
  114. if (type == 1) {
  115. str = Localized(@"JX_UsualGift");
  116. }
  117. if (type == 2) {
  118. str = Localized(@"JX_LuckGift");
  119. }
  120. if (type == 3) {
  121. str = Localized(@"JX_MesGift");
  122. }
  123. cell.titleLabel.text = str;
  124. }
  125. //日期
  126. NSTimeInterval getTime = [dict[@"time"] longLongValue];
  127. if (_selIndex == 1) {
  128. getTime = [dict[@"sendTime"] longLongValue];
  129. }
  130. NSDate * date = [NSDate dateWithTimeIntervalSince1970:getTime];
  131. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  132. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
  133. [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8*60*60]];//中国专用
  134. cell.timeLabel.text = [dateFormatter stringFromDate:date];
  135. //金额
  136. cell.moneyLabel.text = [NSString stringWithFormat:@"%.2f %@",[dict[@"money"] doubleValue],Localized(@"JX_ChinaMoney")];
  137. //是否退款
  138. cell.refundLabel.text = @"";
  139. return cell;
  140. }
  141. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  142. return 68;
  143. }
  144. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  145. [_wait stop];
  146. [self stopLoading];
  147. if (_page == 0) {
  148. [_array removeAllObjects];
  149. [_array addObjectsFromArray:array1];
  150. }else {
  151. [_array addObjectsFromArray:array1];
  152. }
  153. [self.tableView reloadData];
  154. }
  155. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  156. [_wait stop];
  157. return show_error;
  158. }
  159. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  160. [_wait stop];
  161. return show_error;
  162. }
  163. -(void) didServerConnectStart:(JXConnection*)aDownload{
  164. [_wait start];
  165. }
  166. - (void)didReceiveMemoryWarning {
  167. [super didReceiveMemoryWarning];
  168. // Dispose of any resources that can be recreated.
  169. }
  170. /*
  171. #pragma mark - Navigation
  172. // In a storyboard-based application, you will often want to do a little preparation before navigation
  173. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  174. // Get the new view controller using [segue destinationViewController].
  175. // Pass the selected object to the new view controller.
  176. }
  177. */
  178. @end