Files
peko-ios/YuMi/Modules/YMLogin/View/NewLogin/XPLoginAraeViewController.m

186 lines
5.8 KiB
Mathematica
Raw Normal View History

2023-07-06 16:54:13 +08:00
//
2023-07-14 18:50:55 +08:00
// XPLoginAraeViewController.m
2023-07-06 16:54:13 +08:00
// YuMi
//
// Created by YuMi on 2023/6/25.
//
2023-07-14 18:50:55 +08:00
#import "XPLoginAraeViewController.h"
///view
#import "XPLoginAreaTableViewCell.h"
#import "LoginAreaModel.h"
2023-07-06 16:54:13 +08:00
#import "NSObject+MJExtension.h"
#import "YUMIMacroUitls.h"
#import "Api+Login.h"
2023-07-14 18:50:55 +08:00
///Third
2023-07-06 16:54:13 +08:00
#import <Masonry/Masonry.h>
2023-12-07 19:44:52 +08:00
@interface XPLoginAraeViewController ()<UITableViewDelegate,UITableViewDataSource,XPLoginAreaTableViewCellDelegate>
2023-07-06 16:54:13 +08:00
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *listData;
2023-07-14 18:50:55 +08:00
@property (nonatomic,strong) NSMutableArray *titleList;
2023-07-06 16:54:13 +08:00
@end
2023-07-14 18:50:55 +08:00
@implementation XPLoginAraeViewController
2023-07-06 16:54:13 +08:00
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
2023-07-14 18:50:55 +08:00
[self initSubViewConstraints];
2023-12-07 19:44:52 +08:00
[self getPhoneAreaCodeList];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
#pragma mark - LoginVerifCodeProtocol
2023-07-06 16:54:13 +08:00
2023-12-07 19:44:52 +08:00
-(void)getPhoneAreaCodeList{
//
NSString *path = [[NSBundle mainBundle] pathForResource:@"pi_area_info" ofType:@"json"];
//
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
// JSON
NSDictionary *codeData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSArray *codeList = [LoginAreaModel modelsWithArray:codeData[@"RECORDS"]];
[self getLocalPlistWithList:codeList];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
-(void)getLocalPlistWithList:(NSArray *)list{
2023-07-06 16:54:13 +08:00
2023-12-07 19:44:52 +08:00
NSArray * letterList = @[@"",@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z"];
2023-07-06 16:54:13 +08:00
NSMutableArray *otherList = [NSMutableArray array];
2023-12-07 19:44:52 +08:00
NSMutableArray *defaultList = [NSMutableArray array];
LoginAreaModel *TwModel;
LoginAreaModel *HKModel ;
LoginAreaModel *SPModel ;
LoginAreaModel *MYModel ;
LoginAreaModel *ChinsModel ;
[self.titleList addObject:@""];
2023-07-06 16:54:13 +08:00
for (NSString *letter in letterList) {
2023-07-14 18:50:55 +08:00
NSMutableArray *modelList = [NSMutableArray array];
for (LoginAreaModel *model in list) {
2023-12-11 16:11:56 +08:00
if([model.code isEqualToString:@"886"]){
2023-12-07 19:44:52 +08:00
TwModel = model;
}
2023-12-11 16:11:56 +08:00
if([model.code isEqualToString:@"852"]){
2023-12-07 19:44:52 +08:00
HKModel = model;
}
2023-12-11 16:11:56 +08:00
if([model.code isEqualToString:@"65"]){
2023-12-07 19:44:52 +08:00
SPModel = model;
}
2023-12-11 16:11:56 +08:00
if([model.code isEqualToString:@"60"]){
2023-12-07 19:44:52 +08:00
MYModel = model;
}
2023-12-11 16:11:56 +08:00
if([model.code isEqualToString:@"86"]){
2023-12-07 19:44:52 +08:00
ChinsModel = model;
}
2023-07-06 16:54:13 +08:00
NSString *fristLetter = [model.name substringWithRange:NSMakeRange(0, 1)];
if([letter isEqualToString:fristLetter]){
2023-07-14 18:50:55 +08:00
[modelList addObject:model];
2023-07-06 16:54:13 +08:00
}else{
if(![letterList containsObject:fristLetter] && ![otherList containsObject:model]){
[otherList addObject:model];
}
}
}
2023-07-14 18:50:55 +08:00
if(modelList.count > 0){
2023-07-06 16:54:13 +08:00
2023-07-14 18:50:55 +08:00
[self.titleList addObject:letter];
[self.listData addObject:modelList];
2023-07-06 16:54:13 +08:00
}
}
2023-12-07 19:44:52 +08:00
if(TwModel != nil){
[defaultList addObject:TwModel];
}
if(HKModel != nil){
[defaultList addObject:HKModel];
}
if(SPModel != nil){
[defaultList addObject:SPModel];
}
if(MYModel != nil){
[defaultList addObject:MYModel];
}
if(ChinsModel != nil){
[defaultList addObject:ChinsModel];
}
[self.listData insertObject:defaultList atIndex:0];
2023-12-11 16:11:56 +08:00
if(otherList.count > 0){
[self.listData addObject:otherList];
[self.titleList addObject:@"#"];
}
2023-07-06 16:54:13 +08:00
[self.tableView reloadData];
}
#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return self.listData.count;
}
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
2023-07-14 18:50:55 +08:00
return self.titleList[section];
2023-07-06 16:54:13 +08:00
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.listData[section] count];
}
- (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView {
2023-07-14 18:50:55 +08:00
return self.titleList;
2023-07-06 16:54:13 +08:00
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
2023-07-14 18:50:55 +08:00
XPLoginAreaTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPLoginAreaTableViewCell class]) forIndexPath:indexPath];
2023-12-07 19:44:52 +08:00
if(cell.delegate == nil){
cell.delegate = self;
}
2023-07-06 16:54:13 +08:00
if(indexPath.section < self.listData.count){
2023-07-14 18:50:55 +08:00
NSArray *listModel = self.listData[indexPath.section];
if(indexPath.row < listModel.count){
cell.areaModel =listModel[indexPath.row];
2023-07-06 16:54:13 +08:00
}
}
return cell;
}
2023-12-07 19:44:52 +08:00
#pragma mark - XPLoginAreaTableViewCellDelegate
- (void)didSelectModel:(LoginAreaModel *)model{
LoginAreaModel *codeModel = model;
if(self.delegate && [self.delegate respondsToSelector:@selector(chooseAreaCodeSuccess:)]){
2023-12-11 16:11:56 +08:00
[self.delegate chooseAreaCodeSuccess:codeModel.code];
2023-12-07 19:44:52 +08:00
}
[self.navigationController popViewControllerAnimated:YES];
2023-07-06 16:54:13 +08:00
}
#pragma mark - Private Method
- (void)initSubViews {
2023-07-14 18:50:55 +08:00
self.title = YMLocalizedString(@"XPChooseRreaCodeVC0");
2023-07-06 16:54:13 +08:00
[self.view addSubview:self.tableView];
}
2023-07-14 18:50:55 +08:00
- (void)initSubViewConstraints {
2023-07-06 16:54:13 +08:00
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
}
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.rowHeight = kGetScaleWidth(37);
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;;
_tableView.backgroundColor = [UIColor whiteColor];
2023-07-14 18:50:55 +08:00
[_tableView registerClass:[XPLoginAreaTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPLoginAreaTableViewCell class])];
2023-07-06 16:54:13 +08:00
}
return _tableView;
}
2023-07-14 18:50:55 +08:00
- (NSMutableArray *)titleList{
if (!_titleList){
_titleList = [NSMutableArray array];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return _titleList;
2023-07-06 16:54:13 +08:00
}
- (NSMutableArray *)listData{
if (!_listData){
_listData = [NSMutableArray array];
}
return _listData;
}
@end