hjx 1 рік тому
батько
коміт
748f1703de

+ 6 - 0
TOKTOK/TOKTOK.xcodeproj/project.pbxproj

@@ -135,6 +135,7 @@
 		84CADD132A1CA7F1004B0600 /* t_xstt_city_data.db in Resources */ = {isa = PBXBuildFile; fileRef = 84CADD122A1CA7F1004B0600 /* t_xstt_city_data.db */; };
 		84CADD162A1DEEF9004B0600 /* XSTTBlindBoxToOrderModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CADD152A1DEEF9004B0600 /* XSTTBlindBoxToOrderModel.m */; };
 		84CADD192A1F0DD5004B0600 /* XSTTBlindBoxDetailsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CADD182A1F0DD5004B0600 /* XSTTBlindBoxDetailsModel.m */; };
+		84CADD1C2A1F52DF004B0600 /* XSTTAddressModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CADD1B2A1F52DF004B0600 /* XSTTAddressModel.m */; };
 		84CD5AF929F7719E00531BB6 /* AppDelegate+XSTTPushNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CD5AF829F7719E00531BB6 /* AppDelegate+XSTTPushNotification.m */; };
 		84CD5AFD2A04E7BE00531BB6 /* XSTTBeerDetailsRadarMapView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CD5AFC2A04E7BE00531BB6 /* XSTTBeerDetailsRadarMapView.m */; };
 		84D3FCDD268C45DE00D61979 /* UIControl+XSTTButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D3FCDC268C45DE00D61979 /* UIControl+XSTTButton.m */; };
@@ -421,6 +422,8 @@
 		84CADD152A1DEEF9004B0600 /* XSTTBlindBoxToOrderModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XSTTBlindBoxToOrderModel.m; sourceTree = "<group>"; };
 		84CADD172A1F0DD5004B0600 /* XSTTBlindBoxDetailsModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XSTTBlindBoxDetailsModel.h; sourceTree = "<group>"; };
 		84CADD182A1F0DD5004B0600 /* XSTTBlindBoxDetailsModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XSTTBlindBoxDetailsModel.m; sourceTree = "<group>"; };
+		84CADD1A2A1F52DF004B0600 /* XSTTAddressModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XSTTAddressModel.h; sourceTree = "<group>"; };
+		84CADD1B2A1F52DF004B0600 /* XSTTAddressModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XSTTAddressModel.m; sourceTree = "<group>"; };
 		84CD5AF729F7719E00531BB6 /* AppDelegate+XSTTPushNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AppDelegate+XSTTPushNotification.h"; sourceTree = "<group>"; };
 		84CD5AF829F7719E00531BB6 /* AppDelegate+XSTTPushNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "AppDelegate+XSTTPushNotification.m"; sourceTree = "<group>"; };
 		84CD5AFB2A04E7BE00531BB6 /* XSTTBeerDetailsRadarMapView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XSTTBeerDetailsRadarMapView.h; sourceTree = "<group>"; };
@@ -1036,6 +1039,8 @@
 				84287A7D29E146C60037FD51 /* XSTTAddressListTableViewController.m */,
 				84287A7F29E14FC20037FD51 /* XSTTAddressListTableViewCell.h */,
 				84287A8029E14FC20037FD51 /* XSTTAddressListTableViewCell.m */,
+				84CADD1A2A1F52DF004B0600 /* XSTTAddressModel.h */,
+				84CADD1B2A1F52DF004B0600 /* XSTTAddressModel.m */,
 			);
 			path = AddressList;
 			sourceTree = "<group>";
@@ -1583,6 +1588,7 @@
 				840EE8FE28F56C50000CC9DF /* XSTTRefreshHeader.m in Sources */,
 				840EE90128F56E08000CC9DF /* XSTTSocialCircleListModel.m in Sources */,
 				840EE90728F5704C000CC9DF /* UITableView+XSTTDefault.m in Sources */,
+				84CADD1C2A1F52DF004B0600 /* XSTTAddressModel.m in Sources */,
 				84685AE3269C2019002AA521 /* XSTTBreweryListViewCell.m in Sources */,
 				840EE92029012E2F000CC9DF /* XSTTStoreListModel.m in Sources */,
 				84D748D926841F5300AD7C92 /* XSTTNetworkManager.m in Sources */,

+ 2 - 1
TOKTOK/TOKTOK/Mine/Address/AddressList/XSTTAddressListTableViewCell.h

@@ -6,6 +6,7 @@
 //
 
 #import <UIKit/UIKit.h>
+#import "XSTTAddressModel.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
@@ -18,7 +19,7 @@ typedef NS_ENUM(NSUInteger, XSTTAddressListTableViewCellActionType) {
 
 @property (nonatomic, strong) void (^xstt_cellAction)(XSTTAddressListTableViewCellActionType type, XSTTAddressListTableViewCell *cell);
 
-- (void)reloadData:(NSIndexPath *)data status:(bool)del;
+- (void)reloadData:(XSTTAddressModel *)data status:(bool)del;
 
 @end
 

+ 7 - 8
TOKTOK/TOKTOK/Mine/Address/AddressList/XSTTAddressListTableViewCell.m

@@ -123,16 +123,15 @@
     _xstt_cellAction(XSTTAddressListTableViewCellActionTypeEdit, self);
 }
 
