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
125
126
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//
// CardBeenUseViewController.m
// Lighting
//
// Created by 曹云霄 on 2016/10/19.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "CardBeenUseViewController.h"
#import "CardCollectionViewCell.h"
#import "CardOrderInformationReusableView.h"
#import "CardAmplificationViewController.h"
@interface CardBeenUseViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,strong) RsJingDongECardRequest *requestModel;
@property (nonatomic,strong) WYPopoverController *settingsPopoverController;
/**
* 数据源
*/
@property (nonatomic,strong) NSMutableArray *datasArray;
@end
@implementation CardBeenUseViewController
#pragma mark - lazy
- (RsJingDongECardRequest *)requestModel
{
if (!_requestModel) {
_requestModel = [[RsJingDongECardRequest alloc]init];
DataPage *page = [[DataPage alloc]init];
page.page = ZERO;
page.rows = KROWS;
page.order = @"desc";
_requestModel.guideIdEquals = [Shoppersmanager manager].shoppers.employee.fid;
_requestModel.stateEquals = self.cardState;
_requestModel.page = page;
}
return _requestModel;
}
- (NSMutableArray *)datasArray
{
if (!_datasArray) {
_datasArray = [NSMutableArray array];
}
return _datasArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupCollectionView];
self.tempIndex = @"0";
}
#pragma mark -获取数据
- (void)loadWebDataSource
{
WS(weakSelf);
if (self.pullPageIndex == ZERO) {
[self.datasArray removeAllObjects];
}
self.requestModel.page.page = self.pullPageIndex;
[self getCardDatasActionCompleted:^(RsJingDongECardResponse *result) {
if (weakSelf.pullPageIndex >= result.totalpages) {
[weakSelf endRefresh:EndRefreshNotData];
}else {
[weakSelf endRefresh:EndRefreshDefault];
}
}];
}
#pragma mark - 获取卡劵
- (void)getCardDatasActionCompleted:(void(^)(RsJingDongECardResponse *result))completed
{
WS(weakSelf);
[HTTP networkRequestWithURL:SERVERREQUESTURL(CARDINFORMATION) withRequestType:ZERO withParameter:self.requestModel withReturnValueBlock:^(id returnValue) {
if (RESULT(returnValue)) {
RsJingDongECardResponse *cardInformation = [[RsJingDongECardResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
completed(cardInformation);
[weakSelf.datasArray addObjectsFromArray:cardInformation.list];
[weakSelf.collectionView reloadData];
}else{
[XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
}
}withFailureBlock:^(NSError *error) {
[weakSelf endRefresh:EndRefreshDefault];
[XBLoadingView showHUDViewWithText:error.localizedDescription];
}];
}
#pragma mark - 使用京东卡劵
- (void)useJDECard:(NSString *)JDECardNumber
{
WS(weakSelf);
[XBLoadingView showHUDViewWithDefault];
[HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(USEJDECARD),JDECardNumber] withRequestType:ZERO withParameter:nil withReturnValueBlock:^(id returnValue) {
[XBLoadingView hideHUDViewWithDefault];
if (RESULT(returnValue)) {
[weakSelf deleteUsedJDECard:JDECardNumber];
}else{
[XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
}
}withFailureBlock:^(NSError *error) {
[XBLoadingView showHUDViewWithText:error.localizedDescription];
}];
}
#pragma mark - 区分已经使用的E卡
- (void)deleteUsedJDECard:(NSString *)eCardNumber
{
//@property (nonatomic, strong) NSMutableArray<TOJingdongEcardEntity> *eCards;
// 手动改为可变数组
for (int i=0; i<self.datasArray.count; i++) {
GroupByOrderNumber *order = self.datasArray[i];
for (int j=0; j<order.eCards.count; j++) {
TOJingdongEcardEntity *ecard = order.eCards[j];
if ([eCardNumber isEqualToString:ecard.cardNumber]) {
ecard.state = USED;
[self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:j inSection:i]]];
}
}
}
}
#pragma mark - UICollectionView
- (void)setupCollectionView
{
self.beenUseLayout.itemSize = CGSizeMake((ScreenWidth-48-20*4)/3, 200);
self.beenUseLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
self.beenUseLayout.minimumLineSpacing = 20;
self.beenUseLayout.minimumInteritemSpacing = 20;
[self.collectionView registerNib:[UINib nibWithNibName:@"CardOrderInformationReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CardOrderInformationReusableView"];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CardCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CardCollectionViewCell" forIndexPath:indexPath];
GroupByOrderNumber *model = self.datasArray[indexPath.section];
cell.Cardmodel = model.eCards[indexPath.row];
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
GroupByOrderNumber *model = self.datasArray[section];
return model.eCards.count;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
CardOrderInformationReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CardOrderInformationReusableView" forIndexPath:indexPath];
headerView.model = self.datasArray[indexPath.section];
headerView.uploadReceiptsButton.hidden = true;
return headerView;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
return CGSizeMake(0, 80);
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return self.datasArray.count;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.cardState isEqualToString:CHECK]) {
return;
}
CardAmplificationViewController *cardVC = [[CardAmplificationViewController alloc]init];
self.settingsPopoverController = [[WYPopoverController alloc] initWithContentViewController:cardVC];
self.settingsPopoverController.theme.fillBottomColor = [UIColor clearColor];
self.settingsPopoverController.theme.fillTopColor = [UIColor clearColor];
[self.settingsPopoverController presentPopoverAsDialogAnimated:YES
options:WYPopoverAnimationOptionFadeWithScale];
[self.settingsPopoverController beginThemeUpdates];
GroupByOrderNumber *model = self.datasArray[indexPath.section];
cardVC.cardModel = model.eCards[indexPath.row];
cardVC.preferredContentSize = CGSizeMake(500, 370);
[self.settingsPopoverController endThemeUpdates];
// 更新E卡状态
WS(weakSelf);
[cardVC setRefreshJDCardList:^(NSString *cardNumber) {
[weakSelf.settingsPopoverController dismissPopoverAnimated:YES completion:^{
[weakSelf useJDECard:cardNumber];
}];
}];
}
- (void)dealloc
{
[Notification removeObserver:self];
}
@end