SPSBMineTableViewController.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. //
  2. // SPSBMineTableViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/5/12.
  6. //
  7. #import "SPSBMineTableViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBBusinessManager.h"
  10. #import "SPSBRedDotModel.h"
  11. #import "SPSBMineGuideViewController.h"
  12. #import "SPSBAboutViewController.h"
  13. #import "SPSBMailAddressListViewController.h"
  14. #import "SPSBPurchasersListViewController.h"
  15. #import "SPSBMineMessageTableViewController.h"
  16. #import "SPSBAccountSettingTableViewController.h"
  17. #import "SPSBActionSheetViewController.h"
  18. #import "SPSBCustomerServiceManager.h"
  19. #import "SPSBMakePhoneCallManager.h"
  20. #import "SPSBDisplayDiscountCouponViewController.h"
  21. typedef NS_ENUM(NSUInteger, SPSBMineTableViewRowType) {
  22. SPSBMineTableViewRowTypePurchasers = 0,
  23. SPSBMineTableViewRowTypeMessage,
  24. SPSBMineTableViewRowTypeDiscountCoupon,
  25. SPSBMineTableViewRowTypeMail,
  26. SPSBMineTableViewRowTypeGuide,
  27. SPSBMineTableViewRowTypeAccountSetting,
  28. SPSBMineTableViewRowTypeHelpAndCustomerService,
  29. SPSBMineTableViewRowTypeAbout,
  30. };
  31. @interface SPSBMineTableViewController () {
  32. NSArray *_titleArray;
  33. NSArray *_imageArray;
  34. SPSBMakePhoneCallManager *_makePhoneCallManager;
  35. }
  36. @end
  37. @implementation SPSBMineTableViewController
  38. - (instancetype)init {
  39. self = [super initWithStyle:UITableViewStyleGrouped backgroundColor:SPSBTableViewBackgroundColorGray];
  40. if (!self) return nil;
  41. _titleArray = @[@"购买人员", @"我的消息", @"优惠券", @"邮寄信息", @"新手指南", @"账户设置", @"帮助与客服", @"关于我们", @""];
  42. _imageArray = @[@"info", @"message", @"money", @"location", @"guide", @"safe", @"my_phone", @"about", @""];
  43. _makePhoneCallManager = [[SPSBMakePhoneCallManager alloc] initWithController:self];
  44. return self;
  45. }
  46. - (void)viewDidLoad {
  47. [super viewDidLoad];
  48. [self setupTableView];
  49. }
  50. #pragma mark - Action
  51. - (void)toPurchasers {
  52. @weakify(self)
  53. spsb_needLogin(^{
  54. @strongify(self)
  55. self->_spsb_needRefreshRedDot = true;
  56. SPSBPurchasersListViewController *vc = SPSBPurchasersListViewController.new;
  57. vc.spsb_type = SPSBPurchasersListTypeManage;
  58. [self.navigationController pushViewController:vc animated:true];
  59. });
  60. }
  61. - (void)toMessage {
  62. @weakify(self)
  63. spsb_needLogin(^{
  64. @strongify(self)
  65. self->_spsb_needRefreshRedDot = true;
  66. [self.navigationController pushViewController:SPSBMineMessageTableViewController.new animated:true];
  67. });
  68. }
  69. - (void)toDiscountCoupon {
  70. spsb_needLogin(^{
  71. [self.navigationController pushViewController:SPSBDisplayDiscountCouponViewController.new animated:true];
  72. });
  73. }
  74. - (void)toMail {
  75. @weakify(self)
  76. spsb_needLogin(^{
  77. @strongify(self)
  78. [self.navigationController pushViewController:SPSBMailAddressListViewController.new animated:true];
  79. });
  80. }
  81. - (void)toGuide {
  82. [self.navigationController pushViewController:SPSBMineGuideViewController.new animated:true];
  83. }
  84. - (void)toAccountSetting {
  85. spsb_needLogin(^{
  86. [self.navigationController pushViewController:SPSBAccountSettingTableViewController.new animated:true];
  87. });
  88. }
  89. - (void)toHelpAndCustomerService {
  90. SPSBActionSheetViewController *vc = SPSBActionSheetViewController.new;
  91. @weakify(self)
  92. [vc addActionWithTitle:@"客服电话" action:^{
  93. @strongify(self)
  94. [self makePhoneCall];
  95. }];
  96. [vc addActionWithTitle:@"在线客服" action:^{
  97. @strongify(self)
  98. [self onlineService];
  99. }];
  100. [self presentViewController:vc animated:false completion:nil];
  101. }
  102. - (void)makePhoneCall {
  103. [_makePhoneCallManager showHandleContactMenu];
  104. }
  105. - (void)onlineService {
  106. [spsb_customerServiceManager() toOnlineContactWithBaseController:self];
  107. }
  108. - (void)toAbout {
  109. [self.navigationController pushViewController:SPSBAboutViewController.new animated:true];
  110. }
  111. #pragma mark - Network Action
  112. #pragma mark - Delegate & DataSource
  113. static NSString * const reuseIdentifier = @"SPSBMineTableViewCell";
  114. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  115. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
  116. if (!cell) {
  117. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
  118. UIImageView *imageView = UIImageView.new;
  119. imageView.tag = 3000;
  120. [cell.contentView addSubview:imageView];
  121. [imageView makeConstraints:^(JXHConstraintMaker *make) {
  122. make.leading.equalTo(17);
  123. make.centerY.equalTo(cell.contentView);
  124. }];
  125. UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(16) text:nil textColor:spsb_333333_color()];
  126. titleLabel.tag = 3001;
  127. [cell.contentView addSubview:titleLabel];
  128. [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
  129. make.leading.equalTo(55);
  130. make.centerY.equalTo(cell.contentView);
  131. }];
  132. UIImageView *arrow = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
  133. [cell.contentView addSubview:arrow];
  134. [arrow makeConstraints:^(JXHConstraintMaker *make) {
  135. make.trailing.equalTo(-15);
  136. make.centerY.equalTo(cell.contentView);
  137. }];
  138. if (indexPath.section == 0 && indexPath.row == 1) {
  139. UIView *tipsView = [[UIView alloc] init];
  140. tipsView.tag = 3002;
  141. [cell.contentView addSubview:tipsView];
  142. [tipsView makeConstraints:^(JXHConstraintMaker *make) {
  143. make.top.and.bottom.equalTo(0);
  144. make.trailing.equalTo(-33);
  145. }];
  146. UILabel *label = [UILabel convenienceWithFont:spsb_font(15) text:nil textColor:spsb_999999_color() textAlignment:NSTextAlignmentRight];
  147. label.tag = 3003;
  148. [tipsView addSubview:label];
  149. [label makeConstraints:^(JXHConstraintMaker *make) {
  150. make.trailing.equalTo(0);
  151. make.centerY.equalTo(tipsView);
  152. }];
  153. UIView *dian = UIView.new;
  154. dian.backgroundColor = spsb_FF5E5E_color();
  155. [dian setLayerCornerRadius:4 clipToBounds:false];
  156. [tipsView addSubview:dian];
  157. [dian makeConstraints:^(JXHConstraintMaker *make) {
  158. make.leading.equalTo(0);
  159. make.trailing.equalTo(label.leading).offset(-5);
  160. make.centerY.equalTo(tipsView);
  161. make.size.equalTo(CGSizeMake(8, 8));
  162. }];
  163. }
  164. }
  165. UIImageView *icon = [cell.contentView viewWithTag:3000];
  166. UILabel *title = [cell.contentView viewWithTag:3001];
  167. SPSBMineTableViewRowType type = indexPath.section * 3 + indexPath.row;
  168. icon.image = [UIImage imageNamed:_imageArray[type]];
  169. title.text = _titleArray[type];
  170. UIView *tipsView = [cell.contentView viewWithTag:3002];
  171. if (type == SPSBMineTableViewRowTypeMessage) {
  172. if (spsb_redDotModel().spsb_msg.integerValue <= 0) {
  173. tipsView.hidden = true;
  174. return cell;
  175. }
  176. tipsView.hidden = false;
  177. UILabel *tips = [tipsView viewWithTag:3003];
  178. NSInteger msg = spsb_redDotModel().spsb_msg.integerValue;
  179. if (msg > 100) {
  180. tips.text = @"99+新消息";
  181. } else {
  182. tips.text = [NSString stringWithFormat:@"%ld新消息", (long)msg];
  183. }
  184. } else {
  185. tipsView.hidden = true;
  186. }
  187. return cell;
  188. }
  189. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  190. return 3;
  191. }
  192. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  193. if (section == 2) return 2;
  194. return 3;
  195. }
  196. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  197. [tableView deselectRowAtIndexPath:indexPath animated:false];
  198. SPSBMineTableViewRowType type = indexPath.section * 3 + indexPath.row;
  199. switch (type) {
  200. case SPSBMineTableViewRowTypePurchasers:
  201. [self toPurchasers];
  202. break;
  203. case SPSBMineTableViewRowTypeMessage:
  204. [self toMessage];
  205. break;
  206. case SPSBMineTableViewRowTypeDiscountCoupon:
  207. [self toDiscountCoupon];
  208. break;
  209. case SPSBMineTableViewRowTypeMail:
  210. [self toMail];
  211. break;
  212. case SPSBMineTableViewRowTypeGuide:
  213. [self toGuide];
  214. break;
  215. case SPSBMineTableViewRowTypeAccountSetting:
  216. [self toAccountSetting];
  217. break;
  218. case SPSBMineTableViewRowTypeHelpAndCustomerService:
  219. [self toHelpAndCustomerService];
  220. break;
  221. case SPSBMineTableViewRowTypeAbout:
  222. [self toAbout];
  223. break;
  224. default:
  225. break;
  226. }
  227. }
  228. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  229. return jxh_onePixe();
  230. }
  231. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  232. return UIView.new;
  233. }
  234. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  235. return 12;
  236. }
  237. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  238. UIView *footerView = [[UIView alloc] init];
  239. footerView.backgroundColor = spsb_F5F5F5_color();
  240. return footerView;
  241. }
  242. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  243. if (scrollView.contentOffset.y < 0) {
  244. scrollView.contentOffset = CGPointMake(0, 0);
  245. return;
  246. }
  247. if (_spsb_scrollAction) {
  248. _spsb_scrollAction(scrollView.contentOffset.y);
  249. }
  250. }
  251. #pragma mark - UI
  252. - (void)setupTableView {
  253. self.tableView.rowHeight = 50.f;
  254. }
  255. @end