-- (void)reloadData:(NSIndexPath *)data status:(bool)del {
-    _icon.text = @"叶";
-    _phone.text = @"158 1234 5678";
-    if (data.row % 2 == 0) {
-        _name.text = @"叶良辰";
-        [_address setAttributedStringWithText:@"广东省广州市天河区黄埔大道中660号汇金国际金融中心B栋" lineSpacing:2.5];
+- (void)reloadData:(XSTTAddressModel *)data status:(bool)del {
+    _name.text = data.xstt_name;
+    if (data.xstt_name.length > 0) {
+        _icon.text = [data.xstt_name substringWithRange:NSMakeRange(0, 1)];
     } else {
-        _name.text = @"叶良辰叶良辰";
-        [_address setAttributedStringWithText:@"广东省广州市天河区黄埔大道中" lineSpacing:2.5];
+        _icon.text = @"";
     }
+    _phone.text = data.xstta_showPhone;
+    [_address setAttributedStringWithText:data.xstt_fullAddress lineSpacing:2.5];
     
     if (del) {
         _deleteButton.hidden = false;

+ 3 - 0
TOKTOK/TOKTOK/Mine/Address/AddressList/XSTTAddressListTableViewController.h

@@ -11,7 +11,10 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface XSTTAddressListTableViewController : XSTTTableViewController
 
+@property (nonatomic, strong) void (^xstt_dataChange)(NSInteger dataCount);
+
 - (void)changeStatus:(bool)del;
+- (void)getList;
 
 @end
 

+ 71 - 4
TOKTOK/TOKTOK/Mine/Address/AddressList/XSTTAddressListTableViewController.m

@@ -10,9 +10,12 @@
 #import "XSTTAddressListTableViewCell.h"
 #import "XSTTConfirmAlertViewController.h"
 #import "XSTTEditAddressViewController.h"
+#import "UIViewController+XSTTNetworkManager.h"
+#import "XSTTAddressModel.h"
 
 @interface XSTTAddressListTableViewController () {
     bool _delete;
+    NSMutableArray<XSTTAddressModel *> *_dataArray;
 }
 
 @end
@@ -29,9 +32,11 @@
     [super viewDidLoad];
     [self initData];
     [self setupTableView];
+    [self getList];
 }
 
 - (void)initData {
+    _dataArray = NSMutableArray.new;
     _delete = false;
 }
 
@@ -42,9 +47,19 @@
 }
 
 - (void)deleteAction:(XSTTAddressListTableViewCell *)cell {
+    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
+    if (indexPath.row >= _dataArray.count) return;
     XSTTConfirmAlertViewController *vc = [XSTTConfirmAlertViewController alertWithTitle:@"确定要删除该地址吗?" content:nil];
+    @weakify(self)
     [vc setConfirmButtonTitle:@"确认" titleColor:nil action:^{
-        
+        @strongify(self)
+        [self deleteAddressWithId:self->_dataArray[indexPath.row].xstt_userAddressId];
+        [self->_dataArray removeObjectAtIndex:indexPath.row];
+        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom];
+        if (self->_dataArray.count == 0) {
+            self.tableView.backgroundColor = xstt_FFFFFF_color(1.f);
+            [self.tableView setDefaultFootViewWithError:nil image:jxh_getImage(address_list_default) tips:@"你还未添加收货地址" height:jxh_viewHeight(self.view) - jxh_safeInsets(self.view).top - jxh_safeInsets(self.view).bottom action:nil];
+        }
     }];
     [vc setCancelButtonTitle:@"取消" titleColor:nil action:^{
         
@@ -53,12 +68,63 @@
 }
 
 - (void)editAction:(XSTTAddressListTableViewCell *)cell {
+    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
+    if (indexPath.row >= _dataArray.count) return;
     XSTTEditAddressViewController *vc = XSTTEditAddressViewController.new;
-    vc.xstt_data = NSObject.new;
+    @weakify(self)
+    vc.xstt_finishEdit = ^{
+        @strongify(self)
+        [self getList];
+    };
+    vc.xstt_addressId = _dataArray[indexPath.row].xstt_userAddressId;
     [self.navigationController pushViewController:vc animated:true];
 }
 
 #pragma mark - Network Action
+- (void)getList {
+    [self networkUseMethod:XSTTNetworkMethodGET loadingTips:XSTTGetDataLoadingCommonTips isLogin:true signKey:XSTTNetworkSignKeyApp url:xstt_appUrl(XSTTURLGetAddressList) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id  _Nullable data) {
+        [self getListSuccesss:data];
+        return @"";
+    } failure:^NSString * _Nullable(NSError * _Nonnull error, id  _Nullable data) {
+        [self getListFailure:error];
+        return XSTTGetDataFailureCommonTips;
+    }];
+}
+
+- (void)getListSuccesss:(id)data {
+    _dataArray = [XSTTAddressModel getModelListWithArray:data[@"data"]].mutableCopy;
+    [self.tableView reloadData];
+    if (_dataArray.count == 0) {
+        self.tableView.backgroundColor = xstt_FFFFFF_color(1.f);
+        [self.tableView setDefaultFootViewWithError:nil image:jxh_getImage(address_list_default) tips:@"你还未添加收货地址" height:jxh_viewHeight(self.view) - jxh_safeInsets(self.view).top - jxh_safeInsets(self.view).bottom action:nil];
+    } else {
+        self.tableView.backgroundColor = xstt_F7F7F7_color();
+        [self.tableView removeDefaultFootView];
+    }
+    _xstt_dataChange(_dataArray.count);
+}
+
+- (void)getListFailure:(NSError *)error {
+    if (_dataArray.count == 0) {
+        self.tableView.backgroundColor = xstt_FFFFFF_color(1.f);
+        @weakify(self)
+        [self.tableView setDefaultFootViewWithError:error image:nil tips:nil height:jxh_viewHeight(self.view) - jxh_safeInsets(self.view).top - jxh_safeInsets(self.view).bottom action:^{
+            @strongify(self)
+            [self getList];
+        }];
+    }
+}
+
+- (void)deleteAddressWithId:(NSString *)addressId {
+    [self networkUseMethod:XSTTNetworkMethodPOST loadingTips:nil isLogin:true signKey:XSTTNetworkSignKeyApp url:xstt_appUrl(XSTTURLDeleteAddress) urlParameters:nil parameters:^NSDictionary * _Nonnull{
+        return @{@"userAddressId": addressId};
+    } success:^NSString * _Nullable(NSError * _Nonnull error, id  _Nullable data) {
+        return nil;
+    } failure:^NSString * _Nullable(NSError * _Nonnull error, id  _Nullable data) {
+        return nil;
+    }];
+}
+
 #pragma mark - Delegate & DataSource
 
 static NSString * const reuseIdentifier = @"XSTTAddressListTableViewCell";
@@ -83,12 +149,12 @@ static NSString * const reuseIdentifier = @"XSTTAddressListTableViewCell";
             }
         };
     }
