12
12
#import " ShopOrderTextFieldCell.h"
13
13
#import " ShopGoodsInfoView.h"
14
14
#import " UIView+Common.h"
15
+ #import " LocationViewController.h"
16
+ #import " ShopAddressCell.h"
15
17
16
18
#define kCellIdentifier_ShopOrderTextFieldCell @" ShopOrderTextFieldCell.h"
17
19
@@ -22,6 +24,8 @@ @interface ExchangeGoodsViewController () <UITableViewDataSource, UITableViewDel
22
24
@property (strong , nonatomic ) TPKeyboardAvoidingTableView *myTableView;
23
25
@property (strong , nonatomic ) UIButton *shopOrderBtn;
24
26
27
+ @property (strong , nonatomic ) NSString *receiverName, *receiverAddress, *receiverPhone, *remark;
28
+ @property (strong , nonatomic ) NSArray *locations;
25
29
@end
26
30
27
31
@implementation ExchangeGoodsViewController
@@ -38,20 +42,19 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
38
42
39
43
- (void )orderCommitAction : (UIButton *)button
40
44
{
41
- ShopOrderTextFieldCell *receiveName = [_myTableView cellForRowAtIndexPath: [NSIndexPath indexPathForItem: 0 inSection: 0 ]];
42
- if ([receiveName.textField.text isEmpty ]) {
45
+ if ([_receiverName isEmpty ]) {
43
46
[NSObject showHudTipStr: @" 收货人名字很重要" ];
44
47
return ;
45
48
}
46
-
47
- ShopOrderTextFieldCell *address = [_myTableView cellForRowAtIndexPath: [NSIndexPath indexPathForItem: 1 inSection: 0 ]];
48
- if ([address.textField.text isEmpty ]) {
49
+ if (_locations.count == 0 ) {
50
+ [NSObject showHudTipStr: @" 请选择所在地" ];
51
+ return ;
52
+ }
53
+ if ([_receiverAddress isEmpty ]) {
49
54
[NSObject showHudTipStr: @" 详细地址也很重要" ];
50
55
return ;
51
56
}
52
-
53
- ShopOrderTextFieldCell *phone = [_myTableView cellForRowAtIndexPath: [NSIndexPath indexPathForItem: 2 inSection: 0 ]];
54
- if ([phone.textField.text isEmpty ]) {
57
+ if ([_receiverPhone isEmpty ]) {
55
58
[NSObject showHudTipStr: @" 联系电话非常重要" ];
56
59
return ;
57
60
}
@@ -75,6 +78,7 @@ - (void)viewDidLoad {
75
78
tableView.delegate = self;
76
79
tableView.dataSource = self;
77
80
[tableView registerClass: [ShopOrderTextFieldCell class ] forCellReuseIdentifier: kCellIdentifier_ShopOrderTextFieldCell ];
81
+ [tableView registerNib: [UINib nibWithNibName: kCellIdentifier_ShopAddressCell bundle: nil ] forCellReuseIdentifier: kCellIdentifier_ShopAddressCell ];
78
82
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
79
83
tableView.separatorColor = [UIColor colorWithHexString: @" 0xFFDDDDDD" ];
80
84
tableView.separatorInset = UIEdgeInsetsMake (0 , 12 , 0 , 12 );
@@ -125,44 +129,57 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
125
129
126
130
- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section
127
131
{
128
- NSInteger row = 4 ;
132
+ NSInteger row = 5 ;
129
133
return row;
130
134
}
131
135
132
136
- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath
133
137
{
134
-
135
- ShopOrderTextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_ShopOrderTextFieldCell forIndexPath: indexPath];
136
-
137
- switch (indexPath.row ) {
138
- case 0 :
139
- {
140
- cell.nameLabel .text = @" 收货人 *" ;
141
- cell.textField .placeholder = @" 小王" ;
142
- break ;
143
- }
144
- case 1 :
145
- {
146
- cell.nameLabel .text = @" 详细地址 *" ;
147
- cell.textField .placeholder = @" 省,市,县(镇),街道" ;
148
- break ;
149
- }
150
- case 2 :
151
- {
152
- cell.nameLabel .text = @" 联系电话 *" ;
153
- cell.textField .placeholder = @" 电话" ;
154
- break ;
155
- }
156
- case 3 :
157
- {
158
- cell.nameLabel .text = @" 备注" ;
159
- cell.textField .placeholder = @" 备注信息如:衣服码数XXL" ;
160
- break ;
138
+ if (indexPath.row == 1 ) {
139
+ ShopAddressCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_ShopAddressCell forIndexPath: indexPath];
140
+ cell.locationF .text = [[self .locations valueForKey: @" name" ] componentsJoinedByString: @" - " ];
141
+ return cell;
142
+ }else {
143
+ ShopOrderTextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_ShopOrderTextFieldCell forIndexPath: indexPath];
144
+
145
+ switch (indexPath.row ) {
146
+ case 0 :
147
+ {
148
+ cell.nameLabel .text = @" 收货人 *" ;
149
+ cell.textField .placeholder = @" 小王" ;
150
+ cell.textField .text = self.receiverName ;
151
+ RAC (self, receiverName) = [cell.textField.rac_textSignal takeUntil: cell.rac_prepareForReuseSignal];
152
+ break ;
153
+ }
154
+ case 2 :
155
+ {
156
+ cell.nameLabel .text = @" 详细地址 *" ;
157
+ cell.textField .placeholder = @" 省,市,县(镇),街道" ;
158
+ cell.textField .text = self.receiverAddress ;
159
+ RAC (self, receiverAddress) = [cell.textField.rac_textSignal takeUntil: cell.rac_prepareForReuseSignal];
160
+ break ;
161
+ }
162
+ case 3 :
163
+ {
164
+ cell.nameLabel .text = @" 联系电话 *" ;
165
+ cell.textField .placeholder = @" 电话" ;
166
+ cell.textField .text = self.receiverPhone ;
167
+ RAC (self, receiverPhone) = [cell.textField.rac_textSignal takeUntil: cell.rac_prepareForReuseSignal];
168
+ break ;
169
+ }
170
+ case 4 :
171
+ {
172
+ cell.nameLabel .text = @" 备注" ;
173
+ cell.textField .placeholder = @" 备注信息如:衣服码数XXL" ;
174
+ cell.textField .text = self.remark ;
175
+ RAC (self, remark) = [cell.textField.rac_textSignal takeUntil: cell.rac_prepareForReuseSignal];
176
+ break ;
177
+ }
178
+ default :
179
+ break ;
161
180
}
162
- default :
163
- break ;
181
+ return cell;
164
182
}
165
- return cell;
166
183
}
167
184
168
185
#pragma mark - UITableViewDelegate
@@ -174,15 +191,11 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte
174
191
175
192
- (CGFloat )tableView : (UITableView *)tableView heightForRowAtIndexPath : (NSIndexPath *)indexPath
176
193
{
177
- return [ShopOrderTextFieldCell cellHeight ];
178
- }
179
-
180
- - (BOOL )tableView : (UITableView *)tableView shouldHighlightRowAtIndexPath : (NSIndexPath *)indexPath
181
- {
182
- if (indexPath.section > 0 ) {
183
- return YES ;
194
+ if (indexPath.row == 1 ) {
195
+ return [ShopAddressCell cellHeight ];
196
+ }else {
197
+ return [ShopOrderTextFieldCell cellHeight ];
184
198
}
185
- return NO ;
186
199
}
187
200
188
201
- (CGFloat )tableView : (UITableView *)tableView heightForHeaderInSection : (NSInteger )section
@@ -192,8 +205,10 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege
192
205
193
206
- (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath
194
207
{
195
- [self .view endEditing: YES ];
196
208
[tableView deselectRowAtIndexPath: indexPath animated: YES ];
209
+ if (indexPath.row == 1 ) {
210
+ [self goToLocationVC ];
211
+ }
197
212
}
198
213
199
214
#pragma mark - UITextFieldDelegate
@@ -214,6 +229,19 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
214
229
[self .view endEditing: YES ];
215
230
}
216
231
232
+ #pragma mark location
233
+
234
+ - (void )goToLocationVC {
235
+ LocationViewController *vc = [LocationViewController new ];
236
+ vc.originalSelectedList = [_locations valueForKey: @" id" ];
237
+
238
+ __weak typeof (self) weakSelf = self;
239
+ vc.complateBlock = ^(NSArray *selectedList){
240
+ weakSelf.locations = selectedList;
241
+ [weakSelf.myTableView reloadData ];
242
+ };
243
+ [self .navigationController pushViewController: vc animated: YES ];
244
+ }
217
245
218
246
#pragma mark-
219
247
#pragma mark---------------------- AlertView ---------------------------
@@ -225,7 +253,7 @@ - (void)showPwdAlertView
225
253
[_pwdAlertView show ];
226
254
}
227
255
228
- - (void )alertView : (UIAlertView *)alertView clickedButtonAtIndex : (NSInteger )buttonIndex {
256
+ - (void )alertView : (UIAlertView *)alertView didDismissWithButtonIndex : (NSInteger )buttonIndex {
229
257
230
258
if (alertView.firstOtherButtonIndex == buttonIndex) {
231
259
UITextField *field = [alertView textFieldAtIndex: 0 ];
@@ -245,58 +273,35 @@ - (void)exchangeActionRquest:(NSString *)pwd
245
273
[self .view beginLoading ];
246
274
[[Coding_NetAPIManager sharedManager ] request_shop_check_passwordWithpwd: pwd andBlock: ^(id data, NSError *error) {
247
275
if (!error) {
248
-
249
- ShopOrderTextFieldCell *nameCell = [weakSelf.myTableView cellForRowAtIndexPath: [NSIndexPath indexPathForItem: 0 inSection: 0 ]];
250
- ShopOrderTextFieldCell *addressCell = [weakSelf.myTableView cellForRowAtIndexPath: [NSIndexPath indexPathForItem: 1 inSection: 0 ]];
251
- ShopOrderTextFieldCell *phoneCell = [weakSelf.myTableView cellForRowAtIndexPath: [NSIndexPath indexPathForItem: 2 inSection: 0 ]];
252
- ShopOrderTextFieldCell *remarkCell = [weakSelf.myTableView cellForRowAtIndexPath: [NSIndexPath indexPathForItem: 3 inSection: 0 ]];
253
-
254
- NSString *receiverName = nameCell.textField .text ;
255
- NSString *receiverAddress = addressCell.textField .text ;
256
- NSString *receiverPhone = phoneCell.textField .text ;
257
- NSString *remark = remarkCell.textField .text ;
258
- NSMutableDictionary *mparms = [NSMutableDictionary dictionary ];
259
- if (![receiverName isEmpty ]) {
260
- [mparms setObject: receiverName forKey: @" receiverName" ];
261
- }
262
- if (![receiverAddress isEmpty ]) {
263
- [mparms setObject: receiverAddress forKey: @" receiverAddress" ];
264
- }
265
- if (![receiverPhone isEmpty ]) {
266
- [mparms setObject: receiverPhone forKey: @" receiverPhone" ];
267
- }
268
- if (![remark isEmpty ]) {
269
- [mparms setObject: remark forKey: @" remark" ];
270
- }else
271
- [mparms setObject: @" " forKey: @" remark" ];
272
-
273
- if (![_shopGoods.giftId isEmpty ]) {
274
- [mparms setObject: _shopGoods.id forKey: @" giftId" ];
275
- }
276
- if (![pwd isEmpty ]) {
277
- [mparms setObject: [pwd sha1Str ] forKey: @" password" ];
276
+ NSMutableDictionary *mparms = @{}.mutableCopy ;
277
+ mparms[@" receiverName" ] = _receiverName;
278
+ if (_locations.count >= 2 ) {
279
+ mparms[@" province" ] = _locations[0 ][@" id" ];
280
+ mparms[@" city" ] = _locations[1 ][@" id" ];
281
+ mparms[@" district" ] = _locations.count >= 3 ? _locations[2 ][@" id" ]: nil ;
282
+ }else {
283
+ mparms[@" province" ] =
284
+ mparms[@" city" ] =
285
+ mparms[@" district" ] = nil ;
278
286
}
279
287
288
+ mparms[@" receiverAddress" ] = _receiverAddress;
289
+ mparms[@" receiverPhone" ] = _receiverPhone;
290
+ mparms[@" remark" ] = _remark;
291
+ mparms[@" giftId" ] = _shopGoods.id ;
292
+ mparms[@" password" ] = [pwd sha1Str ];
293
+
280
294
[[Coding_NetAPIManager sharedManager ] request_shop_exchangeWithParms: mparms andBlock: ^(id data, NSError *error) {
281
- [self .view endLoading ];
295
+ [weakSelf .view endLoading ];
282
296
if (!error) {
283
297
[NSObject showHudTipStr: @" 恭喜你,提交订单成功!" ];
284
- // [self.navigationController popViewControllerAnimated:YES];
285
298
ShopOrderViewController *orderViewController = [[ShopOrderViewController alloc ] init ];
286
- [self .navigationController pushViewController: orderViewController animated: YES ];
299
+ [weakSelf .navigationController pushViewController: orderViewController animated: YES ];
287
300
288
- }else
289
- {
290
- [self .view endLoading ];
291
-
292
- [NSObject showError: error];
293
301
}
294
302
}];
295
- }else
296
- {
297
- [self .view endLoading ];
298
-
299
- [NSObject showHudTipStr: @" 密码不正确" ];
303
+ }else {
304
+ [weakSelf.view endLoading ];
300
305
}
301
306
}];
302
307
}
0 commit comments