JXRecordCell.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // JXRecordCell.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2019/4/20.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXRecordCell.h"
  9. #import "JXRecordModel.h"
  10. @interface JXRecordCell ()
  11. @property (nonatomic, strong) UILabel *desc;
  12. @property (nonatomic, strong) UILabel *time;
  13. @property (nonatomic, strong) UILabel *money;
  14. @property (nonatomic, strong) UILabel *status;
  15. @end
  16. @implementation JXRecordCell
  17. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  18. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  19. self.desc = [[UILabel alloc] initWithFrame:CGRectMake(10, 13, 200, 18)];
  20. self.desc.font = SYSFONT(15);
  21. [self.contentView addSubview:self.desc];
  22. self.time = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.desc.frame)+5, 100, 15)];
  23. self.time.font = SYSFONT(13);
  24. self.time.textColor = [UIColor grayColor];
  25. [self.contentView addSubview:self.time];
  26. self.money = [[UILabel alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-110, 13, 100, 18)];
  27. self.money.font = [UIFont boldSystemFontOfSize:16];
  28. self.money.textAlignment = NSTextAlignmentRight;
  29. [self.contentView addSubview:self.money];
  30. self.status = [[UILabel alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-110, CGRectGetMaxY(self.money.frame)+5, 100, 15)];
  31. self.status.font = SYSFONT(13);
  32. self.status.textColor = [UIColor grayColor];
  33. self.status.textAlignment = NSTextAlignmentRight;
  34. [self.contentView addSubview:self.status];
  35. _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 63.5, JX_SCREEN_WIDTH, LINE_WH)];
  36. _lineView.backgroundColor = THE_LINE_COLOR;
  37. [self.contentView addSubview:_lineView];
  38. }
  39. return self;
  40. }
  41. - (void)setData:(JXRecordModel *)model {
  42. self.desc.text = model.desc;
  43. self.time.text = [self stringToDate:model.time withDateFormat:[self isThisYear:model.time] ? @"MM-dd" : @"yyyy-MM-dd"];
  44. self.status.text = [self getPayType:model.status];
  45. if (model.type == 1 || model.type == 2 || model.type == 3 || model.type == 4 || model.type == 7 || model.type == 10 || model.type == 12) {
  46. self.money.text = @"-";
  47. self.money.textColor = [UIColor blackColor];
  48. }else {
  49. self.money.text = @"+";
  50. self.money.textColor = THEMECOLOR;
  51. }
  52. self.money.text = [self.money.text stringByAppendingString:[NSString stringWithFormat:@"%.2f",model.money]];
  53. }
  54. - (NSString *)getPayType:(int)status {
  55. NSString *str = [NSString string];
  56. if (status == 0) {//创建
  57. str= Localized(@"JX_Create");
  58. }
  59. else if (status == 1) {//支付完成
  60. str= Localized(@"JX_PayToComplete");
  61. }
  62. else if (status == 2) {//交易完成
  63. str= Localized(@"JX_CompleteTheTransaction");
  64. }
  65. else if (status == -1) {//交易关闭
  66. str= Localized(@"JX_TradingClosed");
  67. }
  68. return str;
  69. }
  70. //字符串转日期格式
  71. - (NSString *)stringToDate:(long)date withDateFormat:(NSString *)format {
  72. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  73. [dateFormatter setDateFormat:format];
  74. NSDate*timeDate = [[NSDate alloc] initWithTimeIntervalSince1970:date];
  75. return [dateFormatter stringFromDate:timeDate];
  76. }
  77. //是否是今年
  78. - (BOOL)isThisYear:(long)date{
  79. NSCalendar *calendar = [NSCalendar currentCalendar];
  80. int unit = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay;
  81. // 1.获得当前时间的年月日
  82. NSDateComponents *nowCmps = [calendar components:unit fromDate:[NSDate date]];
  83. // 2.获得self的年月日
  84. NSDateComponents *selfCmps = [calendar components:unit fromDate:[NSDate dateWithTimeIntervalSince1970:date]];
  85. return nowCmps.year == selfCmps.year;
  86. }
  87. @end