-    [cell reloadData:indexPath status:_delete];
+    [cell reloadData:_dataArray[indexPath.row] status:_delete];
     return cell;
 }
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    return 10;
+    return _dataArray.count;
 }
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -96,6 +162,7 @@ static NSString * const reuseIdentifier = @"XSTTAddressListTableViewCell";
 }
 
 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
+    if (_dataArray.count == 0) return jxh_onePixe();
     return 12;
 }
 

+ 23 - 5
TOKTOK/TOKTOK/Mine/Address/AddressList/XSTTAddressListViewController.m

@@ -12,6 +12,7 @@
 
 @interface XSTTAddressListViewController () {
     XSTTAddressListTableViewController *_tableVC;
+    UIButton *_manageButton;
 }
 
 @end
@@ -29,8 +30,20 @@
     [_tableVC changeStatus:sender.selected];
 }
 
+- (void)tableViewDataChange:(NSInteger)dataCount {
+    _manageButton.hidden = dataCount == 0;
+    _manageButton.selected = false;
+    [_tableVC changeStatus:_manageButton.selected];
+}
+
 - (void)newAction {
-    [self.navigationController pushViewController:XSTTEditAddressViewController.new animated:true];
+    XSTTEditAddressViewController *vc = XSTTEditAddressViewController.new;
+    @weakify(self)
+    vc.xstt_finishEdit = ^{
+        @strongify(self)
+        [self->_tableVC getList];
+    };
+    [self.navigationController pushViewController:vc animated:true];
 }
 
 #pragma mark - Network Action
