//
//  MyPrizeListVC.m
//  Open
//
//  Created by 雷俊博 on 2019/9/3.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "MyPrizeListVC.h"
#import "orderHeader.h"


#import "PrizeDetailInfoViewController.h"
#import "ListPrizeTableViewCell.h"
#import "NoDataView.h"

#import "Constants.h"


#import "CTAPIBaseManager.h"

#import "QRRedPackageGiftView.h"
#import <WXApi.h>



static NSString * const identifier = @"identifier";
@interface MyPrizeListVC ()<UITableViewDataSource, UITableViewDelegate>
{
    orderHeader *_headView;
    BOOL _isup;
}
@property(nonatomic, strong, nonnull) UITableView *tableView;

@property (nonatomic, strong)orderHeader *headerView;

@property(nonatomic, strong, nullable) NSArray  *dataArray;

@property (nonatomic, strong, nullable)NSMutableArray *dataArry2;



@property (nonatomic, strong)CTAPIBaseManager *manager;


@end

@implementation MyPrizeListVC

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
    // Do any additional setup after loading the view.
    
    [self.view addSubview:self.tableView];
    [self navConfig];
    
    WeakSelf
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //进行数据刷新操作
        [weakSelf loadData];
    }];
    
    // 马上进入刷新状态
    [self.tableView.mj_header beginRefreshing];
   
}



- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
//    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHex:0xf8502c];
//
//    [self.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
//
//        [self.navigationController.navigationBar setBackgroundImage:[self convertViewToImage:[self getNavBackView]] forBarMetrics:UIBarMetricsDefault];
//
//    } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
//        [self.navigationController.navigationBar setBackgroundImage:[self convertViewToImage:[self getNavBackView]] forBarMetrics:UIBarMetricsDefault];
//    }];
    
    [self.navigationController.navigationBar navBarBackGroundColor:[UIColor colorWithHex:0xf8502c] image:nil isOpaque:YES];//颜色
      
    [self.navigationController.navigationBar navBarBottomLineHidden:YES];
    
    [self.navigationController setNavigationBarHidden:YES];
    
    [JANALYTICSService startLogPageView:@"我的奖品"];
    [MobClick beginLogPageView:@"我的奖品"];
    [GTCountSDK trackCountEvent:@"life_MyPrizes" withArgs:@{}];//个推统计
    
    //self.navigationController.navigationBar.translucent = NO;
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    
    [JANALYTICSService stopLogPageView:@"我的奖品"];
    [MobClick endLogPageView:@"我的奖品"];
    
    self.navigationController.navigationBar.translucent = YES;
}

- (void)navConfig
{
    UIView*navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    navView.backgroundColor = [UIColor colorWithHex:0xf8502c];
    //返回按钮
    UIButton* backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    backBtn.frame = CGRectMake(10, cl_kStatusBarHeight, 60, 44);
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    [backBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel* lb_title = [UILabel new];
    lb_title.text = self.title;
    lb_title.font = [UIFont boldSystemFontOfSize:17];
    lb_title.textAlignment = NSTextAlignmentCenter;
    lb_title.textColor = [UIColor whiteColor];
    [navView addSubview:backBtn];
    [navView addSubview:lb_title];
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(cl_kStatusBarHeight);
        make.centerX.equalTo(navView);
        make.height.offset(44);
    }];
    [self.view addSubview:navView];
}


- (void)dealloc
{
    NSLog(@"MyPrizeListVc已释放");
}

-(void)createUI{
    self.view.backgroundColor=[UIColor whiteColor];
   
    UIView *back = nil;
   
    back = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 42)];
    
    
    back.backgroundColor = [UIColor colorWithHex:0xd9d9d9 alpha:0.5];
    
  
    [self.view addSubview:back];
    [self.view addSubview:self.headerView];
    
    
  
    
}




