ASSettingViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. //
  2. // ASSettingViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/7/5.
  6. //
  7. #import "ASSettingViewController.h"
  8. #import "ASSettingListCell.h"
  9. #import "ASInfomationSetController.h"
  10. #import "ASHelpListViewController.h"
  11. #import "AppDelegate.h"
  12. @interface ASSettingViewController () <UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, strong) UIView *bottomV;
  14. @property (nonatomic, strong) UILabel *versionLb;
  15. @property (nonatomic, strong) UITableView *tableV;
  16. @property (nonatomic, strong) NSArray *titleArr;
  17. @property (nonatomic, strong) NSArray *detailArr;
  18. //@property (nonatomic, strong) KWLoginedUserModel *userInfo;
  19. @end
  20. @implementation ASSettingViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.titleStr = @"Setting";
  24. [self setNavRightSearch:^{
  25. }];
  26. self.statusBgV.backgroundColor = Col_FFF;
  27. self.customNavBar.backgroundColor = Col_FFF;
  28. [self loadSubVs];
  29. // [self configData];
  30. }
  31. - (void)viewWillAppear:(BOOL)animated {
  32. [super viewWillAppear:animated];
  33. // self.userInfo = [KWLoginedManager.shareInstance getCurrentLoginedUser];
  34. [self configData];
  35. // @weakify(self);
  36. // [KWLoginedManager.shareInstance getUserInfo:^(bool flag) {
  37. // weak_self.userInfo = [KWLoginedManager.shareInstance getCurrentLoginedUser];
  38. // [weak_self configData];
  39. // }];
  40. }
  41. - (void)configData {
  42. self.titleArr = @[@"INFORMATION",
  43. @"SHIPPING ADDRESS",
  44. @"SUBSCRIBE",
  45. @"CUSTOMER SERVICE",
  46. @"HELP & SUPPORT",
  47. @"LOG OUT",
  48. @"DELETE ACCOUNT"];
  49. /*
  50. KWLoginedManager.shareInstance.isLogined ? @[@"Information",
  51. @"Shipping Address",
  52. // @"Account Settings",
  53. @"Subscribe",
  54. @"Customer Service",
  55. @"Help & Support",
  56. @"Log Out", @"Delete Account"] : @[@"Infomation",
  57. @"Shipping Address",
  58. // @"Account Settings",
  59. @"Subscribe",
  60. @"Customer Service",
  61. @"Help & Support"];
  62. */
  63. self.detailArr = @[@"", @"",@"",@"",@"",@"",@"",@""];
  64. [self.tableV reloadData];
  65. }
  66. - (void)loadSubVs {
  67. [self.view addSubview:self.tableV];
  68. [self.bottomV addSubview:self.versionLb];
  69. [self.versionLb mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.top.equalTo(self.bottomV).offset(66);
  71. make.left.equalTo(self.bottomV).offset(20);
  72. make.centerX.equalTo(self.bottomV);
  73. make.height.equalTo(@20);
  74. }];
  75. [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.top.equalTo(self.customNavBar.mas_bottom);
  77. make.left.right.equalTo(self.view);
  78. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  79. }];
  80. }
  81. - (UILabel *)versionLb {
  82. if (!_versionLb) {
  83. UILabel *lb = [UILabel new];
  84. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  85. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  86. lb.text = [NSString stringWithFormat:@"V%@",app_Version];
  87. lb.textColor = Col_000;
  88. lb.textAlignment = NSTextAlignmentCenter;
  89. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  90. lb.numberOfLines = 1;
  91. _versionLb = lb;
  92. }
  93. return _versionLb;
  94. }
  95. -(UIView *)bottomV {
  96. if (!_bottomV) {
  97. UIView *v = [UIView new];
  98. v.frame = CGRectMake(0, 0, KScreenWidth, 100);
  99. v.backgroundColor = _F8F8F8;
  100. _bottomV = v;
  101. }
  102. return _bottomV;
  103. }
  104. - (UITableView *)tableV {
  105. if (!_tableV) {
  106. UITableView *tabV = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  107. tabV.backgroundColor = _F8F8F8;
  108. [tabV registerClass:[ASSettingListCell class] forCellReuseIdentifier:@"ASSettingListCell"];
  109. tabV.delegate = self;
  110. tabV.dataSource = self;
  111. tabV.rowHeight = UITableViewAutomaticDimension;
  112. tabV.estimatedRowHeight = 100;
  113. tabV.separatorStyle = UITableViewCellSeparatorStyleNone;
  114. UIView *v = [UIView new];
  115. v.frame = CGRectMake(0, 0, KScreenWidth, 10);
  116. v.backgroundColor = _F8F8F8;
  117. tabV.tableHeaderView = v;
  118. tabV.tableFooterView = self.bottomV;
  119. _tableV = tabV;
  120. }
  121. return _tableV;
  122. }
  123. #pragma mark - UITableViewDelegate,UITableViewDataSource
  124. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  125. switch (indexPath.row) {
  126. case 0:{
  127. // if (![self checkLogin:true]) {
  128. // return;
  129. // }
  130. ASInfomationSetController *vc = [ASInfomationSetController new];
  131. [self.navigationController pushViewController:vc animated:true];
  132. break;
  133. }
  134. case 1:{
  135. // if (![self checkLogin:true]) {
  136. // return;
  137. // }
  138. // KWAddressListViewController *vc = [KWAddressListViewController new];
  139. // vc.addressType = AddressTypeSettingAddress;
  140. // [self.navigationController pushViewController:vc animated:true];
  141. break;
  142. }
  143. case 3:{
  144. ASHelpListViewController *vc = [ASHelpListViewController new];
  145. vc.isHelp = false;
  146. [self.navigationController pushViewController:vc animated:true];
  147. break;
  148. }
  149. case 4:{
  150. ASHelpListViewController *vc = [ASHelpListViewController new];
  151. vc.isHelp = true;
  152. [self.navigationController pushViewController:vc animated:true];
  153. break;
  154. }
  155. case 5: {
  156. [self logout];
  157. break;
  158. }
  159. case 6: {
  160. // [self showDeleteAccountAlert];
  161. break;
  162. }
  163. default:
  164. break;
  165. }
  166. }
  167. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  168. return self.titleArr.count;
  169. }
  170. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  171. ASSettingListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASSettingListCell" forIndexPath:indexPath];
  172. [cell setTitle:self.titleArr[indexPath.row] points:self.detailArr[indexPath.row] enable:true];
  173. if (//KWLoginedManager.shareInstance.isLogined &&
  174. ((indexPath.row == _titleArr.count - 1) || (indexPath.row == _titleArr.count - 2))) {
  175. cell.moreIcon.hidden = true;
  176. } else {
  177. cell.moreIcon.hidden = false;
  178. }
  179. cell.switchBtn.hidden = !(indexPath.row == 2);
  180. if (indexPath.row == 2) {
  181. BOOL isSub = ASUserInfoManager.shared.userInfo.is_subscribed;
  182. [cell.switchBtn setIsOpen:isSub animate:false];
  183. __weak typeof(self) weakSelf = self;
  184. [cell.switchBtn setClickBack:^{
  185. [weakSelf configSubscrib:!isSub];
  186. }];
  187. } else {
  188. cell.switchBtn.clickBack = nil;
  189. }
  190. return cell;
  191. }
  192. // MARK: - 退出登录
  193. - (void)logout {
  194. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  195. __weak typeof(self) weak_self = self;
  196. [ASNetTools.shared postWithPath:postLogOut param:@{} success:^(id _Nonnull json) {
  197. [MBProgressHUD hideHUDForView:self.view animated:true];
  198. [weak_self popAndToLogin];
  199. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  200. [MBProgressHUD hideHUDForView:self.view animated:true];
  201. NSLog(@"err:%@",code);
  202. [weak_self.view makeToast:@"Oh No, Bad Net"];
  203. }];
  204. }
  205. - (void)configSubscrib:(BOOL)is_subscribed {
  206. NSDictionary *param = @{
  207. @"customer":@{
  208. @"email": ASUserInfoManager.shared.userInfo.email,
  209. @"firstname": ASUserInfoManager.shared.userInfo.firstname,
  210. @"lastname": ASUserInfoManager.shared.userInfo.lastname,
  211. @"extension_attributes":@{
  212. @"is_subscribed":[NSNumber numberWithBool:is_subscribed]
  213. }
  214. }
  215. };
  216. __weak typeof(self) weakSelf = self;
  217. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  218. [ASNetTools.shared putWithPath:putUserInfo param:param success:^(id _Nonnull json) {
  219. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  220. ASUserInfoManager.shared.userInfo.is_subscribed = is_subscribed;
  221. [weakSelf.tableV reloadData];
  222. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  223. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  224. [weakSelf.view makeToast:@"Bad Net"];
  225. [weakSelf.tableV reloadData];
  226. }];
  227. }
  228. // MARK: - 注销账号
  229. - (void)showDeleteAccountAlert {
  230. __weak typeof(self) weakSelf = self;
  231. ASCustomWindow *window = [ASCustomWindow show:@"Are You Sure To Delete Your Account?\n(This action can't be undone. All the data of your account will be delete)" isMast:false upBlock:^{
  232. } cancelBlock:^{
  233. [weakSelf showDeletedReasonInput];
  234. }];
  235. window.vc.titleLb.text = @"Delete Account?";
  236. [window.vc.sureBt setTitle:@"No" forState:UIControlStateNormal];
  237. [window.vc.cancelBt setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  238. NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:@"Yes"];
  239. [attStr setAttributes:@{
  240. NSFontAttributeName:[UIFont fontWithName:Rob_Regular size:16],
  241. NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle],
  242. NSUnderlineColorAttributeName:[UIColor colorWithHexString:@"#000000"],
  243. NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#000000"]
  244. } range:NSMakeRange(0, attStr.length)];
  245. [window.vc.cancelBt setAttributedTitle:attStr forState:UIControlStateNormal];
  246. [window.vc.cancelBt mas_remakeConstraints:^(MASConstraintMaker *make) {
  247. make.bottom.equalTo(window.vc.sureBt);
  248. make.height.equalTo(@35);
  249. make.right.equalTo(window.vc.sureBt.mas_left).offset(-20);
  250. make.left.greaterThanOrEqualTo(window.vc.contentV).offset(20);
  251. }];
  252. }
  253. - (void)showDeletedReasonInput {
  254. __weak typeof(self) weakSelf = self;
  255. [APHomeActiveWindow show:@"Deleted Account" des:@"Dear user, could you tell me the reason for leaving?" sureBlock:^(NSString *reason) {
  256. NSString *str = @"";
  257. if (!reason.isEmpty) {
  258. str = reason;
  259. }
  260. [weakSelf deleteAccount:str];
  261. } cancelBlock:^{
  262. }];
  263. }
  264. - (void)deleteAccount:(NSString *)msg {
  265. // [MBProgressHUD showHUDAddedTo:self.view animated:true];
  266. // @weakify(self);
  267. // [PPNetworkHelper POST:DeleteAccount parameters:@{@"deleteReason":msg} success:^(id responseObject) {
  268. // [MBProgressHUD hideHUDForView:self.view animated:true];
  269. // if (RequestSuccess) {
  270. // NSLog(@"success:%@",responseObject);
  271. // [XXX_Tabber shareInstance].xxx_barCartBtn.badgeValue = @"0";
  272. // [weak_self popAndToLogin];
  273. //
  274. // } else {
  275. // NSLog(@"fail:%@",RequestErrorMsg);
  276. // [weak_self.view makeToast:RequestErrorMsg];
  277. // }
  278. // } failure:^(NSError *error) {
  279. // [MBProgressHUD hideHUDForView:self.view animated:true];
  280. // NSLog(@"err:%@",error);
  281. // [weak_self.view makeToast:@"Oh No, Bad Net"];
  282. // }];
  283. }
  284. @end