@@ -44,6 +57,11 @@
 
 - (void)createTableVC {
     _tableVC = XSTTAddressListTableViewController.new;
+    @weakify(self)
+    _tableVC.xstt_dataChange = ^(NSInteger dataCount) {
+        @strongify(self)
+        [self tableViewDataChange:dataCount];
+    };
     [self addChildViewController:_tableVC];
     [self.view addSubview:_tableVC.tableView];
     [_tableVC.tableView makeConstraints:^(JXHConstraintMaker *make) {
@@ -75,10 +93,10 @@
 }
 
 - (void)setupNavigationBar {
-    UIButton *manageButton = [UIButton convenienceWithFont:xstt_font(17) target:self action:@selector(manageAction:)];
-    [manageButton setTitle:@"管理" titleColor:xstt_000000_color(0.87) state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
-    [manageButton setTitle:@"完成" titleColor:xstt_000000_color(0.87) state:JXHButtonControlStateSelected | JXHButtonControlStateSelectedAndHighlighted];
-    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:manageButton];
+    _manageButton = [UIButton convenienceWithFont:xstt_font(17) target:self action:@selector(manageAction:)];
+    [_manageButton setTitle:@"管理" titleColor:xstt_000000_color(0.87) state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
+    [_manageButton setTitle:@"完成" titleColor:xstt_000000_color(0.87) state:JXHButtonControlStateSelected | JXHButtonControlStateSelectedAndHighlighted];
+    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_manageButton];
 }
 
 @end

+ 35 - 0
TOKTOK/TOKTOK/Mine/Address/AddressList/XSTTAddressModel.h

@@ -0,0 +1,35 @@
+//
+//  XSTTAddressModel.h
+//  TOKTOK
+//
+//  Created by shanp on 2023/5/25.
+//
+
+#import "XSTTBaseNetworkModel.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface XSTTAddressDistrictModel : XSTTBaseNetworkModel
+
+@property (nonatomic, strong) NSString *xstt_districtId;
+@property (nonatomic, strong) NSString *xstt_districtName;
+@property (nonatomic, strong) NSString *xstt_pid;
+
+@end
+
+@interface XSTTAddressModel : XSTTBaseNetworkModel
+
+@property (nonatomic, strong) NSString *xstt_userAddressId;
+@property (nonatomic, strong) NSString *xstt_name;
+@property (nonatomic, strong) NSString *xstt_phone;
+@property (nonatomic, strong) NSString *xstt_defaultAddress;
+@property (nonatomic, strong) NSString *xstta_showPhone;
+//列表用
+@property (nonatomic, strong) NSString *xstt_fullAddress;
+//详情用
+@property (nonatomic, strong) NSString *xstt_detailAddress;
+@property (nonatomic, strong) NSArray<XSTTAddressDistrictModel *> *xstt_districtList;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 29 - 0
TOKTOK/TOKTOK/Mine/Address/AddressList/XSTTAddressModel.m

@@ -0,0 +1,29 @@
+//
+//  XSTTAddressModel.m
+//  TOKTOK
+//
+//  Created by shanp on 2023/5/25.
+//
+
+#import "XSTTAddressModel.h"
+
+@implementation XSTTAddressDistrictModel
+
+@end
+
+@implementation XSTTAddressModel
+
+- (id)GETxstt_districtListWithDictionary:(nullable NSDictionary *)dic key:(NSString *)key {
+    return [XSTTAddressDistrictModel getModelListWithArray:dic[key]];
+}
+
+- (bool)handleAdditionalProperty {
+    if (_xstt_phone.length == 11) {
+        _xstta_showPhone = [NSString stringWithFormat:@"%@ %@ %@", [_xstt_phone substringWithRange:NSMakeRange(0, 3)], [_xstt_phone substringWithRange:NSMakeRange(3, 4)], [_xstt_phone substringWithRange:NSMakeRange(7, 4)]];
+    } else {
+        _xstta_showPhone = _xstt_phone;
+    }
+    return true;
+}
+
+@end

+ 2 - 1
TOKTOK/TOKTOK/Mine/Address/EditAddress/XSTTEditAddressViewController.h

@@ -11,7 +11,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface XSTTEditAddressViewController : UIViewController
 
-@property (nonatomic, strong, nullable) id xstt_data;
+@property (nonatomic, strong, nullable) NSString *xstt_addressId;
+@property (nonatomic, strong) void (^xstt_finishEdit)(void);
 
 @end
 

+ 322 - 8
TOKTOK/TOKTOK/Mine/Address/EditAddress/XSTTEditAddressViewController.m

@@ -10,8 +10,15 @@
 #import <UITextView+JXHPlaceHolder.h>
 #import "XSTTVerificationProfile.h"
 #import <JXHTextField.h>
+#import "XSTTPickerViewController.h"
+#import <JXHFMDBManager.h>
+#import "XSTTSQLProfile.h"
+#import "XSTTConfirmAlertViewController.h"
+#import "XSTTAddressModel.h"
+#import "UIView+XSTTLoadingTipsView.h"
+#import "UIViewController+XSTTNetworkManager.h"
 
-@interface XSTTEditAddressViewController ()<UITextViewDelegate, UITextFieldDelegate, UIScrollViewDelegate> {
+@interface XSTTEditAddressViewController ()<UITextViewDelegate, UITextFieldDelegate, UIScrollViewDelegate, XSTTPickerViewDelegate> {
     UIScrollView *_bgView;
     UIButton *_saveButton;
     JXHTextField *_name;
@@ -21,6 +28,12 @@
     UISwitch *_default;
     NSString *_lastText;
     NSString *_tempText;
+    
+    NSMutableArray<NSArray<NSString *> *> *_areaArray;
+    XSTTAddressModel *_data;
+    
+    NSMutableArray<XSTTAddressDistrictModel *>  *_chooseAreaData;
+    NSMutableArray<NSNumber *>  *_chooseIndexs;
 }
 
 @end
@@ -29,14 +42,276 @@
 
 - (void)viewDidLoad {
     [super viewDidLoad];
+    [self initData];
+    if (_xstt_addressId) {
+        [self getData];
+    } else {
+        [self setNewData];
+    }
+}
+
+- (void)setNewData {
+    _data = XSTTAddressModel.new;
     [self setupUI];
+    [self setCityData];
+}
+
+- (void)initData {
+    _areaArray = NSMutableArray.new;
+    NSArray *p = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"name" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+        return [database executeQuery:@"select * from t_xstt_city_province"];
+    }];
+    if (p.count == 0) {
+        [self noCityDataWarning];
+        return;
+    }
+    [_areaArray addObject:p];
 }
 
 #pragma mark - Action
 - (void)saveAction {
+    if (_name.text.length < XSTTNameMinWords) {
+        [self.view showToastWithTitle:@"请正确输入收货人"];
+        return;
+    }
+    NSMutableString *phone = [NSMutableString stringWithString:_number.text];
+    [phone replaceOccurrencesOfString:@" " withString:@"" options:1 range:NSMakeRange(0, phone.length)];
+    if (phone.length != XSTTPhoneNumberWords || !jxh_isNumber(phone)) {
+        [self.view showToastWithTitle:@"请正确输入手机号码"];
+        return;
+    }
+    if (_chooseAreaData.count != 3) {
+        [self.view showToastWithTitle:@"请选择省市区"];
+        return;
+    }
+    if (_address.text.length <= 0) {
+        [self.view showToastWithTitle:@"请输入详细地址"];
+        return;
+    }
+    [self updateDataWithPhone:phone];
+}
+
+- (void)noCityDataWarning {
+    XSTTConfirmAlertViewController *vc = [XSTTConfirmAlertViewController alertWithTitle:@"城市数据缺失请重新打开App" content:nil];
+    @weakify(self)
+    [vc setConfirmButtonTitle:nil titleColor:nil action:^{
+        @strongify(self)
+        [self.navigationController popViewControllerAnimated:true];
+    }];
+    [self presentViewController:vc animated:true completion:nil];
+}
+
+- (void)setCityData {
+    NSArray *p = _areaArray[0];
+    if (_data.xstt_districtList.count == 3) {
+        _chooseAreaData = _data.xstt_districtList.mutableCopy;
+        NSInteger pI = [p indexOfObject:_chooseAreaData[0].xstt_districtName];
+        NSArray *c = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"name" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+            return [database executeQuery:@"select * from t_xstt_city_city where pid = ?", self->_chooseAreaData[0].xstt_districtId];
+        }];
+        if (c.count == 0) {
+            [self noCityDataWarning];
+            return;
+        }
+        _areaArray[1] = c;
+        NSInteger cI = [c indexOfObject:_chooseAreaData[1].xstt_districtName];
+        NSArray *d = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"name" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+            return [database executeQuery:@"select * from t_xstt_city_district where pid = ?", self->_chooseAreaData[1].xstt_districtId];
+        }];
+        if (d.count == 0) {
+            [self noCityDataWarning];
+            return;
+        }
+        _areaArray[2] = d;
+        NSInteger dI = [d indexOfObject:_chooseAreaData[2].xstt_districtName];
+        _chooseIndexs = @[@(pI), @(cI), @(dI)].mutableCopy;
+        return;
+    }
+    _chooseAreaData = NSMutableArray.new;
+    NSArray *ids = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"id" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+        return [database executeQuery:@"select * from t_xstt_city_province where name = ?", p[0]];
+    }];
+    if (ids.count == 0) {
+        [self noCityDataWarning];
+        return;
+    }
+    NSArray *c = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"name" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+        return [database executeQuery:@"select * from t_xstt_city_city where pid = ?", ids[0]];
+    }];
+    if (c.count == 0) {
+        [self noCityDataWarning];
+        return;
+    }
+    _areaArray[1] = c;
+    ids = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"id" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+        return [database executeQuery:@"select * from t_xstt_city_city where name = ?", c[0]];
+    }];
+    if (ids.count == 0) {
+        [self noCityDataWarning];
+        return;
+    }
+    NSArray *d = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"name" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+        return [database executeQuery:@"select * from t_xstt_city_district where pid = ?", ids[0]];
+    }];
+    if (d.count == 0) {
+        [self noCityDataWarning];
+        return;
+    }
+    _areaArray[2] = d;
+    _chooseIndexs = @[@0, @0, @0].mutableCopy;
+}
+
+- (void)chooseArea {
+    XSTTPickerViewController *vc = XSTTPickerViewController.new;
+    vc.xstt_pickerDelegate = self;
+    vc.xstt_dataArray = _areaArray;
+    @weakify(self)
+    vc.xstt_finishChose = ^(XSTTPickerView * _Nonnull pickerView) {
+        @strongify(self)
+        [self completeToChoseAreaWithPickerView:pickerView];
+    };
+    vc.xstt_willDisplay = ^(XSTTPickerView * _Nonnull pickerView) {
+        @strongify(self)
+        [pickerView setRow:self->_chooseIndexs[0].integerValue inComponent:0 animated:false];
+        [pickerView setRow:self->_chooseIndexs[1].integerValue inComponent:1 animated:false];
+        [pickerView setRow:self->_chooseIndexs[2].integerValue inComponent:2 animated:false];
+    };
+    [self presentViewController:vc animated:false completion:nil];
+}
+
+- (void)completeToChoseAreaWithPickerView:(XSTTPickerView *)pickerView {
+    _chooseIndexs = @[pickerView.xstt_choseArray[0], pickerView.xstt_choseArray[1], pickerView.xstt_choseArray[2]].mutableCopy;
+    NSArray *array = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:nil condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+        return [database executeQuery:@"select * from t_xstt_city_province where name = ?", self->_areaArray[0][pickerView.xstt_choseArray[0].integerValue]];
+    }];
+    if (array.count == 0) {
+        [self noCityDataWarning];
+        return;
+    }
+    XSTTAddressDistrictModel *model = XSTTAddressDistrictModel.new;
+    model.xstt_pid = array[0][@"pid"];
+    model.xstt_districtId = array[0][@"id"];
+    model.xstt_districtName = array[0][@"name"];
+    _chooseAreaData[0] = model;
+    array = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:nil condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+        return [database executeQuery:@"select * from t_xstt_city_city where name = ?", self->_areaArray[1][pickerView.xstt_choseArray[1].integerValue]];
+    }];
+    if (array.count == 0) {
+        [self noCityDataWarning];
+        return;
+    }
+    model = XSTTAddressDistrictModel.new;
+    model.xstt_pid = array[0][@"pid"];
+    model.xstt_districtId = array[0][@"id"];
+    model.xstt_districtName = array[0][@"name"];
+    _chooseAreaData[1] = model;
+    array = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:nil condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+        return [database executeQuery:@"select * from t_xstt_city_district where name = ?", self->_areaArray[2][pickerView.xstt_choseArray[2].integerValue]];
+    }];
+    if (array.count == 0) {
+        [self noCityDataWarning];
+        return;
+    }
+    model = XSTTAddressDistrictModel.new;
+    model.xstt_pid = array[0][@"pid"];
+    model.xstt_districtId = array[0][@"id"];
+    model.xstt_districtName = array[0][@"name"];
+    _chooseAreaData[2] = model;
+    
+    _area.text = [NSString stringWithFormat:@"%@ %@ %@", _chooseAreaData[0].xstt_districtName, _chooseAreaData[1].xstt_districtName, _chooseAreaData[2].xstt_districtName];
+    _area.textColor = xstt_000000_color(0.6);
 }
 
 #pragma mark - Network Action
