SPSBQueryHomeViewController.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. //
  2. // SPSBQueryHomeViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/20.
  6. //
  7. #import "SPSBQueryHomeViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBBusinessManager.h"
  10. #import "SPSBSQLProfile.h"
  11. #import "SPSBKeyProfile.h"
  12. #import "SPSBQueryCityModel.h"
  13. #import "SPSBConfirmAlertViewController.h"
  14. #import "SPSBHtmlViewController.h"
  15. #import "SPSBURLApiProfile.h"
  16. #import <CALayer+JXHShadow.h>
  17. #import "SPSBUMEventAnalysis.h"
  18. #import "SPSBActionSheetViewController.h"
  19. #import "WXApi.h"
  20. #import "SPSBChooseCityViewController.h"
  21. #import "SPSBNavigationController.h"
  22. #import "SPSBQueryListViewController.h"
  23. #define spsb_queryViewWDSBButtonTag 3000
  24. #define spsb_queryViewGVMButtonTag 4000
  25. @interface SPSBQueryHomeViewController (){
  26. UIScrollView *_backgroundView;
  27. UIImageView *_headerView;
  28. UILabel *_cityLabel;
  29. UIView *_wdsbView;
  30. UIView *_gvmView;
  31. SPSBQueryCityModel *_gvmData;
  32. bool _firstTips;
  33. }
  34. @end
  35. @implementation SPSBQueryHomeViewController
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. _firstTips = true;
  39. [self getLocationCity];
  40. [self setupUI];
  41. }
  42. - (void)viewDidAppear:(BOOL)animated {
  43. [super viewDidAppear:animated];
  44. if (_firstTips && spsb_locationCheckPublicDataCity().length > 0 && ![spsb_lastCheckPublicDataCity() isEqualToString:spsb_locationCheckPublicDataCity()]) {
  45. _firstTips = false;
  46. NSString *locationCity = spsb_locationCheckPublicDataCity();
  47. SPSBConfirmAlertViewController *vc = [SPSBConfirmAlertViewController alertWithTitle:@"提示" content:[NSString stringWithFormat:@"当前定位在“%@”,是否切换至%@?", locationCity, locationCity]];
  48. [vc setCancelButtonTitle:nil titleColor:nil action:^{
  49. spsb_setLocationCheckPublicDataCity(spsb_lastCheckPublicDataCity());
  50. }];
  51. @weakify(self)
  52. [vc setConfirmButtonTitle:nil titleColor:nil action:^{
  53. @strongify(self)
  54. NSArray *array = [JXHFMDBManager searchWithPath:SPSBShanpQueryCitySQL backKey:nil condition:^id(FMDatabase *database) {
  55. return [database executeQuery:@"select * from t_sp_query_city where city_name = ?", spsb_locationCheckPublicDataCity()];
  56. }];
  57. NSDictionary *dic = @{};
  58. if (array.count != 0) {
  59. dic = array[0];
  60. }
  61. self->_gvmData = [SPSBQueryCityModel getModelWithDictionary:dic];
  62. [self reloadGvmView];
  63. spsb_setLastCheckPublicDataCity(spsb_locationCheckPublicDataCity());
  64. [jxh_userDefaults() setObject:spsb_lastCheckPublicDataCity() forKey:SPSBCheckPublicDataCity];
  65. [jxh_userDefaults() synchronize];
  66. }];
  67. [self presentViewController:vc animated:false completion:nil];
  68. }
  69. }
  70. #pragma mark - Action
  71. - (void)getLocationCity {
  72. NSString *city = spsb_lastCheckPublicDataCity();
  73. if (city.length == 0) {
  74. city = spsb_locationCheckPublicDataCity();
  75. if (city.length == 0) {
  76. NSArray *array = [JXHFMDBManager searchWithPath:SPSBShanpQueryCitySQL backKey:@"city_name" condition:^id(FMDatabase *database) {
  77. return [database executeQuery:@"select * from t_sp_query_city LIMIT 1"];
  78. }];
  79. if (array.count > 0) {
  80. spsb_setLocationCheckPublicDataCity(array[0]);
  81. } else {
  82. spsb_setLocationCheckPublicDataCity(@"北京");
  83. }
  84. city = spsb_locationCheckPublicDataCity();
  85. }
  86. spsb_setLastCheckPublicDataCity(spsb_locationCheckPublicDataCity());
  87. [jxh_userDefaults() setObject:spsb_lastCheckPublicDataCity() forKey:SPSBCheckPublicDataCity];
  88. [jxh_userDefaults() synchronize];
  89. }
  90. NSArray *array = [JXHFMDBManager searchWithPath:SPSBShanpQueryCitySQL backKey:nil condition:^id(FMDatabase *database) {
  91. return [database executeQuery:@"select * from t_sp_query_city where city_name = ?", city];
  92. }];
  93. NSDictionary *dic = @{};
  94. if (array.count != 0) {
  95. dic = array[0];
  96. }
  97. _gvmData = [SPSBQueryCityModel getModelWithDictionary:dic];
  98. debugLog(@"%@", _gvmData);
  99. }
  100. - (void)headerViewAction {
  101. SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
  102. vc.spsb_url = SPSBQueryAnytimeLink;
  103. vc.title = @"随时查";
  104. [self.navigationController pushViewController:vc animated:true];
  105. }
  106. - (void)buttonAction:(JXHCenterButton *)sender {
  107. bool isAccumulationFund = sender.tag == spsb_queryViewWDSBButtonTag + 1;
  108. [SPSBUMEventAnalysis analyseEventWithId:isAccumulationFund ? @"QueryPlatformGJJ" : @"QueryPlatformSB"];
  109. debugLog(@"%ld", (long)sender.tag);
  110. @weakify(self)
  111. spsb_needLogin(^{
  112. @strongify(self)
  113. SPSBQueryListViewController *vc = SPSBQueryListViewController.new;
  114. vc.spsb_isQueryAccumulationFund = isAccumulationFund;
  115. [self.navigationController pushViewController:vc animated:true];
  116. });
  117. }
  118. - (void)changeCity {
  119. [SPSBUMEventAnalysis analyseEventWithId:@"position"];
  120. SPSBChooseCityViewController *vc = SPSBChooseCityViewController.new;
  121. @weakify(self)
  122. vc.spsb_finishChoose = ^(SPSBQueryCityModel * _Nonnull model) {
  123. @strongify(self)
  124. [self finishChooseCity:model];
  125. };
  126. SPSBNavigationController *nav = [[SPSBNavigationController alloc] initWithRootViewController:vc];
  127. [self presentViewController:nav animated:true completion:nil];
  128. }
  129. - (void)finishChooseCity:(SPSBQueryCityModel *)model {
  130. _gvmData = model;
  131. [self reloadGvmView];
  132. spsb_setLastCheckPublicDataCity(model.spsb_city_name);
  133. spsb_setLocationCheckPublicDataCity(model.spsb_city_name);
  134. [jxh_userDefaults() setObject:spsb_lastCheckPublicDataCity() forKey:SPSBCheckPublicDataCity];
  135. [jxh_userDefaults() synchronize];
  136. }
  137. - (void)serviceAction {
  138. SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
  139. vc.spsb_url = SPSBSocialSecurityCityServiceLink;
  140. [self.navigationController pushViewController:vc animated:true];
  141. }
  142. - (void)phoneAction {
  143. bool can = false;
  144. SPSBActionSheetViewController *vc = SPSBActionSheetViewController.new;
  145. @weakify(self)
  146. if (_gvmData.spsb_shebao_tel.length > 0) {
  147. can = true;
  148. [vc addActionWithTitle:@"社保局热线" action:^{
  149. @strongify(self)
  150. [self sbPhoneAction];
  151. }];
  152. }
  153. if (_gvmData.spsb_fund_tel.length > 0) {
  154. can = true;
  155. [vc addActionWithTitle:@"公积金中心热线" action:^{
  156. @strongify(self)
  157. [self fPhoneAction];
  158. }];
  159. }
  160. if (can) {
  161. [self presentViewController:vc animated:false completion:nil];
  162. }
  163. }
  164. - (void)sbPhoneAction {
  165. NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", [(_gvmData.spsb_shebao_tel) stringByReplacingOccurrencesOfString:@" " withString:@""]];
  166. jxh_openUrl([NSURL URLWithString:callPhone], ^(BOOL success) {
  167. });
  168. }
  169. - (void)fPhoneAction {
  170. NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", [(_gvmData.spsb_fund_tel) stringByReplacingOccurrencesOfString:@" " withString:@""]];
  171. jxh_openUrl([NSURL URLWithString:callPhone], ^(BOOL success) {
  172. });
  173. }
  174. - (void)shebao_telAction {
  175. [self phoneAction];
  176. }
  177. - (void)fund_telAction {
  178. [self phoneAction];
  179. }
  180. - (void)shebao_urlAction {
  181. [SPSBUMEventAnalysis analyseEventWithId:@"QueryOfficialSB"];
  182. SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
  183. vc.title = @"社保查询";
  184. vc.spsb_url = _gvmData.spsb_shebao_url;
  185. [self.navigationController pushViewController:vc animated:true];
  186. }
  187. - (void)fund_urlAction {
  188. [SPSBUMEventAnalysis analyseEventWithId:@"QueryOfficialGJJ"];
  189. SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
  190. vc.title = @"公积金查询";
  191. vc.spsb_url = _gvmData.spsb_fund_url;
  192. [self.navigationController pushViewController:vc animated:true];
  193. }
  194. - (void)wxAction {
  195. bool can = false;
  196. SPSBActionSheetViewController *vc = SPSBActionSheetViewController.new;
  197. @weakify(self)
  198. if (_gvmData.spsb_shebao_wx.length > 0) {
  199. can = true;
  200. [vc addActionWithTitle:@"社保公众号" action:^{
  201. @strongify(self)
  202. [self sbWXAction];
  203. }];
  204. }
  205. if (_gvmData.spsb_fund_wx.length > 0) {
  206. can = true;
  207. [vc addActionWithTitle:@"公积金公众号" action:^{
  208. @strongify(self)
  209. [self fWXAction];
  210. }];
  211. }
  212. if (can) {
  213. [self presentViewController:vc animated:false completion:nil];
  214. }
  215. }
  216. - (void)sbWXAction {
  217. [SPSBUMEventAnalysis analyseEventWithId:@"QueryOfficialSGGZH"];
  218. UIPasteboard *pboard = [UIPasteboard generalPasteboard];
  219. pboard.string = _gvmData.spsb_shebao_wx;
  220. [self openWX];
  221. }
  222. - (void)fWXAction {
  223. [SPSBUMEventAnalysis analyseEventWithId:@"QueryOfficialGJJGZH"];
  224. UIPasteboard *pboard = [UIPasteboard generalPasteboard];
  225. pboard.string = _gvmData.spsb_fund_wx;
  226. [self openWX];
  227. }
  228. - (void)shebao_wxAction {
  229. [self wxAction];
  230. }
  231. - (void)fund_wxAction {
  232. [self wxAction];
  233. }
  234. - (void)openWX {
  235. UIPasteboard *pboard = [UIPasteboard generalPasteboard];
  236. if ([WXApi isWXAppInstalled] && [WXApi isWXAppSupportApi]) {
  237. SPSBConfirmAlertViewController *vc = [SPSBConfirmAlertViewController alertWithTitle:@"提示" content:[NSString stringWithFormat:@"已复制公众号'%@',现在打开微信吗", pboard.string]];
  238. [vc setCancelButtonTitle:@"暂不打开" titleColor:nil action:^{
  239. }];
  240. [vc setConfirmButtonTitle:@"马上打开" titleColor:nil action:^{
  241. [WXApi openWXApp];
  242. }];
  243. [self presentViewController:vc animated:false completion:nil];
  244. } else {
  245. SPSBConfirmAlertViewController *vc = [SPSBConfirmAlertViewController alertWithTitle:@"提示" content:[NSString stringWithFormat:@"已复制公众号'%@',请在微信里搜索", pboard.string]];
  246. [vc setConfirmButtonTitle:nil titleColor:nil action:^{
  247. }];
  248. [self presentViewController:vc animated:false completion:nil];
  249. }
  250. }
  251. #pragma mark - Network Action
  252. #pragma mark - UI
  253. - (void)setupUI {
  254. //取消返回按钮
  255. self.navigationItem.leftBarButtonItem = nil;
  256. self.title = @"查询";
  257. [self createBackgroundView];
  258. [self createHeaderView];
  259. [self createWdsbView];
  260. [self createGvmView];
  261. }
  262. - (void)createHeaderView {
  263. _headerView = [[UIImageView alloc] initWithImage:jxh_getImage(query_home_banner)];
  264. [_backgroundView addSubview:_headerView];
  265. [_headerView makeConstraints:^(JXHConstraintMaker *make) {
  266. make.top.and.leading.and.trailing.equalTo(0);
  267. make.height.equalTo(jxh_screenWidth() * 0.272);
  268. }];
  269. _headerView.userInteractionEnabled = true;
  270. [_headerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headerViewAction)]];
  271. }
  272. #define spsb_queryViewButtonSize (CGSize){(jxh_screenWidth() - 40 - 15) / 2, 120}
  273. - (void)createWdsbView {
  274. _wdsbView = UIView.new;
  275. [_backgroundView addSubview:_wdsbView];
  276. [_wdsbView makeConstraints:^(JXHConstraintMaker *make) {
  277. make.top.equalTo(self->_headerView.bottom);
  278. make.width.equalTo(jxh_screenWidth());
  279. make.leading.and.trailing.equalTo(0);
  280. }];
  281. NSArray *titles = @[@"社保订单", @"公积金订单"];
  282. NSArray *images = @[jxh_getImage(search_shebao_jiao), jxh_getImage(search_gjj_jiao)];
  283. JXHCenterButton *tempButton = nil;
  284. for (NSInteger i = 0; i < titles.count; i ++) {
  285. JXHCenterButton *button = [self createButtonItemWithTitle:titles[i] image:images[i] tag:spsb_queryViewWDSBButtonTag + i action:@selector(buttonAction:)];
  286. [_wdsbView addSubview:button];
  287. [button makeConstraints:^(JXHConstraintMaker *make) {
  288. if (tempButton) {
  289. make.leading.equalTo(tempButton.trailing).offset(15);
  290. } else {
  291. make.leading.equalTo(20);
  292. }
  293. make.size.equalTo(spsb_queryViewButtonSize);
  294. make.top.equalTo(62);
  295. }];
  296. tempButton = button;
  297. }
  298. for (NSInteger i = 0; i < 2; i ++) {
  299. UILabel *label = [UILabel convenienceWithFont:spsb_semiboldFont(18) text:i == 0 ? @"我的订单查询" : @"政府官网查询" textColor:spsb_333333_color()];
  300. [_wdsbView addSubview:label];
  301. [label makeConstraints:^(JXHConstraintMaker *make) {
  302. make.leading.equalTo(34);
  303. make.top.equalTo(i == 0 ? 20 : 214);
  304. if (i == 1) {
  305. make.bottom.equalTo(-16);
  306. }
  307. }];
  308. UIView *icon = UIView.new;
  309. icon.backgroundColor = spsb_3296FB_color();
  310. [icon setLayerCornerRadius:1.75 clipToBounds:false];
  311. [_wdsbView addSubview:icon];
  312. [icon makeConstraints:^(JXHConstraintMaker *make) {
  313. make.size.equalTo(CGSizeMake(3.5, 17));
  314. make.leading.equalTo(20);
  315. make.centerY.equalTo(label);
  316. }];
  317. if (i == 1) {
  318. UIButton *cityButton = [UIButton convenienceWithTarget:self action:@selector(changeCity)];
  319. [cityButton setLayerCornerRadius:13 clipToBounds:false];
  320. [cityButton setLayerBorderWidth:0.7 borderColor:spsb_3296FB_color()];
  321. [_wdsbView addSubview:cityButton];
  322. [cityButton makeConstraints:^(JXHConstraintMaker *make) {
  323. make.trailing.equalTo(-20);
  324. make.centerY.equalTo(label);
  325. make.height.equalTo(26);
  326. make.leading.greaterThanOrEqualTo(jxh_screenWidth() / 2);
  327. }];
  328. _cityLabel = [UILabel convenienceWithFont:spsb_semiboldFont(14) text:_gvmData.spsb_city_name textColor:spsb_3296FB_color()];
  329. [cityButton addSubview:_cityLabel];
  330. [_cityLabel makeConstraints:^(JXHConstraintMaker *make) {
  331. make.leading.equalTo(13);
  332. make.centerY.equalTo(cityButton);
  333. }];
  334. UIImageView *cityIcon = [[UIImageView alloc] initWithImage:jxh_getImage(city_choose)];
  335. [cityButton addSubview:cityIcon];
  336. [cityIcon setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  337. [cityIcon makeConstraints:^(JXHConstraintMaker *make) {
  338. make.leading.equalTo(self->_cityLabel.trailing).offset(4);
  339. make.trailing.equalTo(-11);
  340. make.centerY.equalTo(cityButton);
  341. make.size.equalTo(CGSizeMake(8, 8));
  342. }];
  343. }
  344. }
  345. }
  346. - (void)createGvmView {
  347. if (!_gvmView) {
  348. _gvmView = UIView.new;
  349. _gvmView.backgroundColor = spsb_FFFFFF_color(1.f);
  350. [_backgroundView addSubview:_gvmView];
  351. [_gvmView makeConstraints:^(JXHConstraintMaker *make) {
  352. make.top.equalTo(self->_wdsbView.bottom);
  353. make.leading.and.trailing.equalTo(0);
  354. make.bottom.equalTo(-78);
  355. }];
  356. }
  357. NSMutableArray *array = [@[@"shebao_url", @"fund_url", @"shebao_wx", @"fund_wx", @"shebao_tel", @"fund_tel"] mutableCopy];
  358. if (_gvmData.spsb_shebao_tel.length > 0) {
  359. [array removeObject:@"fund_tel"];
  360. } else {
  361. [array removeObject:@"shebao_tel"];
  362. }
  363. if (_gvmData.spsb_shebao_wx.length > 0) {
  364. [array removeObject:@"fund_wx"];
  365. } else {
  366. [array removeObject:@"shebao_wx"];
  367. }
  368. NSArray *titles = @[@"社保查询", @"公积金查询", @"公众号查询", @"政府官方热线", @""];
  369. NSArray *images = @[jxh_getImage(search_shebao_jiao), jxh_getImage(search_gjj_jiao), jxh_getImage(search_wechat), jxh_getImage(search_phone)];
  370. JXHCenterButton *tempButton = nil;
  371. NSInteger count = 0;
  372. for (NSInteger i = 0; i < array.count; i ++) {
  373. NSString *key = [NSString stringWithFormat:@"spsb_%@", array[i]];
  374. NSString *value = [_gvmData valueForKey:key];
  375. if (!value || value.length == 0) {
  376. continue;
  377. }
  378. SEL action = NSSelectorFromString([NSString stringWithFormat:@"%@Action", array[i]]);
  379. JXHCenterButton *button = [self createButtonItemWithTitle:titles[i] image:images[i] tag:spsb_queryViewGVMButtonTag + i action:action];
  380. [_gvmView addSubview:button];
  381. [button makeConstraints:^(JXHConstraintMaker *make) {
  382. if (tempButton && count % 2 == 1) {
  383. make.leading.equalTo(tempButton.trailing).offset(15);
  384. make.trailing.equalTo(-20);
  385. } else {
  386. make.leading.equalTo(20);
  387. }
  388. if (tempButton && count % 2 == 1) {
  389. make.top.equalTo(tempButton);
  390. } else if (tempButton && count % 2 == 0) {
  391. make.top.equalTo(tempButton.bottom).offset(15);
  392. } else {
  393. make.top.equalTo(0);
  394. }
  395. make.size.equalTo(spsb_queryViewButtonSize);
  396. }];
  397. tempButton = button;
  398. count ++;
  399. }
  400. JXHCenterButton *button = [self createButtonItemWithTitle:@"城市服务查询" image:jxh_getImage(search_service) tag:0 action:@selector(serviceAction)];
  401. [_gvmView addSubview:button];
  402. [button makeConstraints:^(JXHConstraintMaker *make) {
  403. if (tempButton && count % 2 == 1) {
  404. make.leading.equalTo(tempButton.trailing).offset(15);
  405. make.trailing.equalTo(-20);
  406. } else {
  407. make.leading.equalTo(20);
  408. }
  409. if (tempButton && count % 2 == 1) {
  410. make.top.equalTo(tempButton);
  411. } else if (tempButton && count % 2 == 0) {
  412. make.top.equalTo(tempButton.bottom).offset(15);
  413. } else {
  414. make.top.equalTo(0);
  415. }
  416. make.size.equalTo(spsb_queryViewButtonSize);
  417. make.bottom.equalTo(0);
  418. }];
  419. }
  420. - (JXHCenterButton *)createButtonItemWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag action:(SEL)action {
  421. JXHCenterButton *button = [JXHCenterButton convenienceWithAxis:JXHCenterButtonAxisVertical interval:12 font:spsb_font(14) target:self action:action];
  422. button.tag = tag;
  423. button.backgroundColor = spsb_FFFFFF_color(1.f);
  424. [button setTitle:title titleColor:spsb_333333_color() image:image backgroundImage:nil state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
  425. [button.layer setShadowWithOffset:(CGSize){0, 0} alpha:0.08 blur:32 spread:0 color:spsb_3296FB_color() cornerRadius:8 pathRect:(CGRect){CGPointZero, spsb_queryViewButtonSize}];
  426. return button;
  427. }
  428. - (void)reloadGvmView {
  429. _cityLabel.text = _gvmData.spsb_city_name;
  430. NSArray *arr = _gvmView.subviews;
  431. for (UIView *view in arr) {
  432. [view removeFromSuperview];
  433. }
  434. [self createGvmView];
  435. }
  436. - (void)createBackgroundView {
  437. _backgroundView = [UIScrollView convenienceWithBackgroundColor:spsb_FFFFFF_color(1.f)];
  438. [self.view addSubview:_backgroundView];
  439. [_backgroundView makeConstraints:^(JXHConstraintMaker *make) {
  440. make.top.equalTo(self.view.safetop);
  441. make.bottom.equalTo(-SPSBTabBarHeight);
  442. make.leading.and.trailing.equalTo(0);
  443. }];
  444. }
  445. @end
  446. #undef spsb_queryViewWDSBButtonTag
  447. #undef spsb_queryViewGVMButtonTag
  448. #undef spsb_queryViewButtonSize