1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// KWMGiftCardVC.m
// iCemarose
//
// Created by HouWeiBin on 16/9/28.
// Copyright © 2016年 kollway. All rights reserved.
//
#import "KWMGiftCardVC.h"
#import "PSPDFAlertView.h"
#import "UIColor+SAMAdditions.h"
@interface KWMGiftCardVC ()
@end
@implementation KWMGiftCardVC{
UIBarButtonItem *rightButton;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initTitle];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
+(NSString *)kwmTag{
return @"KWMGiftCardVC";
}
- (void)initTitle{
self.title = @"输入礼品卡";
self.btnAddGift.layer.borderWidth = 0.5;
self.btnAddGift.layer.borderColor = [UIColor sam_colorWithHex:@"#4E4E4E"].CGColor;
rightButton = [[UIBarButtonItem alloc] initWithTitle:@"新增" style:UIBarButtonItemStylePlain target:self action:@selector(clickRightBtn)];
self.navigationItem.rightBarButtonItem = rightButton;
}
//点击新增礼品卡
-(void)clickRightBtn{
KWMAddGiftCardVC *addGiftCardVC = (KWMAddGiftCardVC *)[KWMBaseVC findControllerBy:[KWMAddGiftCardVC kwmTag] fromStoryboard:@"ShopCart"];
addGiftCardVC.checkout = self.checkout;
addGiftCardVC.delegate = self;
[self.navigationController pushViewController:addGiftCardVC animated:YES];
}
//点击去添加礼品卡
- (IBAction)onClickAddGift:(id)sender{
KWMAddGiftCardVC *addGiftCardVC = (KWMAddGiftCardVC *)[KWMBaseVC findControllerBy:[KWMAddGiftCardVC kwmTag] fromStoryboard:@"ShopCart"];
addGiftCardVC.checkout = self.checkout;
addGiftCardVC.delegate = self;
[self.navigationController pushViewController:addGiftCardVC animated:YES];
}
-(void)kwm_onClickAddGift:(BUYCheckout *)checkout{
self.checkout = checkout;
[self.tbvGiftCard reloadData];
if(self.delegate != nil){
[self.delegate kwm_addedGiftCard:checkout];
}
}
-(void)kwm_onClickRemove:(BUYGiftCard *)giftCard{
PSPDFAlertView *alertView = [[PSPDFAlertView alloc] initWithTitle:@"" message:@"是否删除该礼品卡?"];
[alertView setCancelButtonWithTitle:@"取消" block:^{
}];
[alertView addButtonWithTitle:@"確定" block:^{
[self removeGiftCard:giftCard];
}];
[alertView show];
[self.tbvGiftCard reloadData];
}
-(void)removeGiftCard:(BUYGiftCard *)giftCard{
if(giftCard == nil){
return;
}
[self showLoading];
[self.client removeGiftCard:giftCard fromCheckout:self.checkout completion:^(NSDictionary *dictionary, BUYCheckout * _Nullable checkout, NSError * _Nullable error) {
[self hideLoading];
if (error == nil && checkout) {
[self showToast:@"成功删除该礼品卡"];
[self.tbvGiftCard reloadData];
self.checkout = checkout;
if(self.delegate != nil){
[self.delegate kwm_removedGiftCard:checkout];
}
}else{
[self showError:error];
[self showToast:@"删除礼品卡失败"];
}
}];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(self.checkout!=nil && self.checkout.giftCardsArray!=nil && self.checkout.giftCardsArray.count > 0){
self.vNoGiftCard.hidden = YES;
return self.checkout.giftCardsArray.count;
}else{
self.vNoGiftCard.hidden = NO;
return 0;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
KWMGiftCardCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KWMGiftCardCell"];
cell.delegate = self;
if(self.checkout!=nil&&self.checkout.giftCardsArray!=nil){
BUYGiftCard *giftCard = [self.checkout.giftCardsArray objectAtIndex:indexPath.row];
[cell setData:giftCard];
}
return cell;
}
@end