123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // SPSBChooseCityManager.m
- // 我的社保
- //
- // Created by jiaxian_he on 2021/5/31.
- //
- #import "SPSBChooseCityManager.h"
- #import "SPSBSQLProfile.h"
- @interface SPSBChooseCityManager () {
- NSArray *_provinceIDArray;
- NSArray *_provinceArray;
- NSString *_fileName;
- }
- @end
- @implementation SPSBChooseCityManager
- + (SPSBChooseCityManager *)shareManagerWithFileName:(NSString *)fileName {
- SPSBChooseCityManager *manager = SPSBChooseCityManager.new;
- manager->_fileName = fileName;
- [manager setProvinceArrayAndProvinceIDArray];
- return manager;
- }
- - (void)setProvinceArrayAndProvinceIDArray {
- _provinceIDArray = [JXHFMDBManager searchWithPath:_fileName backKey:@"id" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_city where parent_id = ?", @"0"];
- }];
- _provinceArray = [JXHFMDBManager searchWithPath:_fileName backKey:@"name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_city where parent_id = ?", @"0"];
- }];
- }
- - (NSArray *)getPrimaryProvinceArrayAndProvinceIDArrayAndIndexsWithSelectedCityArray:(NSArray *)selectedCityArray {
- NSInteger provinceIndex = 0;
- if (selectedCityArray && [_provinceArray containsObject:selectedCityArray[0]]) {
- provinceIndex = [_provinceArray indexOfObject:selectedCityArray[0]];
- }
- NSArray *cityArray = [self getCityArrayWithProvinceIndex:provinceIndex];
- NSInteger cityIndex = 0;
- if (selectedCityArray && [cityArray containsObject:selectedCityArray[1]]) {
- cityIndex = [cityArray indexOfObject:selectedCityArray[1]];
- }
- return @[@[_provinceArray, cityArray], @(provinceIndex), @(cityIndex)];
- }
- - (NSArray *)getProvinceArrayAndProvinceIDArrayWithProvinceIndex:(NSInteger)provinceIndex {
- NSArray *cityArray = [self getCityArrayWithProvinceIndex:provinceIndex];
- return @[_provinceArray, cityArray];
- }
- - (NSArray *)getCityArrayWithProvinceIndex:(NSInteger)provinceIndex {
- NSArray *cityArray = [JXHFMDBManager searchWithPath:_fileName backKey:@"name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_city where parent_id = ?", self->_provinceIDArray[provinceIndex]];
- }];
- if (cityArray.count == 0) {
- cityArray = [NSArray arrayWithObject:_provinceArray[provinceIndex]];
- }
- return cityArray;
- }
- - (NSString *)getCityIdWithProvinceIndex:(NSInteger)provinceIndex cityIndex:(NSInteger)cityIndex {
- NSArray *cityArray = [JXHFMDBManager searchWithPath:_fileName backKey:@"id" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_city where parent_id = ?", self->_provinceIDArray[provinceIndex]];
- }];
- if (cityArray.count > cityIndex) {
- return cityArray[cityIndex];
- }
- return @"";
- }
- - (NSArray *)getCityArrayWithId:(NSString *)cityId {
- NSArray *cityArray = [JXHFMDBManager searchWithPath:_fileName backKey:@"name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_city where id = ?", cityId];
- }];
- return cityArray;
- }
- - (NSArray *)addSelectedCityArrayCityId:(NSString *)cityId {
- NSArray *selectedArray;
- NSArray *array = [JXHFMDBManager searchWithPath:_fileName backKey:@"name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_city where id = ?", cityId];
- }];
- if (array.count != 0) {
- NSString *city = array[0];
- NSString *parentCityId = [JXHFMDBManager searchWithPath:_fileName backKey:@"parent_id" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_city where id = ?", cityId];
- }][0];
- array = [JXHFMDBManager searchWithPath:_fileName backKey:@"name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_city where id = ?", parentCityId];
- }];
- if (array.count != 0) {
- NSString *provice = array[0];
- selectedArray = @[provice, city];
- }
- }
- if (!selectedArray) {
- selectedArray = @[@"", @""];
- }
- return selectedArray;
- }
- @end
|