123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- //
- // SPSBQueryListViewController.m
- // 我的社保
- //
- // Created by shanp on 2021/5/27.
- //
- #import "SPSBQueryListViewController.h"
- #import "SPSBUIGeneralHeader.h"
- #import "SPSBQueryListTableViewController.h"
- #import "SPSBPurchasersModel.h"
- #import "SPSBBusinessManager.h"
- #import "SPSBGeneralManager.h"
- #import <JXHClassifyView.h>
- #import "SPSBSQLProfile.h"
- #import "UIView+SPSBLoadingTipsView.h"
- #import "SPSBPurchasersListViewController.h"
- #import "SPSBNavigationController.h"
- #import "SPSBNotificationDelegateManager.h"
- #import "SPSBPurchaseSBDetailsViewController.h"
- #import "SPSBPurchaseGJJDetailsViewController.h"
- #import "SPSBMyPurchaseOrder.h"
- #define spsb_queryListHeaderButtonTag 3000
- #define spsb_queryListDefaultViewImageTag 3000
- #define spsb_queryListDefaultViewLabelTag 4000
- #define spsb_queryListDefaultViewButtonTag 5000
- @interface SPSBQueryListViewController ()<SPSBNotificationDelegate> {
- NSString *_choseYear;
- UIImageView *_choseIcon;
- UIImageView *_headerView;
- SPSBPurchaseBusinessType _businessType;
- SPSBPurchasersModel *_chosePurchasers;
- JXHClassifyView *_classifyView;
- JXHCenterButton *_choosePurchasersButton;
- SPSBQueryListTableViewController *_tableVC;
- UIView *_noCustomerView;
- bool _isFirstLoad;
- NSInteger _firstYear;
- }
- @end
- @implementation SPSBQueryListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self initData];
- [self setupUI];
- spsb_setNotificationKey(SPSBPurchaseNotificationKey);
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (_noCustomerView && spsb_purchasersArray().count != 0) {
- [_noCustomerView removeFromSuperview];
- _noCustomerView = nil;
- _chosePurchasers = spsb_purchasersArray().lastObject;
- _tableVC.spsb_purchasers = _chosePurchasers;
- [_choosePurchasersButton setTitle:_chosePurchasers.spsb_user_name state:JXHButtonControlStateNormal];
- [self createContentView];
- }
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- if (_isFirstLoad) {
- _isFirstLoad = false;
- [self tableViewReloadData];
- }
-
- }
- - (void)dealloc {
- spsb_removeNotificationKey(SPSBPurchaseNotificationKey);
- }
- - (void)initData {
- _firstYear = spsb_firstYear();
- _choseYear = spsb_getNewDate().spsb_year;
- _businessType = _spsb_isQueryAccumulationFund ? SPSBAccumulationFundPurchase : SPSBSocialInsurancePurchase;
- }
- #pragma mark - Action
- - (void)changePurchasers {
- if (spsb_purchasersArray().count == 0) {
- [self.view showToastWithTitle:@"暂无参保人"];
- } else {
- SPSBPurchasersListViewController *vc = SPSBPurchasersListViewController.new;
- vc.spsb_type = SPSBPurchasersListTypeQuery;
- @weakify(self)
- vc.spsb_finishChose = ^(SPSBPurchasersModel * _Nonnull purchasers) {
- @strongify(self)
- [self chosePurchasers:purchasers];
- };
- SPSBNavigationController *nav = [[SPSBNavigationController alloc] initWithRootViewController:vc];
- [self presentViewController:nav animated:true completion:^{
-
- }];
- }
- }
- - (void)changeQuery:(JXHCenterButton *)sender {
- [_choseIcon remakeConstraints:^(JXHConstraintMaker *make) {
- make.bottom.equalTo(0);
- make.centerX.equalTo(sender);
- }];
- if (sender.tag == spsb_queryListHeaderButtonTag) {
- _businessType = SPSBSocialInsurancePurchase;
- } else {
- _businessType = SPSBAccumulationFundPurchase;
- }
- _tableVC.spsb_businessType = _businessType;
- if (_noCustomerView) {
- NSArray *data = [self getNoCustomerData];
- ((UIImageView *)[_noCustomerView viewWithTag:spsb_queryListDefaultViewImageTag]).image = data[0];
- ((UILabel *)[_noCustomerView viewWithTag:spsb_queryListDefaultViewLabelTag]).text = data[1];
- [((UIButton *)[_noCustomerView viewWithTag:spsb_queryListDefaultViewButtonTag]) setTitle:data[2] state:JXHButtonControlStateNormal];
- }
- if (_chosePurchasers) {
- [self tableViewReloadData];
- }
- }
- - (void)tableViewReloadData {
- [_classifyView scrollClassifyForIndex:_choseYear.integerValue - _firstYear];
- [_tableVC reloadData];
- }
- - (void)chosePurchasers:(SPSBPurchasersModel *)purchasers {
- _chosePurchasers = purchasers;
- _choseYear = spsb_getNewDate().spsb_year;
- _tableVC.spsb_choseYear = _choseYear;
- _tableVC.spsb_purchasers = _chosePurchasers;
-
- [_tableVC refreshAllData];
- [_choosePurchasersButton setTitle:_chosePurchasers.spsb_user_name state:JXHButtonControlStateNormal];
- [self tableViewReloadData];
- [JXHFMDBManager updateWithPath:SPSBShanpSocialInsuranceLocationSQL condition:^id(FMDatabase *database) {
- return @([database executeUpdate:@"delete from cache_data where key = ?", SPSBQueryPurchasersSQLKey]);
- }];
- [JXHFMDBManager updateWithPath:SPSBShanpSocialInsuranceLocationSQL condition:^id(FMDatabase *database) {
- return @([database executeUpdate:@"insert into cache_data (key, data) values (?, ?)", SPSBQueryPurchasersSQLKey, jxh_archiver(self->_chosePurchasers.spsb_id, SPSBQueryPurchasersSQLKey)]);
- }];
- }
- - (void)buyAction {
- spsb_setMyPurchaseOrder(SPSBMyPurchaseOrder.new);
- spsb_myPurchaseOrder().spsb_isSupplementaryPay = false;
- switch (_businessType) {
- case SPSBSocialInsurancePurchase: {
- [self.navigationController pushViewController:SPSBPurchaseSBDetailsViewController.new animated:true];
- }
- break;
- case SPSBAccumulationFundPurchase: {
- [self.navigationController pushViewController:SPSBPurchaseGJJDetailsViewController.new animated:true];
- }
- break;
- default:
- break;
- }
- }
- #pragma mark - Network Action
- #pragma mark - SPSBNotificationDelegate
- - (void)spsb_refundSuccuss {
- if (spsb_purchasersArray().count == 0) return;
- [_tableVC refreshAllData];
- [self.navigationController popToViewController:self animated:true];
- }
- #pragma mark - UI
- - (void)setupUI {
- self.title = @"查询";
- [self createRightButton];
- [self createHeaderView];
- [self createContentView];
- }
- - (void)createContentView {
- if (spsb_purchasersArray().count == 0) {
- [self createNoPurchasersTipsView];
- return;
- }
- [self createClassifyView];
- [self createTableView];
- _isFirstLoad = true;
- }
- - (void)createClassifyView {
- NSMutableArray *array = NSMutableArray.new;
- for (NSInteger i = _firstYear; i <= _choseYear.integerValue + 2; i ++)
- {
- [array addObject:[NSString stringWithFormat:@"%ld", (long)i]];
- }
- JXHClassifyViewConfiguration *configuration = ({
- JXHClassifyViewConfiguration *configuration = JXHClassifyViewConfiguration.new;
- configuration.jxh_titleArray = array;
- configuration.jxh_height = 50;
- configuration.jxh_font = spsb_font(15);
- configuration.jxh_normalColor = spsb_999999_color();
- configuration.jxh_selectedColor = spsb_3296FB_color();
- configuration.jxh_margen = 0.f;
- configuration.jxh_interval = 0.f;
- configuration.jxh_selectedViewSize = (CGSize){40, 2};
- configuration.jxh_selectedViewColor = spsb_3296FB_color();
- configuration.jxh_equalWidth = jxh_screenWidth() / 5;
- configuration.jxh_isNeedSelectedView = true;
- configuration;
- });
-
- @weakify(self)
- _classifyView = [[JXHClassifyView alloc] initWithConfiguration:configuration chooseAction:^(JXHClassifyView * _Nonnull classifyView, NSInteger index) {
- @strongify(self)
- self->_choseYear = [NSString stringWithFormat:@"%ld", (long)self->_firstYear + index];
- self->_tableVC.spsb_choseYear = self->_choseYear;
- [self tableViewReloadData];
- }];
- [self.view addSubview:_classifyView];
- [_classifyView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.trailing.equalTo(0);
- make.top.equalTo(self->_headerView.bottom);
- make.height.equalTo(configuration.jxh_height);
- }];
- }
- - (void)createTableView {
- _tableVC = SPSBQueryListTableViewController.new;
- _tableVC.spsb_businessType = _businessType;
- _tableVC.spsb_choseYear = _choseYear;
- _tableVC.spsb_purchasers = _chosePurchasers;
- [self addChildViewController:_tableVC];
- [self.view addSubview:_tableVC.tableView];
- [_tableVC.tableView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self->_classifyView.bottom);
- make.leading.and.trailing.and.bottom.equalTo(0);
- }];
- }
- - (void)createNoPurchasersTipsView {
- _noCustomerView = UIView.new;
- NSArray *data = [self getNoCustomerData];
- UIImageView *imageView = [[UIImageView alloc] initWithImage:data[0]];
- imageView.tag = spsb_queryListDefaultViewImageTag;
- [_noCustomerView addSubview:imageView];
- UILabel *label = [UILabel convenienceWithFont:spsb_font(14) text:data[1] textColor:spsb_9197A3_color() textAlignment:NSTextAlignmentCenter];
- label.tag = spsb_queryListDefaultViewLabelTag;
- [_noCustomerView addSubview:label];
- UIButton *button = [UIButton convenienceWithFont:spsb_font(15) target:self action:@selector(buyAction)];
- [button setTitle:data[2] titleColor:spsb_3296FB_color() state:JXHButtonControlStateNormal];
- button.tag = spsb_queryListDefaultViewButtonTag;
- [_noCustomerView addSubview:button];
- [imageView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.leading.and.trailing.equalTo(0);
- }];
- [label makeConstraints:^(JXHConstraintMaker *make) {
- make.centerX.equalTo(imageView);
- make.top.equalTo(imageView.bottom).offset(3);
- }];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(label.bottom).offset(50);
- make.bottom.equalTo(0);
- make.centerX.equalTo(imageView);
- }];
- [self.view addSubview:_noCustomerView];
- [_noCustomerView makeConstraints:^(JXHConstraintMaker *make) {
- make.centerX.equalTo(self.view);
- make.centerY.equalTo(self.view).offset(55);
- }];
- }
- - (NSArray *)getNoCustomerData {
- if (_businessType == SPSBSocialInsurancePurchase) {
- return @[jxh_getImage(search_shebao_qs), @"暂无社保缴纳记录", @"立即参保"];
- }
- return @[jxh_getImage(search_gjj_qs), @"暂无公积金缴存记录", @"立即缴存"];
- }
- - (void)createHeaderView {
- _headerView = [[UIImageView alloc] initWithImage:jxh_getImage(search_bg)];
- _headerView.userInteractionEnabled = true;
- _headerView.backgroundColor = spsb_3296FB_color();
- [self.view addSubview:_headerView];
- [_headerView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self.view.safetop);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(jxh_screenWidth() * 0.29);
- }];
-
- NSArray *images = @[jxh_getImage(search_shebao), jxh_getImage(search_gjj)];
- NSArray *titles = @[@"社保查询", @"公积金查询"];
- JXHCenterButton *tempButton = nil;
- NSInteger chose = _spsb_isQueryAccumulationFund ? 1 : 0;
- for (NSInteger i = 0; i < images.count; i ++) {
- JXHCenterButton *button = [JXHCenterButton convenienceWithAxis:JXHCenterButtonAxisVertical interval:8 font:spsb_semiboldFont(14) target:self action:@selector(changeQuery:)];
- [button setTitle:titles[i] titleColor:spsb_FFFFFF_color(1.f) image:images[i] backgroundImage:nil state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
- button.tag = spsb_queryListHeaderButtonTag + i;
- [_headerView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- if (tempButton) {
- make.leading.equalTo(tempButton.trailing);
- } else {
- make.leading.equalTo(0);
- }
- make.top.and.bottom.equalTo(0);
- make.width.equalTo(jxh_screenWidth() / 2);
- }];
-
- tempButton = button;
-
- if (i == chose) {
- _choseIcon = [[UIImageView alloc] initWithImage:jxh_getImage(inquire_arrow)];
- [_headerView addSubview:_choseIcon];
- [_choseIcon makeConstraints:^(JXHConstraintMaker *make) {
- make.bottom.equalTo(0);
- make.centerX.equalTo(button);
- }];
- }
- }
- }
- - (void)createRightButton {
- _choosePurchasersButton = [JXHCenterButton convenienceWithAxis:JXHCenterButtonAxisHorizontal interval:6 font:spsb_font(15) target:self action:@selector(changePurchasers)];
- [_choosePurchasersButton.jxh_titleLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.width.lessThanOrEqualTo(100);
- }];
- [_choosePurchasersButton setImage:jxh_getImage(arrow_down) state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
- [_choosePurchasersButton setTitleColor:spsb_3296FB_color() state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
- [_choosePurchasersButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
- _choosePurchasersButton.frame = CGRectMake(0, 0, 100, 44);
-
- if (_spsb_purchasers) {
- _chosePurchasers = _spsb_purchasers;
- [_choosePurchasersButton setTitle:_chosePurchasers.spsb_user_name state:JXHButtonControlStateNormal];
- } else {
- if (spsb_purchasersArray().count == 0) {
- [_choosePurchasersButton setTitle:@"请选择" state:JXHButtonControlStateNormal];
- } else {
- NSString *cacheId = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceLocationSQL key:SPSBQueryPurchasersSQLKey condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from cache_data where key = ?", SPSBQueryPurchasersSQLKey];
- }];
- _chosePurchasers = nil;
- if (cacheId) {
- for (SPSBPurchasersModel *purchasers in spsb_purchasersArray()) {
- if ([purchasers.spsb_id isEqualToString:cacheId]) {
- _chosePurchasers = purchasers;
- break;
- }
- }
- }
- if (!_chosePurchasers) {
- _chosePurchasers = spsb_purchasersArray().lastObject;
- }
- [_choosePurchasersButton setTitle:_chosePurchasers.spsb_user_name state:JXHButtonControlStateNormal];
- }
- }
-
- UIBarButtonItem *selectItem = [[UIBarButtonItem alloc] initWithCustomView:_choosePurchasersButton];
- self.navigationItem.rightBarButtonItem = selectItem;
- }
- @end
- #undef spsb_queryListHeaderButtonTag
- #undef spsb_queryListDefaultViewImageTag
- #undef spsb_queryListDefaultViewLabelTag
- #undef spsb_queryListDefaultViewButtonTag
|