SPSBConsultationViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. //
  2. // SPSBConsultationViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/20.
  6. //
  7. #import "SPSBConsultationViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBConsultationTableViewController.h"
  10. #import "UIViewController+SPSBInitialization.h"
  11. #import "UIViewController+SPSBNavigationBar.h"
  12. #import "SPSBBroadcastView.h"
  13. #import "SPSBCustomerServiceManager.h"
  14. #import "SPSBTabBarView.h"
  15. #import "UIViewController+SPSBNetworkManager.h"
  16. #import "SPSBCustomerServiceManager.h"
  17. #import "SPSBMakePhoneCallManager.h"
  18. #import "SPSBBusinessManager.h"
  19. #import "SPSBFeedbackListModel.h"
  20. #import "SPSBFeedbackListViewController.h"
  21. #import "SPSBAddFeedbackViewViewController.h"
  22. #import "SPSBNavigationController.h"
  23. typedef NS_ENUM(NSUInteger, SPSBConsultationHeaderActionType) {
  24. SPSBConsultationHeaderActionTypeCustomerService = 3000,
  25. SPSBConsultationHeaderActionTypePhone,
  26. SPSBConsultationHeaderActionTypeFeedback,
  27. };
  28. @interface SPSBConsultationViewController () {
  29. SPSBConsultationTableViewController *_tableVC;
  30. UIView *_headerView;
  31. NSString *_cacheBroadcast;
  32. SPSBBroadcastView *_broadcastView;
  33. UIView *_tipsView;
  34. SPSBMakePhoneCallManager *_makePhoneCallManager;
  35. }
  36. @end
  37. @implementation SPSBConsultationViewController
  38. - (instancetype)init {
  39. self = [super init];
  40. if (!self) return nil;
  41. self.spsb_isLightContent = true;
  42. return self;
  43. }
  44. - (UIStatusBarStyle)preferredStatusBarStyle {
  45. return self.spsb_statusBarStyle;
  46. }
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. [self initData];
  50. [self setupUI];
  51. }
  52. - (void)initData {
  53. _cacheBroadcast = @"";
  54. _makePhoneCallManager = [[SPSBMakePhoneCallManager alloc] initWithController:self];
  55. }
  56. - (void)viewWillAppear:(BOOL)animated {
  57. [super viewWillAppear:animated];
  58. [_broadcastView beginAnimation];
  59. [self getBroadcast];
  60. [self reloadViewTips];
  61. //去掉智齿的toolbar
  62. [self.navigationController setToolbarHidden:true animated:true];
  63. }
  64. - (void)viewWillDisappear:(BOOL)animated {
  65. [super viewWillDisappear:animated];
  66. [_broadcastView stopAnimation];
  67. }
  68. #pragma mark - Action
  69. - (void)reloadViewTips {
  70. NSString *tips = [NSString stringWithFormat:@"%ld", (long)spsb_customerServiceManager().spsb_notificationNum];
  71. [spsb_tabBarView() tipsViewHidden:spsb_customerServiceManager().spsb_notificationNum <= 0 tips:tips tabBarType:SPSBTabBarTypeConsultation];
  72. _tipsView.hidden = spsb_customerServiceManager().spsb_notificationNum <= 0;
  73. ((UILabel *)[_tipsView viewWithTag:spsb_numberTipsViewLabelTag]).text = tips;
  74. }
  75. - (void)headerButtonAction:(UIButton *)sender {
  76. switch (sender.tag) {
  77. case SPSBConsultationHeaderActionTypeCustomerService:
  78. [spsb_customerServiceManager() toOnlineContactWithBaseController:self];
  79. break;
  80. case SPSBConsultationHeaderActionTypePhone:
  81. [_makePhoneCallManager showHandleContactMenu];
  82. break;
  83. case SPSBConsultationHeaderActionTypeFeedback: {
  84. @weakify(self)
  85. spsb_needLogin(^{
  86. @strongify(self)
  87. [self getFeedbackList];
  88. });
  89. }
  90. break;
  91. default:
  92. break;
  93. }
  94. }
  95. #pragma mark - Network Action
  96. - (void)getBroadcast {
  97. [self networkUseMethod:SPSBNetworkMethodGET loadingTips:nil isLogin:false url:spsb_appUrl(SPSBUrlGetBroadcast) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  98. [self getBroadcastSuccess:data];
  99. return nil;
  100. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  101. return nil;
  102. }];
  103. }
  104. - (void)getBroadcastSuccess:(id)data {
  105. if (![_cacheBroadcast isEqualToString:data[@"data"]]) {
  106. _cacheBroadcast = data[@"data"];
  107. [_broadcastView reloadData:_cacheBroadcast];
  108. }
  109. }
  110. - (void)getFeedbackList {
  111. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在加载" isLogin:true url:spsb_appUrl(SPSBUrlGetFeedbackList) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  112. [self getFeedbackListSuccess:data];
  113. return @"";
  114. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  115. return @"加载失败";
  116. }];
  117. }
  118. - (void)getFeedbackListSuccess:(id)data {
  119. NSArray *array = [SPSBFeedbackListModel getModelListWithArray:data[@"data"]];
  120. if (array.count == 0) {
  121. SPSBAddFeedbackViewViewController *vc = SPSBAddFeedbackViewViewController.new;
  122. @weakify(self)
  123. vc.spsb_successSave = ^{
  124. @strongify(self)
  125. [self getFeedbackList];
  126. };
  127. SPSBNavigationController *nav = [[SPSBNavigationController alloc] initWithRootViewController:vc];
  128. [self presentViewController:nav animated:true completion:nil];
  129. } else {
  130. SPSBFeedbackListViewController *vc = SPSBFeedbackListViewController.new;
  131. vc.spsb_data = array;
  132. [self.navigationController pushViewController:vc animated:true];
  133. }
  134. }
  135. #pragma mark - UI
  136. - (void)setupUI {
  137. //取消返回按钮
  138. self.navigationItem.leftBarButtonItem = nil;
  139. self.spsb_isHiddenNavigationBar = true;
  140. self.title = @"咨询";
  141. [self createHeaderView];
  142. [self createTableView];
  143. [self createNavigationBar];
  144. [self setNavigationBar];
  145. }
  146. - (void)createTableView {
  147. _tableVC = SPSBConsultationTableViewController.new;
  148. _tableVC.tableView.tableHeaderView = _headerView;
  149. @weakify(self)
  150. _tableVC.spsb_scrollAction = ^(CGFloat offset) {
  151. @strongify(self)
  152. [self judgeNavigationBarWithOffset:offset];
  153. };
  154. [self addChildViewController:_tableVC];
  155. [self.view addSubview:_tableVC.tableView];
  156. [_tableVC.tableView makeConstraints:^(JXHConstraintMaker *make) {
  157. make.top.and.leading.and.trailing.equalTo(0);
  158. make.bottom.equalTo(self.view.safebottom).offset(-SPSBTabBarHeight);
  159. }];
  160. }
  161. - (void)createHeaderView {
  162. CGFloat top;
  163. if (@available(iOS 11.0, *)) {
  164. top = jxh_safeInsets(spsb_keyWindow()).top - 20;
  165. } else {
  166. top = jxh_statusBarHeight() - 20;
  167. }
  168. CGFloat headerHeight = jxh_screenWidth() / 2.5685;
  169. _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, jxh_screenWidth(), top + headerHeight + 114 + 12)];
  170. _headerView.backgroundColor = spsb_3296FB_color();
  171. UIImageView *backgroundView1 = [[UIImageView alloc] initWithImage:jxh_getImage(zixun_bg)];
  172. [_headerView addSubview:backgroundView1];
  173. [backgroundView1 makeConstraints:^(JXHConstraintMaker *make) {
  174. make.top.equalTo(top);
  175. make.leading.and.trailing.equalTo(0);
  176. make.size.equalTo(CGSizeMake(jxh_screenWidth(), headerHeight));
  177. }];
  178. CGFloat _height = jxh_screenWidth() / 2.68;
  179. UIImageView *backgroundView = [[UIImageView alloc] initWithImage:jxh_getImage(advisory_bg)];
  180. [backgroundView1 addSubview:backgroundView];
  181. [backgroundView makeConstraints:^(JXHConstraintMaker *make) {
  182. make.bottom.equalTo(backgroundView1);
  183. make.leading.and.trailing.equalTo(0);
  184. make.size.equalTo(CGSizeMake(jxh_screenWidth(), _height));
  185. }];
  186. @weakify(self)
  187. _broadcastView = [[SPSBBroadcastView alloc] initWithReloadDataAction:^(CGFloat height) {
  188. @strongify(self)
  189. self->_headerView.frame = CGRectMake(0, 0, jxh_screenWidth(), top + headerHeight + height + 114 + 12);
  190. [self->_broadcastView makeConstraints:^(JXHConstraintMaker *make) {
  191. make.height.update(height);
  192. }];
  193. [self->_tableVC.tableView reloadData];
  194. }];
  195. [_headerView addSubview:_broadcastView];
  196. [_broadcastView makeConstraints:^(JXHConstraintMaker *make) {
  197. make.top.equalTo(backgroundView.bottom);
  198. make.leading.and.trailing.equalTo(0);
  199. make.height.equalTo(0);
  200. }];
  201. UIView *buttonView = UIView.new;
  202. buttonView.backgroundColor = spsb_FFFFFF_color(1.f);
  203. [_headerView addSubview:buttonView];
  204. [buttonView makeConstraints:^(JXHConstraintMaker *make) {
  205. make.top.equalTo(self->_broadcastView.bottom);
  206. make.leading.and.trailing.equalTo(0);
  207. make.height.equalTo(114);
  208. }];
  209. NSArray *titleArray = @[@"在线客服", @"咨询热线", @"留言反馈"];
  210. NSArray *imageArray = @[jxh_getImage(kefu), jxh_getImage(rexian), jxh_getImage(liuyan)];
  211. JXHCenterButton *tempButton = nil;
  212. for (NSInteger i = 0; i < 3; i ++) {
  213. JXHCenterButton *button = [JXHCenterButton convenienceWithAxis:JXHCenterButtonAxisVertical interval:10 font:spsb_font(14) target:self action:@selector(headerButtonAction:)];
  214. [button setTitle:titleArray[i] titleColor:spsb_333333_color() image:imageArray[i] backgroundImage:nil state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
  215. button.tag = SPSBConsultationHeaderActionTypeCustomerService + i;
  216. [buttonView addSubview:button];
  217. [button makeConstraints:^(JXHConstraintMaker *make) {
  218. make.top.and.bottom.equalTo(0);
  219. make.width.equalTo(jxh_screenWidth() / 3);
  220. if (tempButton) {
  221. make.leading.equalTo(tempButton.trailing);
  222. } else {
  223. make.leading.equalTo(0);
  224. }
  225. }];
  226. tempButton = button;
  227. if (i == 0) {
  228. _tipsView = spsb_createNumberTipsViewWithTag(10000);
  229. [buttonView addSubview:_tipsView];
  230. [_tipsView makeConstraints:^(JXHConstraintMaker *make) {
  231. make.leading.equalTo(button.jxh_icon.trailing).offset(-10);
  232. make.top.equalTo(15);
  233. }];
  234. }
  235. }
  236. UIView *view = UIView.new;
  237. view.backgroundColor = spsb_F5F5F5_color();
  238. [_headerView addSubview:view];
  239. [view makeConstraints:^(JXHConstraintMaker *make) {
  240. make.leading.and.trailing.equalTo(0);
  241. make.top.equalTo(buttonView.bottom);
  242. make.bottom.equalTo(0);
  243. }];
  244. }
  245. - (void)setNavigationBar {
  246. self.spsb_barBackButton.hidden = true;
  247. [self setBackButtonAndTitleColorIsWhite:false];
  248. self.spsb_navigationBar.backgroundColor = spsb_FFFFFF_color(1.f);
  249. self.spsb_navigationBar.alpha = 0;
  250. }
  251. - (void)judgeNavigationBarWithOffset:(CGFloat)offset {
  252. self.spsb_navigationBar.alpha = offset * 0.025;
  253. if (self.spsb_navigationBar.alpha > 0.5) {
  254. self.spsb_isLightContent = false;
  255. } else {
  256. self.spsb_isLightContent = true;
  257. }
  258. }
  259. @end