MineBodyView.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // MineBodyView.m
  3. // KulexiuForStudent
  4. //
  5. // Created by Kyle on 2022/3/21.
  6. //
  7. #import "MineBodyView.h"
  8. @interface MineBodyView ()
  9. @property (weak, nonatomic) IBOutlet UIView *subjectView;
  10. @property (weak, nonatomic) IBOutlet UILabel *subjectLabel;
  11. @property (weak, nonatomic) IBOutlet UIView *memberView;
  12. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *memberViewHeight;
  13. @property (weak, nonatomic) IBOutlet UILabel *finishCourseLabel;
  14. @property (weak, nonatomic) IBOutlet UILabel *residueCourseLabel;
  15. @property (weak, nonatomic) IBOutlet UILabel *followTeacherLabel;
  16. @property (weak, nonatomic) IBOutlet UIView *dealView;
  17. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *dealViewHeight;
  18. @property (weak, nonatomic) IBOutlet UIImageView *userAvatar;
  19. @property (weak, nonatomic) IBOutlet UILabel *userName;
  20. @property (weak, nonatomic) IBOutlet UILabel *userIdLabel;
  21. @property (weak, nonatomic) IBOutlet UILabel *memberCountLabel;
  22. @property (nonatomic, copy) MineViewCallback callback;
  23. @end
  24. @implementation MineBodyView
  25. - (void)awakeFromNib {
  26. [super awakeFromNib];
  27. self.isMember = NO;
  28. }
  29. + (instancetype)shareInstance {
  30. MineBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"MineBodyView" owner:nil options:nil] firstObject];
  31. return view;
  32. }
  33. - (void)operationCallback:(MineViewCallback)callback {
  34. if (callback) {
  35. self.callback = callback;
  36. }
  37. }
  38. - (void)configWithSource:(StudentInfoModel *)sourceModel {
  39. self.finishCourseLabel.text = [NSString stringWithFormat:@"%.0f",sourceModel.finshClassHours];
  40. self.residueCourseLabel.text = [NSString stringWithFormat:@"%.0f",sourceModel.unfinshClassHours];
  41. self.followTeacherLabel.text = [NSString stringWithFormat:@"%.0f",sourceModel.starTeacherNum];
  42. NSString *userName = @"";
  43. if (![NSString isEmptyString:sourceModel.username]) {
  44. userName = sourceModel.username;
  45. }
  46. else {
  47. userName = [NSString stringWithFormat:@"游客%@",sourceModel.userId];
  48. }
  49. self.userName.text = userName;
  50. self.userIdLabel.text = [NSString stringWithFormat:@"学号:%@",sourceModel.userId];
  51. self.memberCountLabel.text = [NSString stringWithFormat:@"会员有效期剩余%.0f天",sourceModel.membershipDays];
  52. [self.userAvatar sd_setImageWithURL:[NSURL URLWithString:[sourceModel.heardUrl getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  53. if ([NSString isEmptyString:sourceModel.subjectName]) {
  54. self.subjectLabel.text = @"";
  55. self.subjectView.hidden = YES;
  56. }
  57. else {
  58. self.subjectLabel.text = sourceModel.subjectName;
  59. self.subjectView.hidden = NO;
  60. }
  61. }
  62. - (IBAction)toMemberDetail:(id)sender {
  63. if (self.callback) {
  64. self.callback(MINEVIEWTYPE_MEMBER);
  65. }
  66. }
  67. - (IBAction)clickAction:(UITapGestureRecognizer *)sender {
  68. NSInteger index = sender.view.tag;
  69. if (self.callback) {
  70. self.callback(index);
  71. }
  72. }
  73. - (IBAction)finishCourse:(id)sender {
  74. if (self.callback) {
  75. self.callback(MINEVIEWTYPE_FINISHCOURSE);
  76. }
  77. }
  78. - (IBAction)unfinishCourse:(id)sender {
  79. if (self.callback) {
  80. self.callback(MINEVIEWTYPE_UNFINISHCOURSE);
  81. }
  82. }
  83. - (IBAction)followTeacher:(id)sender {
  84. if (self.callback) {
  85. self.callback(MINEVIEWTYPE_FOLLOW);
  86. }
  87. }
  88. - (CGFloat)getViewHeight {
  89. return 80 + 15 + (self.memberViewHeight.constant) / 2 + 10 + 100 + 12 + 93 + 15 + 270 + self.dealViewHeight.constant;
  90. }
  91. - (IBAction)modifyUser:(id)sender {
  92. if (self.callback) {
  93. self.callback(MINEVIEWTYPE_USER);
  94. }
  95. }
  96. - (void)setIsMember:(BOOL)isMember {
  97. _isMember = isMember;
  98. if (_isMember) {
  99. self.memberViewHeight.constant = 82.0f;
  100. self.memberView.hidden = NO;
  101. self.dealView.hidden = NO;
  102. self.dealViewHeight.constant = 50.0f;
  103. }
  104. else {
  105. self.memberViewHeight.constant = 0.0f;
  106. self.memberView.hidden = YES;
  107. self.dealView.hidden = YES;
  108. self.dealViewHeight.constant = 0.0f;
  109. }
  110. }
  111. /*
  112. // Only override drawRect: if you perform custom drawing.
  113. // An empty implementation adversely affects performance during animation.
  114. - (void)drawRect:(CGRect)rect {
  115. // Drawing code
  116. }
  117. */
  118. @end