- (void)loadData
{
    
    NSString *url = [NSString stringWithFormat:@"%@score/getwinRecord",CoinsBaseUrl];
    
    NSDictionary *dic = @{
                          @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                          @"telephone": [EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],
                          @"reqTimesTamp":[NSNumber numberWithInteger:[self getNowTimeTimestamp3]],
                          };
    
    
    NSArray *result = [dic.allKeys sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        
        NSLog(@"%@~%@",obj1,obj2); //3~4 2~1 3~1 3~2
        
        
        
        
        return [obj1 compare:obj2]; //升序
        
    }];
    NSString *sign = nil;
    for (int i = 0; i < result.count; i++) {
        NSString *key = result[i];
        if (i==0) {
            sign = [NSString stringWithFormat:@"%@=%@",key,dic[key]];
        }else{
            
            sign = [NSString stringWithFormat:@"%@&%@=%@",sign,key,dic[key]];
        }
    }
    
    sign = [NSString stringWithFormat:@"%@&kk#d12",sign];
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithDictionary:dic];
    
    NSString *signString = [[MyMD5 md5:sign] lowercaseString];
    [params setObject:signString forKey:@"sign"];
    
    WeakSelf
    
    NSLog(@"奖品列表url:%@",url);
    NSLog(@"奖品列表params:%@",params);
    

    [self.manager POSTWithUrl:url params:params success:^(id  _Nonnull responseObject) {

        NSLog(@"奖品列表responseObject:%@",responseObject);
        
        [weakSelf.tableView.mj_header endRefreshing];
        if (responseObject) {
            NSNumber *code = responseObject[@"code"];
            NSString *des = responseObject[@"des"];
            if ([code isKindOfClass:[NSNumber class]]) {
                if (code.integerValue == 0) {
                    
                    [weakSelf.dataArry2 removeAllObjects];
                    NSArray *results = responseObject[@"result"];
                    if ([results isKindOfClass:[NSArray class]]) {
                        
                    }else{
                        results = nil;
                    }
                    weakSelf.dataArray = results;
                    
                    
                    dispatch_async(dispatch_get_global_queue(0, 0), ^{
                        
                      
                        for (int i = 0; i < results.count; i++) {
                            NSDictionary *dic = results[i];
                            if ([dic[@"lotterStatus"] isEqualToString:@"未领取"]) {
                                [weakSelf.dataArry2 addObject:dic];
                            }
                        }
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [weakSelf.tableView reloadData];
                            UIButton *btn = [weakSelf.headerView viewWithTag:79];
                            [btn setTitle:[NSString stringWithFormat:@"未领取(%ld)",weakSelf.dataArry2.count] forState:UIControlStateNormal];
                        });
                        
                    });
                    
                }else{
                    [SVProgressHUD showInfoWithStatus:des];
                }
            }else{
                [SVProgressHUD showInfoWithStatus:@"服务器错误"];
            }
        }
        
    } fail:^(NSError * _Nonnull error) {
        NSLog(@"奖品列表error:%@",error);
        [weakSelf.tableView.mj_header endRefreshing];
        if (error.code == NSURLErrorTimedOut) {
            [SVProgressHUD showInfoWithStatus:@"请求超时"];
        }else if (error.code == NSURLErrorCancelled){
           // [SVProgressHUD showInfoWithStatus:@"取消请求"];
        }else if (error.code == NSURLErrorNotConnectedToInternet){
             [SVProgressHUD showInfoWithStatus:@"无网络"];
           
        }

    }];

}


