Skip to content

Commit 044accd

Browse files
committed
兑换商品
1 parent 74ad4b9 commit 044accd

6 files changed

Lines changed: 140 additions & 83 deletions

File tree

Coding_iOS/Controllers/Shop/ExchangeGoodsViewController.m

Lines changed: 82 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ @interface ExchangeGoodsViewController () <UITableViewDataSource, UITableViewDel
2020
{
2121
}
2222

23-
@property (strong, nonatomic) NSString *tagNameToAdd;
24-
@property (strong, nonatomic) NSMutableArray *tagList, *selectedTags;
2523
@property (strong, nonatomic) TPKeyboardAvoidingTableView *myTableView;
2624
@property (strong, nonatomic) UIButton *shopOrderBtn;
2725

@@ -59,6 +57,8 @@ - (void)orderCommitAction:(UIButton *)button
5957
return;
6058
}
6159

60+
[self showPwdAlertView];
61+
6262
}
6363

6464
#pragma mark-
@@ -111,57 +111,13 @@ - (void)viewDidLoad {
111111
}];
112112
orderBtn;
113113
});
114-
// _shopOrderBtn.enabled = NO;
115114
_myTableView.tableFooterView = footView;
116115
}
117116

118117
- (void)viewWillAppear:(BOOL)animated
119118
{
120119
[super viewWillAppear:animated];
121-
[self sendRequest];
122120
}
123-
124-
- (void)sendRequest
125-
{
126-
// [self.view beginLoading];
127-
// __weak typeof(self) weakSelf = self;
128-
// [[Coding_NetAPIManager sharedManager] request_TagListInProject:_curProject type:ProjectTagTypeTopic andBlock:^(id data, NSError *error) {
129-
// [weakSelf.view endLoading];
130-
// if (data) {
131-
// weakSelf.tagList = data;
132-
// [weakSelf.myTableView reloadData];
133-
// }
134-
// }];
135-
}
136-
137-
#pragma mark - click
138-
//- (void)okBtnClick
139-
//{
140-
// if (self.tagsChangedBlock) {
141-
// self.tagsChangedBlock(self, _selectedTags);
142-
// }
143-
//}
144-
//
145-
//- (void)addBtnClick:(UIButton *)sender
146-
//{
147-
// [self.view endEditing:YES];
148-
// if (_tagNameToAdd.length > 0) {
149-
// __weak typeof(self) weakSelf = self;
150-
// ProjectTag *curTag = [ProjectTag tagWithName:_tagNameToAdd];
151-
// [[Coding_NetAPIManager sharedManager] request_AddTag:curTag toProject:_curProject andBlock:^(id data, NSError *error) {
152-
// if (data) {
153-
// curTag.id = data;
154-
// [weakSelf.tagList addObject:curTag];
155-
// weakSelf.tagNameToAdd = @"";
156-
// [weakSelf.myTableView reloadData];
157-
// sender.enabled = FALSE;
158-
//
159-
// [NSObject showHudTipStr:@"添加标签成功^^"];
160-
// }
161-
// }];
162-
// }
163-
//}
164-
//
165121
#pragma mark - UITableViewDataSource
166122
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
167123
{
@@ -239,38 +195,14 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
239195
{
240196
[self.view endEditing:YES];
241197
[tableView deselectRowAtIndexPath:indexPath animated:YES];
242-
243-
// if (indexPath.section > 0) {
244-
// EditLabelCell *cell = (EditLabelCell *)[tableView cellForRowAtIndexPath:indexPath];
245-
// cell.selectBtn.selected = !cell.selectBtn.selected;
246-
//
247-
// ProjectTag *tagInSelected = [ProjectTag tags:_selectedTags hasTag:_tagList[indexPath.row]];
248-
// if (cell.selectBtn.selected && !tagInSelected) {
249-
// [_selectedTags addObject:_tagList[indexPath.row]];
250-
// }else if (!cell.selectBtn.selected && tagInSelected){
251-
// [_selectedTags removeObject:tagInSelected];
252-
// }
253-
// self.navigationItem.rightBarButtonItem.enabled = ![ProjectTag tags:_selectedTags isEqualTo:_orignalTags];
254-
// }
255198
}
256199

257200
#pragma mark - UITextFieldDelegate
258201

259202
- (void)textFieldDidChange:(UITextField *)textField
260203
{
261-
_tagNameToAdd = [textField.text trimWhitespace];
262-
BOOL enabled = _tagNameToAdd.length > 0 ? TRUE : FALSE;
263-
if (enabled) {
264-
for (ProjectTag *lbl in _tagList) {
265-
if ([lbl.name isEqualToString:_tagNameToAdd]) {
266-
enabled = FALSE;
267-
break;
268-
}
269-
}
270-
}
271-
272-
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
273-
ShopOrderTextFieldCell *cell = (ShopOrderTextFieldCell *)[_myTableView cellForRowAtIndexPath:indexPath];
204+
// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
205+
// ShopOrderTextFieldCell *cell = (ShopOrderTextFieldCell *)[_myTableView cellForRowAtIndexPath:indexPath];
274206
}
275207

276208
- (BOOL)textFieldShouldReturn:(UITextField *)textField
@@ -285,5 +217,83 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
285217
[self.view endEditing:YES];
286218
}
287219

