123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- //
- // SPSBPickerViewManager.m
- // 我的社保
- //
- // Created by shanp on 2021/5/14.
- //
- #import "SPSBPickerViewManager.h"
- #import "SPSBPickerViewController.h"
- #import "SPSBSQLProfile.h"
- #import "SPSBBusinessManager.h"
- SPSBPickerViewType const SPSBPickerViewTypeMailAddress = @"MailAddress";
- @interface SPSBPickerViewManager ()<SPSBPickerViewDelegate> {
- NSArray *_provinceIdArray;
- NSArray *_provinceArray;
- NSArray *_cityArray;
- NSArray *_cityIdArray;
- NSArray *_districtArray;
-
- void (^_tempComplete)(SPSBPickerViewResult result);
-
- SPSBPickerViewType _currentType;
- }
- @end
- @implementation SPSBPickerViewManager
- - (instancetype)initWithTypes:(NSArray<SPSBPickerViewType> *)types {
- self = [super init];
- if (!self) return nil;
- [self createDateWithTypes:types];
- return self;
- }
- - (void)createDateWithTypes:(NSArray<SPSBPickerViewType> *)types {
- if ([types containsObject:SPSBPickerViewTypeMailAddress]) {
- _provinceIdArray = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceCitySQL backKey:@"id" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from city where parentId = ?", @"100000"];
- }];
- _provinceArray = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceCitySQL backKey:@"name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from city where parentId = ?", @"100000"];
- }];
- }
- }
- - (void)showPickerViewWithType:(SPSBPickerViewType)type defaultValue:(nullable NSString *)defaultValue complete:(void (^)(SPSBPickerViewResult result))complete {
- SEL action = NSSelectorFromString([NSString stringWithFormat:@"show%@WithValue:", type]);
- if (![self respondsToSelector:action]) {
- return;
- }
- _tempComplete = complete;
- _currentType = type;
- IMP imp = [self methodForSelector:action];
- void (*func)(id, SEL, NSString *) = (void *)imp;
- func(self, action, defaultValue);
- }
- #pragma mark - Delegate
- - (void)pickerView:(SPSBPickerView *)pickerView didChoseRow:(NSInteger)row inComponent:(NSInteger)component {
- if ([_currentType isEqualToString:SPSBPickerViewTypeMailAddress]) {
- [self pickerView:pickerView didChoseMailAddressRow:row inComponent:component];
- }
- }
- #pragma mark - MailAddress
- - (void)showMailAddressWithValue:(nullable NSString *)value {
- if (!_provinceIdArray || !_provinceArray) return;
-
- SPSBPickerViewController *vc = SPSBPickerViewController.new;
- vc.spsb_pickerDelegate = self;
- vc.spsb_dataArray = @[_provinceArray, @[], @[]];
- @weakify(self)
- vc.spsb_finishChose = ^(SPSBPickerView * _Nonnull pickerView) {
- @strongify(self)
- [self completeToChoseMailAddressWithPickerView:pickerView];
- };
- vc.spsb_willDisplay = ^(SPSBPickerView * _Nonnull pickerView) {
- [pickerView chooseRow:0 inComponent:0 animated:false];
- [pickerView chooseRow:0 inComponent:1 animated:false];
- [pickerView chooseRow:0 inComponent:2 animated:false];
- };
- [_spsb_controller presentViewController:vc animated:false completion:nil];
- }
- - (void)pickerView:(SPSBPickerView *)pickerView didChoseMailAddressRow:(NSInteger)row inComponent:(NSInteger)component {
- if (component == 0) {
- _cityArray = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceCitySQL backKey:@"name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from city where parentId = ?", self->_provinceIdArray[row]];
- }];
- _cityIdArray = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceCitySQL backKey:@"id" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from city where parentId = ?", self->_provinceIdArray[row]];
- }];
- if (_cityIdArray.count == 0) {
- _districtArray = @[];
- } else {
- _districtArray = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceCitySQL backKey:@"name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from city where parentId = ?", self->_cityIdArray[0]];
- }];
- }
- [pickerView reloadViewWithData:@[_provinceArray, _cityArray, _districtArray]];
- [pickerView chooseRow:0 inComponent:1 animated:false];
- [pickerView chooseRow:0 inComponent:2 animated:false];
- } else if (component == 1) {
- if (_cityIdArray.count == 0) {
- _districtArray = @[];
- } else {
- _districtArray = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceCitySQL backKey:@"name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from city where parentId = ?", self->_cityIdArray[row]];
- }];
- }
- [pickerView reloadViewWithData:@[_provinceArray, _cityArray, _districtArray]];
- [pickerView chooseRow:0 inComponent:2 animated:false];
- }
- }
- - (void)completeToChoseMailAddressWithPickerView:(SPSBPickerView *)pickerView {
- if (!_tempComplete) return;
- NSString *province = _provinceArray[[pickerView.spsb_choseArray[0] integerValue]];
- NSString *city;
- if (_cityArray.count != 0) {
- city = _cityArray[[pickerView.spsb_choseArray[1] integerValue]];
- } else {
- city = @"";
- }
- if ([city isEqualToString:province]) {
- city = @"";
- }
- NSString *district;
- if (_districtArray.count != 0) {
- district = _districtArray[[pickerView.spsb_choseArray[2] integerValue]];
- } else {
- district = @"";
- }
- NSString *displayString = [NSString stringWithFormat:@"%@%@%@", province, city, district];
- SPSBPickerViewResult result;
- result.spsb_uploadData = displayString;
- result.spsb_showData = displayString;
- _tempComplete(result);
- _tempComplete = nil;
- }
- //#pragma mark - Gender
- //- (void)showGenderWithValue:(nullable NSString *)value {
- // SPSBPickerViewController *vc = SPSBPickerViewController.new;
- // vc.spsb_dataArray = @[@[@"男", @"女"]];
- // NSUInteger row = [vc.spsb_dataArray[0] indexOfObject:value];
- // if (row >= vc.spsb_dataArray[0].count) {
- // row = 0;
- // }
- // @weakify(self)
- // vc.spsb_finishChose = ^(SPSBPickerView * _Nonnull pickerView) {
- // @strongify(self)
- // [self completeToChoseGenderWithPickerView:pickerView];
- // };
- // vc.spsb_willDisplay = ^(SPSBPickerView * _Nonnull pickerView) {
- // [pickerView chooseRow:row inComponent:0 animated:false];
- // };
- // [_spsb_controller presentViewController:vc animated:false completion:nil];
- //}
- //
- //- (void)completeToChoseGenderWithPickerView:(SPSBPickerView *)pickerView {
- // if (!_tempComplete) return;
- // NSInteger selectedRow = [pickerView.spsb_choseArray.firstObject integerValue];
- // NSString *data;
- // NSString *displayData;
- // if (selectedRow == 0) {
- // data = @"1";
- // displayData = spsb_genderArray()[1];
- // } else {
- // data = @"0";
- // displayData = spsb_genderArray()[0];
- // }
- // SPSBPickerViewResult result;
- // result.spsb_uploadData = data;
- // result.spsb_showData = displayData;
- // _tempComplete(result);
- // _tempComplete = nil;
- //}
- //
- //#pragma mark - Age
- //- (void)showAgeWithValue:(nullable NSString *)value {
- // NSArray *dataArray = [JXHFMDBManager searchWithPath:SPSBFixedDataSQL key:SPSBFixedAgeSQLKey condition:^id(FMDatabase *database) {
- // return [database executeQuery:@"select * from data where key = ?", SPSBFixedAgeSQLKey];
- // }];
- // SPSBPickerViewController *vc = SPSBPickerViewController.new;
- // vc.spsb_pickerDelegate = self;
- // vc.spsb_dataArray = @[dataArray];
- // @weakify(self)
- // vc.spsb_finishChose = ^(SPSBPickerView * _Nonnull pickerView) {
- // @strongify(self)
- // [self completeToAgeWithPickerView:pickerView];
- // };
- // [_spsb_controller presentViewController:vc animated:false completion:nil];
- //}
- //
- //- (void)completeToAgeWithPickerView:(SPSBPickerView *)pickerView {
- // if (!_tempComplete) return;
- // NSInteger index = [pickerView.spsb_choseArray[0] integerValue];
- // NSString *data = [NSString stringWithFormat:@"%ld", (long)index + 1];
- // NSString *displayData = [NSString stringWithFormat:@"%ld岁", (long)index + 1];
- // SPSBPickerViewResult result;
- // result.spsb_uploadData = data;
- // result.spsb_showData = displayData;
- // _tempComplete(result);
- // _tempComplete = nil;
- //}
- //
- //#pragma mark - Birthday
- //- (void)showBirthdayWithValue:(nullable NSString *)value {
- // NSArray *lastChoseArr;
- // if (value.length > 0) {
- // lastChoseArr = @[[value substringToIndex:4], [value substringWithRange:NSMakeRange(5, value.length - 7)], [value substringFromIndex:value.length - 2]];
- // } else {
- // lastChoseArr = @[@"1990年", @"正月", @"初一"];
- // }
- // NSInteger year = [lastChoseArr[0] integerValue];
- // _leapMonth = spsb_leapMonth(year);
- // NSMutableArray *monthArray = [_chineseCalendarArray[1] mutableCopy];
- // if (_leapMonth != 0) {
- // [monthArray insertObject:_leapMonthArray[_leapMonth - 1] atIndex:_leapMonth];
- // }
- // _tempMonthArray = monthArray;
- // NSInteger monthIndex = [monthArray indexOfObject:lastChoseArr[1]];
- // NSInteger days;
- // if (_leapMonth != 0) {
- // if (monthIndex < _leapMonth) {
- // days = spsb_monthDays(year, monthIndex + 1);
- // } else if (monthIndex == _leapMonth) {
- // days = spsb_leapDays(year);
- // } else {
- // days = spsb_monthDays(year, monthIndex);
- // }
- // } else {
- // days = spsb_monthDays(year, monthIndex + 1);
- // }
- // NSArray *dayArray = [_chineseCalendarArray[2] subarrayWithRange:NSMakeRange(0, days)];
- // NSInteger dayIndex = [dayArray indexOfObject:lastChoseArr[2]];
- //
- // SPSBPickerViewController *vc = SPSBPickerViewController.new;
- // vc.spsb_pickerDelegate = self;
- // vc.spsb_dataArray = @[_chineseCalendarArray[0], monthArray, dayArray];
- // @weakify(self)
- // vc.spsb_finishChose = ^(SPSBPickerView * _Nonnull pickerView) {
- // @strongify(self)
- // [self completeToChoseBirthdayWithPickerView:pickerView];
- // };
- // vc.spsb_willDisplay = ^(SPSBPickerView * _Nonnull pickerView) {
- // [pickerView chooseRow:year - 1900 inComponent:0 animated:false];
- // [pickerView chooseRow:monthIndex inComponent:1 animated:false];
- // [pickerView chooseRow:dayIndex inComponent:2 animated:false];
- // };
- // [_spsb_controller presentViewController:vc animated:false completion:nil];
- //}
- //
- //- (void)pickerView:(SPSBPickerView *)pickerView didChoseBrithdayRow:(NSInteger)row inComponent:(NSInteger)component {
- // switch (component) {
- // case 0: {
- // NSInteger year = [_chineseCalendarArray[component][row] integerValue];
- // _leapMonth = spsb_leapMonth(year);
- // if (_leapMonth != 0) {
- // NSMutableArray *monthArray = [_chineseCalendarArray[1] mutableCopy];
- // [monthArray insertObject:_leapMonthArray[_leapMonth - 1] atIndex:_leapMonth];
- // NSArray *dataArray = @[_chineseCalendarArray[0], monthArray, _chineseCalendarArray[2]];
- // _tempMonthArray = monthArray;
- // [pickerView reloadViewWithData:dataArray];
- // } else {
- // _tempMonthArray = _chineseCalendarArray[1];
- // [pickerView reloadViewWithData:_chineseCalendarArray];
- //
- // }
- // [pickerView chooseRow:0 inComponent:1 animated:true];
- // }
- // break;
- // case 1: {
- // NSInteger year = [_chineseCalendarArray[0][[pickerView.spsb_choseArray[0] integerValue]] integerValue];
- // NSInteger monthIndex = row;
- // NSInteger days;
- // if (_leapMonth != 0) {
- // if (monthIndex < _leapMonth) {
- // days = spsb_monthDays(year, monthIndex + 1);
- // } else if (monthIndex == _leapMonth) {
- // days = spsb_leapDays(year);
- // } else {
- // days = spsb_monthDays(year, monthIndex);
- // }
- // } else {
- // days = spsb_monthDays(year, monthIndex + 1);
- // }
- // NSArray *dayArray = [_chineseCalendarArray[2] subarrayWithRange:NSMakeRange(0, days)];
- // NSArray *dataArray = @[_chineseCalendarArray[0], _tempMonthArray, dayArray];
- // [pickerView reloadViewWithData:dataArray];
- // [pickerView chooseRow:0 inComponent:2 animated:true];
- // }
- // break;
- //
- // default:
- // break;
- // }
- //}
- //
- //- (void)completeToChoseBirthdayWithPickerView:(SPSBPickerView *)pickerView {
- // if (!_tempComplete) return;
- // NSMutableArray *dateArray = [@[] mutableCopy];
- // for (NSInteger i = 0; i < pickerView.spsb_choseArray.count; i ++) {
- // NSInteger selectedRow = [pickerView.spsb_choseArray[i] integerValue];
- // NSString *date;
- // if (i == 1) {
- // date = _tempMonthArray[selectedRow];
- // } else {
- // date = _chineseCalendarArray[i][selectedRow];
- // }
- //
- // [dateArray addObject:date];
- // }
- // NSString *dateString = [NSString stringWithFormat:@"%@%@%@", dateArray[0], dateArray[1], dateArray[2]];
- // debugLog(@"%@", dateString);
- // SPSBPickerViewResult result;
- // result.spsb_uploadData = dateString;
- // result.spsb_showData = dateString;
- // _tempComplete(result);
- // _tempComplete = nil;
- //}
- //
- //static long lunarInfo[] = {
- // 0x4bd8, 0x4ae0, 0xa570, 0x54d5, 0xd260, 0xd950, 0x5554, 0x56af, 0x9ad0, 0x55d2,
- // 0x4ae0, 0xa5b6, 0xa4d0, 0xd250, 0xd255, 0xb54f, 0xd6a0, 0xada2, 0x95b0, 0x4977,
- // 0x497f, 0xa4b0, 0xb4b5, 0x6a50, 0x6d40, 0xab54, 0x2b6f, 0x9570, 0x52f2, 0x4970,
- // 0x6566, 0xd4a0, 0xea50, 0x6a95, 0x5adf, 0x2b60, 0x86e3, 0x92ef, 0xc8d7, 0xc95f,
- // 0xd4a0, 0xd8a6, 0xb55f, 0x56a0, 0xa5b4, 0x25df, 0x92d0, 0xd2b2, 0xa950, 0xb557,
- // 0x6ca0, 0xb550, 0x5355, 0x4daf, 0xa5b0, 0x4573, 0x52bf, 0xa9a8, 0xe950, 0x6aa0,
- // 0xaea6, 0xab50, 0x4b60, 0xaae4, 0xa570, 0x5260, 0xf263, 0xd950, 0x5b57, 0x56a0,
- // 0x96d0, 0x4dd5, 0x4ad0, 0xa4d0, 0xd4d4, 0xd250, 0xd558, 0xb540, 0xb6a0, 0x95a6,
- // 0x95bf, 0x49b0, 0xa974, 0xa4b0, 0xb27a, 0x6a50, 0x6d40, 0xaf46, 0xab60, 0x9570,
- // 0x4af5, 0x4970, 0x64b0, 0x74a3, 0xea50, 0x6b58, 0x5ac0, 0xab60, 0x96d5, 0x92e0,
- // 0xc960, 0xd954, 0xd4a0, 0xda50, 0x7552, 0x56a0, 0xabb7, 0x25d0, 0x92d0, 0xcab5,
- // 0xa950, 0xb4a0, 0xbaa4, 0xad50, 0x55d9, 0x4ba0, 0xa5b0, 0x5176, 0x52bf, 0xa930,
- // 0x7954, 0x6aa0, 0xad50, 0x5b52, 0x4b60, 0xa6e6, 0xa4e0, 0xd260, 0xea65, 0xd530,
- // 0x5aa0, 0x76a3, 0x96d0, 0x4afb, 0x4ad0, 0xa4d0, 0xd0b6, 0xd25f, 0xd520, 0xdd45,
- // 0xb5a0, 0x56d0, 0x55b2, 0x49b0, 0xa577, 0xa4b0, 0xaa50, 0xb255, 0x6d2f, 0xada0,
- // 0x4b63, 0x937f, 0x49f8, 0x4970, 0x64b0, 0x68a6, 0xea5f, 0x6b20, 0xa6c4, 0xaaef,
- // 0x92e0, 0xd2e3, 0xc960, 0xd557, 0xd4a0, 0xda50, 0x5d55, 0x56a0, 0xa6d0, 0x55d4,
- // 0x52d0, 0xa9b8, 0xa950, 0xb4a0, 0xb6a6, 0xad50, 0x55a0, 0xaba4, 0xa5b0, 0x52b0,
- // 0xb273, 0x6930, 0x7337, 0x6aa0, 0xad50, 0x4b55, 0x4b6f, 0xa570, 0x54e4, 0xd260,
- // 0xe968, 0xd520, 0xdaa0, 0x6aa6, 0x56df, 0x4ae0, 0xa9d4, 0xa4d0, 0xd150, 0xf252,
- // 0xd520};
- //
- //// ====== 传回农历 y年闰哪个月 1-12 , 没闰传回 0
- //NSInteger spsb_leapMonth(NSInteger y) {
- // long var = lunarInfo[y - 1900] & 0xf;
- // return (NSInteger)(var == 0xf ? 0 : var);
- //}
- //
- //// ====== 传回农历 y年闰月的天数
- //NSInteger spsb_leapDays(NSInteger y) {
- // if (spsb_leapMonth(y) != 0) {
- // if ((lunarInfo[y - 1899] & 0xf) != 0)
- // return 30;
- // else
- // return 29;
- // } else
- // return 0;
- //}
- //
- //// ====== 传回农历 y年m月的总天数
- //NSInteger spsb_monthDays(NSInteger y, NSInteger m) {
- // if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)
- // return 29;
- // else
- // return 30;
- //}
- //
- @end
|