CNLiveCommuntyResultListViewController.m 9.54 KB
//
//  CNLiveCommuntyResultListViewController.m
//  CNLiveCommunitModule
//
//  Created by open on 2022/2/16.
//

#import "CNLiveCommuntyResultListViewController.h"

@interface CNLiveCommuntyResultListViewController ()<DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
@property (nonatomic, strong) CNLiveCommuntyActivityResultDetailModel * detailModel;
@property (nonatomic, copy) NSString * signId;
@property (nonatomic, copy) NSString * orderId;
@property (nonatomic, copy) NSString * handworkId;
@end

@implementation CNLiveCommuntyResultListViewController

- (instancetype)initWithStyle:(UITableViewStyle)style SignId:(NSString *)signId OrderId:(NSString *)orderId handworkId:(nonnull NSString *)handworkId
{
    self = [super initWithStyle:style];
    if (self) {
        _handworkId = handworkId;
        _orderId = orderId;
        _signId = signId;
    }
    return self;
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSMutableArray * tempArray = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
    for (UIViewController * vc in self.navigationController.viewControllers) {
        if ([vc isKindOfClass:CNLiveCommuntyResultViewController.class]) {
            [tempArray removeObject:vc];
            break;
        }
        if ([vc isKindOfClass:NSClassFromString(@"CNLiveCommuntSignUpViewController")]) {
            [tempArray removeObject:vc];
            break;
        }
    }
    self.navigationController.viewControllers = tempArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"报名成功";
    

    __weak typeof(self) weakSelf = self;
    [CNLiveCommuntViewModel requestWithCommuntyActivityResultDetailMentOrderId:self.orderId SignId:self.signId handworkId:self.handworkId CompleterBlock:^(CNLiveCommuntyActivityResultDetailModel * _Nonnull detailModel) {
        weakSelf.detailModel = detailModel;
        [weakSelf setupWithBottemView];
        [weakSelf.tableView reloadData];
    }];
}
-(void)setupWithBottemView
{
    if ([self.detailModel.unitPrice isNotBlank] && [self.detailModel.unitPrice floatValue] > 0) {
        __weak typeof(self) weakSelf = self;
        UIView * bottemView = [[UIView alloc] init];
        bottemView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:bottemView];
        [bottemView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(weakSelf.view);
            make.height.mas_equalTo(50+kVerticalBottomSafeHeight);
        }];
        
        NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"合计: %.2f元",(self.detailModel.signupVoList.count * [self.detailModel.unitPrice floatValue])]];
        [str addAttribute:NSForegroundColorAttributeName value:UIColorHex(#222833) range:[str.string rangeOfString:@"合计: "]];
        [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:[str.string rangeOfString:@"合计: "]];
        [str addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:14] range:[str.string rangeOfString:@"合计: "]];
        [str addAttribute:NSForegroundColorAttributeName value:UIColorHex(#DF0D23) range:[str.string rangeOfString:@"¥"]];
        [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:9] range:[str.string rangeOfString:@"¥"]];
        
        UILabel * priceLabel = [[UILabel alloc] init];
        priceLabel.textColor = UIColorHex(#DF0D23);
        priceLabel.font = [UIFont boldSystemFontOfSize:16];
        priceLabel.attributedText = str;
        [bottemView addSubview:priceLabel];
        [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(bottemView.mas_top).offset(7);
            make.right.mas_equalTo(bottemView.mas_right).offset(-10);
        }];
    }
}
- (void)initTableView
{
    [super initTableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.emptyDataSetSource = self;
    self.tableView.emptyDataSetDelegate = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.backgroundColor = UIColorHex(#f9f9f9);
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.frame = CGRectMake(0, kNavigationBarHeight, kScreenWidth, kScreenHeight - kNavigationBarHeight);
    self.tableView.contentInset = UIEdgeInsetsMake(kNavigationBarHeight + 10, 0, 60 + kVerticalBottomSafeHeight, 0);
}
-(void)layoutTableView
{
    [super layoutTableView];

}
#pragma mark - DZNEmptyDataSetSource Methods
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    return [[NSAttributedString alloc] initWithString:@"暂无报名人员信息" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]}];
}
-(UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return [CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_content_empty"];
}
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
{
    return [UIColor whiteColor];
}

- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
{
    return YES;
}

- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView
{
    return YES;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return NO;
}
#pragma mark =

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.detailModel.dataArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.detailModel.dataArray[section] count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary * dic = self.detailModel.dataArray[indexPath.section][indexPath.row];
    return [CNLiveCommuntSignUpOrderViewCell setTableView:tableView Dict:dic];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 30;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return  50;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 50)];
    view.backgroundColor = [UIColor clearColor];
    
    UIView * radiusView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, kScreenWidth - 20, 40)];
    radiusView.backgroundColor = [UIColor whiteColor];
    radiusView.layer.shadowColor = [UIColor blackColor].CGColor;
    radiusView.layer.shadowOffset = CGSizeMake(0, 0);
    radiusView.layer.shadowOpacity = 0.3;
    radiusView.layer.shadowRadius = 8;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 20, 40) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.path = maskPath.CGPath;
    radiusView.layer.mask = maskLayer;
    [view insertSubview:radiusView belowSubview:view];
    
    UILabel * nameLabel = [[UILabel alloc] init];
    nameLabel.textColor = UIColorHex(#333333);
    nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    nameLabel.numberOfLines = 1;
    nameLabel.font = [UIFont systemFontOfSize:15];
    nameLabel.font = [UIFont boldSystemFontOfSize:15];
    nameLabel.text = (self.detailModel.dataArray.count - 1 == section) ? @"活动信息" : [NSString stringWithFormat:@"参与人%ld",section+1];
    [view addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(view);
        make.left.mas_equalTo(view.mas_left).offset(20);
    }];
    
    if (self.detailModel.dataArray.count-1 != section && [self.detailModel.unitPrice isNotBlank] && [self.detailModel.unitPrice integerValue] > 0) {
        UILabel * priceLabel = [[UILabel alloc] init];
        priceLabel.textColor = UIColorHex(#DF0D23);
        priceLabel.font = [UIFont boldSystemFontOfSize:16];
        priceLabel.text = [NSString stringWithFormat:@"%@元",self.detailModel.unitPrice];
        [view addSubview:priceLabel];
        [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(view);
            make.right.mas_equalTo(view.mas_right).offset(-20);
        }];
    }
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
    view.backgroundColor = [UIColor clearColor];
    
    UIView * radiusView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, kScreenWidth - 20, 10)];
    radiusView.backgroundColor = [UIColor whiteColor];
    radiusView.layer.shadowColor = [UIColor blackColor].CGColor;
    radiusView.layer.shadowOffset = CGSizeMake(0, 0);
    radiusView.layer.shadowOpacity = 0.3;
    radiusView.layer.shadowRadius = 10;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 20, 10) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.path = maskPath.CGPath;
    radiusView.layer.mask = maskLayer;
    [view insertSubview:radiusView belowSubview:view];
    
    return view;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

@end