+- (void)getData {
+    [self networkUseMethod:XSTTNetworkMethodGET loadingTips:XSTTGetDataLoadingCommonTips isLogin:true signKey:XSTTNetworkSignKeyApp url:xstt_appUrl(XSTTURLGetAddressDetails) urlParameters:nil parameters:^NSDictionary * _Nonnull{
+        return @{@"userAddressId": self->_xstt_addressId};
+    } success:^NSString * _Nullable(NSError * _Nonnull error, id  _Nullable data) {
+        self->_data = [XSTTAddressModel getModelWithDictionary:data[@"data"]];
+        [self setupUI];
+        [self setCityData];
+        return @"";
+    } failure:^NSString * _Nullable(NSError * _Nonnull error, id  _Nullable data) {
+        self->_xstt_addressId = nil;
+        [self setNewData];
+        return XSTTGetDataFailureCommonTips;
+    }];
+}
+
+- (void)updateDataWithPhone:(NSString *)phone {
+    [self networkUseMethod:XSTTNetworkMethodPOST loadingTips:@"正在上传" isLogin:true signKey:XSTTNetworkSignKeyApp url:xstt_appUrl(_xstt_addressId ? XSTTURLUpdateAddress : XSTTURLCreateNewAddress) urlParameters:nil parameters:^NSDictionary * _Nonnull{
+        NSMutableDictionary *dic = @{@"districtId": self->_chooseAreaData[2].xstt_districtId, @"detailAddress": jxh_deleteBothSidesSpace(self->_address.text), @"defaultAddress": @(self->_default.on), @"phone": phone, @"name": jxh_deleteBothSidesSpace(self->_name.text)}.mutableCopy;
+        if (self->_xstt_addressId) { dic[@"userAddressId"] = self->_xstt_addressId; }
+        return dic;
+    } success:^NSString * _Nullable(NSError * _Nonnull error, id  _Nullable data) {
+        self->_xstt_finishEdit();
+        return @"上传成功";
+    } failure:^NSString * _Nullable(NSError * _Nonnull error, id  _Nullable data) {
+        return @"上传失败";
+    }];
+}
+
+#pragma mark - XSTTPickerViewDelegate
+- (void)pickerView:(XSTTPickerView *)pickerView didChoseRow:(NSInteger)row inComponent:(NSInteger)component {
+    if (component == 0) {
+        NSArray *p = _areaArray[0];
+        NSArray *ids = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"id" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+            return [database executeQuery:@"select * from t_xstt_city_province where name = ?", p[row]];
+        }];
+        if (ids.count == 0) {
+            [self noCityDataWarning];
+            return;
+        }
+        NSArray *c = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"name" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+            return [database executeQuery:@"select * from t_xstt_city_city where pid = ?", ids[0]];
+        }];
+        if (c.count == 0) {
+            [self noCityDataWarning];
+            return;
+        }
+        _areaArray[1] = c;
+        ids = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"id" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+            return [database executeQuery:@"select * from t_xstt_city_city where name = ?", c[0]];
+        }];
+        if (ids.count == 0) {
+            [self noCityDataWarning];
+            return;
+        }
+        NSArray *d = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"name" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+            return [database executeQuery:@"select * from t_xstt_city_district where pid = ?", ids[0]];
+        }];
+        if (d.count == 0) {
+            [self noCityDataWarning];
+            return;
+        }
+        _areaArray[2] = d;
+        _chooseIndexs = @[@(row), @0, @0].mutableCopy;
+        [pickerView reloadViewWithData:_areaArray];
+        [pickerView chooseRow:0 inComponent:1 animated:true];
+        [pickerView chooseRow:0 inComponent:2 animated:true];
+    } else if (component == 1) {
+        NSArray *c = _areaArray[1];
+        NSArray *ids = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"id" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+            return [database executeQuery:@"select * from t_xstt_city_city where name = ?", c[row]];
+        }];
+        if (ids.count == 0) {
+            [self noCityDataWarning];
+            return;
+        }
+        NSArray *d = [JXHFMDBManager searchWithPath:XSTTCityCacheDataSQL backKey:@"name" condition:^id _Nonnull(FMDatabase * _Nonnull database) {
+            return [database executeQuery:@"select * from t_xstt_city_district where pid = ?", ids[0]];
+        }];
+        if (d.count == 0) {
+            [self noCityDataWarning];
+            return;
+        }
+        _areaArray[2] = d;
+        _chooseIndexs[1] = @(row);
+        _chooseIndexs[2] = @0;
+        [pickerView reloadViewWithData:_areaArray];
+        [pickerView chooseRow:0 inComponent:2 animated:true];
+    }
+}
 
 #pragma mark - UIScrollViewDelegate
 - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
