| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- //
- // RedEnvelopeController.m
- // model
- //
- // Created by JuYi on 2018/7/17.
- // Copyright © 2018年 Mine. All rights reserved.
- // 红包界面
- #import "RedEnvelopeController.h"
- #import "MyOrderCell.h"
- #import "ModelTitleView.h" // 选择按钮
- @interface RedEnvelopeController ()<UITableViewDelegate, UITableViewDataSource>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *oneArr;
- @property (nonatomic, strong) NSMutableArray *twoArr;
- @property (nonatomic, assign) NSInteger selectIndex; //1是未领取,2是已领取
- @end
- @implementation RedEnvelopeController
- - (NSMutableArray *)oneArr {
- if (!_oneArr) {
- _oneArr = [NSMutableArray arrayWithCapacity:0];
- }
- return _oneArr;
- }
- - (NSMutableArray *)twoArr {
- if (!_twoArr) {
- _twoArr = [NSMutableArray arrayWithCapacity:0];
- }
- return _twoArr;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.selectIndex = 1;
- //设置导航条
- [self creatNavBar];
- //设置子试图
- [self creatSubViews];
-
- [self getDataFromNetworking];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)creatNavBar {
- self.title = @"我的红包";
- //
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(0, 0, 40, 40);
- [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
- btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); // backBtn2
- [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
- UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
- self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
-
- }
- - (void)backClick {
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark -- 网络请求
- - (void)getDataFromNetworking {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- // [ModelUser user].pk
- NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"1",@"MemberPk", nil];
- [YanCNetWorkManager requestPostWithURLStr:Url_getreceiveredlist(PublicUrl) parameters:dic finish:^(id dataDic) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
-
- NSString *issuccess = dataDic[@"msg"];
-
- if ([issuccess isEqualToString:@"success"]) {
- NSArray *dataArr = dataDic[@"data"];
- if (dataArr.count > 0) {
- for (NSDictionary *dic in dataArr) {
- if ([dic[@"rstate"] isEqualToString:@"1"]) {
- [self.oneArr addObject:dic];
- } else {
- [self.twoArr addObject:dic];
- }
- }
- [self.tableView reloadData];
- }
- } else {
- [MBProgressHUD showInfo:@"请求失败!"];
- }
- } enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- /*
- {
- coin = "99.99";
- memberpk = 1;
- modelpk = 1;
- pk = 3;
- rdate = "2018-07-09 14:53:36";
- rstate = 2;
- },
- */
- - (void)creatSubViews {
- ModelTitleView *titlesView = [[ModelTitleView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
- titlesView.titleArr = @[@"未领取", @"已领取"];
- __weak typeof (self) weakself = self;
- titlesView.ModelTitleViewBlock = ^(NSInteger tag) {
- NSLog(@"tag %ld", tag);
- weakself.selectIndex = tag + 1;
-
- [weakself.tableView reloadData];
-
- };
- [self.view addSubview:titlesView];
- //
- self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titlesView.frame), ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
- self.tableView.backgroundColor = [UIColor whiteColor];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.view addSubview:self.tableView];
- }
- #pragma mark -- UITableViewDelegate, UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- if (self.selectIndex == 1) {
- return _oneArr.count;
- } else {
- return _twoArr.count;
- }
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- static NSString *cellid = @"cellid";
- MyOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
- if (!cell) {
- cell = [[MyOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
- }
- if (self.selectIndex == 1) {
- [cell setMyOrderCellValueWithDic:_oneArr[indexPath.section] titleStr:@"redEnvelope"];
- } else {
- [cell setMyOrderCellValueWithDic:_twoArr[indexPath.section] titleStr:@"redEnvelope"];
- }
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 80;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.01)];
- footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- return footerView;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
- headerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
- return headerView;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.01;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return 0.01;
- } else {
- return 10;
- }
- }
- @end
|