#pragma mark - tableview datasourse delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (self.index == 0) {
        if (self.dataArray.count != 0) {
            self.tableView.backgroundView = nil;
        }else{
            NoDataView *view = [[NoDataView alloc]initWithFrame:self.tableView.bounds];
            self.tableView.backgroundView = view;
        }
        
        return self.dataArray.count;
    }else{
        if (self.dataArry2.count != 0) {
            self.tableView.backgroundView = nil;
        }else{
            NoDataView *view = [[NoDataView alloc]initWithFrame:self.tableView.bounds];
            self.tableView.backgroundView = view;
        }
        
        return self.dataArry2.count;
    }
   
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ListPrizeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (self.index == 0) {
        [cell refreshUIWithData:self.dataArray[indexPath.row]];
    }else{
        [cell refreshUIWithData:self.dataArry2[indexPath.row]];
    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100*WIDTHRADIU;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PrizeDetailInfoViewController *detailVC = [[PrizeDetailInfoViewController alloc]init];
    
    NSDictionary *dic = nil;
    if (self.index == 0) {
        dic = self.dataArray[indexPath.row];
    }else{
        dic = self.dataArry2[indexPath.row];
    }
    
    if ([dic[@"giftId"] isEqualToString:@"1"]) {
        detailVC.type = CTListPrizeTypeCoins200;
    }else if ([dic[@"giftId"] isEqualToString:@"12"]) {
        detailVC.type = CTListPrizeTypeCoins388;
    }else if ([dic[@"giftId"] isEqualToString:@"13"]){
        detailVC.type = CTListPrizeTypeCoins588;
    }
    else if ([dic[@"giftId"] isEqualToString:@"9"]){
        detailVC.type = CTListPrizeTypePackage10;
    }else if ([dic[@"giftId"] isEqualToString:@"11"]){
        detailVC.type = CTListPrizeTypePackage2;
    }else if ([dic[@"giftId"] isEqualToString:@"10"]){
        detailVC.type = CTListPrizeTypePackage3;
    }else if ([dic[@"giftId"] isEqualToString:@"14"]){
         detailVC.type = CTListPrizeTypePackage5;
    }else if ([dic[@"giftId"] isEqualToString:@"17"]){
        detailVC.type = CTListPrizeTypeCouponsFree_YanWo;
    }else if ([dic[@"giftId"] isEqualToString:@"21"]){
        detailVC.type = CTListPrizeTypeCoupons50_YanWo;
    }else if ([dic[@"giftId"] isEqualToString:@"18"]){
        detailVC.type = CTListPrizeTypeInsurance_DaDi;
    }else if ([dic[@"giftId"] isEqualToString:@"22"]){
        detailVC.type = CTListPrizeTypeCustomPackage;
    }else if ([dic[@"giftId"] isEqualToString:@"24"]){
        detailVC.type = CTListPrizeTypeShoe;
    }else if ([dic[@"giftId"] isEqualToString:@"25"]){
        detailVC.type = CTListPrizeTypeSmartCup;
    }else if ([dic[@"giftId"] isEqualToString:@"26"]){
        detailVC.type = CTListPrizeTypeToyCar;
    }else if ([dic[@"giftId"] isEqualToString:@"27"]){
        detailVC.type = CTListPrizeTypeElectricFan;
    }else if ([dic[@"giftId"] isEqualToString:@"28"]){
        detailVC.type = CTListPrizeTypeMedicalMask;
    }else if ([dic[@"giftId"] isEqualToString:@"29"]){
        detailVC.type = CTListPrizeTypeDisinfectant;
    }else if ([dic[@"giftId"] isEqualToString:@"30"]){
        detailVC.type = CTListPrizeTypeTissue;
    }else if ([dic[@"giftId"] isEqualToString:@"34"]){
        detailVC.type = CTListPrizeTypeFan;
    }else if ([dic[@"giftId"] isEqualToString:@"35"]){
        detailVC.type = CTListPrizeTypeWashbasin;
    }else if ([dic[@"giftId"] isEqualToString:@"36"]){
        detailVC.type = CTListPrizeTypeSandals;
    }else if ([dic[@"giftId"] isEqualToString:@"37"]){
        detailVC.type = CTListPrizeTypeFreeBusiness;
    }else if ([dic[@"giftId"] isEqualToString:@"38"]){
        detailVC.type = CTListPrizeType1000Gift;
    }else if ([dic[@"giftId"] isEqualToString:@"39"]){
        detailVC.type = CTListPrizeTypeAccidentInsurance;
    }else if ([dic[@"giftId"] isEqualToString:@"40"]){
        detailVC.type = CTListPrizeTypeMajorDiseaseInsurance;
    }else if ([dic[@"giftId"] isEqualToString:@"41"]){
        detailVC.type = CTListPrizeTypeTeaSet;
    }else if ([dic[@"giftId"] isEqualToString:@"42"]){
        detailVC.type = CTListPrizeTypeTeaMassageStick;
    }else if ([dic[@"giftId"] isEqualToString:@"43"]){
        detailVC.type = CTListPrizeTypeDogCleanerCoupon;
    }else if ([dic[@"giftId"] isEqualToString:@"44"]){
        detailVC.type = CTListPrizeTypeMiniHumidifier;
    }else if ([dic[@"giftId"] isEqualToString:@"45"]){
        detailVC.type = CTListPrizeTypeRazor;
    }else if ([dic[@"giftId"] isEqualToString:@"46"]){
        detailVC.type = CTListPrizeType299PhysicalExaminationCoupons;
    }else if ([dic[@"giftId"] isEqualToString:@"47"]){
        detailVC.type = CTListPrizeType598PhysicalExaminationCoupons;
    }else if ([dic[@"giftId"] isEqualToString:@"48"]){
        detailVC.type = CTListPrizeTypeCookerTool;
    }else if ([dic[@"giftId"] isEqualToString:@"49"]){
        detailVC.type = CTListPrizeTypeWashingLiquid;
    }else if ([dic[@"giftId"] isEqualToString:@"50"]){
        detailVC.type = CTListPrizeTypeStorageBox;
    }else if ([dic[@"giftId"] isEqualToString:@"51"]){
        detailVC.type = CTListPrizeTypeUSBElectronicScale;
    }else if ([dic[@"giftId"] isEqualToString:@"52"]){
        detailVC.type = CTListPrizeTypeAutoFoldUmbrella;
    }else if ([dic[@"giftId"] isEqualToString:@"53"]){
        detailVC.type = CTListPrizeTypeMosquitoKillingLamp;
    }else if ([dic[@"giftId"] isEqualToString:@"54"]){
        detailVC.type = CTListPrizeTypeHUAWeiMate40;
    }else if ([dic[@"giftId"] isEqualToString:@"55"]){
        detailVC.type = CTListPrizeTypeKKPackage;
    }else if ([dic[@"giftId"] isEqualToString:@"57"]){
        detailVC.type = CTListPrizeTypeKKPackage2;
    }else if ([dic[@"giftId"] isEqualToString:@"58"]){
        detailVC.type = CTListPrizeTypeHoldFan;
    } else if ([dic[@"giftId"] isEqualToString:@"59"]){
        detailVC.type = CTListPrizeTypequalityDrawing;
    } else if ([dic[@"giftId"] isEqualToString:@"60"]){
        detailVC.type = CTListPrizeTypeTeapot;
    }else if ([dic[@"giftId"] isEqualToString:@"61"]){
        detailVC.type = CTListPrizeTypeiPhone12Pro;
    }else if ([dic[@"giftId"] isEqualToString:@"62"]){
        detailVC.type = CTListPrizeTypeUglyOrange;
    } else if ([dic[@"giftId"] isEqualToString:@"63"]){
        detailVC.type = CTListPrizeTypeRedmi9A;
    } else if ([dic[@"giftId"] isEqualToString:@"64"]){
        detailVC.type = CTListPrizeTypeSummerSleepingMat;
    }else if ([dic[@"giftId"] isEqualToString:@"66"]){
        detailVC.type = CTListPrizeTypePhoneBill;
    }else if ([dic[@"giftId"] isEqualToString:@"67"]){
        detailVC.type = CTListPrizeTypeFilialObedienceExperienceCoupons;
    }else if ([dic[@"giftId"] isEqualToString:@"69"]){
        detailVC.type = CTListPrizeTypeChineseWolfberry;
    }else if ([dic[@"giftId"] isEqualToString:@"70"]){
        detailVC.type = CTListPrizeTypeSummerQuilt;
    }else if ([dic[@"giftId"] isEqualToString:@"71"]){
        detailVC.type = CTListPrizeTypeWashingMachine;
    }else if ([dic[@"giftId"] isEqualToString:@"72"]){
        detailVC.type = CTListPrizeTypeDisposableMop;
    }else if ([dic[@"giftId"] isEqualToString:@"74"]){
        detailVC.type = CTListPrizeTypeHairDrier;
    }else if ([dic[@"giftId"] isEqualToString:@"75"]){
        detailVC.type = CTListPrizeTypeKitchenRack;
    }else if ([dic[@"giftId"] isEqualToString:@"76"]){
        detailVC.type = CTListPrizeTypeMultifunctionalPluginBoard;
    }else if ([dic[@"giftId"] isEqualToString:@"78"]){
        //颈椎按摩器
        detailVC.type = CTListPrizeTypeCervicalSpineMassager;
    }else if ([dic[@"giftId"] isEqualToString:@"79"]){
        //无线蓝牙耳机
        detailVC.type = CTListPrizeTypeWirelessBluetoothHeadset;
    }else if ([dic[@"giftId"] isEqualToString:@"80"]){
        //冬季水杯
        detailVC.type = CTListPrizeTypeWinterCup;
    }else if ([dic[@"giftId"] isEqualToString:@"82"]){
        //收纳箱
        detailVC.type = CTListPrizeTypeBin;
    }else if ([dic[@"giftId"] isEqualToString:@"83"]){
        //空气加湿器
        detailVC.type = CTListPrizeTypeAirHumidifier;
    }else if ([dic[@"giftId"] isEqualToString:@"84"]){
        //创意洗菜篮
        detailVC.type = CTListPrizeTypeCreativeLaundryBasket;
    }else if ([dic[@"giftId"] isEqualToString:@"85"]){
        //交通意外险
        detailVC.type = CTListPrizeTypeTrafficAccidentInsurance;
    }else if ([dic[@"giftId"] isEqualToString:@"87"]){
        //浴室防滑垫
        detailVC.type = CTListPrizeTypeBathroomMat;
    }else if ([dic[@"giftId"] isEqualToString:@"88"]){
        // ipad mini
        detailVC.type = CTListPrizeTypeIpadMini;
    }else if ([dic[@"giftId"] isEqualToString:@"89"]){
        // 陶瓷砂锅
        detailVC.type = CTListPrizeTypeCeramicCasserole;
    }else if ([dic[@"giftId"] isEqualToString:@"90"]){
        // 床上书桌
        detailVC.type = CTListPrizeTypeBedDesk;
    }else if ([dic[@"giftId"] isEqualToString:@"91"]){
        // 毛球修剪器
        detailVC.type = CTListPrizeTypeHairBallTrimmer;
    }else if ([dic[@"giftId"] isEqualToString:@"92"]){
        // 毛绒坐垫
        detailVC.type = CTListPrizeTypePlushCushions;
    }else if ([dic[@"giftId"] isEqualToString:@"93"]){
        // 原浆抽纸
        detailVC.type = CTListPrizeTypeVirginPulpPaper;
    }else if ([dic[@"giftId"] isEqualToString:@"94"]){
        //88888金币
        detailVC.type = CTListPrizeTypeGoldCOINS;
    }else if ([dic[@"giftId"] isEqualToString:@"95"]){
        // 高档保温杯
        detailVC.type = CTListPrizeTypeTopCup;
    }else if ([dic[@"giftId"] isEqualToString:@"96"]){
        // 实木衣架
        detailVC.type = CTListPrizeTypeSolidWoodHangers;
    }else if ([dic[@"giftId"] isEqualToString:@"98"]){
        // 吸水防滑垫
        detailVC.type = CTListPrizeTypeAbsorbent;
    }else if ([dic[@"giftId"] isEqualToString:@"99"]){
        // 电子秤
        detailVC.type = CTListPrizeTypeElectronicScale;
    }else if ([dic[@"giftId"] isEqualToString:@"100"]){
        //充电无线鼠标
        detailVC.type = CTListPrizeTypeWirelessMouse;
    }else if ([dic[@"giftId"] isEqualToString:@"101"]){
        //新冠病毒意外险
        detailVC.type = CTListPrizeTypePlagueGuard;
    }else if ([dic[@"giftId"] isEqualToString:@"103"]){
        //洗碗手套
        detailVC.type = CTListPrizeTypeDishwashingGloves;
    }else if ([dic[@"giftId"] isEqualToString:@"105"]){
        //新春挂件
        detailVC.type = CTListPrizeTypeNewYearHanged;
    }else if ([dic[@"giftId"] isEqualToString:@"106"]){
        //过年糖果盘
        detailVC.type = CTListPrizeTypeNewYearCandy;
    }else if ([dic[@"giftId"] isEqualToString:@"107"]){
        //24小时家庭医生
        detailVC.type = CTListPrizeTypeHourDoctor;
    }else if ([dic[@"giftId"] isEqualToString:@"109"]){
        //原木餐巾纸
        detailVC.type = CTListPrizeTypeLogNapkins;
    }else if ([dic[@"giftId"] isEqualToString:@"110"]){
        //耐高温水杯
        detailVC.type = CTListPrizeTypeHighTempCup;
    }else if ([dic[@"giftId"] isEqualToString:@"111"]){
        //吸水厚毛巾
        detailVC.type = CTListPrizeTypeHeavyAbsorbentTowel;
    }else if ([dic[@"giftId"] isEqualToString:@"113"]){
        //黑科技扫把
        detailVC.type = CTListPrizeTypeHackTechBroom;
    }else if ([dic[@"giftId"] isEqualToString:@"114"]){
        //头部抓痒按摩器
        detailVC.type = CTListPrizeTypeHeadScratcherMassager;
    }else if ([dic[@"giftId"] isEqualToString:@"115"]){
        //中国红口罩
        detailVC.type = CTListPrizeTypeChineseRedMaskr;
    }else if ([dic[@"giftId"] isEqualToString:@"116"]){
        //招行交通意外险
        detailVC.type = CTListPrizeTypeCmbchinaTrafficInsurance;
    }else if ([dic[@"giftId"] isEqualToString:@"144"]){//玻璃杯
        detailVC.type = CTListPrizeTypeBOLIBEI;
    }else if ([dic[@"giftId"] isEqualToString:@"145"]){//空气净化器
        detailVC.type = CTListPrizeTypeKONGQI;
    }else if ([dic[@"giftId"] isEqualToString:@"146"]){//凉拖鞋
        detailVC.type = CTListPrizeTypeLIANGTUOXIE;
    }else if ([dic[@"giftId"] isEqualToString:@"147"]){//吸水毛巾
        detailVC.type = CTListPrizeTypeXISHUIMAOPJIN;
    }else{
        detailVC.type = CTListPrizeTypeUnKnow;
    }
    if ([dic[@"lotterStatus"] isEqualToString:@"未领取"]) {
        detailVC.state = CTListPrizeStateUnGet;
    }else if ([dic[@"lotterStatus"] isEqualToString:@"发放中"]){
        detailVC.state = CTListPrizeStateGiving;
    }else if ([dic[@"lotterStatus"] isEqualToString:@"已领取"]){
        detailVC.state = CTListPrizeStateReceived;
    }else if ([dic[@"lotterStatus"] isEqualToString:@"已过期"]){
        detailVC.state = CTListPrizeStateInvalid;
    }else if ([dic[@"lotterStatus"] isEqualToString:@"领取失败"]){
        detailVC.state = CTListPrizeStateFailure;
    }else {
        detailVC.state = CTListPrizeStateUnKnow;
    }
    detailVC.title = @"奖品详情";
    detailVC.contentDic = dic;
    
    
    if (detailVC.type == CTListPrizeTypeFreeBusiness) {
        if (detailVC.state == CTListPrizeStateUnGet) {
            [QRRedPackageGiftView showViewWithVC:self block:^(BOOL success) {
                
            }];
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        
        return;
    }else if(detailVC.type == CTListPrizeType1000Gift) {
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            if (![WXApi isWXAppInstalled]) {
                [Tools showMessage:@"请先安装微信"];
                return;
            }
            WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
            launchMiniProgramReq.userName = @"gh_b4315ce55e4c";  //拉起的小程序的username
            launchMiniProgramReq.path = @"pages/common/blank-page/index?scene=104617277";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
            launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
            [WXApi sendReq:launchMiniProgramReq completion:nil];
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        
        return;
    }else if (detailVC.type == CTListPrizeTypeAccidentInsurance) {
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            [self jumpToHTML5:@"https://esales.aegonthtf.com/msalesclient/tripworryfree/index.html#/giftInsurance?sourceFrom=aegonthtf&sid=kksb&follow=0" andJAnalytics:@"健康大礼包"];
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        
        return;
    }else if (detailVC.type == CTListPrizeTypeMajorDiseaseInsurance) {
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            [self jumpToHTML5:@"https://esales.aegonthtf.com/sales/giftInsurance/giftInsurance.html?sourceFrom=aegonthtf&sid=kksb&follow=0" andJAnalytics:@"健康大礼包"];
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        
        return;
    }else if (detailVC.type == CTListPrizeTypeDogCleanerCoupon) {
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            if (![Tools isBlankString:dic[@"ticketNo"]]) {
                [self jumpToHTML5:dic[@"ticketNo"] andJAnalytics:@"现金抵扣劵"];
            }
            
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        
        return;
    }else if (detailVC.type == CTListPrizeType299PhysicalExaminationCoupons){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            [self jumpToHTML5:@"https://m.shanzhen.me/cooperation/customize_examcoupon?comId=1299a83cb48a48b3a91458786a4f80aa&activityCode=ACT028770203" andJAnalytics:@"单人体检劵"];
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        
        return;
        
    }else if (detailVC.type == CTListPrizeType598PhysicalExaminationCoupons){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            [self jumpToHTML5:@"https://m.shanzhen.me/cooperation/customize_examcoupon?comId=08194d43e93241b3b61518488e91d2c5&activityCode=ACT545439111" andJAnalytics:@"双人体检劵"];
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        return;
    }else if (detailVC.type == CTListPrizeTypeKKPackage){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            WebVC *webvc = [[WebVC alloc]init];
        
            //webvc.url = @"http://172.16.10.194/awardBox";
            webvc.url = @"http://nginx.weface.com.cn/awardBox/index.html";
            webvc.title = @"6.6元红包";
            webvc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webvc animated:YES];
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        return;
    }else if (detailVC.type == CTListPrizeTypeKKPackage2){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            WebVC *webvc = [[WebVC alloc]init];
        
            //webvc.url = @"http://172.16.10.194/awardBox";
            webvc.url = @"http://nginx.weface.com.cn/awardBox/index.html";
            webvc.title = @"现金红包";
            webvc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webvc animated:YES];
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        return;
    }else if (detailVC.type == CTListPrizeTypePhoneBill){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            [[clickEvent instance] clickEventRooterVC:self getFederatedLoginRequestWithUrl:@"https://web.kanface.com:444/common/forward/FamilyChargeForwardUrl" menuName:@"话费充值"];
//            WebVC *webvc = [[WebVC alloc]init];
//            NSString  *phone = [getPeopleID PeopleIphoneNmber];
//            if (phone.length > 0) {
//                webvc.url = [NSString stringWithFormat:@"http://www.qld02.com/t/blackcard/callFee/callFeeForH5.html?channel=shebao&mobile=%@",[getPeopleID PeopleIphoneNmber]];
//            }else{
//                webvc.url = @"http://www.qld02.com/t/blackcard/callFee/callFeeForH5.html?channel=shebao";
//            }
//            webvc.title = @"话费劵";
//            webvc.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:webvc animated:YES];
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        return;
    }else if (detailVC.type == CTListPrizeTypeGoldCOINS){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            WebVC *webvc = [[WebVC alloc]init];
            webvc.url = @"https://nginx.weface.com.cn/appH5/piggyBankcl/k8888.html";
            webvc.title = @"88888金币";
            webvc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webvc animated:YES];
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        return;
    }else if (detailVC.type == CTListPrizeTypeFilialObedienceExperienceCoupons){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            WebVC *webvc = [[WebVC alloc]init];
        
            //webvc.url = @"http://172.16.10.194/awardBox";
            webvc.url = @"https://m.shanzhen.me/cooperation/coupon?comId=4690e4f302d246e8922e1fde0d927a2d&activityCode=ACT970812964";
            webvc.title = @"孝心体检券";
            webvc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webvc animated:YES];
            
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        return;
    }else if (detailVC.type == CTListPrizeTypeTrafficAccidentInsurance){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            [self jumpToHTML5:@"https://xhbback.axinsur.com/plan/F0F5F0F5F0/init" andJAnalytics:@"健康大礼包"];
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        return;
    }else if (detailVC.type == CTListPrizeTypeCmbchinaTrafficInsurance){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            [self jumpToHTML5:@"https://www.cignacmb.com/insurance/zengxian/yiwaixian.html" andJAnalytics:@"健康大礼包"];
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        return;
    }else if (detailVC.type == CTListPrizeTypePlagueGuard){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            [self jumpToHTML5:@"https://www.fxyf99.com/bsite/products/bz0211126057/1282624579156910080" andJAnalytics:@"健康大礼包"];
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        return;
    }else if (detailVC.type == CTListPrizeTypeHourDoctor){
        
        if (detailVC.state == CTListPrizeStateUnGet) {
            [self jumpToHTML5:@"http://t.fxyf99.com/WDGoJDFt" andJAnalytics:@"家庭医生"];
        }else if (detailVC.state == CTListPrizeStateGiving){
            [Tools showMessage:@"奖品发放中!!!"];
        }else if (detailVC.state == CTListPrizeStateReceived){
             [Tools showMessage:@"奖品已领取!!!"];
        }else if (detailVC.state == CTListPrizeStateInvalid){
            [Tools showMessage:@"奖品已过期!!!"];
        }else if (detailVC.state == CTListPrizeStateFailure){
            [Tools showMessage:@"奖品发放失败!!!"];
        }
        return;
    }
    
    if (detailVC.type != CTListPrizeTypeUnKnow && detailVC.state != CTListPrizeStateUnKnow) {
        
        WeakSelf
        detailVC.clickBlock = ^(BOOL isCLick) {
            // 马上进入刷新状态
            [weakSelf.tableView.mj_header beginRefreshing];
        };
        detailVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:detailVC animated:YES];
    }else{
        [SVProgressHUD showInfoWithStatus:@"该奖励现无法查看,\n需更新版本"];
        return;
    }
    
}