@@ -99,9 +374,36 @@
     return true;
 }
 
+- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
+    if (textField == _number) {
+        NSMutableString *num = textField.text.mutableCopy;
+        if (range.length > 0) {
+            [num replaceCharactersInRange:range withString:@""];
+        } else {
+            [num replaceCharactersInRange:range withString:string];
+        }
+        [num replaceOccurrencesOfString:@" " withString:@"" options:1 range:NSMakeRange(0, num.length)];
+        if (!jxh_isNumber(num)) return false;
+        if (num.length > 3) {
+            [num replaceCharactersInRange:NSMakeRange(3, 0) withString:@" "];
+        }
+        if (num.length > 8) {
+            [num replaceCharactersInRange:NSMakeRange(8, 0) withString:@" "];
+        }
+        if (num.length > XSTTPhoneNumberWords + 2) {
+            _number.text = [num substringWithRange:NSMakeRange(0, XSTTPhoneNumberWords + 2)];
+            return false;
+        }
+        _number.text = num;
+        return false;
+    }
+    
+    return true;
+}
+
 #pragma mark - UI
 - (void)setupUI {
-    self.title = _xstt_data == nil ? @"添加收货地址" : @"编辑收货地址";
+    self.title = _xstt_addressId == nil ? @"添加收货地址" : @"编辑收货地址";
     [self createBgView];
     [self createContentView];
     [self createBottomButton];
@@ -120,7 +422,7 @@
 }
 
 - (void)createContentView {
-    NSArray *titles = @[@"收货人", @"手机号码", @"所在地区", @"详细地址", @"详细地址"];
+    NSArray *titles = @[@"收货人", @"手机号码", @"所在地区", @"详细地址", @"设为默认地址"];
     UIView *tempView = nil;
     for (NSInteger i = 0; i < titles.count; i ++) {
         UIView *view = UIView.new;
@@ -167,6 +469,7 @@
                     make.leading.equalTo(116);
                     make.top.and.bottom.equalTo(0);
                 }];
