SPSBPurchasersListTableViewCell.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // SPSBPurchasersListTableViewCell.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/5/14.
  6. //
  7. #import "SPSBPurchasersListTableViewCell.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBPurchasersModel.h"
  10. @interface SPSBPurchasersListTableViewCell () {
  11. UIView *_bg;
  12. UIView *_headerBg;
  13. UILabel *_iconLabel;
  14. UILabel *_nameLabel;
  15. UILabel *_idCardLabel;
  16. UIImageView *_chooseImage;
  17. }
  18. @end
  19. @implementation SPSBPurchasersListTableViewCell
  20. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier type:(SPSBPurchasersListType)type {
  21. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  22. if (!self) return nil;
  23. self.contentView.backgroundColor = spsb_F5F5F5_color();
  24. self.selectionStyle = UITableViewCellSelectionStyleNone;
  25. _headerBg = [[UIView alloc] init];
  26. [self.contentView addSubview:_headerBg];
  27. [_headerBg makeConstraints:^(JXHConstraintMaker *make) {
  28. make.leading.equalTo(0);
  29. make.trailing.equalTo(0);
  30. make.top.equalTo(0);
  31. make.height.equalTo(30);
  32. }];
  33. _bg = UIView.new;
  34. _bg.backgroundColor = spsb_FFFFFF_color(1.f);
  35. [_bg setLayerCornerRadius:4 clipToBounds:false];
  36. [self.contentView addSubview:_bg];
  37. [_bg makeConstraints:^(JXHConstraintMaker *make) {
  38. make.top.equalTo(0);
  39. make.leading.equalTo(12);
  40. make.trailing.equalTo(-12);
  41. make.height.equalTo(100);
  42. }];
  43. UIView *icon = UIView.new;
  44. icon.backgroundColor = spsb_28AFF0_color();
  45. [icon setLayerCornerRadius:24 clipToBounds:false];
  46. [_bg addSubview:icon];
  47. [icon makeConstraints:^(JXHConstraintMaker *make) {
  48. make.leading.equalTo(20);
  49. make.centerY.equalTo(self->_bg);
  50. make.size.equalTo(CGSizeMake(48, 48));
  51. }];
  52. _iconLabel = [UILabel convenienceWithFont:spsb_semiboldFont(15) text:nil textColor:spsb_FFFFFF_color(1.f) textAlignment:NSTextAlignmentCenter];
  53. [icon addSubview:_iconLabel];
  54. [_iconLabel makeConstraints:^(JXHConstraintMaker *make) {
  55. make.center.equalTo(icon);
  56. }];
  57. _nameLabel = [UILabel convenienceWithFont:spsb_semiboldFont(17) text:@"" textColor:spsb_333333_color()];
  58. [_bg addSubview:_nameLabel];
  59. [_nameLabel makeConstraints:^(JXHConstraintMaker *make) {
  60. make.leading.equalTo(icon.trailing).offset(15);
  61. make.trailing.equalTo(-80);
  62. make.top.equalTo(30);
  63. }];
  64. _idCardLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"" textColor:spsb_808080_color()];
  65. [_bg addSubview:_idCardLabel];
  66. [_idCardLabel makeConstraints:^(JXHConstraintMaker *make) {
  67. make.leading.equalTo(self->_nameLabel);
  68. make.top.equalTo(self->_nameLabel.bottom).offset(10);
  69. }];
  70. if (type == SPSBPurchasersListTypeManage) {
  71. [self createButtons];
  72. } else {
  73. [self createChooseImage];
  74. }
  75. return self;
  76. }
  77. - (void)createButtons {
  78. UIButton *deleteButton = [UIButton convenienceWithTarget:self action:@selector(deleteAction)];
  79. [deleteButton setImage:jxh_getImage(purchasers_delete) state:JXHButtonControlStateNormal];
  80. [_bg addSubview:deleteButton];
  81. [deleteButton makeConstraints:^(JXHConstraintMaker *make) {
  82. make.trailing.equalTo(-6);
  83. make.centerY.equalTo(self->_bg);
  84. make.size.equalTo(CGSizeMake(42, 42));
  85. }];
  86. UIButton *editButton = [UIButton convenienceWithTarget:self action:@selector(_editAction)];
  87. [editButton setImage:jxh_getImage(purchasers_edit) state:JXHButtonControlStateNormal];
  88. [_bg addSubview:editButton];
  89. [editButton makeConstraints:^(JXHConstraintMaker *make) {
  90. make.trailing.equalTo(deleteButton.leading);
  91. make.centerY.equalTo(self->_bg);
  92. make.size.equalTo(CGSizeMake(42, 42));
  93. }];
  94. }
  95. - (void)createChooseImage {
  96. _chooseImage = [[UIImageView alloc] init];
  97. [_chooseImage setImage:jxh_getImage(filter_n)];
  98. [_chooseImage setHighlightedImage:jxh_getImage(filter_s)];
  99. [_bg addSubview:_chooseImage];
  100. [_chooseImage makeConstraints:^(JXHConstraintMaker *make) {
  101. make.trailing.equalTo(-20);
  102. make.centerY.equalTo(self->_bg);
  103. }];
  104. }
  105. - (void)reloadData:(SPSBPurchasersModel *)purchaser isFirstRow:(bool)isFirstRow isChose:(bool)isChose {
  106. _headerBg.backgroundColor = isFirstRow ? spsb_28AFF0_color() : spsb_F5F5F5_color();
  107. _iconLabel.text = purchaser.spsba_icon_name;
  108. _nameLabel.text = purchaser.spsb_user_name;
  109. _idCardLabel.text = purchaser.spsb_id_card;
  110. if (_chooseImage) {
  111. _chooseImage.highlighted = isChose;
  112. }
  113. }
  114. - (void)deleteAction {
  115. if (_spsb_action) {
  116. _spsb_action(self, false);
  117. }
  118. }
  119. - (void)_editAction {
  120. if (_spsb_action) {
  121. _spsb_action(self, true);
  122. }
  123. }
  124. @end