#pragma mark - event response
- (void)backClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 跳转h5
-(void)jumpToHTML5:(NSString*)url andJAnalytics:(NSString*)janalytics
{
    WebViewController *tc=[WebViewController new];
    tc.URL =[NSURL URLWithString:url];
            tc.hidesBottomBarWhenPushed =YES;
    tc.janalytics = janalytics;
    [self.navigationController pushViewController:tc animated:YES];

}

#pragma mark - 获取当前时间戳

-(NSInteger )getNowTimeTimestamp3{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss SSS"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    //设置时区,这个对于时间的处理有时很重要
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
    
    [formatter setTimeZone:timeZone];
    
    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    
    NSInteger timeSp = [datenow timeIntervalSince1970]*1000;
    
    return timeSp;
}


#pragma mark - private methods


//渐变色
- (UIImage *)convertViewToImage:(UIView *)v
{
    CGSize s = v.bounds.size;
    //UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale);
    UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
    format.opaque = NO;
    format.scale = [UIScreen mainScreen].scale;
    UIGraphicsImageRenderer*re=[[UIGraphicsImageRenderer alloc] initWithSize:s format:format];
    [v.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

#pragma mark - getters and setters
- (UIView *)getNavBackView
{
    UIView*backView = [[UIView alloc]initWithFrame:CGRectMake(0,0, ScreenWidth,cl_kNavigationBarHeight)];
    CAGradientLayer*gradientLayer = [CAGradientLayer layer];
    gradientLayer.locations = @[@0.0, @1.0];
    gradientLayer.startPoint = CGPointMake(1, 0);
    gradientLayer.endPoint = CGPointMake(1, 1);
    [gradientLayer setColors:@[(id)[[UIColor colorWithHex:0xff5633] CGColor],(id)[[UIColor colorWithHex:0xf8502c] CGColor]]];//渐变数组
    gradientLayer.frame = backView.frame;
    [backView.layer addSublayer:gradientLayer];
    return backView;
}


#pragma mark - getters and setters
- (UITableView *)tableView {
    if (!_tableView){
           _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,  cl_kNavigationBarHeight + 42, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - 42) style:UITableViewStyleGrouped];
        
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableFooterView = [UIView new];
        [_tableView registerClass:[ListPrizeTableViewCell class] forCellReuseIdentifier:@"identifier"];
    }
    return _tableView;
}

- (orderHeader *)headerView
{
    if (!_headView) {
       
        _headView = [[orderHeader alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, self.view.bounds.size.width, 40)];
        _headView.backgroundColor = [UIColor whiteColor];
        
        
        
        _headView.items = @[@"全部奖品",@"未领取"];
        
        //消除强引用
        __weak typeof(self) weakSelf = self;
        
        _headView.itemClickAtIndex = ^(NSInteger index){
            
            weakSelf.index = index;
            
            [weakSelf.tableView reloadData];
            
        };
    }
    
    return _headView;
}



- (CTAPIBaseManager *)manager
{
    if (!_manager) {
        _manager  = [[CTAPIBaseManager alloc]init];
    }
    return _manager;
}

- (NSMutableArray *)dataArry2
{
    if (!_dataArry2) {
        _dataArry2 = [[NSMutableArray alloc]init];
    }
    return _dataArry2;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