+                if (_data.xstt_name) { _name.text = _data.xstt_name; }
             }
                 break;
             case 1: {
@@ -178,16 +481,20 @@
                 }];
                 
                 _number = [JXHTextField convenienceWithFont:xstt_font(17) placeholder:@"请输入手机号码" placeholderColor:xstt_000000_color(0.4) textColor:xstt_000000_color(0.6) clearButtonMode:UITextFieldViewModeWhileEditing returnType:UIReturnKeyDone keyboardType:UIKeyboardTypeNumberPad delegate:self];
-                _number.jxh_maxCount = XSTTPhoneNumberWords;
+                _number.jxh_maxCount = XSTTPhoneNumberWords + 2;
                 [view addSubview:_number];
                 [_number makeConstraints:^(JXHConstraintMaker *make) {
                     make.trailing.equalTo(-XSTTMargin);
                     make.leading.equalTo(num.trailing).offset(12);
                     make.top.and.bottom.equalTo(0);
                 }];
+                
+                if (_data.xstt_phone) { _number.text = _data.xstta_showPhone; }
             }
                 break;
             case 2: {
+                [view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseArea)]];
+                
                 _area = [UILabel convenienceWithFont:xstt_font(17) text:@"请选择省市区" textColor:xstt_000000_color(0.4)];
                 [view addSubview:_area];
                 [_area makeConstraints:^(JXHConstraintMaker *make) {
@@ -202,12 +509,17 @@
                     make.trailing.equalTo(-8);
                     make.centerY.equalTo(0);
                 }];
+                
+                if (_data.xstt_districtList.count == 3) {
+                    _area.text = [NSString stringWithFormat:@"%@ %@ %@", _data.xstt_districtList[0].xstt_districtName, _data.xstt_districtList[1].xstt_districtName, _data.xstt_districtList[2].xstt_districtName];
+                    _area.textColor = xstt_000000_color(0.6);
+                }
             }
                 break;
             case 3: {
                 _address = UITextView.new;
                 _address.font = xstt_font(17);
-                _address.textColor = xstt_000000_color(0.8);
+                _address.textColor = xstt_000000_color(0.6);
                 _address.enablesReturnKeyAutomatically = true;
 //                [_address setTextContainerInset:(UIEdgeInsets){12, XSTTMargin, 12, XSTTMargin}];
                 _address.textContainer.lineFragmentPadding = 0;
@@ -222,11 +534,12 @@
                     make.top.greaterThanOrEqualTo(8);
                     make.bottom.lessThanOrEqualTo(-8);
                 }];
+                if (_data.xstt_detailAddress) { _address.text = _data.xstt_detailAddress; }
             }
                 break;
             case 4: {
                 _default = UISwitch.new;
-//                [_default addTarget:self action:@selector(changeDefault) forControlEvents:UIControlEventValueChanged];
+//                [_default addTarget:self action:@selector(changeDefault:) forControlEvents:UIControlEventValueChanged];
                 _default.onTintColor = xstt_FF5700_color();
                 [view addSubview:_default];
                 [_default makeConstraints:^(JXHConstraintMaker *make) {
@@ -234,6 +547,7 @@
                     make.centerY.equalTo(0);
                     make.size.equalTo((CGSize){51, 31});
                 }];
+                if (_data.xstt_defaultAddress) { _default.on = _data.xstt_defaultAddress.boolValue; }
             }
                 break;
                 
@@ -247,8 +561,8 @@
     CGSize size = (CGSize){jxh_screenWidth() - XSTTMargin * 2, 45};
     _saveButton = [UIButton convenienceWithTarget:self action:@selector(saveAction)];
     [_saveButton setStatusType:XSTTButtonStatusTypePrimary font:xstt_mediumFont(17) size:size];
