1212#import " ShopOrderTextFieldCell.h"
1313#import " ShopGoodsInfoView.h"
1414#import " UIView+Common.h"
15+ #import " LocationViewController.h"
16+ #import " ShopAddressCell.h"
1517
1618#define kCellIdentifier_ShopOrderTextFieldCell @" ShopOrderTextFieldCell.h"
1719
@@ -22,6 +24,8 @@ @interface ExchangeGoodsViewController () <UITableViewDataSource, UITableViewDel
2224@property (strong , nonatomic ) TPKeyboardAvoidingTableView *myTableView;
2325@property (strong , nonatomic ) UIButton *shopOrderBtn;
2426
27+ @property (strong , nonatomic ) NSString *receiverName, *receiverAddress, *receiverPhone, *remark;
28+ @property (strong , nonatomic ) NSArray *locations;
2529@end
2630
2731@implementation ExchangeGoodsViewController
@@ -38,20 +42,19 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
3842
3943- (void )orderCommitAction : (UIButton *)button
4044{
41- ShopOrderTextFieldCell *receiveName = [_myTableView cellForRowAtIndexPath: [NSIndexPath indexPathForItem: 0 inSection: 0 ]];
42- if ([receiveName.textField.text isEmpty ]) {
45+ if ([_receiverName isEmpty ]) {
4346 [NSObject showHudTipStr: @" 收货人名字很重要" ];
4447 return ;
4548 }
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 ]) {
4954 [NSObject showHudTipStr: @" 详细地址也很重要" ];
5055 return ;
5156 }
52-
53- ShopOrderTextFieldCell *phone = [_myTableView cellForRowAtIndexPath: [NSIndexPath indexPathForItem: 2 inSection: 0 ]];
54- if ([phone.textField.text isEmpty ]) {
57+ if ([_receiverPhone isEmpty ]) {
5558 [NSObject showHudTipStr: @" 联系电话非常重要" ];
5659 return ;
5760 }
@@ -75,6 +78,7 @@ - (void)viewDidLoad {
7578 tableView.delegate = self;
7679 tableView.dataSource = self;
7780 [tableView registerClass: [ShopOrderTextFieldCell class ] forCellReuseIdentifier: kCellIdentifier_ShopOrderTextFieldCell ];
81+ [tableView registerNib: [UINib nibWithNibName: kCellIdentifier_ShopAddressCell bundle: nil ] forCellReuseIdentifier: kCellIdentifier_ShopAddressCell ];
7882 tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
7983 tableView.separatorColor = [UIColor colorWithHexString: @" 0xFFDDDDDD" ];
8084 tableView.separatorInset = UIEdgeInsetsMake (0 , 12 , 0 , 12 );
@@ -125,44 +129,57 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
125129
126130- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section
127131{
128- NSInteger row = 4 ;
132+ NSInteger row = 5 ;
129133 return row;
130134}
131135
132136- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath
133137{
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 ;
161180 }
162- default :
163- break ;
181+ return cell;
164182 }
165- return cell;
166183}
167184
168185#pragma mark - UITableViewDelegate
@@ -174,15 +191,11 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte
174191
175192- (CGFloat)tableView : (UITableView *)tableView heightForRowAtIndexPath : (NSIndexPath *)indexPath
176193{
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 ];
184198 }
185- return NO ;
186199}
187200
188201- (CGFloat)tableView : (UITableView *)tableView heightForHeaderInSection : (NSInteger )section
@@ -192,8 +205,10 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege
192205
193206- (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath
194207{
195- [self .view endEditing: YES ];
196208 [tableView deselectRowAtIndexPath: indexPath animated: YES ];
209+ if (indexPath.row == 1 ) {
210+ [self goToLocationVC ];
211+ }
197212}
198213
199214#pragma mark - UITextFieldDelegate
@@ -214,6 +229,19 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
214229 [self .view endEditing: YES ];
215230}
216231
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+ }
217245
218246#pragma mark-
219247#pragma mark---------------------- AlertView ---------------------------
@@ -225,7 +253,7 @@ - (void)showPwdAlertView
225253 [_pwdAlertView show ];
226254}
227255
228- - (void )alertView : (UIAlertView *)alertView clickedButtonAtIndex : (NSInteger )buttonIndex {
256+ - (void )alertView : (UIAlertView *)alertView didDismissWithButtonIndex : (NSInteger )buttonIndex {
229257
230258 if (alertView.firstOtherButtonIndex == buttonIndex) {
231259 UITextField *field = [alertView textFieldAtIndex: 0 ];
@@ -245,58 +273,35 @@ - (void)exchangeActionRquest:(NSString *)pwd
245273 [self .view beginLoading ];
246274 [[Coding_NetAPIManager sharedManager ] request_shop_check_passwordWithpwd: pwd andBlock: ^(id data, NSError *error) {
247275 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 ;
278286 }
279287
288+ mparms[@" receiverAddress" ] = _receiverAddress;
289+ mparms[@" receiverPhone" ] = _receiverPhone;
290+ mparms[@" remark" ] = _remark;
291+ mparms[@" giftId" ] = _shopGoods.id ;
292+ mparms[@" password" ] = [pwd sha1Str ];
293+
280294 [[Coding_NetAPIManager sharedManager ] request_shop_exchangeWithParms: mparms andBlock: ^(id data, NSError *error) {
281- [self .view endLoading ];
295+ [weakSelf .view endLoading ];
282296 if (!error) {
283297 [NSObject showHudTipStr: @" 恭喜你,提交订单成功!" ];
284- // [self.navigationController popViewControllerAnimated:YES];
285298 ShopOrderViewController *orderViewController = [[ShopOrderViewController alloc ] init ];
286- [self .navigationController pushViewController: orderViewController animated: YES ];
299+ [weakSelf .navigationController pushViewController: orderViewController animated: YES ];
287300
288- }else
289- {
290- [self .view endLoading ];
291-
292- [NSObject showError: error];
293301 }
294302 }];
295- }else
296- {
297- [self .view endLoading ];
298-
299- [NSObject showHudTipStr: @" 密码不正确" ];
303+ }else {
304+ [weakSelf.view endLoading ];
300305 }
301306 }];
302307}
0 commit comments