220+
221+
#pragma mark-
222+
#pragma mark---------------------- AlertView ---------------------------
223+
224+
- (void)showPwdAlertView
225+
{
226+
UIAlertView *_pwdAlertView = [[UIAlertView alloc] initWithTitle:@"确认订单" message:@"请输入密码已确认兑换" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
227+
_pwdAlertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
228+
[_pwdAlertView show];
229+
}
230+
231+
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
232+
233+
if (alertView.firstOtherButtonIndex == buttonIndex) {
234+
UITextField *field = [alertView textFieldAtIndex:0];
235+
if ([field.text isEmpty]) {
236+
[NSObject showHudTipStr:@"密码不能为空"];
237+
return;
238+
}
239+
240+
[self exchangeActionRquest:field.text];
241+
242+
}
243+
}
244+
245+
- (void)exchangeActionRquest:(NSString *)pwd
246+
{
247+
__weak typeof(self) weakSelf = self;
248+
[[Coding_NetAPIManager sharedManager] request_shop_check_passwordWithpwd:pwd andBlock:^(id data, NSError *error) {
249+
if (data) {
250+
251+
ShopOrderTextFieldCell *nameCell = [weakSelf.myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
252+
ShopOrderTextFieldCell *addressCell = [weakSelf.myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:1 inSection:0]];
253+
ShopOrderTextFieldCell *phoneCell = [weakSelf.myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:2 inSection:0]];
254+
ShopOrderTextFieldCell *remarkCell = [weakSelf.myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:3 inSection:0]];
255+
256+
NSString *receiverName = nameCell.textField.text;
257+
NSString *receiverAddress = addressCell.textField.text;
258+
NSString *receiverPhone = phoneCell.textField.text;
259+
NSString *remark = remarkCell.textField.text;
260+
NSMutableDictionary *mparms = [NSMutableDictionary dictionary];
261+
if (![receiverName isEmpty]) {
262+
[mparms setObject:receiverName forKey:@"receiverName"];
263+
}
264+
if (![receiverAddress isEmpty]) {
265+
[mparms setObject:receiverAddress forKey:@"receiverAddress"];
266+
}
267+
if (![receiverPhone isEmpty]) {
268+
[mparms setObject:receiverPhone forKey:@"receiverPhone"];
269+
}
270+
if (![remark isEmpty]) {
271+
[mparms setObject:remark forKey:@"remark"];
272+
}else
273+
[mparms setObject:@"" forKey:@"remark"];
274+
275+
if (![_shopGoods.giftId isEmpty]) {
276+
[mparms setObject:_shopGoods.id forKey:@"giftId"];
277+
}
278+
if (![pwd isEmpty]) {
279+
[mparms setObject:[pwd sha1Str] forKey:@" "];
280+
}
281+
282+
[[Coding_NetAPIManager sharedManager] request_shop_exchangeWithParms:mparms andBlock:^(id data, NSError *error) {
283+
if (!error) {
284+
[NSObject showHudTipStr:@"恭喜你,兑换成功!"];
285+
[self.navigationController popViewControllerAnimated:YES];
286+
}else
287+
{
288+
[NSObject showError:error];
289+
}
290+
}];
291+
}else
292+
{
293+
[NSObject showHudTipStr:@"密码不正确"];
294+
}
295+
}];
296+
}
297+
288298
@end
289299

Coding_iOS/Controllers/Shop/ShopOrderViewController.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ - (void)viewDidLoad
3939

4040
//添加myCarousel
4141
self.myCarousel = ({
42-
iCarousel *icarousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, kMySegmentControl_Height, kScreen_Width, kScreen_Height - kMySegmentControl_Height)];
42+
iCarousel *icarousel = [[iCarousel alloc] initWithFrame:CGRectZero];
4343
icarousel.dataSource = self;
4444
icarousel.delegate = self;
4545
icarousel.decelerationRate = 1.0;
@@ -49,6 +49,10 @@ - (void)viewDidLoad
4949
icarousel.clipsToBounds = YES;
5050
icarousel.bounceDistance = 0.2;
5151
[self.view addSubview:icarousel];
52+
[icarousel mas_makeConstraints:^(MASConstraintMaker *make) {
53+
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(kMySegmentControl_Height, 0, 0, 0));
54+
}];
55+
5256
icarousel;
5357
});
5458

