LuckyDrawDetailsViewController.m 5.42 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//
//  LuckyDrawDetailsViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2016/11/6.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "LuckyDrawDetailsViewController.h"
#import "NotDrawTableViewCell.h"
#import "CustomWKWebViewController.h"
#import "UsedDrawTableViewCell.h"
#import "PromotionLuckDrawResultModel.h"


16
@interface LuckyDrawDetailsViewController ()<UITableViewDataSource,UITableViewDelegate>
曹云霄's avatar
曹云霄 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71


@property (nonatomic,strong) RsLotteryRequest *drawModel;

/**
 *  数据源
 */
@property (nonatomic,strong) NSMutableArray *datasArray;

@end

@implementation LuckyDrawDetailsViewController

#pragma mark - lazy
- (RsLotteryRequest *)drawModel
{
    if (!_drawModel) {
        _drawModel = [[RsLotteryRequest alloc]init];
        _drawModel.winnerIdEquals = [Shoppersmanager manager].shoppers.employee.fid;
        DataPage *page = [[DataPage alloc]init];
        page.rows = KROWS;
        page.page = ONE;
        page.order = SORTDIRECTION_DESC;
        _drawModel.page = page;
        switch (self.drawValue) {
            case ALLDRAW:
            {
                _drawModel.stateEquals = nil;
            }
                break;
            case NOTDRAW:
            {
                _drawModel.stateEquals = INITIAL;
            }
                break;
            case USEDDRAW:
            {
                _drawModel.stateEquals = ACCOMPLISHED;
            }
                break;
            default:
                break;
        }
    }
    return _drawModel;
}

- (NSMutableArray *)datasArray
{
    if (!_datasArray) {
        _datasArray = [NSMutableArray array];
    }
    return _datasArray;
}

72 73
#pragma mark -加载数据
- (void)loadWebDataSource
曹云霄's avatar
曹云霄 committed
74 75
{
    WS(weakSelf);
76 77 78 79 80 81 82 83 84
    if (self.pullPageIndex == ONE) {
        [self.datasArray removeAllObjects];
    }
    self.drawModel.page.page = self.pullPageIndex;
    [self getDrawDatasCompleted:^(RsLotteryResponse *result) {
        if (weakSelf.pullPageIndex >= result.totalpages) {
            [weakSelf endRefresh:EndRefreshNotData];
        }else {
            [weakSelf endRefresh:EndRefreshDefault];
曹云霄's avatar
曹云霄 committed
85 86 87 88 89
        }
    }];
}

#pragma mark - 抽奖数据
90
- (void)getDrawDatasCompleted:(void(^)(RsLotteryResponse *result))completed
曹云霄's avatar
曹云霄 committed
91 92 93 94 95
{
    WS(weakSelf);
    [HTTP networkRequestWithURL:SERVERREQUESTURL(LOTTERYED) withRequestType:ZERO withParameter:self.drawModel withReturnValueBlock:^(id returnValue) {
        if (RESULT(returnValue)) {
            RsLotteryResponse *drawRecord = [[RsLotteryResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
96
            completed(drawRecord);
曹云霄's avatar
曹云霄 committed
97
            [weakSelf.datasArray addObjectsFromArray:drawRecord.list];
98
            [weakSelf.tableView reloadData];
曹云霄's avatar
曹云霄 committed
99 100 101 102
        }else {
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
        }
    } withFailureBlock:^(NSError *error) {
103
        [weakSelf endRefresh:EndRefreshDefault];
曹云霄's avatar
曹云霄 committed
104 105 106 107
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
    }];
}

108

曹云霄's avatar
曹云霄 committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RsAwardDraw *drawEntity = self.datasArray[indexPath.row];
    if ([drawEntity.draw.state isEqualToString:@"initial"]) {
        NotDrawTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NotDrawTableViewCell" forIndexPath:indexPath];
        cell.orderNumberLabel.text = drawEntity.draw.orderNumber;
        cell.drawButton.tag = indexPath.row;
        [cell.drawButton addTarget:self action:@selector(drawButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }
    UsedDrawTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UsedDrawTableViewCell" forIndexPath:indexPath];
    cell.orderNumber.text = drawEntity.draw.orderNumber;
    cell.drawTimeLabel.text = drawEntity.draw.drawDate;
    cell.trophyLabel.text = drawEntity.draw.awardDescription;
    return cell;
}

126

曹云霄's avatar
曹云霄 committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.datasArray.count;
}

#pragma mark - 去抽奖
- (void)drawButtonClickAction:(UIButton *)sender
{
    RsAwardDraw *drawEntity = self.datasArray[sender.tag];
    [self showLuckyDrawControl:drawEntity.draw.lotteryId andOrderNumber:drawEntity.draw.orderNumber andDrawid:drawEntity.draw.fid luckyDrawFinish:^(NSDictionary *dict) {
        
        if ([dict isKindOfClass:[NSDictionary class]]) {
            if ([BaseViewController isBlankString:dict[@"awardId"]]) {
                [XBLoadingView showHUDViewWithText:@"未中奖"];
            }else {
                [XBLoadingView showHUDViewWithText:[NSString stringWithFormat:@"恭喜你获得了 %@",dict[@"description"]]];
            }
        }
    }];
}

#pragma mark - 抽奖界面
- (void)showLuckyDrawControl:(NSString *)lotteryId andOrderNumber:(NSString *)orderNumber andDrawid:(NSString *)drawid luckyDrawFinish:(void(^)(NSDictionary *dict))complete
{
    CustomWKWebViewController *wkWebView = [[CustomWKWebViewController alloc]init];
    NSString *server = [NSString stringWithFormat:SERVERREQUESTURL(DRAW),lotteryId,drawid,orderNumber];
    NSString *newServer = [server stringByReplacingOccurrencesOfString:@"/app" withString:@""];
    wkWebView.urlString = newServer;
    [wkWebView setLuckyDrawFinishBlock:^(NSDictionary *result) {
        complete(result);
    }];
    [wkWebView setDismissLuckyDrawController:^{
        
    }];
    [self presentViewController:wkWebView animated:YES completion:nil];
}



@end