-    [_saveButton setTitle:_xstt_data == nil ? @"保存" : @"确认修改" state:JXHButtonControlStateNormal];
-    _saveButton.enabled = _xstt_data != nil;
+    [_saveButton setTitle:_xstt_addressId == nil ? @"保存" : @"确认修改" state:JXHButtonControlStateNormal];
+//    _saveButton.enabled = _xstt_addressId != nil;
     [self.view addSubview:_saveButton];
     [_saveButton makeConstraints:^(JXHConstraintMaker *make) {
         make.leading.equalTo(XSTTMargin);

+ 12 - 0
TOKTOK/TOKTOK/Mine/Mine.xcassets/Address/address_list_default.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "hema-2.pdf",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
TOKTOK/TOKTOK/Mine/Mine.xcassets/Address/address_list_default.imageset/hema-2.pdf


+ 7 - 0
TOKTOK/TOKTOK/Public/Profile/XSTTURLApiProfile.h

@@ -75,6 +75,13 @@ CONST_STRING_INTERFACE XSTTURLGetStoreList;//门店列表
 CONST_STRING_INTERFACE XSTTURLGetBlindBoxList;//盲盒列表
 CONST_STRING_INTERFACE XSTTURLGetBlindBoxDetails;//盲盒详情
 
+#pragma mark - 地址相关
+CONST_STRING_INTERFACE XSTTURLCreateNewAddress;//新增地址
+CONST_STRING_INTERFACE XSTTURLGetAddressDetails;//地址详情
+CONST_STRING_INTERFACE XSTTURLGetAddressList;//地址列表
+CONST_STRING_INTERFACE XSTTURLDeleteAddress;//删除地址
+CONST_STRING_INTERFACE XSTTURLUpdateAddress;//更新地址
+
 #pragma mark - 气泡相关
 CONST_STRING_INTERFACE XSTTURLGetCircleContentList;//获取气泡列表
 CONST_STRING_INTERFACE XSTTURLGetMineCircleContentList;//获取我发表气泡列表

+ 7 - 0
TOKTOK/TOKTOK/Public/Profile/XSTTURLApiProfile.m

@@ -111,6 +111,13 @@ CONST_STRING XSTTURLGetStoreList = @"/stores/list";//门店列表
 CONST_STRING XSTTURLGetBlindBoxList = @"/box/list";//盲盒列表
 CONST_STRING XSTTURLGetBlindBoxDetails = @"/box/detail";//盲盒详情
 
+#pragma mark - 地址相关
+CONST_STRING XSTTURLCreateNewAddress = @"/user/address/create";//新增地址
+CONST_STRING XSTTURLGetAddressDetails = @"/user/address/detail";//地址详情
+CONST_STRING XSTTURLGetAddressList = @"/user/address/list";//地址列表
+CONST_STRING XSTTURLDeleteAddress = @"/user/address/remove";//删除地址
+CONST_STRING XSTTURLUpdateAddress = @"/user/address/update";//更新地址
+
 #pragma mark - 气泡相关
 CONST_STRING XSTTURLGetCircleContentList = @"/cont/content/list";//获取气泡列表
 CONST_STRING XSTTURLGetMineCircleContentList = @"/cont/content/mine";//获取我发表气泡列表

+ 3 - 2
TOKTOK/TOKTOK/Public/View/XSTTPickerView.h

@@ -21,12 +21,13 @@ typedef NSArray<NSArray<NSString *> *> XSTTPickerViewArray;
 @interface XSTTPickerView : UIView
 
 @property (nonatomic, weak) id<XSTTPickerViewDelegate> xstt_pickerViewDelegate;
-@property (nonatomic, readonly, strong) NSArray *xstt_choseArray;
+@property (nonatomic, readonly, strong) NSArray<NSNumber *> *xstt_choseArray;
 @property (nonatomic, strong) void (^xstt_clickButton)(bool isConfirm);
 
 - (instancetype)initWithData:(XSTTPickerViewArray *)data;
 - (void)reloadViewWithData:(XSTTPickerViewArray *)data;
-- (void)chooseRow:(NSInteger)row inComponent:(NSInteger)component animated:(bool)animated;
+- (void)chooseRow:(NSInteger)row inComponent:(NSInteger)component animated:(bool)animated;//触发代理
+- (void)setRow:(NSInteger)row inComponent:(NSInteger)component animated:(bool)animated;//不触发代理
 - (NSInteger)choseRowInComponent:(NSInteger)component;
 
 @end

+ 12 - 3
TOKTOK/TOKTOK/Public/View/XSTTPickerView.m

@@ -13,7 +13,7 @@
 @interface XSTTPickerView ()<UIPickerViewDelegate, UIPickerViewDataSource> {
     XSTTPickerViewArray *_dataArray;
     NSArray *_rowCountArray;
-    NSMutableArray *_selectedArray;
+    NSMutableArray<NSNumber *> *_selectedArray;
     UIPickerView *_pickerView;
 }
 
@@ -54,6 +54,16 @@
     [self pickerView:_pickerView didSelectRow:row inComponent:component];
 }
 
+- (void)setRow:(NSInteger)row inComponent:(NSInteger)component animated:(bool)animated {
+    [_pickerView selectRow:row inComponent:component animated:animated];
+    [self setRow:row inComponent:component];
+}
+
+- (void)setRow:(NSInteger)row inComponent:(NSInteger)component {
+    _selectedArray[component] = @(row);
+    _xstt_choseArray = [_selectedArray copy];
+}
+
 - (NSInteger)choseRowInComponent:(NSInteger)component {
     return [_pickerView selectedRowInComponent:component];
 }
@@ -74,8 +84,7 @@
 
 #pragma mark - UIPickerViewDelegate & UIPickerViewDataSource
 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
-    _selectedArray[component] = @(row);
-    _xstt_choseArray = [_selectedArray copy];
+    [self setRow:row inComponent:component];
     [_xstt_pickerViewDelegate pickerView:self didChoseRow:row inComponent:component];
 }