Coding_iOS/Models/ShopGoods.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@property (strong, nonatomic) NSNumber *id;
1414
@property (strong, nonatomic) NSNumber *points_cost;
15-
@property (strong, nonatomic) NSString *image ,*name;
15+
@property (strong, nonatomic) NSString *image ,*name ,*giftId;
1616
@property (assign, nonatomic) BOOL exchangeable; //能否兑换的
1717
@property (strong, nonatomic) NSString *description_mine;
1818

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,8 @@ typedef NS_ENUM(NSUInteger, VerifyType){
246246
- (void)request_shop_OrderListWithOrder:(ShopOrderModel *)_order andBlock:(void (^)(id data, NSError *error))block;
247247

248248

249+
- (void)request_shop_check_passwordWithpwd:(NSString *)pwd andBlock:(void (^)(id data, NSError *error))block;
250+
251+
- (void)request_shop_exchangeWithParms:(NSDictionary *)parms andBlock:(void (^)(id data, NSError *error))block;
252+
249253
@end

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,4 +2450,34 @@ - (void)request_shop_OrderListWithOrder:(ShopOrderModel *)_order andBlock:(void
24502450
}];
24512451
}
24522452

2453+
- (void)request_shop_check_passwordWithpwd:(NSString *)pwd andBlock:(void (^)(id data, NSError *error))block
2454+
{
2455+
if ([pwd isEmpty]) {
2456+
return;
2457+
}
2458+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/account/check_password" withParams:@{@"password":[pwd sha1Str]} withMethodType:Post autoShowError:YES andBlock:^(id data, NSError *error) {
2459+
NSNumber *code = [data valueForKey:@"code"];
2460+
if (code.intValue == 0) {
2461+
block(code, nil);
2462+
}else{
2463+
block(nil, error);
2464+
}
2465+
}];
2466+
}
2467+
///
2468+
2469+
- (void)request_shop_exchangeWithParms:(NSDictionary *)parms andBlock:(void (^)(id data, NSError *error))block
2470+
{
2471+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/gifts/exchange" withParams:parms withMethodType:Post autoShowError:YES andBlock:^(id data, NSError *error) {
2472+
data = [data valueForKey:@"data"];
2473+
if (data) {
2474+
block(data, nil);
2475+
}else{
2476+
block(nil, error);
2477+
}
2478+
}];
2479+
2480+
}
2481+
2482+
24532483
@end

Coding_iOS/Views/TableListView/ShopOrderListView.m

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ - (instancetype)initWithFrame:(CGRect)frame withOder:(ShopOrderModel *)order
3737
tableView.dataSource = self;
3838
tableView.estimatedRowHeight = 690/2;
3939
[tableView registerClass:[ShopOderCell class] forCellReuseIdentifier:@"ShopOderCell"];
40-
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
40+
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
41+
tableView.separatorColor = [UIColor colorWithHexString:@"0xFFDDDDDD"];
42+
tableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 12);
4143
[self addSubview:tableView];
4244
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
4345
make.edges.equalTo(self);
@@ -50,9 +52,23 @@ - (instancetype)initWithFrame:(CGRect)frame withOder:(ShopOrderModel *)order
5052
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
5153
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
5254

55+
56+
}
57+
return self;
58+
}
59+
60+
- (void)reloadData
61+
{
62+
_dataSource = [_myOrder getDataSourceByOrderType];
63+
[self.myTableView reloadData];
64+
65+
[self configBlankPage:EaseBlankPageTypeTopic hasData:(_dataSource.count > 0) hasError:NO reloadButtonBlock:^(id sender) {
66+
67+
}];
68+
69+
if (_dataSource.count > 0) {
5370
UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width
5471
, (86 +88 +25)/2)];
55-
5672
UILabel *tipsLabel = [[UILabel alloc] initWithFrame:CGRectZero];
5773
tipsLabel.font = [UIFont systemFontOfSize:12];
5874
tipsLabel.backgroundColor = [UIColor clearColor];
@@ -69,13 +85,6 @@ - (instancetype)initWithFrame:(CGRect)frame withOder:(ShopOrderModel *)order
6985

7086
_myTableView.tableFooterView = footView;
7187
}
72-
return self;
73-
}
74-
75-
- (void)reloadData
76-
{
77-
_dataSource = [_myOrder getDataSourceByOrderType];
78-
[self.myTableView reloadData];
7988
}
8089

8190
- (void)refresh

0 commit comments

Comments
 (0)