123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 |
- //
- // SPSBQueryHomeViewController.m
- // 我的社保
- //
- // Created by shanp on 2021/4/20.
- //
- #import "SPSBQueryHomeViewController.h"
- #import "SPSBUIGeneralHeader.h"
- #import "SPSBBusinessManager.h"
- #import "SPSBSQLProfile.h"
- #import "SPSBKeyProfile.h"
- #import "SPSBQueryCityModel.h"
- #import "SPSBConfirmAlertViewController.h"
- #import "SPSBHtmlViewController.h"
- #import "SPSBURLApiProfile.h"
- #import <CALayer+JXHShadow.h>
- #import "SPSBUMEventAnalysis.h"
- #import "SPSBActionSheetViewController.h"
- #import "WXApi.h"
- #import "SPSBChooseCityViewController.h"
- #import "SPSBNavigationController.h"
- #import "SPSBQueryListViewController.h"
- #define spsb_queryViewWDSBButtonTag 3000
- #define spsb_queryViewGVMButtonTag 4000
- @interface SPSBQueryHomeViewController (){
- UIScrollView *_backgroundView;
- UIImageView *_headerView;
- UILabel *_cityLabel;
-
- UIView *_wdsbView;
- UIView *_gvmView;
-
- SPSBQueryCityModel *_gvmData;
- bool _firstTips;
- }
- @end
- @implementation SPSBQueryHomeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- _firstTips = true;
- [self getLocationCity];
- [self setupUI];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- if (_firstTips && spsb_locationCheckPublicDataCity().length > 0 && ![spsb_lastCheckPublicDataCity() isEqualToString:spsb_locationCheckPublicDataCity()]) {
- _firstTips = false;
- NSString *locationCity = spsb_locationCheckPublicDataCity();
- SPSBConfirmAlertViewController *vc = [SPSBConfirmAlertViewController alertWithTitle:@"提示" content:[NSString stringWithFormat:@"当前定位在“%@”,是否切换至%@?", locationCity, locationCity]];
- [vc setCancelButtonTitle:nil titleColor:nil action:^{
- spsb_setLocationCheckPublicDataCity(spsb_lastCheckPublicDataCity());
- }];
- @weakify(self)
- [vc setConfirmButtonTitle:nil titleColor:nil action:^{
- @strongify(self)
- NSArray *array = [JXHFMDBManager searchWithPath:SPSBShanpQueryCitySQL backKey:nil condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_query_city where city_name = ?", spsb_locationCheckPublicDataCity()];
- }];
- NSDictionary *dic = @{};
- if (array.count != 0) {
- dic = array[0];
- }
- self->_gvmData = [SPSBQueryCityModel getModelWithDictionary:dic];
- [self reloadGvmView];
- spsb_setLastCheckPublicDataCity(spsb_locationCheckPublicDataCity());
- [jxh_userDefaults() setObject:spsb_lastCheckPublicDataCity() forKey:SPSBCheckPublicDataCity];
- [jxh_userDefaults() synchronize];
- }];
-
- [self presentViewController:vc animated:false completion:nil];
- }
- }
- #pragma mark - Action
- - (void)getLocationCity {
- NSString *city = spsb_lastCheckPublicDataCity();
- if (city.length == 0) {
- city = spsb_locationCheckPublicDataCity();
-
- if (city.length == 0) {
- NSArray *array = [JXHFMDBManager searchWithPath:SPSBShanpQueryCitySQL backKey:@"city_name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_query_city LIMIT 1"];
- }];
- if (array.count > 0) {
- spsb_setLocationCheckPublicDataCity(array[0]);
- } else {
- spsb_setLocationCheckPublicDataCity(@"北京");
- }
- city = spsb_locationCheckPublicDataCity();
- }
- spsb_setLastCheckPublicDataCity(spsb_locationCheckPublicDataCity());
- [jxh_userDefaults() setObject:spsb_lastCheckPublicDataCity() forKey:SPSBCheckPublicDataCity];
- [jxh_userDefaults() synchronize];
- }
- NSArray *array = [JXHFMDBManager searchWithPath:SPSBShanpQueryCitySQL backKey:nil condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_query_city where city_name = ?", city];
- }];
- NSDictionary *dic = @{};
- if (array.count != 0) {
- dic = array[0];
- }
- _gvmData = [SPSBQueryCityModel getModelWithDictionary:dic];
- debugLog(@"%@", _gvmData);
- }
- - (void)headerViewAction {
- SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
- vc.spsb_url = SPSBQueryAnytimeLink;
- vc.title = @"随时查";
- [self.navigationController pushViewController:vc animated:true];
- }
- - (void)buttonAction:(JXHCenterButton *)sender {
- bool isAccumulationFund = sender.tag == spsb_queryViewWDSBButtonTag + 1;
- [SPSBUMEventAnalysis analyseEventWithId:isAccumulationFund ? @"QueryPlatformGJJ" : @"QueryPlatformSB"];
- debugLog(@"%ld", (long)sender.tag);
- @weakify(self)
- spsb_needLogin(^{
- @strongify(self)
- SPSBQueryListViewController *vc = SPSBQueryListViewController.new;
- vc.spsb_isQueryAccumulationFund = isAccumulationFund;
- [self.navigationController pushViewController:vc animated:true];
- });
- }
- - (void)changeCity {
- [SPSBUMEventAnalysis analyseEventWithId:@"position"];
- SPSBChooseCityViewController *vc = SPSBChooseCityViewController.new;
- @weakify(self)
- vc.spsb_finishChoose = ^(SPSBQueryCityModel * _Nonnull model) {
- @strongify(self)
- [self finishChooseCity:model];
- };
- SPSBNavigationController *nav = [[SPSBNavigationController alloc] initWithRootViewController:vc];
- [self presentViewController:nav animated:true completion:nil];
- }
- - (void)finishChooseCity:(SPSBQueryCityModel *)model {
- _gvmData = model;
- [self reloadGvmView];
- spsb_setLastCheckPublicDataCity(model.spsb_city_name);
- spsb_setLocationCheckPublicDataCity(model.spsb_city_name);
- [jxh_userDefaults() setObject:spsb_lastCheckPublicDataCity() forKey:SPSBCheckPublicDataCity];
- [jxh_userDefaults() synchronize];
- }
- - (void)serviceAction {
- SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
- vc.spsb_url = SPSBSocialSecurityCityServiceLink;
- [self.navigationController pushViewController:vc animated:true];
- }
- - (void)phoneAction {
- bool can = false;
- SPSBActionSheetViewController *vc = SPSBActionSheetViewController.new;
- @weakify(self)
- if (_gvmData.spsb_shebao_tel.length > 0) {
- can = true;
- [vc addActionWithTitle:@"社保局热线" action:^{
- @strongify(self)
- [self sbPhoneAction];
- }];
- }
- if (_gvmData.spsb_fund_tel.length > 0) {
- can = true;
- [vc addActionWithTitle:@"公积金中心热线" action:^{
- @strongify(self)
- [self fPhoneAction];
- }];
- }
- if (can) {
- [self presentViewController:vc animated:false completion:nil];
- }
- }
- - (void)sbPhoneAction {
- NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", [(_gvmData.spsb_shebao_tel) stringByReplacingOccurrencesOfString:@" " withString:@""]];
- jxh_openUrl([NSURL URLWithString:callPhone], ^(BOOL success) {
- });
- }
- - (void)fPhoneAction {
- NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", [(_gvmData.spsb_fund_tel) stringByReplacingOccurrencesOfString:@" " withString:@""]];
- jxh_openUrl([NSURL URLWithString:callPhone], ^(BOOL success) {
- });
- }
- - (void)shebao_telAction {
- [self phoneAction];
- }
- - (void)fund_telAction {
- [self phoneAction];
- }
- - (void)shebao_urlAction {
- [SPSBUMEventAnalysis analyseEventWithId:@"QueryOfficialSB"];
- SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
- vc.title = @"社保查询";
- vc.spsb_url = _gvmData.spsb_shebao_url;
- [self.navigationController pushViewController:vc animated:true];
- }
- - (void)fund_urlAction {
- [SPSBUMEventAnalysis analyseEventWithId:@"QueryOfficialGJJ"];
- SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
- vc.title = @"公积金查询";
- vc.spsb_url = _gvmData.spsb_fund_url;
- [self.navigationController pushViewController:vc animated:true];
- }
- - (void)wxAction {
- bool can = false;
- SPSBActionSheetViewController *vc = SPSBActionSheetViewController.new;
- @weakify(self)
- if (_gvmData.spsb_shebao_wx.length > 0) {
- can = true;
- [vc addActionWithTitle:@"社保公众号" action:^{
- @strongify(self)
- [self sbWXAction];
- }];
- }
- if (_gvmData.spsb_fund_wx.length > 0) {
- can = true;
- [vc addActionWithTitle:@"公积金公众号" action:^{
- @strongify(self)
- [self fWXAction];
- }];
- }
- if (can) {
- [self presentViewController:vc animated:false completion:nil];
- }
- }
- - (void)sbWXAction {
- [SPSBUMEventAnalysis analyseEventWithId:@"QueryOfficialSGGZH"];
- UIPasteboard *pboard = [UIPasteboard generalPasteboard];
- pboard.string = _gvmData.spsb_shebao_wx;
- [self openWX];
- }
- - (void)fWXAction {
- [SPSBUMEventAnalysis analyseEventWithId:@"QueryOfficialGJJGZH"];
- UIPasteboard *pboard = [UIPasteboard generalPasteboard];
- pboard.string = _gvmData.spsb_fund_wx;
- [self openWX];
- }
- - (void)shebao_wxAction {
- [self wxAction];
- }
- - (void)fund_wxAction {
- [self wxAction];
- }
- - (void)openWX {
- UIPasteboard *pboard = [UIPasteboard generalPasteboard];
- if ([WXApi isWXAppInstalled] && [WXApi isWXAppSupportApi]) {
- SPSBConfirmAlertViewController *vc = [SPSBConfirmAlertViewController alertWithTitle:@"提示" content:[NSString stringWithFormat:@"已复制公众号'%@',现在打开微信吗", pboard.string]];
- [vc setCancelButtonTitle:@"暂不打开" titleColor:nil action:^{
- }];
- [vc setConfirmButtonTitle:@"马上打开" titleColor:nil action:^{
- [WXApi openWXApp];
- }];
- [self presentViewController:vc animated:false completion:nil];
- } else {
- SPSBConfirmAlertViewController *vc = [SPSBConfirmAlertViewController alertWithTitle:@"提示" content:[NSString stringWithFormat:@"已复制公众号'%@',请在微信里搜索", pboard.string]];
- [vc setConfirmButtonTitle:nil titleColor:nil action:^{
- }];
- [self presentViewController:vc animated:false completion:nil];
- }
- }
- #pragma mark - Network Action
- #pragma mark - UI
- - (void)setupUI {
- //取消返回按钮
- self.navigationItem.leftBarButtonItem = nil;
- self.title = @"查询";
- [self createBackgroundView];
- [self createHeaderView];
- [self createWdsbView];
- [self createGvmView];
- }
- - (void)createHeaderView {
- _headerView = [[UIImageView alloc] initWithImage:jxh_getImage(query_home_banner)];
- [_backgroundView addSubview:_headerView];
- [_headerView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.leading.and.trailing.equalTo(0);
- make.height.equalTo(jxh_screenWidth() * 0.272);
- }];
-
- _headerView.userInteractionEnabled = true;
- [_headerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headerViewAction)]];
- }
- #define spsb_queryViewButtonSize (CGSize){(jxh_screenWidth() - 40 - 15) / 2, 120}
- - (void)createWdsbView {
- _wdsbView = UIView.new;
- [_backgroundView addSubview:_wdsbView];
- [_wdsbView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self->_headerView.bottom);
- make.width.equalTo(jxh_screenWidth());
- make.leading.and.trailing.equalTo(0);
- }];
-
- NSArray *titles = @[@"社保订单", @"公积金订单"];
- NSArray *images = @[jxh_getImage(search_shebao_jiao), jxh_getImage(search_gjj_jiao)];
- JXHCenterButton *tempButton = nil;
- for (NSInteger i = 0; i < titles.count; i ++) {
- JXHCenterButton *button = [self createButtonItemWithTitle:titles[i] image:images[i] tag:spsb_queryViewWDSBButtonTag + i action:@selector(buttonAction:)];
- [_wdsbView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- if (tempButton) {
- make.leading.equalTo(tempButton.trailing).offset(15);
- } else {
- make.leading.equalTo(20);
- }
- make.size.equalTo(spsb_queryViewButtonSize);
- make.top.equalTo(62);
- }];
-
- tempButton = button;
- }
-
- for (NSInteger i = 0; i < 2; i ++) {
- UILabel *label = [UILabel convenienceWithFont:spsb_semiboldFont(18) text:i == 0 ? @"我的订单查询" : @"政府官网查询" textColor:spsb_333333_color()];
- [_wdsbView addSubview:label];
- [label makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(34);
- make.top.equalTo(i == 0 ? 20 : 214);
- if (i == 1) {
- make.bottom.equalTo(-16);
- }
- }];
-
- UIView *icon = UIView.new;
- icon.backgroundColor = spsb_3296FB_color();
- [icon setLayerCornerRadius:1.75 clipToBounds:false];
- [_wdsbView addSubview:icon];
- [icon makeConstraints:^(JXHConstraintMaker *make) {
- make.size.equalTo(CGSizeMake(3.5, 17));
- make.leading.equalTo(20);
- make.centerY.equalTo(label);
- }];
-
- if (i == 1) {
- UIButton *cityButton = [UIButton convenienceWithTarget:self action:@selector(changeCity)];
- [cityButton setLayerCornerRadius:13 clipToBounds:false];
- [cityButton setLayerBorderWidth:0.7 borderColor:spsb_3296FB_color()];
- [_wdsbView addSubview:cityButton];
- [cityButton makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-20);
- make.centerY.equalTo(label);
- make.height.equalTo(26);
- make.leading.greaterThanOrEqualTo(jxh_screenWidth() / 2);
- }];
-
- _cityLabel = [UILabel convenienceWithFont:spsb_semiboldFont(14) text:_gvmData.spsb_city_name textColor:spsb_3296FB_color()];
- [cityButton addSubview:_cityLabel];
- [_cityLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(13);
- make.centerY.equalTo(cityButton);
- }];
-
- UIImageView *cityIcon = [[UIImageView alloc] initWithImage:jxh_getImage(city_choose)];
- [cityButton addSubview:cityIcon];
- [cityIcon setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
- [cityIcon makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(self->_cityLabel.trailing).offset(4);
- make.trailing.equalTo(-11);
- make.centerY.equalTo(cityButton);
- make.size.equalTo(CGSizeMake(8, 8));
- }];
- }
-
- }
- }
- - (void)createGvmView {
- if (!_gvmView) {
- _gvmView = UIView.new;
- _gvmView.backgroundColor = spsb_FFFFFF_color(1.f);
- [_backgroundView addSubview:_gvmView];
- [_gvmView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self->_wdsbView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.bottom.equalTo(-78);
- }];
- }
-
-
- NSMutableArray *array = [@[@"shebao_url", @"fund_url", @"shebao_wx", @"fund_wx", @"shebao_tel", @"fund_tel"] mutableCopy];
- if (_gvmData.spsb_shebao_tel.length > 0) {
- [array removeObject:@"fund_tel"];
- } else {
- [array removeObject:@"shebao_tel"];
- }
- if (_gvmData.spsb_shebao_wx.length > 0) {
- [array removeObject:@"fund_wx"];
- } else {
- [array removeObject:@"shebao_wx"];
- }
- NSArray *titles = @[@"社保查询", @"公积金查询", @"公众号查询", @"政府官方热线", @""];
- NSArray *images = @[jxh_getImage(search_shebao_jiao), jxh_getImage(search_gjj_jiao), jxh_getImage(search_wechat), jxh_getImage(search_phone)];
- JXHCenterButton *tempButton = nil;
- NSInteger count = 0;
- for (NSInteger i = 0; i < array.count; i ++) {
- NSString *key = [NSString stringWithFormat:@"spsb_%@", array[i]];
- NSString *value = [_gvmData valueForKey:key];
- if (!value || value.length == 0) {
- continue;
- }
- SEL action = NSSelectorFromString([NSString stringWithFormat:@"%@Action", array[i]]);
- JXHCenterButton *button = [self createButtonItemWithTitle:titles[i] image:images[i] tag:spsb_queryViewGVMButtonTag + i action:action];
- [_gvmView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- if (tempButton && count % 2 == 1) {
- make.leading.equalTo(tempButton.trailing).offset(15);
- make.trailing.equalTo(-20);
- } else {
- make.leading.equalTo(20);
- }
- if (tempButton && count % 2 == 1) {
- make.top.equalTo(tempButton);
- } else if (tempButton && count % 2 == 0) {
- make.top.equalTo(tempButton.bottom).offset(15);
- } else {
- make.top.equalTo(0);
- }
- make.size.equalTo(spsb_queryViewButtonSize);
- }];
-
- tempButton = button;
- count ++;
- }
-
- JXHCenterButton *button = [self createButtonItemWithTitle:@"城市服务查询" image:jxh_getImage(search_service) tag:0 action:@selector(serviceAction)];
- [_gvmView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- if (tempButton && count % 2 == 1) {
- make.leading.equalTo(tempButton.trailing).offset(15);
- make.trailing.equalTo(-20);
- } else {
- make.leading.equalTo(20);
- }
- if (tempButton && count % 2 == 1) {
- make.top.equalTo(tempButton);
- } else if (tempButton && count % 2 == 0) {
- make.top.equalTo(tempButton.bottom).offset(15);
- } else {
- make.top.equalTo(0);
- }
- make.size.equalTo(spsb_queryViewButtonSize);
- make.bottom.equalTo(0);
- }];
- }
- - (JXHCenterButton *)createButtonItemWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag action:(SEL)action {
- JXHCenterButton *button = [JXHCenterButton convenienceWithAxis:JXHCenterButtonAxisVertical interval:12 font:spsb_font(14) target:self action:action];
- button.tag = tag;
- button.backgroundColor = spsb_FFFFFF_color(1.f);
- [button setTitle:title titleColor:spsb_333333_color() image:image backgroundImage:nil state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
- [button.layer setShadowWithOffset:(CGSize){0, 0} alpha:0.08 blur:32 spread:0 color:spsb_3296FB_color() cornerRadius:8 pathRect:(CGRect){CGPointZero, spsb_queryViewButtonSize}];
-
- return button;
- }
- - (void)reloadGvmView {
- _cityLabel.text = _gvmData.spsb_city_name;
- NSArray *arr = _gvmView.subviews;
- for (UIView *view in arr) {
- [view removeFromSuperview];
- }
- [self createGvmView];
- }
- - (void)createBackgroundView {
- _backgroundView = [UIScrollView convenienceWithBackgroundColor:spsb_FFFFFF_color(1.f)];
- [self.view addSubview:_backgroundView];
- [_backgroundView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self.view.safetop);
- make.bottom.equalTo(-SPSBTabBarHeight);
- make.leading.and.trailing.equalTo(0);
- }];
- }
- @end
- #undef spsb_queryViewWDSBButtonTag
- #undef spsb_queryViewGVMButtonTag
- #undef spsb_queryViewButtonSize
|