123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518 |
- //
- // SPSBHomeViewController.m
- // 我的社保
- //
- // Created by shanp on 2021/4/20.
- //
- #import "SPSBHomeViewController.h"
- #import "SPSBUIGeneralHeader.h"
- #import "UIViewController+SPSBInitialization.h"
- #import "UIViewController+SPSBNavigationBar.h"
- #import "UIViewController+SPSBNetworkManager.h"
- #import "SPSBNotificationDelegateManager.h"
- #import "SPSBHtmlViewController.h"
- #import "WXApi.h"
- #import "SPSBAdvertisementBannerScrollView.h"
- #import "SPSBKeyProfile.h"
- #import "SPSBUMEventAnalysis.h"
- #import "SPSBBusinessManager.h"
- #import "SPSBHomeViewADModel.h"
- #import <CALayer+JXHShadow.h>
- #import <UIImageView+WebCache.h>
- #import "SPSBMyPurchaseOrder.h"
- #import "SPSBRouteManager.h"
- #import "SPSBCustomerServiceManager.h"
- #import <BMKLocationKit/BMKLocationManager.h>
- #import "SPSBSQLProfile.h"
- #import "SPSBPurchaseGJJDetailsViewController.h"
- #import "SPSBPurchaseSBDetailsViewController.h"
- #import "SPSBTransferDetailsViewController.h"
- #import "SPSBHomeViewButtonsModel.h"
- #define spsb_navigationButtonTag 2000
- #define spsb_buttonViewButtonTag 3000
- #define spsb_calculateButtonTag 4000
- #define spsb_adsViewButtonTag 3000
- #define spsb_adsViewButtonIconTag 10000
- #define spsb_adsViewButtonTitleTag 10001
- #define spsb_adsViewButtonContentTag 10002
- #define spsb_adsViewHotTag 4000
- #define spsb_adsViewScrollButtonTag 5000
- #define spsb_strategyViewButtonTag 3000
- #define spsb_policyViewButtonTag 6000
- typedef NS_ENUM(NSUInteger, SPSBPurchaseButtonType) {
- SPSBPurchaseButtonTypeSBPurchase,
- SPSBPurchaseButtonTypeGJJPurchase,
- SPSBPurchaseButtonTypeSBSupplementary,
- SPSBPurchaseButtonTypeGJJSupplementary,
- SPSBPurchaseButtonTypeSBTransfer,
- SPSBPurchaseButtonTypeGJJTransfer
- };
- typedef struct SPSBBannerResult {
- NSArray *spsb_images;
- NSArray *spsb_names;
- NSArray *spsb_actions;
- NSArray *spsb_path;
- } SPSBBannerResult;
- @interface SPSBHomeViewController ()<UIScrollViewDelegate, SPSBNotificationDelegate, SPSBAdvertisementBannerPorotocol> {
- UIScrollView *_bgView;
- UIView *_navigationContentView;
- UIImageView *_imageView;
- UIView *_buttonView;
- NSUInteger _buttonCount;
- UIScrollView *_buttonScrollView;
- UIView *_prossView;
- UIView *_choseProssLine;
- UIStackView *_middleView;
-
- UIView *_bannerView;
- SPSBAdvertisementBannerScrollView *_banner;
-
- UIView *_adsView;
- UIView *_adsButtonView;
- UIButton *_adsChangeButton;
- NSInteger _adsEndIndex;
- NSInteger _adsScrollTimes;
- UIView *_adsScrollView;
- NSMutableArray<SPSBHomeViewADModel *> *_adsArray;
-
- UIView *_featureView;
- UIView *_policyView;
- UIView *_strategyView;
-
- NSArray<UIImage *> *_bannerImages;
- NSArray *_bannerActions;
-
- bool _isFirstLoad;
- BMKLocationManager *_locationManager;
- UIView *_navigationBarButtonView;
- }
- @end
- @implementation SPSBHomeViewController
- - (instancetype)init {
- self = [super init];
- if (!self) return nil;
- self.spsb_isLightContent = true;
- _isFirstLoad = true;
- _buttonCount = 0;
- spsb_setNotificationKeys(@[SPSBAppStatusNotificationKey, SPSBPurchaseNotificationKey]);
- debugLog(@"微信版本----%@", [WXApi getApiVersion]);
- return self;
- }
- - (void)dealloc {
- spsb_removeNotificationKeys(@[SPSBAppStatusNotificationKey, SPSBPurchaseNotificationKey]);
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- return self.spsb_statusBarStyle;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setupUI];
- [self getLocation];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- UIView *view = [_adsButtonView viewWithTag:spsb_adsViewHotTag];
- if (view) {
- [self adsHotAnimation:true view:view];
- }
- if (_isFirstLoad) {
- _isFirstLoad = false;
- if (spsb_customerServiceManager().spsb_isClickNotification) {
- [spsb_customerServiceManager() delayToOnlineContact];
- } else {
- [spsb_customerServiceManager() checkSobot];
- }
- }
- }
- #pragma mark - 定位
- - (void)getLocation {
- _locationManager = [[BMKLocationManager alloc] init];
- [_locationManager requestLocationWithReGeocode:true withNetworkState:false completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {
-
- if (location.location) {
- debugLog(@"------------%@", location.rgcData.city);
- spsb_setCoordinate(location.location.coordinate);
- NSString *locationCity = location.rgcData.city;
- for (NSInteger i = 0; i < locationCity.length; i ++) {
- debugLog(@"----%@", [locationCity substringToIndex:i + 1]);
- NSArray *array = [JXHFMDBManager searchWithPath:SPSBShanpQueryCitySQL backKey:@"city_name" condition:^id(FMDatabase *database) {
- return [database executeQuery:@"select * from t_sp_query_city where city_name = ?", [locationCity substringToIndex:i + 1]];
- }];
- if (array.count > 0) {
- spsb_setLocationCheckPublicDataCity(array[0]);
- break;
- }
- }
- return;
- }
-
- if (spsb_lastCheckPublicDataCity().length > 0) {
- spsb_setLocationCheckPublicDataCity(spsb_lastCheckPublicDataCity());
- } else {
- 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(@"北京");
- }
- }
- }];
- }
- #pragma mark - Action
- - (void)topAction {
- [_bgView setContentOffset:(CGPoint){0, 0} animated:true];
- }
- - (void)strategyAction:(UIButton *)sender {
- SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
- switch (sender.tag - spsb_strategyViewButtonTag) {
- case 0: {
- vc.spsb_url = SPSBWhyToPayLink;
- vc.title = @"缴五险一金的好处";
- }
- break;
- case 1: {
- vc.spsb_url = SPSBHowToPayLink;
- vc.title = @"服务指南";
- }
- break;
- case 2: {
- vc.spsb_url = SPSBQueryAnytimeLink;
- vc.title = @"查询指引";
- }
- break;
-
- default:
- break;
- }
-
- [self.navigationController pushViewController:vc animated:true];
- }
- - (void)featureAction {
- SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
- vc.spsb_url = SPSBServiceForEnterpriseLink;
- vc.spsb_isJsMethod = true;
- vc.spsb_jsString = @""
- "var app = {\n"
- "\n"
- " entReturn : function()\n"
- " {\n"
- " var url = \"iOSvsJS:backAction\";\n"
- " document.location = url;\n"
- " }\n"
- "}";
- [self.navigationController pushViewController:vc animated:true];
- }
- - (void)purchaseViewAction:(UIButton *)sender {
- SPSBPurchaseButtonType type = sender.tag - spsb_buttonViewButtonTag;
- if (type <= SPSBPurchaseButtonTypeGJJSupplementary) {
- spsb_setMyPurchaseOrder(SPSBMyPurchaseOrder.new);
- switch (type) {
- case SPSBPurchaseButtonTypeSBPurchase: {
- [SPSBUMEventAnalysis analyseEventWithId:@"ShebaoPurchase"];
- spsb_myPurchaseOrder().spsb_isSupplementaryPay = false;
- [self.navigationController pushViewController:SPSBPurchaseSBDetailsViewController.new animated:true];
- }
- break;
- case SPSBPurchaseButtonTypeGJJPurchase: {
- [SPSBUMEventAnalysis analyseEventWithId:@"GongjijinPurchase"];
- spsb_myPurchaseOrder().spsb_isSupplementaryPay = false;
- [self.navigationController pushViewController:SPSBPurchaseGJJDetailsViewController.new animated:true];
- }
- break;
- case SPSBPurchaseButtonTypeSBSupplementary: {
- [SPSBUMEventAnalysis analyseEventWithId:@"ShebaoPurchase"];
- spsb_myPurchaseOrder().spsb_isSupplementaryPay = true;
- [self.navigationController pushViewController:SPSBPurchaseSBDetailsViewController.new animated:true];
- }
- break;
- case SPSBPurchaseButtonTypeGJJSupplementary: {
- [SPSBUMEventAnalysis analyseEventWithId:@"GongjijinPurchase"];
- spsb_myPurchaseOrder().spsb_isSupplementaryPay = true;
- [self.navigationController pushViewController:SPSBPurchaseGJJDetailsViewController.new animated:true];
- }
- break;
- default:
- break;
- }
- } else {
- SPSBTransferDetailsViewController *vc = SPSBTransferDetailsViewController.new;
- vc.spsb_type = type == SPSBPurchaseButtonTypeSBTransfer ? SPSBSocialInsuranceTransfer : SPSBAccumulationFundTransfer;
- [self.navigationController pushViewController:vc animated:true];
- }
- }
- - (void)navigationPurchaseAction:(UIButton *)sender {
- spsb_setMyPurchaseOrder(SPSBMyPurchaseOrder.new);
- switch (sender.tag - spsb_navigationButtonTag) {
- case SPSBPurchaseButtonTypeSBPurchase: {
- spsb_myPurchaseOrder().spsb_isSupplementaryPay = false;
- [self.navigationController pushViewController:SPSBPurchaseSBDetailsViewController.new animated:true];
- }
- break;
- case SPSBPurchaseButtonTypeGJJPurchase: {
- spsb_myPurchaseOrder().spsb_isSupplementaryPay = false;
- [self.navigationController pushViewController:SPSBPurchaseGJJDetailsViewController.new animated:true];
- }
- break;
- case SPSBPurchaseButtonTypeSBSupplementary: {
- spsb_myPurchaseOrder().spsb_isSupplementaryPay = true;
- [self.navigationController pushViewController:SPSBPurchaseSBDetailsViewController.new animated:true];
- }
- break;
- case SPSBPurchaseButtonTypeGJJSupplementary: {
- spsb_myPurchaseOrder().spsb_isSupplementaryPay = true;
- [self.navigationController pushViewController:SPSBPurchaseGJJDetailsViewController.new animated:true];
- }
- break;
- default:
- break;
- }
- }
- - (void)calculateAction:(UIButton *)sender {
- if (sender.tag == spsb_calculateButtonTag) {
- SPSBHtmlViewController *explainViewController = [[SPSBHtmlViewController alloc] init];
- explainViewController.spsb_url = SPSBHomeSocialSecurityCalculatorLink;
- [self.navigationController pushViewController:explainViewController animated:true];
- } else if (sender.tag == spsb_calculateButtonTag + 1) {
- WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
- launchMiniProgramReq.userName = @"gh_e7ef692d1516"; //拉起的小程序的username
- launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
- [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
- }];
- }
- }
- - (void)getBannerImagesSuccess:(SPSBBannerResult)result {
- NSArray *oldImages = [jxh_userDefaults() objectForKey:SPSBBarImageList];
- [jxh_userDefaults() setObject:result.spsb_path forKey:SPSBBarImageList];
- [jxh_userDefaults() setObject:result.spsb_actions forKey:SPSBBarImageAction];
- [jxh_userDefaults() synchronize];
- _bannerImages = result.spsb_images;
- _bannerActions = result.spsb_actions;
- if (_banner && _banner.superview) {
- [self judgeBannerView];
- }
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
- for (NSString *old in oldImages) {
- if (![(result.spsb_names) containsObject:old]) {
- NSMutableString *str = [NSMutableString stringWithString:old];
- [str replaceOccurrencesOfString:@"/" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, str.length)];
- jxh_deleteFileInCache(SPSBBarImageList, str);
- }
- }
- });
- }
- - (void)adsAction:(UIButton *)sender {
- NSInteger i = sender.tag - spsb_adsViewButtonTag;
- if (_adsArray.count > i) {
- [self countAdsTouchActionWithIndex:i];
- SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
- vc.spsb_url = _adsArray[i].spsb_link;
- [self.navigationController pushViewController:vc animated:true];
- }
- }
- - (void)policyViewAction:(UIButton *)sender {
- NSInteger i = sender.tag - spsb_policyViewButtonTag;
- if (spsb_policyArray().count > i) {
- SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
- vc.spsb_url = spsb_policyArray()[i].spsb_link;
- [self.navigationController pushViewController:vc animated:true];
- }
- }
- - (void)countAdsTouchActionWithIndex:(NSUInteger)index {
- NSMutableString *actionId = [_adsArray[index].spsb_img mutableCopy];
- [actionId replaceOccurrencesOfString:@"." withString:@"" options:NSLiteralSearch range:NSMakeRange(0, actionId.length)];
- [actionId replaceOccurrencesOfString:@"/" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, actionId.length)];
- [SPSBUMEventAnalysis analyseEventWithId:actionId];
- }
- - (void)changeAds {
- [SPSBUMEventAnalysis analyseEventWithId:@"more"];
- [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(scrollAdsView) object:nil];
- _adsScrollView.hidden = true;
- [_adsArray removeAllObjects];
- NSArray *ads = spsb_adsArray();
- for (NSInteger i = 0; i < 6; i ++) {
- _adsEndIndex ++;
- if (_adsEndIndex > ads.count - 1) {
- _adsEndIndex = 0;
- }
- SPSBHomeViewADModel *model = ads[_adsEndIndex];
- UIButton *button = [_adsView viewWithTag:spsb_adsViewButtonTag + i];
- button.hidden = false;//防止切换时刚好在做动画
- UIImageView *icon = [button viewWithTag:spsb_adsViewButtonIconTag];
- UILabel *title = [button viewWithTag:spsb_adsViewButtonTitleTag];
- UILabel *content = [button viewWithTag:spsb_adsViewButtonContentTag];
- [icon sd_setImageWithURL:spsb_fileURL(model.spsb_img)];
- title.text = model.spsb_title;
- content.text = model.spsb_notes;
-
- UIImageView *hot = [button viewWithTag:spsb_adsViewHotTag];
- if (hot) {
- hot.hidden = true;
- }
-
- [_adsArray addObject:model];
- }
- _adsScrollTimes = 1;
- [self performSelector:@selector(scrollAdsView) withObject:nil afterDelay:2];
- }
- - (void)scrollAdsView {
- NSArray *ads = spsb_adsArray();
- NSInteger lastIndex = _adsEndIndex + _adsScrollTimes - 1;
- if (lastIndex > ads.count - 1) {
- lastIndex = lastIndex - ads.count;
- }
- if (_adsScrollTimes > 2) {
- _adsScrollTimes = 0;
- } else if (_adsScrollTimes + 6 > ads.count) {
- _adsScrollTimes = 0;
- }
- NSInteger nextIndex = _adsEndIndex + _adsScrollTimes;
- if (nextIndex > ads.count - 1) {
- nextIndex = nextIndex - ads.count;
- }
- if (ads.count <= lastIndex || ads.count <= nextIndex) return;
- SPSBHomeViewADModel *model = ads[lastIndex];
- UIButton *firstButton = [_adsScrollView viewWithTag:spsb_adsViewScrollButtonTag];
- UIImageView *icon = [firstButton viewWithTag:spsb_adsViewButtonIconTag];
- UILabel *title = [firstButton viewWithTag:spsb_adsViewButtonTitleTag];
- UILabel *content = [firstButton viewWithTag:spsb_adsViewButtonContentTag];
- [icon sd_setImageWithURL:spsb_fileURL(model.spsb_img)];
- title.text = model.spsb_title;
- content.text = model.spsb_notes;
- [firstButton makeConstraints:^(JXHConstraintMaker *make) {
- make.top.update(0);
- }];
- model = ads[nextIndex];
- UIButton *secondButton = [_adsScrollView viewWithTag:spsb_adsViewScrollButtonTag + 1];
- icon = [secondButton viewWithTag:spsb_adsViewButtonIconTag];
- title = [secondButton viewWithTag:spsb_adsViewButtonTitleTag];
- content = [secondButton viewWithTag:spsb_adsViewButtonContentTag];
- [icon sd_setImageWithURL:spsb_fileURL(model.spsb_img)];
- title.text = model.spsb_title;
- content.text = model.spsb_notes;
- [secondButton makeConstraints:^(JXHConstraintMaker *make) {
- make.top.update(66);
- }];
-
- [_adsScrollView layoutSubviews];
- _adsScrollView.hidden = false;
-
- UIButton *button = [_adsView viewWithTag:spsb_adsViewButtonTag + 5];//正常的button
- icon = [button viewWithTag:spsb_adsViewButtonIconTag];
- title = [button viewWithTag:spsb_adsViewButtonTitleTag];
- content = [button viewWithTag:spsb_adsViewButtonContentTag];
- [icon sd_setImageWithURL:spsb_fileURL(model.spsb_img)];
- title.text = model.spsb_title;
- content.text = model.spsb_notes;
- _adsArray[5] = model;
- button.hidden = true;
- [firstButton makeConstraints:^(JXHConstraintMaker *make) {
- make.top.update(-66);
- }];
- [secondButton makeConstraints:^(JXHConstraintMaker *make) {
- make.top.update(0);
- }];
-
- [UIView animateWithDuration:0.5 animations:^{
- [self->_adsScrollView layoutSubviews];
- } completion:^(BOOL finished) {
- button.hidden = false;
- if (!self->_adsScrollView.hidden) {
- self->_adsScrollView.hidden = true;
- self->_adsScrollTimes ++;
- [self performSelector:@selector(scrollAdsView) withObject:nil afterDelay:2];
- }
- }];
- }
- - (void)adsHotAnimation:(bool)big view:(UIView *)view {
- if (view.hidden) {
- return;
- }
- if (!self.view.window) {
- return;
- }
- CGFloat scale = big ? 1.2 : 1;
- [UIView animateWithDuration:0.45 animations:^{
- view.transform = CGAffineTransformMakeScale(scale, scale);
- } completion:^(BOOL finished) {
- [self adsHotAnimation:!big view:view];
- }];
- }
- #pragma mark - Network Action
- #pragma mark - SPSBAdvertisementBannerPorotocol
- - (void)advertisementView:(SPSBAdvertisementBannerScrollView *)advertisementView selectImageWithIndex:(NSInteger)index {
- if (_bannerActions && _bannerActions.count > index) {
- [self countBannerTouchActionWithIndex:index];
- if ([_bannerActions[index] isEqualToString:@""]) {
- debugLog(@"无跳转");
- return;
- }
- if ([_bannerActions[index] hasPrefix:@"/"]) {
- debugLog(@"跳转H5");
- SPSBHtmlViewController *explainViewController = SPSBHtmlViewController.new;
- explainViewController.spsb_url = spsb_fileUrl(_bannerActions[index]);
- explainViewController.spsb_jsString = @""
- "var app = {\n"
- "\n"
- " entReturn : function()\n"
- " {\n"
- " var url = \"iOSvsJS:backAction\";\n"
- " document.location = url;\n"
- " }\n"
- "}";
- explainViewController.spsb_isJsMethod = true;
- [self.navigationController pushViewController:explainViewController animated:true];
- return;
- }
- if ([_bannerActions[index] hasPrefix:@"http"]) {
- debugLog(@"跳转外链H5");
- SPSBHtmlViewController *explainViewController = SPSBHtmlViewController.new;
- explainViewController.spsb_url = _bannerActions[index];
- [self.navigationController pushViewController:explainViewController animated:true];
- return;
- }
- debugLog(@"跳转页面");
- NSDictionary *dict = jxh_jsonToDictionary(_bannerActions[index]);
- if (dict.count > 0) {
- NSString *className = [dict allKeys][0];
- Class targetClass = NSClassFromString(className);
- if (targetClass) {
- id target = [[targetClass alloc] init];
- if ([dict[className] isKindOfClass:[NSDictionary class]]) {
- [dict[className] enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
- [target setValue:obj forKey:key];
- }];
- }
- [self.navigationController pushViewController:target animated:true];
- }
- }
- }
- }
- - (void)countBannerTouchActionWithIndex:(NSUInteger)index {
- NSArray *barImageArray = [jxh_userDefaults() objectForKey:SPSBBarImageList];
- NSMutableString *actionId = [barImageArray[index] mutableCopy];
- [actionId replaceOccurrencesOfString:@"." withString:@"" options:NSLiteralSearch range:NSMakeRange(0, actionId.length)];
- [actionId replaceOccurrencesOfString:@"/" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, actionId.length)];
- [SPSBUMEventAnalysis analyseEventWithId:actionId];
- }
- #pragma mark - SPSBNotificationDelegate
- - (void)spsb_appNeedRefreshBannerImages:(NSArray *)images actions:(NSArray *)actions {
- __block SPSBBannerResult result;
- if (images.count == 0) {
- result.spsb_names = @[];
- result.spsb_path = @[];
- result.spsb_actions = @[];
- result.spsb_images = @[];
- [self getBannerImagesSuccess:result];
- return;
- }
- __block NSInteger num = 0;
- __block NSMutableArray *imageArray = NSMutableArray.new;
- __block NSMutableArray *imageNameArray = NSMutableArray.new;
- __block NSMutableArray *actionArray = NSMutableArray.new;
- __block NSArray *pathArrayCopy = images.copy;//把pathArray复制进block防止pathArray提前释放
- __block NSArray *barImageActionArray = actions.copy;
- for (NSInteger i = 0; i < pathArrayCopy.count; i ++) {
- if ([pathArrayCopy[i] isKindOfClass:[NSString class]]) {
- NSMutableString *str = [NSMutableString stringWithString:pathArrayCopy[i]];
- [str replaceOccurrencesOfString:@"/" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, str.length)];
- UIImage *tempImage = [UIImage imageWithData:jxh_loadImageData(SPSBBarImageList, str)];
- if (tempImage) {
- [imageArray addObject:tempImage];
- [imageNameArray addObject:pathArrayCopy[i]];
- if (barImageActionArray) {
- [actionArray addObject:barImageActionArray[i]];
- }
- num ++;
- if (num == pathArrayCopy.count) {
- result.spsb_names = imageNameArray;
- result.spsb_path = pathArrayCopy;
- result.spsb_actions = actionArray;
- result.spsb_images = imageArray;
- [self getBannerImagesSuccess:result];
- }
- continue;
- }
- __block NSInteger index = i;
- @weakify(self)
- [self.spsb_networkManager networkDownloadImageWithUrl:spsb_fileUrl(pathArrayCopy[index]) key:pathArrayCopy[index] completion:^(NSError * _Nonnull error, id _Nullable data) {
- @strongify(self)
- num ++;
- if (error.code == SPSBNetworkErrorCodeSuccess && data[@"image"]) {
- [imageArray addObject:data[@"image"]];
- [imageNameArray addObject:pathArrayCopy[index]];
- if (barImageActionArray) {
- [actionArray addObject:barImageActionArray[index]];
- }
- NSMutableString *str = [NSMutableString stringWithString:pathArrayCopy[index]];
- [str replaceOccurrencesOfString:@"/" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, str.length)];
- jxh_saveImageToCacheDir(SPSBBarImageList, data[@"image"], str);
- }
- if (num == pathArrayCopy.count) {
- result.spsb_names = imageNameArray;
- result.spsb_path = pathArrayCopy;
- result.spsb_actions = actionArray;
- result.spsb_images = imageArray;
- [self getBannerImagesSuccess:result];
- }
- }];
- } else {
- num ++;
- if (num == pathArrayCopy.count) {
- result.spsb_names = imageNameArray;
- result.spsb_path = pathArrayCopy;
- result.spsb_actions = actionArray;
- result.spsb_images = imageArray;
- [self getBannerImagesSuccess:result];
- }
- }
- }
- }
- - (void)spsb_appNeedRefreshHomeViewAds {
- if (_adsView && _adsView.superview) {
- [self judgeAdsView];
- }
- }
- - (void)spsb_appNeedRefreshHomeViewPolicy {
- if (_policyView && _policyView.superview) {
- [self judgePolicyView];
- }
- }
- - (void)spsb_appNeedRefreshHomeViewButtons {
- if (_prossView && _prossView.superview) {
- [self judgeButtonView];
- }
- }
- - (void)spsb_shouldRefreshPurchaseStatus {
- if (spsb_myPurchaseOrder() && !spsb_myPurchaseOrder().spsb_isSupplementaryPay) {
- [jxh_keyWindow() dismissToast];
- [SPSBRouteManager navigationBackRoot];
- }
- }
- - (void)spsb_shouldRefreshSupplementaryPayStatus {
- if (spsb_myPurchaseOrder() && spsb_myPurchaseOrder().spsb_isSupplementaryPay) {
- [jxh_keyWindow() dismissToast];
- [SPSBRouteManager navigationBackRoot];
- }
- }
- #pragma mark - UIScrollViewDelegate
- - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
- if (scrollView == _buttonScrollView) {
- if (_buttonCount < 5) return;
- if ((*targetContentOffset).x > jxh_screenWidth() / 4) {
- *targetContentOffset = CGPointMake(jxh_screenWidth() + jxh_screenWidth() / 4 * (_buttonCount - 4), 0);
- [_choseProssLine makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.update(20);
- }];
- } else {
- *targetContentOffset = CGPointMake(0, 0);
- [_choseProssLine makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.update(0);
- }];
- }
- [UIView animateWithDuration:0.3 animations:^{
- [self->_choseProssLine.superview layoutSubviews];
- }];
- }
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- if (scrollView == _bgView) {
- self.spsb_navigationBar.alpha = (scrollView.contentOffset.y) * 0.025;
- if (self.spsb_navigationBar.alpha > 0.5) {
- self.spsb_isLightContent = false;
- } else {
- self.spsb_isLightContent = true;
- }
- _navigationContentView.alpha = ((scrollView.contentOffset.y - 200 + jxh_viewHeight(self.spsb_navigationBar)) * 0.025);
- }
- }
- #pragma mark - UI
- - (void)setupUI {
- //取消返回按钮
- self.navigationItem.leftBarButtonItem = nil;
- self.spsb_isHiddenNavigationBar = true;
- [self createNavigationBar];
- [self createBgView];
- [self setNavigationBar];
- [self createImageView];
- [self createButtonView];
- [self createMiddleView];
- [self createBannerView];
- [self createAdsView];
- [self createFeatureView];
- [self createPolicyView];
- [self createStrategyView];
- }
- - (void)createStrategyView {
- _strategyView = UIView.new;
- _strategyView.backgroundColor = spsb_FFFFFF_color(1.f);
- [_bgView addSubview:_strategyView];
- [_strategyView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self->_policyView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.bottom.equalTo(0);
- }];
-
- UIView *topView = UIView.new;
- [_strategyView addSubview:topView];
- [topView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.leading.and.trailing.equalTo(0);
- make.height.equalTo(45);
- }];
-
- UILabel *title = [UILabel convenienceWithFont:spsb_semiboldFont(18) text:@"新手指南" textColor:spsb_333333_color()];
- [topView addSubview:title];
- [title makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.bottom.equalTo(0);
- make.leading.equalTo(30);
- }];
-
- UIView *icon = UIView.new;
- icon.backgroundColor = spsb_3296FB_color();
- [icon setLayerCornerRadius:2 clipToBounds:false];
- [topView addSubview:icon];
- [icon makeConstraints:^(JXHConstraintMaker *make) {
- make.centerY.equalTo(topView);
- make.leading.equalTo(16);
- make.size.equalTo(CGSizeMake(4, 17));
- }];
-
- NSArray *contentArray = @[@"haochu", @"buy", @"chaxun", @"缴五险一金的好处", @"服务指南", @"查询指引", @"解决就读、买房买车等囧况", @"操作流程简单,方便快捷", @"缴费明细,随时知晓",];
-
- UIButton *tempButton;
- for (NSInteger i = 0; i < 3; i ++) {
- if (i == 0) continue;
- UIButton *button = [UIButton convenienceWithTarget:self action:@selector(strategyAction:)];
- button.tag = spsb_strategyViewButtonTag + i;
- [_strategyView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- if (tempButton) {
- make.top.equalTo(tempButton.bottom);
- } else {
- make.top.equalTo(topView.bottom);
- }
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(76);
- }];
-
- UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:contentArray[i]]];
- [button addSubview:icon];
- [icon makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(16);
- make.top.equalTo(16);
- make.size.equalTo(CGSizeMake(24, 24));
- }];
-
- UILabel *firstLine = [UILabel convenienceWithFont:spsb_font(16) text:contentArray[i + 3] textColor:spsb_333333_color()];
- [button addSubview:firstLine];
- [firstLine makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(56);
- make.top.equalTo(16);
- }];
-
- UILabel *secondLine = [UILabel convenienceWithFont:spsb_font(13) text:contentArray[i + 6] textColor:spsb_999999_color()];
- [button addSubview:secondLine];
- [secondLine makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(56);
- make.bottom.equalTo(-15);
- }];
-
- UIImageView *arrowView = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
- [button addSubview:arrowView];
- [arrowView makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-16);
- make.centerY.equalTo(firstLine);
- }];
-
- if (i < 2) {
- [button createLineWithLocation:JXHLineLocationBottom headOffset:54 footOffset:0];
- }
-
- tempButton = button;
- }
-
- UIView *bottomView = [[UIView alloc] init];
- bottomView.backgroundColor = spsb_F5F5F5_color();
- [_strategyView addSubview:bottomView];
- [bottomView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.trailing.and.bottom.equalTo(0);
- make.top.equalTo(tempButton.bottom).offset(16);
- make.height.equalTo(78);
- }];
-
- UIImageView *bottom = [[UIImageView alloc] initWithImage:jxh_getImage(home_footer)];
- [bottomView addSubview:bottom];
- [bottom makeConstraints:^(JXHConstraintMaker *make) {
- make.center.equalTo(bottomView);
- make.size.equalTo(CGSizeMake(18 * 8.45, 18));
- }];
-
- }
- - (void)createFeatureView {
- _featureView = UIView.new;
- _featureView.backgroundColor = spsb_FFFFFF_color(1.f);
- [_bgView addSubview:_featureView];
- [_featureView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self->_middleView.bottom);
- make.leading.and.trailing.equalTo(0);
- }];
-
- UIButton *bottomButton = [UIButton convenienceWithTarget:self action:@selector(featureAction)];
- [bottomButton setBackgroundImage:jxh_getImage(qiye) state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
- [_featureView addSubview:bottomButton];
- [bottomButton makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(16);
- make.trailing.equalTo(-16);
- make.top.equalTo(16);
- make.size.equalTo(CGSizeMake(jxh_screenWidth() - 32, (jxh_screenWidth() - 32) *0.2857));
- make.bottom.equalTo(-16);
- }];
- }
- - (void)createPolicyView {
- _policyView = UIView.new;
- _policyView.backgroundColor = spsb_FFFFFF_color(1.f);
- _policyView.hidden = true;
- [_bgView addSubview:_policyView];
- [_policyView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self->_featureView.bottom);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(0);
- }];
- [self judgePolicyView];
- }
- - (void)judgePolicyView {
- for (UIView *view in _policyView.subviews) {
- [view removeFromSuperview];
- }
- NSArray<SPSBHomeViewADModel *> *policy = spsb_policyArray();
- if (policy.count == 0) {
- [_policyView makeConstraints:^(JXHConstraintMaker *make) {
- make.height.update(0);
- }];
- _policyView.hidden = true;
- return;
- }
- _policyView.hidden = false;
- [_policyView makeConstraints:^(JXHConstraintMaker *make) {
- make.height.update(45 + policy.count * 76 + 10);
- }];
-
- UIView *topView = UIView.new;
- [_policyView addSubview:topView];
- [topView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.leading.and.trailing.equalTo(0);
- make.height.equalTo(45);
- }];
-
- UILabel *title = [UILabel convenienceWithFont:spsb_semiboldFont(18) text:@"政策解读" textColor:spsb_333333_color()];
- [topView addSubview:title];
- [title makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.bottom.equalTo(0);
- make.leading.equalTo(30);
- }];
-
- UIView *icon = UIView.new;
- icon.backgroundColor = spsb_3296FB_color();
- [icon setLayerCornerRadius:2 clipToBounds:false];
- [topView addSubview:icon];
- [icon makeConstraints:^(JXHConstraintMaker *make) {
- make.centerY.equalTo(topView);
- make.leading.equalTo(16);
- make.size.equalTo(CGSizeMake(4, 17));
- }];
-
- UIButton *tempButton = nil;
- for (NSInteger i = 0; i < policy.count; i ++) {
- SPSBHomeViewADModel *model = policy[i];
- UIButton *button = [UIButton convenienceWithTarget:self action:@selector(policyViewAction:)];
- button.tag = spsb_policyViewButtonTag + i;
- [_policyView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- if (!tempButton) {
- make.top.equalTo(45);
- } else {
- make.top.equalTo(tempButton.bottom);
- }
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(76);
- }];
-
- UIImageView *icon = UIImageView.new;
- [icon sd_setImageWithURL:spsb_fileURL(model.spsb_img)];
- [button addSubview:icon];
- [icon makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(16);
- make.top.equalTo(16);
- make.size.equalTo(CGSizeMake(24, 24));
- }];
-
- UILabel *firstLine = [UILabel convenienceWithFont:spsb_font(16) text:model.spsb_title textColor:spsb_333333_color()];
- [button addSubview:firstLine];
- [firstLine makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(56);
- make.top.equalTo(16);
- }];
-
- UILabel *secondLine = [UILabel convenienceWithFont:spsb_font(13) text:model.spsb_notes textColor:spsb_999999_color()];
- [button addSubview:secondLine];
- [secondLine makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(56);
- make.bottom.equalTo(-15);
- }];
-
- UIImageView *arrowView = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
- [button addSubview:arrowView];
- [arrowView makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-16);
- make.centerY.equalTo(firstLine);
- }];
-
- if (i < policy.count - 1) {
- [button createLineWithLocation:JXHLineLocationBottom headOffset:54 footOffset:0];
- }
-
- tempButton = button;
- }
- }
- - (void)createAdsView {
- _adsView = UIView.new;
- _adsView.backgroundColor = spsb_FFFFFF_color(1.f);
- _adsView.clipsToBounds = true;
- [_middleView addArrangedSubview:_adsView];
- [_adsView makeConstraints:^(JXHConstraintMaker *make) {
- make.height.equalTo(0);
- }];
-
- UIView *topView = UIView.new;
- [_adsView addSubview:topView];
- [topView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.leading.and.trailing.equalTo(0);
- make.height.equalTo(45);
- }];
-
- UILabel *title = [UILabel convenienceWithFont:spsb_semiboldFont(18) text:@"新鲜服务" textColor:spsb_333333_color()];
- [topView addSubview:title];
- [title makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.bottom.equalTo(0);
- make.leading.equalTo(30);
- }];
-
- UIView *icon = UIView.new;
- icon.backgroundColor = spsb_3296FB_color();
- [icon setLayerCornerRadius:2 clipToBounds:false];
- [topView addSubview:icon];
- [icon makeConstraints:^(JXHConstraintMaker *make) {
- make.centerY.equalTo(topView);
- make.leading.equalTo(16);
- make.size.equalTo(CGSizeMake(4, 17));
- }];
-
- _adsButtonView = UIView.new;
- [_adsView addSubview:_adsButtonView];
- [_adsButtonView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.trailing.equalTo(0);
- make.top.equalTo(45);
- make.bottom.equalTo(0);
- }];
-
- _adsChangeButton = [UIButton convenienceWithFont:spsb_font(13) target:self action:@selector(changeAds)];
- [_adsChangeButton setTitle:@"换一换" titleColor:spsb_3296FB_color() state:JXHButtonControlStateNormal];
- [_adsView addSubview:_adsChangeButton];
- [_adsChangeButton makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-16);
- make.top.equalTo(0);
- make.height.equalTo(45);
- }];
- [self judgeAdsView];
- }
- - (void)judgeAdsView {
- NSArray<SPSBHomeViewADModel *> *ads = spsb_adsArray();
- if (ads.count == 0) {
- _adsView.hidden = true;
- [self judgeMiddleViewIntervalView];
- return;
- }
- CGFloat adsHeight = 2 + ads.count / 2 * 66 + ads.count % 2 * 66 + 45;
- if (adsHeight > 210 + 45) {
- adsHeight = 210 + 45;
- }
- [_adsView makeConstraints:^(JXHConstraintMaker *make) {
- make.height.update(adsHeight);
- }];
- for (UIView *view in _adsButtonView.subviews) {
- [view removeFromSuperview];
- }
- [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(scrollAdsView) object:nil];
- _adsView.hidden = false;
- [self judgeMiddleViewIntervalView];
-
- _adsEndIndex = -1;
- CGSize buttonSize = (CGSize){(jxh_screenWidth() - 24) / 2 - 16, 66};
- if (adsHeight > 0) {
- _adsArray = NSMutableArray.new;
- UIView *tempView = nil;
- for (NSInteger i = 0; i < 6; i ++) {
- if (i >= ads.count) {
- break;
- }
- SPSBHomeViewADModel *model = ads[i];
- [_adsArray addObject:model];
- UIButton *button = [self createAdsViewButtonWithIconImage:nil iconUrl:model.spsb_img title:model.spsb_title content:model.spsb_notes action:@selector(adsAction:) target:self isMore:false];
- button.tag = spsb_adsViewButtonTag + i;
- [_adsButtonView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- if (i % 2 == 0) {
- if (tempView) {
- make.top.equalTo(tempView.bottom);
- } else {
- make.top.equalTo(2);
- }
- make.leading.equalTo(16);
- } else {
- make.top.equalTo(tempView.top);
- make.leading.equalTo(tempView.trailing).offset(24);
- make.trailing.equalTo(-16);
- }
- make.size.equalTo(buttonSize);
- }];
-
- if (i == 0) {
- UILabel *titleLabel = [button viewWithTag:spsb_adsViewButtonTitleTag];
- UIImageView *hot = [[UIImageView alloc] initWithImage:jxh_getImage(hot)];
- hot.tag = spsb_adsViewHotTag;
- [button addSubview:hot];
- [hot makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(titleLabel.trailing).offset(6);
- make.top.equalTo(titleLabel.top).offset(-2);
- }];
- [self adsHotAnimation:true view:hot];
- }
-
- _adsEndIndex ++;
-
- tempView = button;
-
- }
- UIImageView *hot = [_adsButtonView viewWithTag:spsb_adsViewHotTag];
- [_adsButtonView bringSubviewToFront:hot.superview];
- if (tempView) {
-
- if (ads.count < 6 && ads.count % 2 == 1) {
- UIButton *button = [self createAdsViewButtonWithIconImage:jxh_getImage(tibu) iconUrl:nil title:@"更多服务" content:@"敬请期待" action:nil target:nil isMore:true];
- [_adsButtonView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(tempView.top);
- make.leading.equalTo(tempView.trailing).offset(24);
- make.trailing.equalTo(-16);
- make.size.equalTo(buttonSize);
- }];
- }
- }
-
- if (ads.count > 6) {
- _adsScrollTimes = 1;
- _adsScrollView = UIView.new;
- _adsScrollView.backgroundColor = [UIColor whiteColor];
- _adsScrollView.hidden = true;
- _adsScrollView.clipsToBounds = true;
- [_adsButtonView addSubview:_adsScrollView];
- [_adsScrollView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.leading.equalTo(tempView);
- make.trailing.equalTo(0);
- make.height.equalTo(buttonSize.height);
- }];
-
- SPSBHomeViewADModel *model = ads[_adsEndIndex];
- UIButton *firshtbutton = [self createAdsViewButtonWithIconImage:nil iconUrl:model.spsb_img title:model.spsb_title content:model.spsb_notes action:nil target:nil isMore:false];
- firshtbutton.tag = spsb_adsViewScrollButtonTag;
- [_adsScrollView addSubview:firshtbutton];
- [firshtbutton makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(0);
- make.leading.equalTo(0);
- make.size.equalTo(buttonSize);
- }];
-
- UIButton *secondbutton = [self createAdsViewButtonWithIconImage:nil iconUrl:model.spsb_img title:model.spsb_title content:model.spsb_notes action:nil target:nil isMore:false];
- secondbutton.tag = spsb_adsViewScrollButtonTag + 1;
- [_adsScrollView addSubview:secondbutton];
- [secondbutton makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(66);
- make.leading.equalTo(0);
- make.size.equalTo(buttonSize);
- }];
-
- [self performSelector:@selector(scrollAdsView) withObject:nil afterDelay:2];
- }
-
- if (ads.count > 7) {
- _adsChangeButton.hidden = false;
- } else {
- _adsChangeButton.hidden = true;
- }
- }
- }
- - (UIButton *)createAdsViewButtonWithIconImage:(UIImage *)iconImage iconUrl:(NSString *)iconUrl title:(NSString *)title content:(NSString *)content action:(SEL)action target:(id)target isMore:(bool)isMore {
- UIButton *button = [UIButton convenienceWithTarget:target action:action];
-
- UIView *iconBg = UIView.new;
- iconBg.userInteractionEnabled = false;
- iconBg.backgroundColor = spsb_FFFFFF_color(1.f);
- [iconBg.layer setShadowWithOffset:(CGSize){0, 4} alpha:0.1 blur:12 spread:0 color:spsb_3296FB_color() cornerRadius:20 pathRect:(CGRect){0, 0, 40, 40}];
-
- UIImageView *icon = UIImageView.new;
- icon.tag = spsb_adsViewButtonIconTag;
- if (iconImage) {
- icon.image = iconImage;
- } else if (iconUrl) {
- [icon sd_setImageWithURL:spsb_fileURL(iconUrl)];
- }
- [iconBg addSubview:icon];
- [icon makeConstraints:^(JXHConstraintMaker *make) {
- make.size.equalTo(CGSizeMake(20, 20));
- make.center.equalTo(iconBg);
- }];
-
- [button addSubview:iconBg];
- [iconBg makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(0);
- make.centerY.equalTo(button);
- make.size.equalTo(CGSizeMake(40, 40));
- }];
-
- UILabel *titleLabel = [UILabel convenienceWithFont:spsb_semiboldFont(15) text:title textColor:spsb_333333_color()];
- titleLabel.tag = spsb_adsViewButtonTitleTag;
- [button addSubview:titleLabel];
- [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(50);
- make.top.equalTo(iconBg.top).offset(2);
- }];
-
- UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(12) text:content textColor:spsb_999999_color()];
- contentLabel.tag = spsb_adsViewButtonContentTag;
- [button addSubview:contentLabel];
- [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(50);
- make.trailing.equalTo(0);
- make.bottom.equalTo(iconBg.bottom).offset(-2);
- }];
-
- if (isMore) {
- titleLabel.textColor =
- contentLabel.textColor = spsb_ADADAD_color();
- }
-
- return button;
- }
- - (void)createBannerView {
- _bannerView = UIView.new;
- _bannerView.backgroundColor = spsb_FFFFFF_color(1.f);
- _bannerView.hidden = true;
- [_middleView addArrangedSubview:_bannerView];
-
- _banner = SPSBAdvertisementBannerScrollView.new;
- _banner.spsb_advertisementViewDelegate = self;
- [_banner setLayerCornerRadius:4 clipToBounds:true];
- [_bannerView addSubview:_banner];
- [_banner makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(14);
- make.centerX.equalTo(self->_bannerView);
- make.height.equalTo(0);
- make.bottom.equalTo(-20);
- }];
-
- if (_bannerImages) {
- [self judgeBannerView];
- }
- }
- - (void)judgeBannerView {
- if (_bannerImages.count > 0) {
- [_banner reloadDataWithArray:_bannerImages];
- [_banner makeConstraints:^(JXHConstraintMaker *make) {
- make.height.update(self->_banner.spsb_height);
- }];
- _bannerView.hidden = false;
- } else {
- _bannerView.hidden = true;
- }
- [self judgeMiddleViewIntervalView];
- }
- - (void)createMiddleView {
- _middleView = [UIStackView convenienceWithAxis:UILayoutConstraintAxisVertical alignment:UIStackViewAlignmentFill distribution:UIStackViewDistributionEqualSpacing spacing:0];
- [_bgView addSubview:_middleView];
-
- [_middleView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.trailing.equalTo(0);
- make.top.equalTo(self->_buttonView.bottom).offset(8);
- }];
-
- UIView *intervalView = [[UIView alloc] init];
- intervalView.backgroundColor = spsb_FFFFFF_color(1.f);
- intervalView.hidden = true;
- [_middleView addArrangedSubview:intervalView];
- [intervalView makeConstraints:^(JXHConstraintMaker *make) {
- make.height.equalTo(5);
- }];
- }
- - (void)judgeMiddleViewIntervalView {
- _middleView.arrangedSubviews[0].hidden = _bannerView.hidden && _adsView.hidden;
- }
- - (void)setNavigationBar {
- self.spsb_navigationBar.backgroundColor = spsb_FFFFFF_color(1.f);
- [self.view bringSubviewToFront:self.spsb_navigationBar];
- self.spsb_titleLabel.hidden = true;
- self.spsb_barBackButton.hidden = true;
- self.spsb_navigationBar.alpha = 0;
-
- _navigationContentView = UIView.new;
- _navigationContentView.backgroundColor = [UIColor whiteColor];
- [self.spsb_navigationBar addSubview:_navigationContentView];
- [_navigationContentView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.trailing.and.bottom.equalTo(0);
- make.height.equalTo(jxh_navigationViewHeight());
- }];
- _navigationContentView.alpha = 0;
-
- UILabel *title = [UILabel convenienceWithFont:spsb_semiboldFont(18) text:SPSBAppName textColor:spsb_222222_color()];
- [self.spsb_navigationBar addSubview:title];
- [title setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
- [title makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- make.centerY.equalTo(self->_navigationContentView);
- }];
-
- JXHCenterButton *topButton = [JXHCenterButton convenienceWithAxis:JXHCenterButtonAxisVertical interval:4 font:spsb_font(10) target:self action:@selector(topAction)];
- [topButton setTitle:@"回顶部" titleColor:spsb_222222_color() image:jxh_getImage(home_top_arrow) backgroundImage:nil state:JXHButtonControlStateNormal];
- [_navigationContentView addSubview:topButton];
- [topButton makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.bottom.and.trailing.equalTo(0);
- make.width.equalTo(74);
- }];
-
- _navigationBarButtonView = UIView.new;
- _navigationBarButtonView.backgroundColor = [UIColor whiteColor];
- [_navigationContentView addSubview:_navigationBarButtonView];
- [_navigationBarButtonView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(107);
- make.trailing.equalTo(-72);
- make.top.and.bottom.equalTo(0);
- }];
-
- }
- - (void)createBgView {
- _bgView = [UIScrollView convenienceWithBackgroundColor:spsb_F5F5F5_color()];
- if (@available(iOS 11.0, *)) {
- _bgView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- _bgView.bounces = false;
- _bgView.delegate = self;
- [self.view addSubview:_bgView];
- [_bgView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.and.leading.and.trailing.equalTo(0);
- make.bottom.equalTo(self.view.safebottom).offset(-SPSBTabBarHeight);
- }];
- }
- - (void)createImageView {
- CGFloat height = jxh_screenWidth() * 0.352;
- _imageView = [[UIImageView alloc] initWithImage:jxh_getImage(home_banner)];
- // _imageView.userInteractionEnabled = true;
- // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewAction)];
- // [_imageView addGestureRecognizer:tap];
- [_bgView addSubview:_imageView];
- [_imageView makeConstraints:^(JXHConstraintMaker *make) {
- if (@available(iOS 11.0, *)) {
- make.top.equalTo(0);
- } else {
- if (jxh_statusBarHeight() > 20) {
- make.top.equalTo(0);
- } else {
- make.top.equalTo(-20);
- }
- }
-
- make.leading.and.trailing.equalTo(0);
- make.size.equalTo((CGSize){jxh_screenWidth(), height});
- }];
- }
- - (void)createButtonView {
- _buttonView = UIView.new;
- _buttonView.backgroundColor = spsb_FFFFFF_color(1.f);
- [_bgView addSubview:_buttonView];
- [_buttonView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.and.trailing.equalTo(0);
- make.top.equalTo(self->_imageView.bottom);
- }];
-
- UIStackView *stackView = [UIStackView convenienceWithAxis:UILayoutConstraintAxisVertical alignment:UIStackViewAlignmentFill distribution:UIStackViewDistributionEqualSpacing spacing:0];
- [_buttonView addSubview:stackView];
- [stackView makeConstraints:^(JXHConstraintMaker *make) {
- make.edges.equalTo(self->_buttonView);
- }];
-
- _buttonScrollView = [UIScrollView convenienceWithBackgroundColor:spsb_FFFFFF_color(1.f)];
- _buttonScrollView.scrollsToTop = false;
- _buttonScrollView.bounces = false;
- _buttonScrollView.delegate = self;
- if (@available(iOS 11.0, *)) {
- _buttonScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- }
- [stackView addArrangedSubview:_buttonScrollView];
- [_buttonScrollView makeConstraints:^(JXHConstraintMaker *make) {
- make.height.equalTo(114);
- }];
-
- _buttonScrollView.hidden = true;
-
- _prossView = UIView.new;
- [stackView addArrangedSubview:_prossView];
- [_prossView makeConstraints:^(JXHConstraintMaker *make) {
- make.height.equalTo(3);
- }];
-
- UIView *prossLine = UIView.new;
- prossLine.backgroundColor = spsb_EFEFF4_color();
- [_prossView addSubview:prossLine];
- [prossLine makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(0);
- make.centerX.equalTo(self->_prossView);
- make.size.equalTo(CGSizeMake(40, 3));
- }];
-
- _choseProssLine = UIView.new;
- _choseProssLine.backgroundColor = spsb_3296FB_color();
- [prossLine addSubview:_choseProssLine];
- [_choseProssLine makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(prossLine);
- make.leading.equalTo(prossLine);
- make.size.equalTo(CGSizeMake(20, 3));
- }];
-
- _prossView.hidden = true;
-
- [self judgeButtonView];
-
- CGFloat featureWidth = (jxh_screenWidth() - 32 - 13) / 2;
- CGFloat featureHeight = featureWidth * 0.39;
-
- UIView *featureView = UIView.new;
- [stackView addArrangedSubview:featureView];
- [featureView makeConstraints:^(JXHConstraintMaker *make) {
- make.height.equalTo(featureHeight + 18 + 16);
- }];
-
-
-
- UIButton *leftButton = [UIButton convenienceWithTarget:self action:@selector(calculateAction:)];
- [leftButton setBackgroundImage:jxh_getImage(jisuanqi_1) state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
- leftButton.tag = spsb_calculateButtonTag;
- [featureView addSubview:leftButton];
- [leftButton makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(16);
- make.size.equalTo(CGSizeMake(featureWidth, featureHeight));
- make.bottom.equalTo(-18);
- }];
-
- UIButton *rightButton = [UIButton convenienceWithTarget:self action:@selector(calculateAction:)];
- [rightButton setBackgroundImage:jxh_getImage(jisuanqi_2) state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
- rightButton.tag = spsb_calculateButtonTag + 1;
- [featureView addSubview:rightButton];
- [rightButton makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-16);
- make.size.equalTo(CGSizeMake(featureWidth, featureHeight));
- make.bottom.equalTo(-18);
- }];
- }
- - (void)judgeButtonView {
- if (nil == spsb_homeViewButtons()) return;
- for (UIView *view in _buttonScrollView.subviews) {
- [view removeFromSuperview];
- }
- SPSBHomeViewButtonsModel *model = spsb_homeViewButtons();
- NSArray *judgeArray = @[model.spsb_buyShebao, model.spsb_buyFund, model.spsb_shebaoAdded, model.spsb_fundAdded, model.spsb_shebaoMove, model.spsb_fundMove];
- _buttonCount = 0;
-
- NSArray *titleArray = @[@"社保服务", @"公积金服务", @"社保补缴", @"公积金补缴", @"社保转移", @"公积金转移"];
- NSArray *imageArray = @[jxh_getImage(shebao_jiao),
- jxh_getImage(gjj_jiao),
- jxh_getImage(shebao_bu),
- jxh_getImage(gjj_bu),
- jxh_getImage(shebao_zhuanyi),
- jxh_getImage(gjj_zhuanyi)];
- CGFloat width = jxh_screenWidth() / 4;
- UIButton *tempButton = nil;
- for (NSInteger i = 0; i < 6; i ++) {
- if (![judgeArray[i] boolValue]) continue;
- _buttonCount ++;
- UIButton *button = [UIButton convenienceWithTarget:self action:@selector(purchaseViewAction:)];
- button.tag = spsb_buttonViewButtonTag + i;
- [_buttonScrollView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- if (!tempButton) {
- make.leading.equalTo(0);
- } else {
- make.leading.equalTo(tempButton.trailing);
- }
- make.top.and.bottom.equalTo(0);
- make.height.equalTo(114);
- make.width.equalTo(width);
- if (i == 5) {
- make.trailing.equalTo(0);
- }
- }];
-
- UIImageView *imageView = [[UIImageView alloc] initWithImage:imageArray[i]];
- [button addSubview:imageView];
- [imageView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(20);
- make.centerX.equalTo(button);
- make.size.equalTo(CGSizeMake(50, 50));
- }];
-
- UILabel *titleLabel = [UILabel convenienceWithFont:spsb_semiboldFont(14) text:titleArray[i] textColor:spsb_333333_color() textAlignment:NSTextAlignmentCenter];
- [button addSubview:titleLabel];
- [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(80);
- make.centerX.equalTo(button);
- }];
-
- tempButton = button;
- }
-
- if (_buttonCount == 0) {
- _buttonScrollView.hidden =
- _prossView.hidden =
- _navigationBarButtonView.hidden = true;
- return;
- }
-
- _buttonScrollView.hidden =
- _navigationBarButtonView.hidden = false;
-
- if (_buttonCount > 4) {
- _prossView.hidden = false;
- [_choseProssLine makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.update(0);
- }];
- [_choseProssLine.superview layoutSubviews];
- } else {
- _prossView.hidden = true;
- }
-
- for (UIView *view in _navigationBarButtonView.subviews) {
- [view removeFromSuperview];
- }
-
- width = (jxh_screenWidth() - 107 - 72) / 4;
- imageArray = @[jxh_getImage(shebao_jiao), jxh_getImage(gjj_jiao), jxh_getImage(shebao_bu), jxh_getImage(gjj_bu)];
- tempButton = nil;
- for (NSInteger i = 0; i < 4; i ++) {
- if (![judgeArray[i] boolValue]) continue;
- UIButton *button = [UIButton convenienceWithTarget:self action:@selector(navigationPurchaseAction:)];
- button.tag = spsb_navigationButtonTag + i;
- [_navigationBarButtonView addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- if (!tempButton) {
- make.leading.equalTo(0);
- } else {
- make.leading.equalTo(tempButton.trailing);
- }
- make.width.equalTo(width);
- make.top.and.bottom.equalTo(0);
- }];
-
- UIImageView *imageView = [[UIImageView alloc] initWithImage:imageArray[i]];
- [button addSubview:imageView];
- [imageView makeConstraints:^(JXHConstraintMaker *make) {
- make.center.equalTo(button);
- make.size.equalTo(CGSizeMake(32, 32));
- }];
-
- tempButton = button;
- }
- }
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
- if (@available(iOS 11.0, *)) {
- [_imageView makeConstraints:^(JXHConstraintMaker *make) {
- if (jxh_safeInsets(self.view).top > 20) {
- make.top.update(0);
- } else {
- make.top.update(-20);
- }
- }];
- }
- }
- @end
- #undef spsb_navigationButtonTag
- #undef spsb_buttonViewButtonTag
- #undef spsb_calculateButtonTag
- #undef spsb_adsViewButtonTag
- #undef spsb_adsViewButtonIconTag
- #undef spsb_adsViewButtonTitleTag
- #undef spsb_adsViewButtonContentTag
- #undef spsb_adsViewHotTag
- #undef spsb_adsViewScrollButtonTag
- #undef spsb_strategyViewButtonTag
- #undef spsb_policyViewButtonTag
|